2015-07-22 10:46:53 -03:00
/// @file AP_MotorsHeli_Single.h
/// @brief Motor control class for traditional heli
2016-02-17 21:25:38 -04:00
# pragma once
2015-07-22 10:46:53 -03:00
2015-08-15 13:42:46 -03:00
# include <AP_Common/AP_Common.h>
# include <AP_Math/AP_Math.h> // ArduPilot Mega Vector/Matrix math Library
2017-01-03 05:56:57 -04:00
# include <SRV_Channel/SRV_Channel.h>
2015-07-22 10:46:53 -03:00
# include "AP_MotorsHeli.h"
# include "AP_MotorsHeli_RSC.h"
2019-01-12 00:17:15 -04:00
# include "AP_MotorsHeli_Swash.h"
2023-05-24 21:11:08 -03:00
# include "AP_Motors_Thrust_Linearization.h"
2015-07-22 10:46:53 -03:00
2021-02-07 14:30:05 -04:00
// rsc and extgyro function output channels.
2018-07-11 16:33:00 -03:00
# define AP_MOTORS_HELI_SINGLE_EXTGYRO CH_7
# define AP_MOTORS_HELI_SINGLE_TAILRSC CH_7
2015-07-22 10:46:53 -03:00
// tail types
2019-12-10 00:05:35 -04:00
# define AP_MOTORS_HELI_SINGLE_TAILTYPE_SERVO 0
# define AP_MOTORS_HELI_SINGLE_TAILTYPE_SERVO_EXTGYRO 1
# define AP_MOTORS_HELI_SINGLE_TAILTYPE_DIRECTDRIVE_VARPITCH 2
# define AP_MOTORS_HELI_SINGLE_TAILTYPE_DIRECTDRIVE_FIXEDPITCH_CW 3
# define AP_MOTORS_HELI_SINGLE_TAILTYPE_DIRECTDRIVE_FIXEDPITCH_CCW 4
2020-04-01 11:40:53 -03:00
# define AP_MOTORS_HELI_SINGLE_TAILTYPE_DIRECTDRIVE_VARPIT_EXT_GOV 5
2019-12-10 00:05:35 -04:00
2015-07-22 10:46:53 -03:00
2018-03-08 13:16:31 -04:00
// direct-drive variable pitch defaults
2019-08-07 23:52:17 -03:00
# define AP_MOTORS_HELI_SINGLE_DDVP_SPEED_DEFAULT 50
2015-07-22 10:46:53 -03:00
// default external gyro gain
# define AP_MOTORS_HELI_SINGLE_EXT_GYRO_GAIN 350
// COLYAW parameter min and max values
2022-12-21 20:53:04 -04:00
# define AP_MOTORS_HELI_SINGLE_COLYAW_RANGE 5.0f
2015-07-22 10:46:53 -03:00
2017-03-14 06:46:48 -03:00
// maximum number of swashplate servos
2018-04-01 20:19:52 -03:00
# define AP_MOTORS_HELI_SINGLE_NUM_SWASHPLATE_SERVOS 3
2017-03-14 06:46:48 -03:00
2015-07-22 10:46:53 -03:00
/// @class AP_MotorsHeli_Single
class AP_MotorsHeli_Single : public AP_MotorsHeli {
public :
// constructor
2022-12-06 21:03:36 -04:00
AP_MotorsHeli_Single ( uint16_t speed_hz = AP_MOTORS_HELI_SPEED_DEFAULT ) :
AP_MotorsHeli ( speed_hz ) ,
2019-01-12 00:17:15 -04:00
_tail_rotor ( SRV_Channel : : k_heli_tail_rsc , AP_MOTORS_HELI_SINGLE_TAILRSC ) ,
2023-05-04 20:41:08 -03:00
_swashplate ( AP_MOTORS_MOT_1 , AP_MOTORS_MOT_2 , AP_MOTORS_MOT_3 , AP_MOTORS_MOT_5 )
2015-07-22 10:46:53 -03:00
{
AP_Param : : setup_object_defaults ( this , var_info ) ;
} ;
// set update rate to motors - a value in hertz
2017-03-14 06:46:48 -03:00
void set_update_rate ( uint16_t speed_hz ) override ;
2015-07-22 10:46:53 -03:00
2018-12-28 02:32:05 -04:00
// output_to_motors - sends values out to the motors
void output_to_motors ( ) override ;
2016-02-03 04:59:44 -04:00
// set_desired_rotor_speed - sets target rotor speed as a number from 0 ~ 1
2017-03-14 06:46:48 -03:00
void set_desired_rotor_speed ( float desired_speed ) override ;
2015-07-22 10:46:53 -03:00
2015-08-12 12:41:40 -03:00
// calculate_scalars - recalculates various scalars used
2017-03-14 06:46:48 -03:00
void calculate_scalars ( ) override ;
2015-07-22 10:46:53 -03:00
2015-11-14 18:14:03 -04:00
// calculate_armed_scalars - recalculates scalars that can change while armed
2017-03-14 06:46:48 -03:00
void calculate_armed_scalars ( ) override ;
2018-03-08 13:16:31 -04:00
2015-07-22 10:46:53 -03:00
// get_motor_mask - returns a bitmask of which outputs are being used for motors or servos (1 means being used)
// this can be used to ensure other pwm outputs (i.e. for servos) do not conflict
2021-12-10 12:45:20 -04:00
uint32_t get_motor_mask ( ) override ;
2015-07-22 10:46:53 -03:00
2019-04-03 09:33:11 -03:00
// ext_gyro_gain - set external gyro gain in range 0 ~ 1000
2022-07-05 00:08:56 -03:00
void ext_gyro_gain ( float gain ) override { if ( gain > = 0 & & gain < = 1000 ) { _ext_gyro_gain_std . set ( gain ) ; } }
2015-07-22 10:46:53 -03:00
// has_flybar - returns true if we have a mechical flybar
2017-03-14 06:46:48 -03:00
bool has_flybar ( ) const override { return _flybar_mode ; }
2015-07-22 10:46:53 -03:00
// supports_yaw_passthrought - returns true if we support yaw passthrough
2017-03-14 06:46:48 -03:00
bool supports_yaw_passthrough ( ) const override { return _tail_type = = AP_MOTORS_HELI_SINGLE_TAILTYPE_SERVO_EXTGYRO ; }
2015-08-11 21:37:56 -03:00
2017-03-14 06:46:48 -03:00
void set_acro_tail ( bool set ) override { _acro_tail = set ; }
2015-10-21 17:00:36 -03:00
2023-07-18 17:16:48 -03:00
// Run arming checks
bool arming_checks ( size_t buflen , char * buffer ) const override ;
2018-03-08 13:16:31 -04:00
2023-05-24 21:11:08 -03:00
// Thrust Linearization handling
Thrust_Linearization thr_lin { * this } ;
2015-07-22 10:46:53 -03:00
// var_info
static const struct AP_Param : : GroupInfo var_info [ ] ;
protected :
2015-08-12 12:41:40 -03:00
// init_outputs - initialise Servo/PWM ranges and endpoints
2023-06-30 15:32:10 -03:00
void init_outputs ( ) override ;
2015-07-22 10:46:53 -03:00
2015-08-12 14:22:39 -03:00
// update_motor_controls - sends commands to motor controllers
2017-03-14 06:46:48 -03:00
void update_motor_control ( RotorControlState state ) override ;
2015-08-12 14:22:39 -03:00
2015-08-12 12:41:40 -03:00
// heli_move_actuators - moves swash plate and tail rotor
2017-03-14 06:46:48 -03:00
void move_actuators ( float roll_out , float pitch_out , float coll_in , float yaw_out ) override ;
2015-07-22 10:46:53 -03:00
2015-08-06 05:25:31 -03:00
// move_yaw - moves the yaw servo
2016-02-02 08:25:31 -04:00
void move_yaw ( float yaw_out ) ;
2015-08-06 05:25:31 -03:00
2023-05-24 21:11:08 -03:00
// calculate the motor output for DDFP tails from yaw_out
uint16_t calculate_ddfp_output ( float yaw_out ) ;
2016-02-03 01:37:54 -04:00
// servo_test - move servos through full range of movement
2017-03-14 06:46:48 -03:00
void servo_test ( ) override ;
2016-02-03 01:37:54 -04:00
2015-07-22 10:46:53 -03:00
// external objects we depend upon
AP_MotorsHeli_RSC _tail_rotor ; // tail rotor
2019-01-12 00:17:15 -04:00
AP_MotorsHeli_Swash _swashplate ; // swashplate
2015-07-22 10:46:53 -03:00
2015-10-30 14:38:04 -03:00
// internal variables
float _oscillate_angle = 0.0f ; // cyclic oscillation angle, used by servo_test function
float _servo_test_cycle_time = 0.0f ; // cycle time tracker, used by servo_test function
float _collective_test = 0.0f ; // over-ride for collective output, used by servo_test function
float _roll_test = 0.0f ; // over-ride for roll output, used by servo_test function
float _pitch_test = 0.0f ; // over-ride for pitch output, used by servo_test function
float _yaw_test = 0.0f ; // over-ride for yaw output, used by servo_test function
2018-12-28 02:32:05 -04:00
float _servo4_out = 0.0f ; // output value sent to motor
2023-05-24 21:11:08 -03:00
uint16_t _ddfp_pwm_min = 0 ; // minimum ddfp servo min
uint16_t _ddfp_pwm_max = 0 ; // minimum ddfp servo max
uint16_t _ddfp_pwm_trim = 0 ; // minimum ddfp servo trim
2015-10-30 14:38:04 -03:00
2015-07-22 10:46:53 -03:00
// parameters
AP_Int16 _tail_type ; // Tail type used: Servo, Servo with external gyro, direct drive variable pitch or direct drive fixed pitch
2015-08-09 08:02:54 -03:00
AP_Int16 _ext_gyro_gain_std ; // PWM sent to external gyro on ch7 when tail type is Servo w/ ExtGyro
AP_Int16 _ext_gyro_gain_acro ; // PWM sent to external gyro on ch7 when tail type is Servo w/ ExtGyro in ACRO
2015-07-22 10:46:53 -03:00
AP_Int8 _flybar_mode ; // Flybar present or not. Affects attitude controller used during ACRO flight mode
AP_Int16 _direct_drive_tailspeed ; // Direct Drive VarPitch Tail ESC speed (0 ~ 1000)
2022-12-21 20:53:04 -04:00
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.
2015-07-22 10:46:53 -03:00
2015-08-09 08:02:54 -03:00
bool _acro_tail = false ;
2015-07-22 10:46:53 -03:00
} ;