@ -108,8 +108,10 @@ void AP_MotorsMatrix::output_armed()
@@ -108,8 +108,10 @@ void AP_MotorsMatrix::output_armed()
int16_t yaw_allowed ; // amount of yaw we can fit in
int16_t thr_adj ; // how far we move the throttle point from out_max_range
// initialize reached_limit flag
_reached_limit = AP_MOTOR_NO_LIMITS_REACHED ;
// initialize limits flag
limit . roll_pitch = false ;
limit . yaw = false ;
limit . throttle = false ;
// Throttle is 0 to 1000 only
// To-Do: we should not really be limiting this here because we don't "own" this _rc_throttle object
@ -138,13 +140,15 @@ void AP_MotorsMatrix::output_armed()
@@ -138,13 +140,15 @@ void AP_MotorsMatrix::output_armed()
}
// Every thing is limited
_reached_limit | = AP_MOTOR_ROLLPITCH_LIMIT | AP_MOTOR_YAW_LIMIT | AP_MOTOR_THROTTLE_LIMIT ;
limit . roll_pitch = true ;
limit . yaw = true ;
limit . throttle = true ;
} else {
// check if throttle is below limit
if ( _rc_throttle - > radio_out < out_min ) {
_reached_limit | = AP_MOTOR_THROTTLE_LIMIT ;
limit . throttle = true ;
}
// calculate roll and pitch for each motor
@ -181,7 +185,7 @@ void AP_MotorsMatrix::output_armed()
@@ -181,7 +185,7 @@ void AP_MotorsMatrix::output_armed()
if ( yaw_allowed > _rc_yaw - > pwm_out ) {
yaw_allowed = _rc_yaw - > pwm_out ; // to-do: this is bad form for yaw_allows to change meaning to become the amount that we are going to output
} else {
_reached_limit | = AP_MOTOR_YAW_LIMIT ;
limit . yaw = true ;
}
} else {
// if yawing left
@ -189,7 +193,7 @@ void AP_MotorsMatrix::output_armed()
@@ -189,7 +193,7 @@ void AP_MotorsMatrix::output_armed()
if ( yaw_allowed < _rc_yaw - > pwm_out ) {
yaw_allowed = _rc_yaw - > pwm_out ; // to-do: this is bad form for yaw_allows to change meaning to become the amount that we are going to output
} else {
_reached_limit | = AP_MOTOR_YAW_LIMIT ;
limit . yaw = true ;
}
}
@ -219,7 +223,7 @@ void AP_MotorsMatrix::output_armed()
@@ -219,7 +223,7 @@ void AP_MotorsMatrix::output_armed()
if ( thr_adj > out_max - ( rpy_high + out_max_range ) ) {
thr_adj = out_max - ( rpy_high + out_max_range ) ;
// we haven't even been able to apply full throttle command
_reached_limit | = AP_MOTOR_THROTTLE_LIMIT ;
limit . throttle = true ;
}
} else if ( thr_adj < 0 ) {
// decrease throttle as close as possible to requested throttle
@ -233,11 +237,13 @@ void AP_MotorsMatrix::output_armed()
@@ -233,11 +237,13 @@ void AP_MotorsMatrix::output_armed()
if ( ( rpy_low + out_max_range ) + thr_adj < out_min ) {
rpy_scale = ( float ) ( out_min - thr_adj - out_max_range ) / rpy_low ;
// we haven't even been able to apply full roll, pitch and minimal yaw without scaling
_reached_limit | = AP_MOTOR_ROLLPITCH_LIMIT | AP_MOTOR_YAW_LIMIT ;
limit . roll_pitch = true ;
limit . yaw = true ;
} else if ( ( rpy_high + out_max_range ) + thr_adj > out_max ) {
rpy_scale = ( float ) ( out_max - thr_adj - out_max_range ) / rpy_high ;
// we haven't even been able to apply full roll, pitch and minimal yaw without scaling
_reached_limit | = AP_MOTOR_ROLLPITCH_LIMIT | AP_MOTOR_YAW_LIMIT ;
limit . roll_pitch = true ;
limit . yaw = true ;
}
// add scaled roll, pitch, constrained yaw and throttle for each motor
@ -284,8 +290,10 @@ void AP_MotorsMatrix::output_armed()
@@ -284,8 +290,10 @@ void AP_MotorsMatrix::output_armed()
int16_t motor_adjustment = 0 ;
int16_t yaw_to_execute = 0 ;
// initialize reached_limit flag
_reached_limit = AP_MOTOR_NO_LIMITS_REACHED ;
// initialize limits flag
limit . roll_pitch = false ;
limit . yaw = false ;
limit . throttle = false ;
// Throttle is 0 to 1000 only
_rc_throttle - > servo_out = constrain_int16 ( _rc_throttle - > servo_out , 0 , _max_throttle ) ;
@ -305,10 +313,10 @@ void AP_MotorsMatrix::output_armed()
@@ -305,10 +313,10 @@ void AP_MotorsMatrix::output_armed()
}
// if we have any roll, pitch or yaw input then it's breaching the limit
if ( _rc_roll - > pwm_out ! = 0 | | _rc_pitch - > pwm_out ! = 0 ) {
_reached_limit | = AP_MOTOR_ROLLPITCH_LIMIT ;
limit . roll_pitch = true ;
}
if ( _rc_yaw - > pwm_out ! = 0 ) {
_reached_limit | = AP_MOTOR_YAW_LIMIT ;
limit . yaw = true ;
}
} else { // non-zero throttle
@ -375,7 +383,9 @@ void AP_MotorsMatrix::output_armed()
@@ -375,7 +383,9 @@ void AP_MotorsMatrix::output_armed()
}
// we haven't even been able to apply roll, pitch and minimal yaw without adjusting throttle so mark all limits as breached
_reached_limit | = AP_MOTOR_ROLLPITCH_LIMIT | AP_MOTOR_YAW_LIMIT | AP_MOTOR_THROTTLE_LIMIT ;
limit . roll_pitch = true ;
limit . yaw = true ;
limit . throttle = true ;
}
// if we didn't give all the yaw requested, calculate how much additional yaw we can add
@ -424,7 +434,7 @@ void AP_MotorsMatrix::output_armed()
@@ -424,7 +434,7 @@ void AP_MotorsMatrix::output_armed()
}
// mark yaw limit reached if we didn't get everything we asked for
if ( yaw_to_execute ! = rc_yaw_excess ) {
_reached_limit | = AP_MOTOR_YAW_LIMIT ;
limit . yaw = true ;
}
}