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.

119 lines
3.5 KiB

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_MiniServoModule {
  9. public:
  10. typedef enum { kNormalStop, kBreakStop } StopType_t;
  11. #pragma pack(1)
  12. typedef struct {
  13. u8 id;
  14. u8 status;
  15. s32 has_run_time;
  16. } rotate_cb_status_t;
  17. typedef struct {
  18. u8 id;
  19. u8 status;
  20. s32 pos;
  21. } move_to_cb_status_t;
  22. typedef struct {
  23. u8 id;
  24. u8 status;
  25. s32 pos;
  26. } move_by_cb_status_t;
  27. typedef struct {
  28. u8 id;
  29. u8 status;
  30. s32 has_run_time;
  31. } run_with_torque_cb_status_t;
  32. typedef struct {
  33. u8 id;
  34. u8 status;
  35. s32 pos;
  36. } move_by_nolimit_cb_status_t;
  37. /*******************************************************************************
  38. * READ *
  39. *******************************************************************************/
  40. typedef struct {
  41. int32_t version;
  42. } version_t;
  43. typedef struct {
  44. uint8_t status; // 0:normal 1:������ 2:offline 3:����
  45. uint8_t io_state; //
  46. int16_t torque; //
  47. int16_t speed; //
  48. int16_t pos; //
  49. } status_t;
  50. typedef struct {
  51. uint8_t status;
  52. uint8_t io_state;
  53. int16_t torque;
  54. int16_t speed;
  55. int16_t pos;
  56. int16_t voltage;
  57. int16_t current;
  58. int16_t temperature;
  59. int16_t error_flag;
  60. } debug_info_t;
  61. /*******************************************************************************
  62. * CFG *
  63. *******************************************************************************/
  64. typedef struct {
  65. s16 pos_calibrate;
  66. } basic_param_t;
  67. typedef struct {
  68. s16 minlimit;
  69. s16 maxlimit;
  70. } run_param_t;
  71. typedef struct {
  72. s16 mintemp;
  73. s16 maxtemp;
  74. s16 minvoltage;
  75. s16 maxvoltage;
  76. s16 mincurrent;
  77. s16 maxcurrent;
  78. } warning_limit_param_t;
  79. #pragma pack()
  80. public:
  81. virtual int32_t enable(u8 enable) = 0;
  82. virtual int32_t stop(u8 stop_type) = 0;
  83. virtual int32_t position_calibrate(s32 calibrate_pos) = 0;
  84. virtual int32_t rotate(s32 speed, s32 run_time, function<void(rotate_cb_status_t& status)> status_cb) = 0;
  85. virtual int32_t move_to(s32 pos, s32 speed, s32 torque, function<void(move_to_cb_status_t& status)> status_cb) = 0;
  86. virtual int32_t move_by(s32 pos, s32 speed, s32 torque, function<void(move_by_cb_status_t& status)> status_cb) = 0;
  87. virtual int32_t run_with_torque(s32 torque, s32 run_time, function<void(run_with_torque_cb_status_t& status)> status_cb) = 0;
  88. virtual int32_t move_by_nolimit(s32 pos, s32 speed, s32 torque, function<void(move_by_nolimit_cb_status_t& status)> status_cb) = 0;
  89. virtual int32_t read_version(version_t& version) = 0;
  90. virtual int32_t read_status(status_t& status) = 0;
  91. virtual int32_t read_debug_info(debug_info_t& debug_info) = 0;
  92. virtual int32_t set_run_param(run_param_t& param) = 0;
  93. virtual int32_t set_basic_param(basic_param_t& param) = 0;
  94. virtual int32_t set_warning_limit_param(warning_limit_param_t& param) = 0;
  95. virtual int32_t get_run_param(run_param_t& param) = 0;
  96. virtual int32_t get_basic_param(basic_param_t& param) = 0;
  97. virtual int32_t get_warning_limit_param(warning_limit_param_t& param) = 0;
  98. };
  99. } // namespace iflytop