UserCan.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #ifndef USERCAN_H_
  2. #define USERCAN_H_
  3. #include <AP_Common/AP_Common.h>
  4. #include <AP_HAL/CAN.h>
  5. #include <AP_HAL/Semaphores.h>
  6. #define OUSHENCAN_MAX_NUM_ESCS 6
  7. class UserCAN : public AP_HAL::CANProtocol {
  8. public:
  9. UserCAN();
  10. ~UserCAN();
  11. UserCAN(const UserCAN &other) = delete;
  12. UserCAN &operator=(const UserCAN&) = delete;
  13. void init(uint8_t driver_index, bool enable_filters) override;
  14. void loop();
  15. bool write_frame(uavcan::CanFrame &out_frame, uavcan::MonotonicTime timeout);
  16. bool read_frame(uavcan::CanFrame &recv_frame, uavcan::MonotonicTime timeout);
  17. uint16_t update_count; // counter increments each time main thread updates outputs
  18. uint16_t update_count2;
  19. /*struct telemetry_info_t {
  20. int16_t rpm;// 速度
  21. float current;
  22. float voltage;
  23. int16_t temperature;
  24. uint16_t EF;
  25. } _telemetry[OUSHENCAN_MAX_NUM_ESCS];*/
  26. private:
  27. uint8_t send_ID;
  28. //uint8_t driver_index;
  29. bool _enable_filters;
  30. bool _initialized;
  31. char _thread_name[9];
  32. uint8_t _driver_index;
  33. uavcan::ICanDriver* _can_driver;
  34. uint16_t update_count_buffered; // counter when outputs copied to buffer before before sending to ESCs
  35. uint16_t update_count_sent;
  36. struct motor_rotation_cmd_t {
  37. uint8_t data[8];
  38. };
  39. struct sent_command {
  40. uint8_t data[4];
  41. };
  42. /* union motor_reply_data1_t {
  43. struct PACKED {
  44. uint16_t command_code;
  45. uint8_t reserve;
  46. uint8_t datatype;
  47. uint32_t data_reply;
  48. }packed_data;
  49. uint8_t data[8];
  50. };*/
  51. struct motor_reply_data1_t {
  52. uint8_t data[8];
  53. };
  54. uavcan::CanFrame mot_rot_frame1;
  55. const uavcan::CanFrame* _select_frames[uavcan::MaxCanIfaces] { };
  56. };
  57. #endif