CAxis.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. #pragma once
  2. #include "dt.h"
  3. #include "CHardware.h"
  4. #include "JAxis.h"
  5. //#define WIN32_LEAN_AND_MEAN
  6. #ifdef C_AXIS_EXPORTS
  7. #define C_AXIS_DLL_API __declspec(dllexport)
  8. #else
  9. #define C_AXIS_DLL_API //__declspec(dllimport)
  10. #endif
  11. enum SPEED {
  12. FAST=10, //快速
  13. MEDIUM=5, //中速
  14. SLOW=2 //慢速
  15. };
  16. #define SYNC true //等待到位
  17. #define NOSYNC false //不待待到位
  18. #define MOVEING 1
  19. //#define FORCE_BUFFER_NO 6
  20. //
  21. //#define FORCE_SPRING_BUFFER_NO 10
  22. class C_AXIS_DLL_API CAxis
  23. {
  24. public:
  25. enum AXIS_TYPE { X = 0, Y, Z, R, FORCE, Z1 };
  26. enum TRIG_AXIS { TX = 0, TY, TZ};
  27. typedef struct _HOT_ZONE_ID_STRUCT
  28. {
  29. INT ZoneId; //热区Id
  30. string ModuleType; //模组类型
  31. TRIG_AXIS TrigAxis; //触发热区的轴
  32. // 重载 == 运算符
  33. bool operator==(const _HOT_ZONE_ID_STRUCT& other) const {
  34. return (ZoneId == other.ZoneId) && (ModuleType == other.ModuleType) && (TrigAxis == other.TrigAxis);
  35. }
  36. }HOT_ZONE_ID_STRUCT; //
  37. private:
  38. AXIS_TYPE m_eAxisType = AXIS_TYPE::X;
  39. string m_strAxisType;
  40. string m_strModuleType;
  41. JAxis* m_pAxis = nullptr;
  42. string m_strAxisName = "";
  43. INT m_iUse = 0;
  44. bool m_bIsInitSuccess = false;
  45. UINT m_iHomeTime = 500000; //回零等待时间(秒)
  46. UINT m_iFastTime = 50000; //快速等待时间(秒)
  47. UINT m_iMediumTime = 50000; //中速等待时间(秒)
  48. UINT m_iSlowTime = 100000; //慢速等待时间(秒)
  49. UINT m_iLastWaitTime = 100000; //上次移动的等待时间
  50. UINT m_iCommonWaitTime = 100000; //其他情况等待事件
  51. unsigned long m_lStartSysTime; //开始移动的系统时间
  52. bool m_bEnable = false; //运控卡禁止/启用
  53. std::vector <ns_db::MODULE_HOT_ZONE_STRUCT> m_vecHotZoneList;
  54. static std::mutex m_MutexHotZone;
  55. static std::vector<HOT_ZONE_ID_STRUCT> m_vecHotZoneId;
  56. //轴当前位置,模拟测试时才会使用
  57. double m_dCurrentPosition;
  58. //判断要移动的位置,是否有热区冲突
  59. bool CheckHotZone(double pos);
  60. bool IsTriggerHotZoneX(double pos);
  61. bool IsTriggerHotZoneY(double pos);
  62. bool IsTriggerHotZoneZ(double pos);
  63. bool IsTriggerHotZone(ns_db::MODULE_HOT_ZONE_STRUCT stHotZone, AXIS_TYPE axis,double pos);
  64. //设置当前位置是否触发热区
  65. void SetTriggerHotZone();
  66. void AddHotZoneId(HOT_ZONE_ID_STRUCT stHotZone);
  67. void DeleteHotZoneId(HOT_ZONE_ID_STRUCT stHotZone);
  68. public:
  69. CAxis();
  70. LONG Init(JAxis* pAxis, ns_db::AXIS_LIST_STRUCT *pAxisStruct);
  71. string GetAxisName() {return m_strAxisName;};
  72. string GetModuleType() { return m_strModuleType; };
  73. string GetStringAxisType() { return m_strAxisType; };
  74. string GetStringModuleType() { return m_strModuleType; };
  75. AXIS_TYPE GetAxisType() { return m_eAxisType; };
  76. //LONG SetJogMotionMode
  77. LONG GetAxisStatus(AxisStatus& axisStatus);
  78. LONG GetActualPos(double &pos); //反馈位置
  79. LONG AxisOn();
  80. LONG AxisOff();
  81. LONG GetProfilePos(double& dProfilePos); //指令位置
  82. LONG Sync();
  83. LONG Stop(AxisStopMode eStopMode = AXIS_SMOOTH_STOP);
  84. LONG CheckDone();
  85. LONG Home(bool bSync = SYNC);
  86. LONG Move_PassPosReturn(double dDist, double dPassDist, SPEED speed = FAST);
  87. LONG MoveTo_PassPosReturn(double dPos, double dPassPos, SPEED speed = FAST);
  88. LONG Move(double dDist, SPEED speed = FAST, bool bSync = SYNC);
  89. LONG MoveTo(double dPos, SPEED speed = FAST, bool bSync = SYNC);
  90. LONG Move(double dPos, double speed, bool bSync = SYNC);
  91. LONG MoveTo(double dPos, double speed, bool bSync = SYNC);
  92. LONG MoveForceCurrent(int nTorqueRatio, int nReachTime = 50, int nStopTime = 10);
  93. LONG GetProfileCurrent(double& dProfileTorque); //获取指令电流
  94. LONG GetActualCurrent(double& dProfileTorque); //获取反馈电流
  95. LONG SetStopDec(double val, double val1);
  96. LONG SetBufferParamF(int nBufferNo, std::string sParamFName, double dDoubleParam);
  97. LONG GetBufferParamF(int nBufferNo, std::string sParamFName, double& dDoubleParam);
  98. LONG SetBufferParam(int nBufferNo, std::string sParamFName, int dDoubleParam);
  99. LONG GetBufferParam(int nBufferNo, std::string sParamFName, int& dDoubleParam);
  100. LONG WriteSerialValueF(std::string sSerial, double tValue);
  101. LONG WriteSerialValueN(std::string sSerial, int tValue);
  102. LONG WriteSocketValueF(std::string ascii, double tValue);
  103. LONG WriteSocketValueN(std::string ascii, int tValue);
  104. LONG WriteSocketCommand(std::string ascii);
  105. //LONG RunForcerBuffer(); //运行力控buffer,不断判断弹簧压合到特定位置,到特定位置控制力控轴停下来
  106. //LONG RunSpringForcerBuffer(); //运行弹簧力控buffer,循环判断多段弹簧压合位置,每次到压合位置Z轴停下来
  107. LONG RunBuffer(int id);
  108. LONG StopBuffer(int id);
  109. };