CAxis.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. string m_strModuleName;
  42. JAxis* m_pAxis = nullptr;
  43. string m_strAxisName = "";
  44. INT m_iUse = 0;
  45. bool m_bIsInitSuccess = false;
  46. UINT m_iHomeTime = 500000; //回零等待时间(秒)
  47. UINT m_iFastTime = 50000; //快速等待时间(秒)
  48. UINT m_iMediumTime = 50000; //中速等待时间(秒)
  49. UINT m_iSlowTime = 100000; //慢速等待时间(秒)
  50. UINT m_iLastWaitTime = 100000; //上次移动的等待时间
  51. UINT m_iCommonWaitTime = 100000; //其他情况等待事件
  52. unsigned long m_lStartSysTime; //开始移动的系统时间
  53. bool m_bEnable = false; //运控卡禁止/启用
  54. std::vector <ns_db::MODULE_HOT_ZONE_STRUCT> m_vecHotZoneList;
  55. static std::mutex m_MutexHotZone;
  56. bool m_bHotZoneEnable = false;
  57. static std::vector<HOT_ZONE_ID_STRUCT> m_vecHotZoneId;
  58. //轴当前位置,模拟测试时才会使用
  59. double m_dCurrentPosition;
  60. //判断要移动的位置,是否有热区冲突
  61. bool CheckHotZone(double pos);
  62. bool IsTriggerHotZoneX(double pos);
  63. bool IsTriggerHotZoneY(double pos);
  64. bool IsTriggerHotZoneZ(double pos);
  65. bool IsTriggerHotZone(ns_db::MODULE_HOT_ZONE_STRUCT stHotZone, AXIS_TYPE axis,double pos);
  66. //设置当前位置是否触发热区
  67. void SetTriggerHotZone();
  68. void AddHotZoneId(HOT_ZONE_ID_STRUCT stHotZone);
  69. void DeleteHotZoneId(HOT_ZONE_ID_STRUCT stHotZone);
  70. public:
  71. CAxis();
  72. LONG Init(JAxis* pAxis, ns_db::AXIS_LIST_STRUCT *pAxisStruct);
  73. string GetAxisName() {return m_strAxisName;};
  74. string GetModuleType() { return m_strModuleType; };
  75. string GetModuleName() { return m_strModuleName; };
  76. string GetStringAxisType() { return m_strAxisType; };
  77. string GetStringModuleType() { return m_strModuleType; };
  78. AXIS_TYPE GetAxisType() { return m_eAxisType; };
  79. //LONG SetJogMotionMode
  80. LONG GetAxisStatus(AxisStatus& axisStatus);
  81. LONG GetActualPos(double &pos); //反馈位置
  82. LONG AxisOn();
  83. LONG AxisOff();
  84. LONG GetProfilePos(double& dProfilePos); //指令位置
  85. LONG Sync();
  86. LONG Stop(AxisStopMode eStopMode = AXIS_SMOOTH_STOP);
  87. LONG CheckDone();
  88. LONG Home(bool bSync = SYNC);
  89. LONG Move_PassPosReturn(double dDist, double dPassDist, SPEED speed = FAST);
  90. LONG MoveTo_PassPosReturn(double dPos, double dPassPos, SPEED speed = FAST);
  91. LONG Move(double dDist, SPEED speed = FAST, bool bSync = SYNC);
  92. LONG MoveTo(double dPos, SPEED speed = FAST, bool bSync = SYNC);
  93. LONG Move(double dPos, double speed, bool bSync = SYNC);
  94. LONG MoveTo(double dPos, double speed, bool bSync = SYNC);
  95. LONG MoveForceCurrent(int nTorqueRatio, int nReachTime = 50, int nStopTime = 10);
  96. LONG GetProfileCurrent(double& dProfileTorque); //获取指令电流
  97. LONG GetActualCurrent(double& dProfileTorque); //获取反馈电流
  98. LONG SetStopDec(double val, double val1);
  99. LONG SetBufferParamF(int nBufferNo, std::string sParamFName, double dDoubleParam);
  100. LONG GetBufferParamF(int nBufferNo, std::string sParamFName, double& dDoubleParam);
  101. LONG SetBufferParam(int nBufferNo, std::string sParamFName, int dDoubleParam);
  102. LONG GetBufferParam(int nBufferNo, std::string sParamFName, int& dDoubleParam);
  103. LONG WriteSerialValueF(std::string sSerial, double tValue);
  104. LONG WriteSerialValueN(std::string sSerial, int tValue);
  105. LONG WriteSocketValueF(std::string ascii, double tValue);
  106. LONG WriteSocketValueN(std::string ascii, int tValue);
  107. LONG WriteSocketCommand(std::string ascii);
  108. //LONG RunForcerBuffer(); //运行力控buffer,不断判断弹簧压合到特定位置,到特定位置控制力控轴停下来
  109. //LONG RunSpringForcerBuffer(); //运行弹簧力控buffer,循环判断多段弹簧压合位置,每次到压合位置Z轴停下来
  110. LONG RunBuffer(int id);
  111. LONG StopBuffer(int id);
  112. };