You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

154 lines
6.7 KiB

2 years ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
2 years ago
1 year ago
2 years ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
2 years ago
1 year ago
  1. #pragma once
  2. #include <stdint.h>
  3. #include <functional>
  4. #include "apibasic/basic.hpp"
  5. typedef struct {
  6. uint32_t sg_result : 10;
  7. uint32_t reserved0 : 5;
  8. uint32_t fsactive : 1;
  9. uint32_t cs_actual : 5;
  10. uint32_t reserved1 : 3;
  11. uint32_t stallguard : 1;
  12. uint32_t ot : 1;
  13. uint32_t otpw : 1;
  14. uint32_t s2ga : 1;
  15. uint32_t s2gb : 1;
  16. uint32_t ola : 1;
  17. uint32_t olb : 1;
  18. uint32_t stst : 1;
  19. } TMC5130MotorStatus_t;
  20. typedef struct {
  21. uint32_t reset : 1; // fatal error
  22. uint32_t drv_err : 1; // fatal error
  23. uint32_t uv_cp : 1; // fatal error
  24. } TMC5130MotorState_t; // R+C
  25. typedef struct {
  26. uint32_t sg_result : 10;
  27. uint32_t reserved0 : 1;
  28. uint32_t reserved1 : 1;
  29. uint32_t s2vsa : 1;
  30. uint32_t s2vsb : 1;
  31. uint32_t stealth : 1;
  32. uint32_t fsactive : 1;
  33. uint32_t cs_actual : 5;
  34. uint32_t reserved2 : 3;
  35. uint32_t stallguard : 1;
  36. uint32_t ot : 1;
  37. uint32_t otpw : 1;
  38. uint32_t s2ga : 1;
  39. uint32_t s2gb : 1;
  40. uint32_t ola : 1;
  41. uint32_t olb : 1;
  42. uint32_t stst : 1;
  43. } TMC2160MotorDriverStatus_t;
  44. typedef struct {
  45. uint32_t TARGET_REACHED_F : 1; // XACTUAL = XTARGET
  46. uint32_t POS_COMP_REACHED_F : 1; // XACTUAL = POS_COMP
  47. uint32_t VEL_REACHED_F : 1; // VACTUAL = |VMAX|
  48. uint32_t VEL_STATE_F : 2; // 0:VACTUAL = 0; 1:VACTUAL > 0; 2:VACTUAL < 0
  49. uint32_t RAMP_STATE_F : 2; // 0:AACTUAL = 0; 1:AACTUAL 增加(加速); 2:AACTUAL 减小(减速)
  50. uint32_t STOPL_ACTIVE_F : 1; // 左停止开关有效。
  51. uint32_t STOPR_ACTIVE_F : 1; // 右停止开关有效。
  52. uint32_t VSTOPL_ACTIVE_F : 1; // 左虚拟停止开关有效。
  53. uint32_t VSTOPR_ACTIVE_F : 1; // 右虚拟停止开关有效。
  54. uint32_t ACTIVE_STALL_F : 1; // 电机堵转检测且 VACTUAL > VSTALL_LIMIT。
  55. uint32_t HOME_ERROR_F : 1; // 输入信号电平不等于预期的回零电平。
  56. uint32_t FS_ACTIVE_F : 1; // 全步有效。
  57. uint32_t ENC_FAIL_F : 1; // XACTUAL 和 ENC_POS 中间的差值超出容差。
  58. uint32_t N_ACTIVE_F : 1; // 事件有效
  59. uint32_t ENC_LATCH_F : 1; // ENC_LATCH 被重置。
  60. uint32_t MULTI_CYCLE_FAIL_F : 1; // 仅适用于绝对编码器 MULTI_CYCLE_FAIL_F 表示上一个多圈数据出现故障。
  61. uint32_t ___ : 1; //
  62. uint32_t CL_FIT_F : 1; // 如果 ENC_POS_DEV < CL_COMPLATION,则有效。XACTUAL 和 ENC_POS 之间的差值在容许范围内
  63. uint32_t SERIAL_ENC_FLAGS : 4; // 仅适用于绝对编码器:从编码器接收的 SERIAL_ENC_FLAGS。新的编码器传输请求是会重置这些标志
  64. uint32_t SG : 1; // 仅 TMC26x / TMC21x0 StallGuard2 状态。
  65. uint32_t OT : 1; // 过温关断。
  66. uint32_t OTPW : 1; // 过温预警。
  67. uint32_t S2GA : 1; // 线圈 A 高端 MOSFET 管对地短路检测位。
  68. uint32_t S2GB : 1; // 线圈 B 高端 MOSFET 管对地短路检测位。
  69. uint32_t OLA : 1; // 线圈 A 开路。
  70. uint32_t OLB : 1; // 线圈 B 开路。
  71. uint32_t STST : 1; // 仅 TMC26x / TMC21x0 静止状态。
  72. } TMC4361AMotorStatus_t; // R+CW 事件标志位
  73. typedef struct {
  74. uint32_t reset : 1; // fatal error
  75. uint32_t drv_err : 1; // fatal error
  76. uint32_t uv_cp : 1; // fatal error
  77. } TMC2160MotorGstate_t; // R+C
  78. typedef struct {
  79. uint32_t TARGET_REACHED : 1; //
  80. uint32_t POS_COMP_REACHED : 1; //
  81. uint32_t VEL_REACHED : 1; //
  82. uint32_t VEL_STATE_EQ_0 : 1; //
  83. uint32_t VEL_STATE_EQ_1 : 1; //
  84. uint32_t VEL_STATE_EQ_2 : 1; //
  85. uint32_t RAMP_STATE_EQ_0 : 1; //
  86. uint32_t RAMP_STATE_EQ_1 : 1; //
  87. uint32_t RAMP_STATE_EQ_2 : 1; //
  88. uint32_t MAX_PHASE_TRAP : 1; // 梯形斜坡已经达到其极限速度
  89. uint32_t FROZEN : 1; // 重置 TMC4361A,以便进一步运动。 fatal error
  90. uint32_t STOPL : 1; //
  91. uint32_t STOPR : 1; //
  92. uint32_t VSTOPL_ACTIVE : 1; //
  93. uint32_t VSTOPR_ACTIVE : 1; //
  94. uint32_t HOME_ERROR : 1; //
  95. uint32_t XLATCH_DONE : 1; //
  96. uint32_t FS_ACTIVE : 1; //
  97. uint32_t ENC_FAIL : 1; //
  98. uint32_t N_ACTIVE : 1; //
  99. uint32_t ENC_DONE : 1; //
  100. uint32_t SER_ENC_DATA_FAIL : 1; //
  101. uint32_t ___ : 1; //
  102. uint32_t SER_DATA_DONE : 1; //
  103. uint32_t SERIAL_ENC_Flags : 1; //
  104. uint32_t COVER_DONE : 1; //
  105. uint32_t ENC_VEL0 : 1; // 编码器速度到 0。
  106. uint32_t CL_MAX : 1; //
  107. uint32_t CL_FIT : 1; //
  108. uint32_t STOP_ON_STALL : 1; // 检测到电机堵转。电机斜坡已经停止。 fatal error
  109. uint32_t MOTOR_EV : 1; // 选定的 TMC 电机驱动器标志之一被触发。
  110. uint32_t RST_EV : 1; // 复位被触发。 fatal error
  111. } TMC4361AMotorEventState_t;
  112. namespace iflytop {
  113. using namespace std;
  114. class ZIStepMotor {
  115. public:
  116. virtual ~ZIStepMotor() {}
  117. virtual int32_t step_motor_enable(int32_t enable) = 0;
  118. virtual int32_t step_motor_stop(int32_t breakstop) = 0;
  119. virtual int32_t step_motor_read_pos(int32_t* pos) = 0;
  120. virtual int32_t step_motor_easy_rotate(int32_t direction) = 0;
  121. virtual int32_t step_motor_easy_move_by(int32_t distance) = 0;
  122. virtual int32_t step_motor_easy_move_to(int32_t position) = 0;
  123. virtual int32_t step_motor_easy_move_to_zero() = 0;
  124. virtual int32_t step_motor_easy_set_current_pos(int32_t pos) = 0;
  125. virtual int32_t step_motor_easy_move_to_io(int32_t ioindex, int32_t direction) = 0;
  126. virtual int32_t step_motor_active_cfg() = 0;
  127. virtual int32_t step_motor_read_io_state(int32_t ioindex, int32_t* state) = 0;
  128. virtual int32_t step_motor_easy_move_to_end_point() = 0;
  129. /***********************************************************************************************************************
  130. * DEBUG *
  131. ***********************************************************************************************************************/
  132. virtual int32_t step_motor_read_tmc5130_status(int32_t* status) = 0;
  133. virtual int32_t step_motor_read_tmc5130_state(int32_t* status) = 0;
  134. virtual int32_t step_motor_read_tmc4361a_status(int32_t* status) = 0;
  135. virtual int32_t step_motor_read_tmc4361a_state(int32_t* gstate) = 0;
  136. virtual int32_t step_motor_read_tmc2160_status(int32_t* status) = 0;
  137. virtual int32_t step_motor_read_tmc2160_state(int32_t* status) = 0;
  138. virtual int32_t step_motor_read_io_index_in_stm32(int32_t ioindex, int32_t* index_in_stm32) = 0;
  139. };
  140. } // namespace iflytop