@ -106,6 +106,20 @@ const AP_Param::GroupInfo AP_MotorsMulticopter::var_info[] = {
@@ -106,6 +106,20 @@ const AP_Param::GroupInfo AP_MotorsMulticopter::var_info[] = {
// @User: Advanced
AP_GROUPINFO ( " PWM_TYPE " , 15 , AP_MotorsMulticopter , _pwm_type , PWM_TYPE_NORMAL ) ,
// @Param: PWM_MIN
// @DisplayName: PWM output miniumum
// @Description: This sets the min PWM output value that will ever be output to the motors, 0 = use input RC3_MIN
// @Range: 0 2000
// @User: Advanced
AP_GROUPINFO ( " PWM_MIN " , 16 , AP_MotorsMulticopter , _pwm_min , 0 ) ,
// @Param: PWM_MAX
// @DisplayName: PWM output maximum
// @Description: This sets the max PWM value that will ever be output to the motors, 0 = use input RC3_MAX
// @Range: 0 2000
// @User: Advanced
AP_GROUPINFO ( " PWM_MAX " , 17 , AP_MotorsMulticopter , _pwm_max , 0 ) ,
AP_GROUPEND
} ;
@ -114,10 +128,7 @@ AP_MotorsMulticopter::AP_MotorsMulticopter(uint16_t loop_rate, uint16_t speed_hz
@@ -114,10 +128,7 @@ AP_MotorsMulticopter::AP_MotorsMulticopter(uint16_t loop_rate, uint16_t speed_hz
AP_Motors ( loop_rate , speed_hz ) ,
_throttle_rpy_mix_desired ( AP_MOTORS_THR_LOW_CMP_DEFAULT ) ,
_throttle_rpy_mix ( AP_MOTORS_THR_LOW_CMP_DEFAULT ) ,
_min_throttle ( AP_MOTORS_DEFAULT_MIN_THROTTLE ) ,
_hover_out ( AP_MOTORS_DEFAULT_MID_THROTTLE ) ,
_throttle_radio_min ( 1100 ) ,
_throttle_radio_max ( 1900 ) ,
_batt_voltage_resting ( 0.0f ) ,
_batt_current_resting ( 0.0f ) ,
_batt_resistance ( 0.0f ) ,
@ -133,6 +144,9 @@ AP_MotorsMulticopter::AP_MotorsMulticopter(uint16_t loop_rate, uint16_t speed_hz
@@ -133,6 +144,9 @@ AP_MotorsMulticopter::AP_MotorsMulticopter(uint16_t loop_rate, uint16_t speed_hz
// setup battery voltage filtering
_batt_voltage_filt . set_cutoff_frequency ( AP_MOTORS_BATT_VOLT_FILT_HZ ) ;
_batt_voltage_filt . reset ( 1.0f ) ;
// default throttle ranges (i.e. _min_throttle, _throttle_radio_min, _throttle_radio_max)
set_throttle_range ( 130 , 1100 , 1900 ) ;
} ;
// output - sends commands to the motors
@ -314,17 +328,41 @@ float AP_MotorsMulticopter::get_compensation_gain() const
@@ -314,17 +328,41 @@ float AP_MotorsMulticopter::get_compensation_gain() const
int16_t AP_MotorsMulticopter : : calc_thrust_to_pwm ( float thrust_in ) const
{
return constrain_int16 ( ( _throttle_radio_min + _min_throttle + apply_thrust_curve_and_volt_scaling ( thrust_in ) *
( _throttle_radio_max - ( _throttle_radio_min + _min_throttle ) ) ) , _throttle_radio_min + _min_throttle , _throttle_radio_max ) ;
return constrain_int16 ( ( get_pwm_min ( ) + _min_throttle + apply_thrust_curve_and_volt_scaling ( thrust_in ) *
( get_pwm_max ( ) - ( get_pwm_min ( ) + _min_throttle ) ) ) , get_pwm_min ( ) + _min_throttle , get_pwm_max ( ) ) ;
}
// get minimum or maximum pwm value that can be output to motors
int16_t AP_MotorsMulticopter : : get_pwm_min ( ) const
{
// return _pwm_min if both PWM_MIN and PWM_MAX parmeters are defined and valid
if ( ( _pwm_min > 0 ) & & ( _pwm_max > 0 ) & & ( _pwm_max > _pwm_min ) ) {
return _pwm_min ;
}
return _throttle_radio_min ;
}
// get maximum pwm value that can be output to motors
int16_t AP_MotorsMulticopter : : get_pwm_max ( ) const
{
// return _pwm_max if both PWM_MIN and PWM_MAX parmeters are defined and valid
if ( ( _pwm_min > 0 ) & & ( _pwm_max > 0 ) & & ( _pwm_max > _pwm_min ) ) {
return _pwm_max ;
}
return _throttle_radio_max ;
}
// set_throttle_range - sets the minimum throttle that will be sent to the engines when they're not off (i.e. to prevents issues with some motors spinning and some not at very low throttle)
// also sets throttle channel minimum and maximum pwm
void AP_MotorsMulticopter : : set_throttle_range ( uint16_t min_throttle , int16_t radio_min , int16_t radio_max )
{
// sanity check
if ( ( radio_max > radio_min ) & & ( min_throttle < ( radio_max - radio_min ) ) ) {
_throttle_radio_min = radio_min ;
_throttle_radio_max = radio_max ;
_min_throttle = ( float ) min_throttle * ( ( _throttle_radio_max - _throttle_radio_min ) / 1000.0f ) ;
}
// update _min_throttle
_min_throttle = ( float ) min_throttle * ( ( get_pwm_max ( ) - get_pwm_min ( ) ) / 1000.0f ) ;
}
void AP_MotorsMulticopter : : output_logic ( )
@ -488,16 +526,17 @@ void AP_MotorsMulticopter::output_logic()
@@ -488,16 +526,17 @@ void AP_MotorsMulticopter::output_logic()
}
}
// throttle_pass_through - passes provided pwm directly to all motors - dangerous but used for initialising ESCs
// pwm value is an actual pwm value that will be output, normally in the range of 1000 ~ 2000
void AP_MotorsMulticopter : : throttle_pass_through ( int16_t pwm )
// passes throttle directly to all motors for ESC calibration.
// throttle_input is in the range of 0 ~ 1 where 0 will send get_pwm_min() and 1 will send get_pwm_max()
void AP_MotorsMulticopter : : set_throttle_passthrough_for_esc_calibration ( float throttle_input )
{
if ( armed ( ) ) {
uint16_t pwm_out = get_pwm_min ( ) + constrain_float ( throttle_input , 0.0f , 1.0f ) * ( get_pwm_max ( ) - get_pwm_min ( ) ) ;
// send the pilot's input directly to each enabled motor
hal . rcout - > cork ( ) ;
for ( uint16_t i = 0 ; i < AP_MOTORS_MAX_NUM_MOTORS ; i + + ) {
if ( motor_enabled [ i ] ) {
rc_write ( i , pwm ) ;
rc_write ( i , pwm_out ) ;
}
}
hal . rcout - > push ( ) ;
@ -516,7 +555,7 @@ void AP_MotorsMulticopter::output_motor_mask(float thrust, uint8_t mask)
@@ -516,7 +555,7 @@ void AP_MotorsMulticopter::output_motor_mask(float thrust, uint8_t mask)
if ( mask & ( 1U < < i ) ) {
motor_out = calc_thrust_to_pwm ( thrust ) ;
} else {
motor_out = _throttle_radio_min ;
motor_out = get_pwm_min ( ) ;
}
rc_write ( i , motor_out ) ;
}