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.

107 lines
3.7 KiB

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. typedef struct {
  16. int32_t exec_status;
  17. int32_t tox;
  18. } move_to_cb_status_t;
  19. typedef struct {
  20. int32_t exec_status;
  21. int32_t dx;
  22. } move_by_cb_status_t;
  23. typedef struct {
  24. int32_t exec_status;
  25. } move_to_zero_cb_status_t;
  26. typedef struct {
  27. int32_t exec_status;
  28. int32_t zero_shift_x;
  29. } move_to_zero_with_calibrate_cb_status_t;
  30. typedef struct {
  31. int32_t exec_status;
  32. int32_t lastforms;
  33. } rotate_cb_status_t;
  34. /*******************************************************************************
  35. * READ *
  36. *******************************************************************************/
  37. typedef struct {
  38. int32_t version;
  39. } version_t;
  40. typedef struct {
  41. uint8_t status;
  42. int32_t x;
  43. } status_t;
  44. typedef struct {
  45. uint8_t status;
  46. int32_t x;
  47. } debug_info_t;
  48. /*******************************************************************************
  49. * CFG *
  50. *******************************************************************************/
  51. typedef struct {
  52. u8 x_shaft;
  53. u8 ihold;
  54. u8 irun;
  55. u16 iholddelay;
  56. s32 distance_scale; // 0.001
  57. s32 shift_x;
  58. s32 acc;
  59. s32 dec;
  60. s32 maxspeed;
  61. s32 min_x;
  62. s32 max_x;
  63. } run_param_t;
  64. typedef struct {
  65. uint8_t pad;
  66. } warning_limit_param_t;
  67. typedef struct {
  68. u32 move_to_zero_max_d;
  69. u32 leave_from_zero_max_d;
  70. u32 speed;
  71. u32 dec;
  72. } run_to_zero_param_t;
  73. public:
  74. virtual int32_t move_to(int32_t x, function<void(move_to_cb_status_t& status)> status_cb) = 0;
  75. virtual int32_t move_by(int32_t dx, function<void(move_by_cb_status_t& status)> status_cb) = 0;
  76. virtual int32_t move_to_zero(function<void(move_to_zero_cb_status_t& status)> status_cb) = 0;
  77. 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;
  78. virtual int32_t enable(bool venable) = 0;
  79. virtual int32_t stop(uint8_t stopType) = 0;
  80. virtual int32_t force_change_current_pos(int32_t x) = 0;
  81. virtual int32_t rotate(int32_t speed, int32_t lastforms, function<void(rotate_cb_status_t& status)> status_cb) = 0;
  82. virtual int32_t read_version(version_t& version) = 0;
  83. virtual int32_t read_status(status_t& status) = 0;
  84. virtual int32_t read_debug_info(debug_info_t& debug_info) = 0;
  85. virtual int32_t set_run_param(uint8_t operation, const run_param_t& param, run_param_t& ack) = 0;
  86. 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;
  87. virtual int32_t set_warning_limit_param(uint8_t operation, const warning_limit_param_t& param, warning_limit_param_t& ack) = 0;
  88. };
  89. } // namespace iflytop