|
|
|
@ -20,8 +20,8 @@
@@ -20,8 +20,8 @@
|
|
|
|
|
* Flip_Recover (while copter is between -90deg and original target angle) : use earth frame angle controller to return vehicle to original attitude |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
#define FLIP_THR_INC 200 // throttle increase during Flip_Start stage (under 45deg lean angle)
|
|
|
|
|
#define FLIP_THR_DEC 240 // throttle decrease during Flip_Roll stage (between 45deg ~ -90deg roll)
|
|
|
|
|
#define FLIP_THR_INC 0.20f // throttle increase during Flip_Start stage (under 45deg lean angle)
|
|
|
|
|
#define FLIP_THR_DEC 0.24f // throttle decrease during Flip_Roll stage (between 45deg ~ -90deg roll)
|
|
|
|
|
#define FLIP_ROTATION_RATE 40000 // rotation rate request in centi-degrees / sec (i.e. 400 deg/sec)
|
|
|
|
|
#define FLIP_TIMEOUT_MS 2500 // timeout after 2.5sec. Vehicle will switch back to original flight mode
|
|
|
|
|
#define FLIP_RECOVERY_ANGLE 500 // consider successful recovery when roll is back within 5 degrees of original
|
|
|
|
@ -34,7 +34,6 @@
@@ -34,7 +34,6 @@
|
|
|
|
|
|
|
|
|
|
FlipState flip_state; // current state of flip
|
|
|
|
|
control_mode_t flip_orig_control_mode; // flight mode when flip was initated
|
|
|
|
|
mode_reason_t flip_orig_control_mode_reason; |
|
|
|
|
uint32_t flip_start_time; // time since flip began
|
|
|
|
|
int8_t flip_roll_dir; // roll direction (-1 = roll left, 1 = roll right)
|
|
|
|
|
int8_t flip_pitch_dir; // pitch direction (-1 = pitch forward, 1 = pitch back)
|
|
|
|
@ -64,7 +63,6 @@ bool Sub::flip_init(bool ignore_checks)
@@ -64,7 +63,6 @@ bool Sub::flip_init(bool ignore_checks)
|
|
|
|
|
|
|
|
|
|
// capture original flight mode so that we can return to it after completion
|
|
|
|
|
flip_orig_control_mode = control_mode; |
|
|
|
|
flip_orig_control_mode_reason = control_mode_reason; |
|
|
|
|
|
|
|
|
|
// initialise state
|
|
|
|
|
flip_state = Flip_Start; |
|
|
|
@ -145,9 +143,7 @@ void Sub::flip_run()
@@ -145,9 +143,7 @@ void Sub::flip_run()
|
|
|
|
|
// between 45deg ~ -90deg request 400deg/sec roll
|
|
|
|
|
attitude_control.input_rate_bf_roll_pitch_yaw(FLIP_ROTATION_RATE * flip_roll_dir, 0.0, 0.0); |
|
|
|
|
// decrease throttle
|
|
|
|
|
if (throttle_out >= g.throttle_min) { |
|
|
|
|
throttle_out = MAX(throttle_out - FLIP_THR_DEC, g.throttle_min); |
|
|
|
|
} |
|
|
|
|
throttle_out = MAX(throttle_out - FLIP_THR_DEC, 0.0f); |
|
|
|
|
|
|
|
|
|
// beyond -90deg move on to recovery
|
|
|
|
|
if ((flip_angle < 4500) && (flip_angle > -9000)) { |
|
|
|
@ -157,11 +153,9 @@ void Sub::flip_run()
@@ -157,11 +153,9 @@ void Sub::flip_run()
|
|
|
|
|
|
|
|
|
|
case Flip_Pitch_A: |
|
|
|
|
// between 45deg ~ -90deg request 400deg/sec pitch
|
|
|
|
|
attitude_control.input_rate_bf_roll_pitch_yaw(0.0, FLIP_ROTATION_RATE * flip_pitch_dir, 0.0); |
|
|
|
|
attitude_control.input_rate_bf_roll_pitch_yaw(0.0f, FLIP_ROTATION_RATE * flip_pitch_dir, 0.0); |
|
|
|
|
// decrease throttle
|
|
|
|
|
if (throttle_out >= g.throttle_min) { |
|
|
|
|
throttle_out = MAX(throttle_out - FLIP_THR_DEC, g.throttle_min); |
|
|
|
|
} |
|
|
|
|
throttle_out = MAX(throttle_out - FLIP_THR_DEC, 0.0f); |
|
|
|
|
|
|
|
|
|
// check roll for inversion
|
|
|
|
|
if ((labs(ahrs.roll_sensor) > 9000) && (flip_angle > 4500)) { |
|
|
|
@ -173,9 +167,7 @@ void Sub::flip_run()
@@ -173,9 +167,7 @@ void Sub::flip_run()
|
|
|
|
|
// between 45deg ~ -90deg request 400deg/sec pitch
|
|
|
|
|
attitude_control.input_rate_bf_roll_pitch_yaw(0.0, FLIP_ROTATION_RATE * flip_pitch_dir, 0.0); |
|
|
|
|
// decrease throttle
|
|
|
|
|
if (throttle_out >= g.throttle_min) { |
|
|
|
|
throttle_out = MAX(throttle_out - FLIP_THR_DEC, g.throttle_min); |
|
|
|
|
} |
|
|
|
|
throttle_out = MAX(throttle_out - FLIP_THR_DEC, 0.0f); |
|
|
|
|
|
|
|
|
|
// check roll for inversion
|
|
|
|
|
if ((labs(ahrs.roll_sensor) < 9000) && (flip_angle > -4500)) { |
|
|
|
@ -201,7 +193,7 @@ void Sub::flip_run()
@@ -201,7 +193,7 @@ void Sub::flip_run()
|
|
|
|
|
// check for successful recovery
|
|
|
|
|
if (fabsf(recovery_angle) <= FLIP_RECOVERY_ANGLE) { |
|
|
|
|
// restore original flight mode
|
|
|
|
|
if (!set_mode(flip_orig_control_mode, flip_orig_control_mode_reason)) { |
|
|
|
|
if (!set_mode(flip_orig_control_mode, MODE_REASON_FLIP_COMPLETE)) { |
|
|
|
|
// this should never happen but just in case
|
|
|
|
|
set_mode(STABILIZE, MODE_REASON_UNKNOWN); |
|
|
|
|
} |
|
|
|
@ -212,7 +204,7 @@ void Sub::flip_run()
@@ -212,7 +204,7 @@ void Sub::flip_run()
|
|
|
|
|
|
|
|
|
|
case Flip_Abandon: |
|
|
|
|
// restore original flight mode
|
|
|
|
|
if (!set_mode(flip_orig_control_mode, flip_orig_control_mode_reason)) { |
|
|
|
|
if (!set_mode(flip_orig_control_mode, MODE_REASON_FLIP_COMPLETE)) { |
|
|
|
|
// this should never happen but just in case
|
|
|
|
|
set_mode(STABILIZE, MODE_REASON_UNKNOWN); |
|
|
|
|
} |
|
|
|
@ -222,9 +214,5 @@ void Sub::flip_run()
@@ -222,9 +214,5 @@ void Sub::flip_run()
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// output pilot's throttle without angle boost
|
|
|
|
|
if (is_zero(throttle_out)) { |
|
|
|
|
attitude_control.set_throttle_out_unstabilized(0,false,g.throttle_filt); |
|
|
|
|
} else { |
|
|
|
|
attitude_control.set_throttle_out(throttle_out, false, g.throttle_filt); |
|
|
|
|
} |
|
|
|
|
attitude_control.set_throttle_out(throttle_out, false, g.throttle_filt); |
|
|
|
|
} |
|
|
|
|