CAxis.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. #pragma once
  2. #include "dt.h"
  3. #include "CHardware.h"
  4. #include "JAxis.h"
  5. #include "CMessageBox.h"
  6. //#define WIN32_LEAN_AND_MEAN
  7. #ifdef C_AXIS_EXPORTS
  8. #define C_AXIS_DLL_API __declspec(dllexport)
  9. #else
  10. #define C_AXIS_DLL_API //__declspec(dllimport)
  11. #endif
  12. enum SPEED {
  13. FAST=10, //快速
  14. MEDIUM=5, //中速
  15. SLOW=2 //慢速
  16. };
  17. #define SYNC true //等待到位
  18. #define NOSYNC false //不待待到位
  19. #define MOVEING 1
  20. //#define FORCE_BUFFER_NO 6
  21. //
  22. //#define FORCE_SPRING_BUFFER_NO 10
  23. class C_AXIS_DLL_API CAxis
  24. {
  25. public:
  26. enum AXIS_TYPE { X = 0, Y, Z, R, FORCE, Z1 };
  27. enum TRIG_AXIS { TX = 0, TY, TZ};
  28. typedef struct _HOT_ZONE_ID_STRUCT
  29. {
  30. INT ZoneId; //热区Id
  31. string ModuleType; //模组类型
  32. TRIG_AXIS TrigAxis; //触发热区的轴
  33. // 重载 == 运算符
  34. bool operator==(const _HOT_ZONE_ID_STRUCT& other) const {
  35. return (ZoneId == other.ZoneId) && (ModuleType == other.ModuleType) && (TrigAxis == other.TrigAxis);
  36. }
  37. }HOT_ZONE_ID_STRUCT; //
  38. static void SetHotZone(bool bEnable);
  39. private:
  40. AXIS_TYPE m_eAxisType = AXIS_TYPE::X;
  41. string m_strAxisType;
  42. string m_strModuleType;
  43. string m_strModuleName;
  44. JAxis* m_pAxis = nullptr;
  45. string m_strAxisName = "";
  46. INT m_iUse = 0;
  47. bool m_bIsInitSuccess = false;
  48. UINT m_iHomeTime = 500000; //回零等待时间(秒)
  49. UINT m_iFastTime = 50000; //快速等待时间(秒)
  50. UINT m_iMediumTime = 50000; //中速等待时间(秒)
  51. UINT m_iSlowTime = 100000; //慢速等待时间(秒)
  52. UINT m_iLastWaitTime = 100000; //上次移动的等待时间
  53. UINT m_iCommonWaitTime = 100000; //其他情况等待事件
  54. unsigned long m_lStartSysTime; //开始移动的系统时间
  55. bool m_bEnable = false; //运控卡禁止/启用
  56. std::vector <ns_db::MODULE_HOT_ZONE_STRUCT> m_vecHotZoneList;
  57. static std::mutex m_MutexHotZone;
  58. static bool m_bHotZoneEnable;
  59. static std::vector<HOT_ZONE_ID_STRUCT> m_vecHotZoneId;
  60. //轴当前位置,模拟测试时才会使用
  61. double m_dCurrentPosition;
  62. CMessageBox* m_pMessageBox = nullptr;
  63. private:
  64. //判断要移动的位置,是否有热区冲突
  65. bool CheckHotZone(double pos);
  66. bool IsTriggerHotZoneX(double pos);
  67. bool IsTriggerHotZoneY(double pos);
  68. bool IsTriggerHotZoneZ(double pos);
  69. bool IsTriggerHotZone(ns_db::MODULE_HOT_ZONE_STRUCT stHotZone, AXIS_TYPE axis,double pos);
  70. //设置当前位置是否触发热区
  71. void SetTriggerHotZone();
  72. void AddHotZoneId(HOT_ZONE_ID_STRUCT stHotZone);
  73. void DeleteHotZoneId(HOT_ZONE_ID_STRUCT stHotZone);
  74. void PopWarn(AlarmID iId, std::string strDescribe,std::string otherInfo = "",
  75. LogStream::LogLevel iLevel = LogStream::LogLevel::Error, int buttons = BUTTON_TYPE::CLOSE_BUTTON, std::string strTip = "", std::string strHelp = "");
  76. public:
  77. CAxis();
  78. LONG Init(JAxis* pAxis, ns_db::AXIS_LIST_STRUCT *pAxisStruct);
  79. string GetAxisName() {return m_strAxisName;};
  80. string GetModuleType() { return m_strModuleType; };
  81. string GetModuleName() { return m_strModuleName; };
  82. string GetStringAxisType() { return m_strAxisType; };
  83. string GetStringModuleType() { return m_strModuleType; };
  84. AXIS_TYPE GetAxisType() { return m_eAxisType; };
  85. //LONG SetJogMotionMode
  86. LONG GetAxisStatus(AxisStatus& axisStatus);
  87. LONG GetActualPos(double &pos); //反馈位置
  88. LONG AxisOn();
  89. LONG AxisOff();
  90. LONG GetProfilePos(double& dProfilePos); //指令位置
  91. LONG Sync();
  92. LONG Stop(AxisStopMode eStopMode = AXIS_SMOOTH_STOP);
  93. LONG CheckDone();
  94. LONG Home(bool bSync = SYNC);
  95. /**使能状态获取
  96. */
  97. bool JIsDriveEnabled();
  98. /**获取软限位正负使能配置状态接口
  99. */
  100. int JGetSoftLimitEnableStatus(bool& bEnabledNeg, bool& bEnabledPos);
  101. /**设置正负软限位接口
  102. * Neg 负
  103. * Pos 正
  104. */
  105. int JSetSoftLimit(double dNegLimit,double dPosLimit);
  106. /**获取软限位及软行程
  107. */
  108. int JGetSoftLimit(double& dSoftLimitNeg, double& dSoftLimitPos, double& dSoftTravelRange);
  109. /**直接设置速度的数值
  110. */
  111. int JSetTargetVel(double dVel);
  112. /**设置最大速度(基准速度)user units
  113. */
  114. int JSetMaxVelocity(double dMVel);
  115. /**获取最大速度设置
  116. */
  117. int JGetMaxVelocity(double& dMaxVel);
  118. /**要按最大速度的比例设置速度(0-1)
  119. */
  120. int JSetTargetVelR(double dVelRatio);
  121. LONG Move_PassPosReturn(double dDist, double dPassDist, SPEED speed = FAST);
  122. LONG MoveTo_PassPosReturn(double dPos, double dPassPos, SPEED speed = FAST);
  123. LONG Move(double dDist, SPEED speed = FAST, bool bSync = SYNC);
  124. LONG MoveTo(double dPos, SPEED speed = FAST, bool bSync = SYNC);
  125. LONG Move(double dPos, double speed, bool bSync = SYNC);
  126. LONG MoveTo(double dPos, double speed, bool bSync = SYNC);
  127. LONG MoveForceCurrent(int nTorqueRatio, int nReachTime = 50, int nStopTime = 10);
  128. LONG GetProfileCurrent(double& dProfileTorque); //获取指令电流
  129. LONG GetActualCurrent(double& dProfileTorque); //获取反馈电流
  130. LONG SetStopDec(double val, double val1);
  131. LONG SetBufferParamF(int nBufferNo, std::string sParamFName, double dDoubleParam);
  132. LONG GetBufferParamF(int nBufferNo, std::string sParamFName, double& dDoubleParam);
  133. LONG SetBufferParam(int nBufferNo, std::string sParamFName, int dDoubleParam);
  134. LONG GetBufferParam(int nBufferNo, std::string sParamFName, int& dDoubleParam);
  135. LONG WriteSerialValueF(std::string sSerial, double tValue);
  136. LONG WriteSerialValueN(std::string sSerial, int tValue);
  137. LONG WriteSocketValueF(std::string ascii, double tValue);
  138. LONG WriteSocketValueN(std::string ascii, int tValue);
  139. LONG WriteSocketCommand(std::string ascii);
  140. LONG GetSocketValueF(std::string ascii, float& tValue);
  141. LONG GetSocketValueN(std::string ascii, int& tValue);
  142. //LONG RunForcerBuffer(); //运行力控buffer,不断判断弹簧压合到特定位置,到特定位置控制力控轴停下来
  143. //LONG RunSpringForcerBuffer(); //运行弹簧力控buffer,循环判断多段弹簧压合位置,每次到压合位置Z轴停下来
  144. LONG RunBuffer(int id);
  145. LONG StopBuffer(int id);
  146. };