TradHeli - allow user to enter GPS hold mode (and added safety so if user puts roll or pitch too far from center it comes out of GPS hold mode.
git-svn-id: https://arducopter.googlecode.com/svn/trunk@1229 f9c3cf11-9bcb-44bc-f272-b75c42450872
This commit is contained in:
parent
0b7fd432b5
commit
ab0e8262ce
@ -156,6 +156,9 @@ int roll_control_switch = 1;
|
|||||||
int pitch_control_switch = 1;
|
int pitch_control_switch = 1;
|
||||||
int yaw_control_switch = 1;
|
int yaw_control_switch = 1;
|
||||||
int collective_control_switch = 0;
|
int collective_control_switch = 0;
|
||||||
|
int position_control_switch = 0;
|
||||||
|
int position_control_engaged = 0; // we don't have enough buttons so we will turn this on and off with roll + pitch positions
|
||||||
|
int position_control_safety = 0; // if 0 then safety is off. if 1 then safety is on and position control will not operate
|
||||||
|
|
||||||
/// for sending values out to servos
|
/// for sending values out to servos
|
||||||
Vector3f ccpmPercents_out; // Array of ccpm input values, converted to percents
|
Vector3f ccpmPercents_out; // Array of ccpm input values, converted to percents
|
||||||
|
@ -164,7 +164,8 @@ void heli_setup()
|
|||||||
roll_control_switch = !SW_DIP1;
|
roll_control_switch = !SW_DIP1;
|
||||||
pitch_control_switch = !SW_DIP2;
|
pitch_control_switch = !SW_DIP2;
|
||||||
yaw_control_switch = !SW_DIP3;
|
yaw_control_switch = !SW_DIP3;
|
||||||
collective_control_switch = !SW_DIP4;
|
collective_control_switch = 0; //!SW_DIP4;
|
||||||
|
position_control_switch = !SW_DIP4; // switch 4 controls whether we will do GPS hold or not
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************************************/
|
/*****************************************************************************************************/
|
||||||
@ -208,17 +209,13 @@ void heli_read_radio_trims()
|
|||||||
trim_pitch = 0.0;
|
trim_pitch = 0.0;
|
||||||
if( trim_yaw > 50.0 || trim_yaw < -50.0 )
|
if( trim_yaw > 50.0 || trim_yaw < -50.0 )
|
||||||
trim_yaw = 0.0;
|
trim_yaw = 0.0;
|
||||||
|
|
||||||
//Serial.print("trim_yaw = " );
|
|
||||||
//Serial.print(trim_yaw);
|
|
||||||
//Serial.println();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**********************************************************************/
|
/**********************************************************************/
|
||||||
// Radio decoding
|
// Radio decoding
|
||||||
void heli_read_radio()
|
void heli_read_radio()
|
||||||
{
|
{
|
||||||
static int count = 0;
|
|
||||||
// left channel
|
// left channel
|
||||||
ccpmPercents.x = frontLeftCCPMslope * APM_RC.InputCh(CHANNEL_FRONT_LEFT) + frontLeftCCPMintercept;
|
ccpmPercents.x = frontLeftCCPMslope * APM_RC.InputCh(CHANNEL_FRONT_LEFT) + frontLeftCCPMintercept;
|
||||||
|
|
||||||
@ -240,7 +237,7 @@ void heli_read_radio()
|
|||||||
ch_collective = rollPitchCollPercent.z;
|
ch_collective = rollPitchCollPercent.z;
|
||||||
|
|
||||||
// allow a bit of a dead zone for the yaw
|
// allow a bit of a dead zone for the yaw
|
||||||
if( abs(yawPercent) < 2 )
|
if( fabs(yawPercent) < 2 )
|
||||||
ch_yaw = 0;
|
ch_yaw = 0;
|
||||||
else
|
else
|
||||||
ch_yaw = yawPercent;
|
ch_yaw = yawPercent;
|
||||||
@ -253,6 +250,34 @@ void heli_read_radio()
|
|||||||
|
|
||||||
// hardcode flight mode
|
// hardcode flight mode
|
||||||
flightMode = STABLE_MODE;
|
flightMode = STABLE_MODE;
|
||||||
|
|
||||||
|
// if position_control could be active
|
||||||
|
if( position_control_switch == 1 && position_control_safety == 0 ) {
|
||||||
|
|
||||||
|
//if roll or pitch ever > 40% or < -40% turn off autopilot
|
||||||
|
if( AP_mode == AP_AUTOMATIC_MODE && (fabs(ch_roll) >= 40 || fabs(ch_pitch) >= 40 )) {
|
||||||
|
position_control_safety = 1;
|
||||||
|
target_position = 0; // force it to reset to current position
|
||||||
|
Serial.println("autopilot OFF! safety!");
|
||||||
|
}
|
||||||
|
|
||||||
|
// switch on auto pilot if elevator goes over 50%
|
||||||
|
if( AP_mode == AP_NORMAL_MODE && ch_collective >= 50 ) {
|
||||||
|
AP_mode = AP_AUTOMATIC_MODE;
|
||||||
|
Serial.println("autopilot on!");
|
||||||
|
}
|
||||||
|
|
||||||
|
// switch off auto pilot if elevator goes below 20%
|
||||||
|
if( AP_mode == AP_AUTOMATIC_MODE && ch_collective <= 20 ) {
|
||||||
|
AP_mode = AP_NORMAL_MODE;
|
||||||
|
target_position = 0; // force it to reset to current position
|
||||||
|
Serial.println("autopilot off!");
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
AP_mode = AP_NORMAL_MODE;
|
||||||
|
}
|
||||||
|
// turn off AP_AUTOMATIC_MODE if roll or pitch is > 40% or < -40%
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**********************************************************************/
|
/**********************************************************************/
|
||||||
|
Loading…
Reference in New Issue
Block a user