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.

110 lines
3.9 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. #pragma once
  2. #include <stdint.h>
  3. #include <functional>
  4. #include "basic_type.hpp"
  5. //
  6. namespace iflytop {
  7. using namespace std;
  8. class I_StepMotorCtrlModule {
  9. public:
  10. typedef enum { hbot, corexy } RobotType_t;
  11. typedef enum { kNormalStop, kBreakStop } StopType_t;
  12. /*******************************************************************************
  13. * ACTION *
  14. *******************************************************************************/
  15. #pragma pack(1)
  16. typedef struct {
  17. int32_t exec_status;
  18. int32_t tox;
  19. } move_to_cb_status_t;
  20. typedef struct {
  21. int32_t exec_status;
  22. int32_t dx;
  23. } move_by_cb_status_t;
  24. typedef struct {
  25. int32_t exec_status;
  26. } move_to_zero_cb_status_t;
  27. typedef struct {
  28. int32_t exec_status;
  29. int32_t zero_shift_x;
  30. } move_to_zero_with_calibrate_cb_status_t;
  31. typedef struct {
  32. int32_t exec_status;
  33. int32_t lastforms;
  34. } rotate_cb_status_t;
  35. /*******************************************************************************
  36. * READ *
  37. *******************************************************************************/
  38. typedef struct {
  39. int32_t version;
  40. } version_t;
  41. typedef struct {
  42. uint8_t status;
  43. uint8_t io_state; // x_zero_io x_end_io
  44. int32_t x;
  45. } status_t;
  46. typedef struct {
  47. uint8_t status;
  48. uint8_t io_state; // x_zero_io x_end_io
  49. int32_t x;
  50. } detailed_status_t;
  51. /*******************************************************************************
  52. * CFG *
  53. *******************************************************************************/
  54. typedef struct {
  55. u8 x_shaft;
  56. u8 ihold;
  57. u8 irun;
  58. u16 iholddelay;
  59. s32 distance_scale; // 0.001
  60. s32 shift_x;
  61. s32 acc;
  62. s32 dec;
  63. s32 maxspeed;
  64. s32 min_x;
  65. s32 max_x;
  66. } run_param_t;
  67. typedef struct {
  68. uint8_t pad;
  69. } warning_limit_param_t;
  70. typedef struct {
  71. u32 move_to_zero_max_d;
  72. u32 leave_from_zero_max_d;
  73. u32 speed;
  74. u32 dec;
  75. } run_to_zero_param_t;
  76. #pragma pack()
  77. public:
  78. virtual int32_t move_to(int32_t x, function<void(move_to_cb_status_t& status)> status_cb) = 0;
  79. virtual int32_t move_by(int32_t dx, function<void(move_by_cb_status_t& status)> status_cb) = 0;
  80. virtual int32_t move_to_zero(function<void(move_to_zero_cb_status_t& status)> status_cb) = 0;
  81. virtual int32_t move_to_zero_with_calibrate(int32_t x, function<void(move_to_zero_with_calibrate_cb_status_t& status)> status_cb) = 0;
  82. virtual int32_t enable(bool venable) = 0;
  83. virtual int32_t stop(uint8_t stopType) = 0;
  84. virtual int32_t force_change_current_pos(int32_t x) = 0;
  85. virtual int32_t rotate(int32_t speed, int32_t lastforms, function<void(rotate_cb_status_t& status)> status_cb) = 0;
  86. virtual int32_t read_version(version_t& version) = 0;
  87. virtual int32_t read_status(status_t& status) = 0;
  88. virtual int32_t read_debug_info(detailed_status_t& debug_info) = 0;
  89. virtual int32_t set_run_param(uint8_t operation, const run_param_t& param, run_param_t& ack) = 0;
  90. virtual int32_t set_run_to_zero_param(uint8_t operation, const run_to_zero_param_t& param, run_to_zero_param_t& ack) = 0;
  91. virtual int32_t set_warning_limit_param(uint8_t operation, const warning_limit_param_t& param, warning_limit_param_t& ack) = 0;
  92. };
  93. } // namespace iflytop