AP_RobotisServo.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. This program is free software: you can redistribute it and/or modify
  3. it under the terms of the GNU General Public License as published by
  4. the Free Software Foundation, either version 3 of the License, or
  5. (at your option) any later version.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. GNU General Public License for more details.
  10. You should have received a copy of the GNU General Public License
  11. along with this program. If not, see <http://www.gnu.org/licenses/>.
  12. */
  13. /*
  14. implementation of Robotis Dynamixel 2.0 protocol for controlling servos
  15. */
  16. #pragma once
  17. #include <AP_HAL/AP_HAL.h>
  18. #include <AP_Param/AP_Param.h>
  19. class AP_RobotisServo {
  20. public:
  21. AP_RobotisServo();
  22. /* Do not allow copies */
  23. AP_RobotisServo(const AP_RobotisServo &other) = delete;
  24. AP_RobotisServo &operator=(const AP_RobotisServo&) = delete;
  25. static const struct AP_Param::GroupInfo var_info[];
  26. void update();
  27. private:
  28. AP_HAL::UARTDriver *port;
  29. uint32_t baudrate;
  30. uint32_t us_per_byte;
  31. uint32_t us_gap;
  32. void init(void);
  33. void detect_servos();
  34. uint16_t update_crc(uint16_t crc_accum, uint8_t *data_blk_ptr, uint16_t data_blk_size);
  35. void add_stuffing(uint8_t *packet);
  36. void send_packet(uint8_t *txpacket);
  37. void read_bytes();
  38. void process_packet(const uint8_t *pkt, uint8_t length);
  39. void send_command(uint8_t id, uint16_t reg, uint32_t value, uint8_t len);
  40. void configure_servos(void);
  41. // auto-detected mask of available servos, from a broadcast ping
  42. uint16_t servo_mask;
  43. uint8_t detection_count;
  44. uint8_t configured_servos;
  45. bool initialised;
  46. uint8_t pktbuf[64];
  47. uint8_t pktbuf_ofs;
  48. // servo position limits
  49. AP_Int32 pos_min;
  50. AP_Int32 pos_max;
  51. uint32_t last_send_us;
  52. uint32_t delay_time_us;
  53. };