Line data Source code
1 : /// @file AP_MotorsHeli_Single.h 2 : /// @brief Motor control class for traditional heli 3 : #pragma once 4 : 5 : #include <AP_Common/AP_Common.h> 6 : #include <AP_Math/AP_Math.h> // ArduPilot Mega Vector/Matrix math Library 7 : #include <SRV_Channel/SRV_Channel.h> 8 : #include "AP_MotorsHeli.h" 9 : #include "AP_MotorsHeli_RSC.h" 10 : #include "AP_MotorsHeli_Swash.h" 11 : #include "AP_Motors_Thrust_Linearization.h" 12 : 13 : // rsc function output channel 14 : #define AP_MOTORS_HELI_SINGLE_TAILRSC CH_7 15 : 16 : // direct-drive variable pitch defaults 17 : #define AP_MOTORS_HELI_SINGLE_DDVP_SPEED_DEFAULT 50 18 : 19 : // tail rotor ramp time in seconds 20 : #define AP_MOTORS_HELI_SINGLE_TAIL_RAMP_TIME_DEFAULT 1 21 : 22 : // COLYAW parameter min and max values 23 : #define AP_MOTORS_HELI_SINGLE_COLYAW_RANGE 5.0f 24 : 25 : // maximum number of swashplate servos 26 : #define AP_MOTORS_HELI_SINGLE_NUM_SWASHPLATE_SERVOS 3 27 : 28 : /// @class AP_MotorsHeli_Single 29 : class AP_MotorsHeli_Single : public AP_MotorsHeli { 30 : public: 31 : // constructor 32 80 : AP_MotorsHeli_Single(uint16_t speed_hz = AP_MOTORS_HELI_SPEED_DEFAULT) : 33 : AP_MotorsHeli(speed_hz), 34 80 : _tail_rotor(SRV_Channel::k_heli_tail_rsc, AP_MOTORS_HELI_SINGLE_TAILRSC, 1U), 35 160 : _swashplate(AP_MOTORS_MOT_1, AP_MOTORS_MOT_2, AP_MOTORS_MOT_3, AP_MOTORS_MOT_5, 1U) 36 : { 37 80 : AP_Param::setup_object_defaults(this, var_info); 38 80 : }; 39 : 40 : // set update rate to motors - a value in hertz 41 : void set_update_rate(uint16_t speed_hz) override; 42 : 43 : // output_to_motors - sends values out to the motors 44 : void output_to_motors() override; 45 : 46 : // calculate_armed_scalars - recalculates scalars that can change while armed 47 : void calculate_armed_scalars() override; 48 : 49 : // calculate_scalars - recalculates various scalars used 50 : void calculate_scalars() override; 51 : 52 : // get_motor_mask - returns a bitmask of which outputs are being used for motors or servos (1 means being used) 53 : // this can be used to ensure other pwm outputs (i.e. for servos) do not conflict 54 : uint32_t get_motor_mask() override; 55 : 56 : // Run arming checks 57 : bool arming_checks(size_t buflen, char *buffer) const override; 58 : 59 : // Helper function for param conversions to be done in motors class 60 : void heli_motors_param_conversions(void) override; 61 : 62 : // Thrust Linearization handling 63 : Thrust_Linearization thr_lin {*this}; 64 : 65 : #if HAL_LOGGING_ENABLED 66 : // Blade angle logging - called at 10 Hz 67 : void Log_Write(void) override; 68 : #endif 69 : 70 : // var_info 71 : static const struct AP_Param::GroupInfo var_info[]; 72 : 73 : protected: 74 : 75 : // init_outputs - initialise Servo/PWM ranges and endpoints 76 : void init_outputs() override; 77 : 78 : // update_motor_controls - sends commands to motor controllers 79 : void update_motor_control(AP_MotorsHeli_RSC::DesiredRSCSpoolState state) override; 80 : 81 : // update_spool_state - updates the spool state based on the desired state 82 : AP_Motors::SpoolState update_spool_state(AP_MotorsHeli_RSC::DesiredRSCSpoolState state) override; 83 : 84 : // heli_move_actuators - moves swash plate and tail rotor 85 : void move_actuators(float roll_out, float pitch_out, float coll_in, float yaw_out) override; 86 : 87 : // move_yaw - moves the yaw servo 88 : void move_yaw(float yaw_out); 89 : 90 : // Get yaw offset required to cancel out steady state main rotor torque 91 : float get_yaw_offset(float collective); 92 : 93 : // handle output limit flags and send throttle to servos lib 94 : void output_to_ddfp_tail(float throttle); 95 : 96 : // servo_test - move servos through full range of movement 97 : void servo_test() override; 98 : 99 : // Tail types 100 : enum class TAIL_TYPE { 101 : SERVO = 0, 102 : SERVO_EXTGYRO_OLD = 1, 103 : DIRECTDRIVE_VARPITCH = 2, 104 : DIRECTDRIVE_FIXEDPITCH_CW = 3, 105 : DIRECTDRIVE_FIXEDPITCH_CCW = 4, 106 : DIRECTDRIVE_VARPIT_EXT_GOV = 5 107 : }; 108 : 109 11989560 : TAIL_TYPE get_tail_type() const { return TAIL_TYPE(_tail_type.get()); } 110 : 111 : // Helper to return true for direct drive fixed pitch tail, either CW or CCW 112 : bool have_DDFP_tail() const; 113 : 114 : // Helper to return true if the tail RSC should be used 115 : bool use_tail_RSC() const; 116 : 117 : // external objects we depend upon 118 : AP_MotorsHeli_RSC _tail_rotor; // tail rotor 119 : AP_MotorsHeli_Swash _swashplate; // swashplate 120 : 121 : // internal variables 122 : float _oscillate_angle = 0.0f; // cyclic oscillation angle, used by servo_test function 123 : float _servo_test_cycle_time = 0.0f; // cycle time tracker, used by servo_test function 124 : float _collective_test = 0.0f; // over-ride for collective output, used by servo_test function 125 : float _roll_test = 0.0f; // over-ride for roll output, used by servo_test function 126 : float _pitch_test = 0.0f; // over-ride for pitch output, used by servo_test function 127 : float _yaw_test = 0.0f; // over-ride for yaw output, used by servo_test function 128 : float _servo4_out = 0.0f; // output value sent to motor 129 : 130 : // parameters 131 : AP_Int16 _tail_type; // Tail type used: Servo, Servo with external gyro, direct drive variable pitch or direct drive fixed pitch 132 : AP_Int16 _direct_drive_tailspeed; // Direct Drive VarPitch Tail ESC speed (0 ~ 1000) 133 : AP_Int8 _direct_drive_ramp_time; // Time in seconds for throttle output (TailHeliRSC servo) to ramp from ground idle (RSC_IDLE) to flight idle throttle setting when motor interlock is enabled (throttle hold off). 134 : AP_Float _collective_yaw_scale; // Feed-forward compensation to automatically add rudder input when collective pitch is increased. Can be positive or negative depending on mechanics. 135 : AP_Float _yaw_trim; // Fixed offset applied to yaw output to reduce yaw I. 136 : };