AP_Motors6DOF.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /// @file AP_Motors6DOF.h
  2. /// @brief Motor control class for ROVs with direct control over 6DOF (or fewer) in movement
  3. #pragma once
  4. #include <AP_Common/AP_Common.h>
  5. #include <AP_Math/AP_Math.h> // ArduPilot Mega Vector/Matrix math Library
  6. #include <RC_Channel/RC_Channel.h> // RC Channel Library
  7. #include "AP_MotorsMatrix.h"
  8. #define NETRULPWM 1490
  9. /// @class AP_MotorsMatrix
  10. class AP_Motors6DOF : public AP_MotorsMatrix {
  11. public:
  12. AP_Motors6DOF(uint16_t loop_rate, uint16_t speed_hz = AP_MOTORS_SPEED_DEFAULT) :
  13. AP_MotorsMatrix(loop_rate, speed_hz) {
  14. AP_Param::setup_object_defaults(this, var_info);
  15. _singleton = this;
  16. for (uint8_t i= 0; i < 6; i++)
  17. {
  18. motor_to_can[i]=0;
  19. motor_to_detect[i] = NETRULPWM;
  20. }
  21. pwm_track[0] = 1500;
  22. pwm_track[1] = 1500;
  23. };
  24. // Supported frame types
  25. typedef enum {
  26. SUB_FRAME_BLUEROV1,
  27. SUB_FRAME_VECTORED,
  28. SUB_FRAME_VECTORED_6DOF,
  29. SUB_FRAME_VECTORED_6DOF_90DEG,
  30. SUB_FRAME_SIMPLEROV_3,
  31. SUB_FRAME_SIMPLEROV_4,
  32. SUB_FRAME_SIMPLEROV_5,
  33. SUB_FRAME_CUSTOM
  34. } sub_frame_t;
  35. //----------selfdefine start------------------------
  36. //---------------外部可以调用句柄--------------
  37. static AP_Motors6DOF *_singleton;
  38. static AP_Motors6DOF *get_singleton() {
  39. return _singleton;
  40. }
  41. int32_t motor_to_can[6];//发送给CAN的数据
  42. int32_t motor_to_detect[6];//发送给CAN的数据
  43. int16_t pwm_track[2];
  44. float last_thrust_in[AP_MOTORS_MAX_NUM_MOTORS];
  45. int32_t last_thrust_Dhot[AP_MOTORS_MAX_NUM_MOTORS];
  46. //----------selfdefine end------------------------
  47. // Override parent
  48. void setup_motors(motor_frame_class frame_class, motor_frame_type frame_type) override;
  49. // Override parent
  50. void output_min() override;
  51. // Map thrust input -1~1 to pwm output 1100~1900
  52. int16_t calc_thrust_to_pwm(float thrust_in) const;
  53. int32_t calc_thrust_to_motor(float thrust_in,int8_t i);
  54. void output_motor8_and_motor9(void);
  55. // output_to_motors - sends minimum values out to the motors
  56. void output_to_motors() override;
  57. void output_to_PWM() override;//dshot赋值
  58. // This allows us to read back the output of the altidude controllers
  59. // The controllers are in charge of the throttle input, so this gives vehicle access/visibility to the output of those controllers
  60. float get_throttle_in_bidirectional() const { return constrain_float(2*(_throttle_in - 0.5f), -1.0f, 1.0f); }
  61. // returns a vector with roll, pitch, and yaw contributions
  62. Vector3f get_motor_angular_factors(int motor_number);
  63. // returns true if motor is enabled
  64. bool motor_is_enabled(int motor_number);
  65. bool set_reversed(int motor_number, bool reversed);
  66. // var_info for holding Parameter information
  67. static const struct AP_Param::GroupInfo var_info[];
  68. protected:
  69. // return current_limit as a number from 0 ~ 1 in the range throttle_min to throttle_max
  70. float get_current_limit_max_throttle() override;
  71. //Override MotorsMatrix method
  72. void add_motor_raw_6dof(int8_t motor_num, float roll_fac, float pitch_fac, float yaw_fac, float climb_fac, float forward_fac, float lat_fac, uint8_t testing_order);
  73. void output_armed_stabilizing() override;
  74. void output_armed_stabilizing_vectored();
  75. void output_armed_stabilizing_vectored_6dof();
  76. // Parameters
  77. AP_Int8 _motor_reverse[AP_MOTORS_MAX_NUM_MOTORS];
  78. AP_Float _forwardVerticalCouplingFactor;
  79. float _throttle_factor[AP_MOTORS_MAX_NUM_MOTORS]; // each motors contribution to throttle (climb/descent)
  80. float _forward_factor[AP_MOTORS_MAX_NUM_MOTORS]; // each motors contribution to forward/backward
  81. float _lateral_factor[AP_MOTORS_MAX_NUM_MOTORS]; // each motors contribution to lateral (left/right)
  82. // current limiting
  83. float _output_limited = 1.0f;
  84. float _batt_current_last = 0.0f;
  85. };
  86. namespace AP {
  87. AP_Motors6DOF &motors6dof();
  88. };