Browse Source

Added FlyByWire mode. Simulates Position hold using the control sticks. Untested. Reset your "modes" in setup CLI before flying this code.

git-svn-id: https://arducopter.googlecode.com/svn/trunk@1278 f9c3cf11-9bcb-44bc-f272-b75c42450872
mission-4.1.18
jasonshort 14 years ago
parent
commit
d4c3574a88
  1. 60
      ArduCopterMega/ArduCopterMega.pde
  2. 13
      ArduCopterMega/defines.h

60
ArduCopterMega/ArduCopterMega.pde

@ -86,6 +86,7 @@ byte control_mode = STABILIZE;
boolean failsafe = false; // did our throttle dip below the failsafe value? boolean failsafe = false; // did our throttle dip below the failsafe value?
boolean ch3_failsafe = false; boolean ch3_failsafe = false;
byte oldSwitchPosition; // for remembering the control mode switch byte oldSwitchPosition; // for remembering the control mode switch
byte fbw_timer; // for limiting the execution of FBW input
const char *comma = ","; const char *comma = ",";
@ -94,6 +95,7 @@ const char* flight_mode_strings[] = {
"ACRO", "ACRO",
"STABILIZE", "STABILIZE",
"ALT_HOLD", "ALT_HOLD",
"FBW",
"AUTO", "AUTO",
"POSITION_HOLD", "POSITION_HOLD",
"RTL", "RTL",
@ -736,9 +738,6 @@ void update_current_flight_mode(void)
// perform stabilzation // perform stabilzation
output_stabilize(); output_stabilize();
// hold yaw
//output_yaw_hold();
// apply throttle control // apply throttle control
output_auto_throttle(); output_auto_throttle();
break; break;
@ -754,17 +753,59 @@ void update_current_flight_mode(void)
// clear any AP naviagtion values // clear any AP naviagtion values
nav_pitch = 0; nav_pitch = 0;
nav_roll = 0; nav_roll = 0;
// get desired yaw control from radio
input_yaw_hold();
// Output Pitch, Roll, Yaw and Throttle
// ------------------------------------
// apply throttle control
output_manual_throttle();
// perform stabilzation
output_stabilize();
break;
case FBW:
// we are currently using manual throttle for testing.
fbw_timer++;
//call at 5 hz
if(fbw_timer > 20){
fbw_timer = 0;
current_loc.lat = 0;
current_loc.lng = 0;
next_WP.lat = rc_1.control_in /5; // 10 meteres
next_WP.lng = -rc_2.control_in /5; // 10 meteres
// waypoint distance from plane
// ----------------------------
wp_distance = GPS_wp_distance = getDistance(&current_loc, &next_WP);
// target_bearing is where we should be heading
// --------------------------------------------
nav_bearing = target_bearing = get_bearing(&current_loc, &next_WP);
// not really needed
//update_navigation();
}
// Intput Pitch, Roll, Yaw and Throttle
// ------------------------------------
calc_nav_pid();
calc_nav_roll();
calc_nav_pitch();
// get desired yaw control from radio // get desired yaw control from radio
input_yaw_hold(); input_yaw_hold();
// Output Pitch, Roll, Yaw and Throttle // Output Pitch, Roll, Yaw and Throttle
// ------------------------------------ // ------------------------------------
// apply throttle control // apply throttle control
output_manual_throttle(); output_manual_throttle();
// hold yaw
//output_yaw_hold();
// perform stabilzation // perform stabilzation
output_stabilize(); output_stabilize();
@ -793,9 +834,6 @@ void update_current_flight_mode(void)
// apply throttle control // apply throttle control
output_auto_throttle(); output_auto_throttle();
// hold yaw
//output_yaw_hold();
// perform stabilzation // perform stabilzation
output_stabilize(); output_stabilize();
break; break;
@ -816,9 +854,6 @@ void update_current_flight_mode(void)
// apply throttle control // apply throttle control
output_auto_throttle(); output_auto_throttle();
// hold yaw
//output_yaw_hold();
// perform stabilzation // perform stabilzation
output_stabilize(); output_stabilize();
break; break;
@ -843,9 +878,6 @@ void update_current_flight_mode(void)
// apply throttle control // apply throttle control
output_auto_throttle(); output_auto_throttle();
// hold yaw
//output_yaw_hold();
// perform stabilzation // perform stabilzation
output_stabilize(); output_stabilize();
break; break;

13
ArduCopterMega/defines.h

@ -74,12 +74,13 @@
#define ACRO 0 // rate control #define ACRO 0 // rate control
#define STABILIZE 1 // hold level position #define STABILIZE 1 // hold level position
#define ALT_HOLD 2 // AUTO control #define ALT_HOLD 2 // AUTO control
#define AUTO 3 // AUTO control #define FBW 3 // AUTO control
#define POSITION_HOLD 4 // Hold a single location #define AUTO 4 // AUTO control
#define RTL 5 // AUTO control #define POSITION_HOLD 5 // Hold a single location
#define TAKEOFF 6 // controlled decent rate #define RTL 6 // AUTO control
#define LAND 7 // controlled decent rate #define TAKEOFF 7 // controlled decent rate
#define NUM_MODES 8 #define LAND 8 // controlled decent rate
#define NUM_MODES 9
// Command IDs - Must // Command IDs - Must
#define CMD_BLANK 0x00 // there is no command stored in the mem location requested #define CMD_BLANK 0x00 // there is no command stored in the mem location requested

Loading…
Cancel
Save