Line data Source code
1 : /// @file AP_MotorsTri.h 2 : /// @brief Motor control class for Tricopters 3 : #pragma once 4 : 5 : #include "AP_Motors_config.h" 6 : 7 : #if AP_MOTORS_TRI_ENABLED 8 : 9 : #include <AP_Common/AP_Common.h> 10 : #include <AP_Math/AP_Math.h> // ArduPilot Mega Vector/Matrix math Library 11 : #include "AP_MotorsMulticopter.h" 12 : 13 : // tail servo uses channel 7 14 : #define AP_MOTORS_CH_TRI_YAW CH_7 15 : 16 : #define AP_MOTORS_TRI_SERVO_RANGE_DEG_MIN 5 // minimum angle movement of tail servo in degrees 17 : #define AP_MOTORS_TRI_SERVO_RANGE_DEG_MAX 80 // maximum angle movement of tail servo in degrees 18 : 19 : /// @class AP_MotorsTri 20 : class AP_MotorsTri : public AP_MotorsMulticopter { 21 : public: 22 : 23 : /// Constructor 24 10 : AP_MotorsTri(uint16_t speed_hz = AP_MOTORS_SPEED_DEFAULT) : 25 10 : AP_MotorsMulticopter(speed_hz) 26 : { 27 10 : }; 28 : 29 : // init 30 : void init(motor_frame_class frame_class, motor_frame_type frame_type) override; 31 : 32 : // set frame class (i.e. quad, hexa, heli) and type (i.e. x, plus) 33 : void set_frame_class_and_type(motor_frame_class frame_class, motor_frame_type frame_type) override; 34 : 35 : // set update rate to motors - a value in hertz 36 : void set_update_rate( uint16_t speed_hz ) override; 37 : 38 : // output_to_motors - sends minimum values out to the motors 39 : virtual void output_to_motors() override; 40 : 41 : // get_motor_mask - returns a bitmask of which outputs are being used for motors or servos (1 means being used) 42 : // this can be used to ensure other pwm outputs (i.e. for servos) do not conflict 43 : uint32_t get_motor_mask() override; 44 : 45 : // output a thrust to all motors that match a given motor 46 : // mask. This is used to control tiltrotor motors in forward 47 : // flight. Thrust is in the range 0 to 1 48 : // rudder_dt applys diffential thrust for yaw in the range 0 to 1 49 : void output_motor_mask(float thrust, uint32_t mask, float rudder_dt) override; 50 : 51 : // return the roll factor of any motor, this is used for tilt rotors and tail sitters 52 : // using copter motors for forward flight 53 : float get_roll_factor(uint8_t i) override; 54 : 55 : // return the pitch factor of any motor, this is used for AP_Motors_test 56 : float get_pitch_factor_json(uint8_t i); 57 : 58 : // Run arming checks 59 : bool arming_checks(size_t buflen, char *buffer) const override; 60 : 61 : // Get the testing order for the motors, this is used for AP_Motors_test 62 : uint8_t get_motor_test_order(uint8_t i); 63 : 64 : protected: 65 : // output - sends commands to the motors 66 : void output_armed_stabilizing() override; 67 : 68 : // call vehicle supplied thrust compensation if set 69 : void thrust_compensation(void) override; 70 : 71 22 : const char* _get_frame_string() const override { return "TRI"; } 72 22 : const char* get_type_string() const override { return _pitch_reversed ? "pitch-reversed" : ""; } 73 : 74 : // output_test_seq - spin a motor at the pwm value specified 75 : // motor_seq is the motor's sequence number from 1 to the number of motors on the frame 76 : // pwm value is an actual pwm value that will be output, normally in the range of 1000 ~ 2000 77 : virtual void _output_test_seq(uint8_t motor_seq, int16_t pwm) override; 78 : 79 : // parameters 80 : 81 : float _pivot_angle; // Angle of yaw pivot 82 : float _thrust_right; 83 : float _thrust_rear; 84 : float _thrust_left; 85 : 86 : // reverse pitch 87 : bool _pitch_reversed; 88 : bool _have_tail_servo; 89 : }; 90 : 91 : #endif // AP_MOTORS_TRI_ENABLED