BaseX.h 1.6 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
  19. | 9 | 10 | 11 | 12 | | mod | position-p |
  20. position-i | position-d | position-point | position-max-speed | speed-p |
  21. speed-i | speed-d | speed-point |
  22. */
  23. #define BASE_X_CONFIG_ADDR (0x50)
  24. #define NORMAL_MODE (0x00)
  25. #define POSITION_MODE (0x01)
  26. #define SPEED_MODE (0x02)
  27. class BASE_X {
  28. public:
  29. void SetMode(uint8_t pos, uint8_t mode);
  30. int32_t GetEncoderValue(uint8_t pos);
  31. void SetEncoderValue(uint8_t pos, int32_t encode);
  32. void SetMotorSpeed(uint8_t pos, int8_t duty);
  33. int8_t GetMotorSpeed(uint8_t pos);
  34. int8_t GetMotorSpeed20MS(uint8_t pos);
  35. void SetPositionPID(uint8_t pos, uint8_t kp, uint8_t ki, uint8_t kd);
  36. void SetPositionPoint(uint8_t pos, int32_t position_point);
  37. void SetPostionPIDMaxSpeed(uint8_t pos, uint8_t max_pwm);
  38. void SetSpeedPID(uint8_t pos, uint8_t kp, uint8_t ki, uint8_t kd);
  39. void SetSpeedPoint(uint8_t pos, int8_t speed_point);
  40. void SetServoAngle(uint8_t pos, uint8_t angle);
  41. void SetServoPulseWidth(uint8_t pos, uint16_t width);
  42. private:
  43. uint8_t CheckPos(uint8_t pos);
  44. };
  45. #endif