2011-08-05 13:17:26 -03:00
|
|
|
// 2010 Jose Julio
|
|
|
|
// 2011 Adapted for AC2 by Jason Short
|
|
|
|
//
|
|
|
|
// Automatic Acrobatic Procedure (AAP) v1 : Roll flip
|
|
|
|
// State machine aproach:
|
|
|
|
// Some states are fixed commands (for a fixed time)
|
|
|
|
// Some states are fixed commands (until some IMU condition)
|
|
|
|
// Some states include controls inside
|
2011-09-21 03:20:33 -03:00
|
|
|
#if CH7_OPTION == CH7_FLIP
|
2011-08-05 13:17:26 -03:00
|
|
|
void roll_flip()
|
|
|
|
{
|
|
|
|
#define AAP_THR_INC 180
|
|
|
|
#define AAP_THR_DEC 90
|
2012-05-21 15:07:41 -03:00
|
|
|
#define AAP_ROLL_OUT 2000
|
2011-08-05 13:17:26 -03:00
|
|
|
#define AAP_ROLL_RATE 3000 // up to 1250
|
|
|
|
|
|
|
|
static int AAP_timer = 0;
|
|
|
|
static byte AAP_state = 0;
|
|
|
|
|
|
|
|
// Yaw
|
2011-09-21 03:20:33 -03:00
|
|
|
g.rc_4.servo_out = get_stabilize_yaw(nav_yaw);
|
2011-08-05 13:17:26 -03:00
|
|
|
// Pitch
|
|
|
|
g.rc_2.servo_out = get_stabilize_pitch(0);
|
|
|
|
|
|
|
|
// State machine
|
|
|
|
switch (AAP_state){
|
|
|
|
case 0: // Step 1 : Initialize
|
|
|
|
AAP_timer = 0;
|
|
|
|
AAP_state++;
|
|
|
|
break;
|
|
|
|
case 1: // Step 2 : Increase throttle to start maneuver
|
|
|
|
if (AAP_timer < 95){ // .5 seconds
|
|
|
|
g.rc_1.servo_out = get_stabilize_roll(0);
|
2011-09-25 16:21:54 -03:00
|
|
|
g.rc_3.servo_out = g.rc_3.control_in + AAP_THR_INC;
|
2011-08-05 13:17:26 -03:00
|
|
|
AAP_timer++;
|
|
|
|
}else{
|
|
|
|
AAP_state++;
|
|
|
|
AAP_timer = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2012-05-21 15:07:41 -03:00
|
|
|
case 2: // Step 3 : ROLL (until we reach a certain angle [45deg])
|
2011-08-05 13:17:26 -03:00
|
|
|
if (dcm.roll_sensor < 4500){
|
|
|
|
// Roll control
|
2012-05-21 15:07:41 -03:00
|
|
|
g.rc_1.servo_out = AAP_ROLL_OUT;
|
2011-09-25 16:21:54 -03:00
|
|
|
g.rc_3.servo_out = g.rc_3.control_in - AAP_THR_DEC;
|
2011-08-05 13:17:26 -03:00
|
|
|
}else{
|
|
|
|
AAP_state++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2012-05-21 15:07:41 -03:00
|
|
|
case 3: // Step 4 : CONTINUE ROLL (until we reach a certain angle [-45deg])
|
2011-08-05 13:17:26 -03:00
|
|
|
if ((dcm.roll_sensor >= 4500) || (dcm.roll_sensor < -4500)){
|
2012-05-21 15:07:41 -03:00
|
|
|
g.rc_1.servo_out = 0;
|
2011-09-25 16:21:54 -03:00
|
|
|
g.rc_3.servo_out = g.rc_3.control_in - AAP_THR_DEC;
|
2011-08-05 13:17:26 -03:00
|
|
|
}else{
|
|
|
|
AAP_state++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 4: // Step 5 : Increase throttle to stop the descend
|
|
|
|
if (AAP_timer < 90){ // .5 seconds
|
|
|
|
g.rc_1.servo_out = get_stabilize_roll(0);
|
2011-09-25 16:21:54 -03:00
|
|
|
g.rc_3.servo_out = g.rc_3.control_in + AAP_THR_INC;
|
2011-08-05 13:17:26 -03:00
|
|
|
AAP_timer++;
|
|
|
|
}else{
|
|
|
|
AAP_state++;
|
|
|
|
AAP_timer = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 5: // exit mode
|
2012-05-21 15:07:41 -03:00
|
|
|
AAP_timer = 0;
|
|
|
|
AAP_state = 0;
|
2011-08-05 13:17:26 -03:00
|
|
|
do_flip = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2011-08-05 14:09:27 -03:00
|
|
|
#endif
|