BaseX.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * @Author: Sorzn
  3. * @Date: 2019-12-12 14:33:50
  4. * @LastEditTime: 2019-12-13 15:47:59
  5. * @Description: M5Stack project
  6. * @FilePath: /M5Stack/examples/Modules/BaseX/BaseX.h
  7. */
  8. #ifndef __BASE_X_H__
  9. #define __BASE_X_H__
  10. #include "Arduino.h"
  11. #define BASE_X_ADDR (0x22)
  12. #define BASE_X_SERVO_ANGLE_ADDR (0x00)
  13. #define BASE_X_SERVO_PULSE_ADDR (0x10)
  14. #define BASE_X_PWM_DUTY_ADDR (0x20)
  15. #define BASE_X_ENCODER_ADDR (0x30)
  16. #define BASE_X_SPEED_ADDR (0x40)
  17. /*
  18. | 0 | 1 | 2 | 3 | 4, 5, 6, 7 | 8 | 9 | 10 | 11 | 12 |
  19. | mod | position-p | position-i | position-d | position-point | position-max-speed | speed-p | speed-i | speed-d | speed-point |
  20. */
  21. #define BASE_X_CONFIG_ADDR (0x50)
  22. #define NORMAL_MODE (0x00)
  23. #define POSITION_MODE (0x01)
  24. #define SPEED_MODE (0x02)
  25. class BASE_X
  26. {
  27. public:
  28. void SetMode(uint8_t pos, uint8_t mode);
  29. int32_t GetEncoderValue(uint8_t pos);
  30. void SetEncoderValue(uint8_t pos, int32_t encode);
  31. void SetMotorSpeed(uint8_t pos, int8_t duty);
  32. int8_t GetMotorSpeed(uint8_t pos);
  33. int8_t GetMotorSpeed20MS(uint8_t pos);
  34. void SetPositionPID(uint8_t pos, uint8_t kp, uint8_t ki, uint8_t kd);
  35. void SetPositionPoint(uint8_t pos, int32_t position_point);
  36. void SetPostionPIDMaxSpeed(uint8_t pos, uint8_t max_pwm);
  37. void SetSpeedPID(uint8_t pos, uint8_t kp, uint8_t ki, uint8_t kd);
  38. void SetSpeedPoint(uint8_t pos, int8_t speed_point);
  39. void SetServoAngle(uint8_t pos, uint8_t angle);
  40. void SetServoPulseWidth(uint8_t pos, uint16_t width);
  41. private:
  42. uint8_t CheckPos(uint8_t pos);
  43. };
  44. #endif