CAxis.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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. private:
  39. AXIS_TYPE m_eAxisType = AXIS_TYPE::X;
  40. string m_strAxisType;
  41. string m_strModuleType;
  42. string m_strModuleName;
  43. JAxis* m_pAxis = nullptr;
  44. string m_strAxisName = "";
  45. INT m_iUse = 0;
  46. bool m_bIsInitSuccess = false;
  47. UINT m_iHomeTime = 500000; //回零等待时间(秒)
  48. UINT m_iFastTime = 50000; //快速等待时间(秒)
  49. UINT m_iMediumTime = 50000; //中速等待时间(秒)
  50. UINT m_iSlowTime = 100000; //慢速等待时间(秒)
  51. UINT m_iLastWaitTime = 100000; //上次移动的等待时间
  52. UINT m_iCommonWaitTime = 100000; //其他情况等待事件
  53. unsigned long m_lStartSysTime; //开始移动的系统时间
  54. bool m_bEnable = false; //运控卡禁止/启用
  55. std::vector <ns_db::MODULE_HOT_ZONE_STRUCT> m_vecHotZoneList;
  56. static std::mutex m_MutexHotZone;
  57. bool m_bHotZoneEnable = false;
  58. static std::vector<HOT_ZONE_ID_STRUCT> m_vecHotZoneId;
  59. //轴当前位置,模拟测试时才会使用
  60. double m_dCurrentPosition;
  61. CMessageBox* m_pMessageBox = nullptr;
  62. private:
  63. //判断要移动的位置,是否有热区冲突
  64. bool CheckHotZone(double pos);
  65. bool IsTriggerHotZoneX(double pos);
  66. bool IsTriggerHotZoneY(double pos);
  67. bool IsTriggerHotZoneZ(double pos);
  68. bool IsTriggerHotZone(ns_db::MODULE_HOT_ZONE_STRUCT stHotZone, AXIS_TYPE axis,double pos);
  69. //设置当前位置是否触发热区
  70. void SetTriggerHotZone();
  71. void AddHotZoneId(HOT_ZONE_ID_STRUCT stHotZone);
  72. void DeleteHotZoneId(HOT_ZONE_ID_STRUCT stHotZone);
  73. void PopWarn(AlarmID iId, std::string strDescribe,std::string otherInfo = "",
  74. LogStream::LogLevel iLevel = LogStream::LogLevel::Error, int buttons = BUTTON_TYPE::CLOSE_BUTTON, std::string strTip = "", std::string strHelp = "");
  75. public:
  76. CAxis();
  77. LONG Init(JAxis* pAxis, ns_db::AXIS_LIST_STRUCT *pAxisStruct);
  78. string GetAxisName() {return m_strAxisName;};
  79. string GetModuleType() { return m_strModuleType; };
  80. string GetModuleName() { return m_strModuleName; };
  81. string GetStringAxisType() { return m_strAxisType; };
  82. string GetStringModuleType() { return m_strModuleType; };
  83. AXIS_TYPE GetAxisType() { return m_eAxisType; };
  84. //LONG SetJogMotionMode
  85. LONG GetAxisStatus(AxisStatus& axisStatus);
  86. LONG GetActualPos(double &pos); //反馈位置
  87. LONG AxisOn();
  88. LONG AxisOff();
  89. LONG GetProfilePos(double& dProfilePos); //指令位置
  90. LONG Sync();
  91. LONG Stop(AxisStopMode eStopMode = AXIS_SMOOTH_STOP);
  92. LONG CheckDone();
  93. LONG Home(bool bSync = SYNC);
  94. /**使能状态获取
  95. */
  96. bool JIsDriveEnabled();
  97. /**获取软限位正负使能配置状态接口
  98. */
  99. int JGetSoftLimitEnableStatus(bool& bEnabledNeg, bool& bEnabledPos);
  100. /**设置正负软限位接口
  101. * Neg 负
  102. * Pos 正
  103. */
  104. int JSetSoftLimit(double dNegLimit,double dPosLimit);
  105. /**获取软限位及软行程
  106. */
  107. int JGetSoftLimit(double& dSoftLimitNeg, double& dSoftLimitPos, double& dSoftTravelRange);
  108. /**直接设置速度的数值
  109. */
  110. int JSetTargetVel(double dVel);
  111. /**要按最大速度的比例设置速度(0-1)
  112. */
  113. int JSetTargetVelR(double dVelRatio);
  114. LONG Move_PassPosReturn(double dDist, double dPassDist, SPEED speed = FAST);
  115. LONG MoveTo_PassPosReturn(double dPos, double dPassPos, SPEED speed = FAST);
  116. LONG Move(double dDist, SPEED speed = FAST, bool bSync = SYNC);
  117. LONG MoveTo(double dPos, SPEED speed = FAST, bool bSync = SYNC);
  118. LONG Move(double dPos, double speed, bool bSync = SYNC);
  119. LONG MoveTo(double dPos, double speed, bool bSync = SYNC);
  120. LONG MoveForceCurrent(int nTorqueRatio, int nReachTime = 50, int nStopTime = 10);
  121. LONG GetProfileCurrent(double& dProfileTorque); //获取指令电流
  122. LONG GetActualCurrent(double& dProfileTorque); //获取反馈电流
  123. LONG SetStopDec(double val, double val1);
  124. LONG SetBufferParamF(int nBufferNo, std::string sParamFName, double dDoubleParam);
  125. LONG GetBufferParamF(int nBufferNo, std::string sParamFName, double& dDoubleParam);
  126. LONG SetBufferParam(int nBufferNo, std::string sParamFName, int dDoubleParam);
  127. LONG GetBufferParam(int nBufferNo, std::string sParamFName, int& dDoubleParam);
  128. LONG WriteSerialValueF(std::string sSerial, double tValue);
  129. LONG WriteSerialValueN(std::string sSerial, int tValue);
  130. LONG WriteSocketValueF(std::string ascii, double tValue);
  131. LONG WriteSocketValueN(std::string ascii, int tValue);
  132. LONG WriteSocketCommand(std::string ascii);
  133. //LONG RunForcerBuffer(); //运行力控buffer,不断判断弹簧压合到特定位置,到特定位置控制力控轴停下来
  134. //LONG RunSpringForcerBuffer(); //运行弹簧力控buffer,循环判断多段弹簧压合位置,每次到压合位置Z轴停下来
  135. LONG RunBuffer(int id);
  136. LONG StopBuffer(int id);
  137. };