boolean failsafe; // did our throttle dip below the failsafe value?
boolean ch3_failsafe;
boolean motor_armed;
boolean motor_auto_safe;
// PIDs
// ----
int max_stabilize_dampener; //
int max_yaw_dampener; //
boolean rate_yaw_flag; // used to transition yaw control from Rate control to Yaw hold
@ -209,8 +225,6 @@ boolean rate_yaw_flag; // used to transition yaw control from Rate control
@@ -209,8 +225,6 @@ boolean rate_yaw_flag; // used to transition yaw control from Rate control
boolean motor_light; // status of the Motor safety
boolean GPS_light; // status of the GPS light
float nav_gain_scaler = 1; // Gain scaling for headwind/tailwind TODO: why does this variable need to be initialized to 1?
// GPS variables
// -------------
const float t7 = 10000000.0; // used to scale GPS values for EEPROM storage
@ -218,51 +232,41 @@ float scaleLongUp = 1; // used to reverse longtitude scaling
@@ -218,51 +232,41 @@ float scaleLongUp = 1; // used to reverse longtitude scaling
float scaleLongDown = 1; // used to reverse longtitude scaling
byte ground_start_count = 5; // have we achieved first lock and set Home?
// Magnetometer variables
// ----------------------
Vector3f mag_offsets;
// Location & Navigation
// ---------------------
const float radius_of_earth = 6378100; // meters
const float gravity = 9.81; // meters/ sec^2
//byte wp_radius = 3; // meters
const float radius_of_earth = 6378100; // meters
const float gravity = 9.81; // meters/ sec^2
long nav_bearing; // deg * 100 : 0 to 360 current desired bearing to navigate
long target_bearing; // deg * 100 : 0 to 360 location of the plane to the target
long crosstrack_bearing; // deg * 100 : 0 to 360 desired angle of plane to target
int climb_rate; // m/s * 100 - For future implementation of controlled ascent/descent by rate
long target_bearing; // deg * 100 : 0 to 360 location of the plane to the target
long crosstrack_bearing; // deg * 100 : 0 to 360 desired angle of plane to target
int climb_rate; // m/s * 100 - For future implementation of controlled ascent/descent by rate
float nav_gain_scaler = 1; // Gain scaling for headwind/tailwind TODO: why does this variable need to be initialized to 1?
byte command_must_index; // current command memory location
byte command_may_index; // current command memory location
byte command_must_ID; // current command ID
byte command_may_ID; // current command ID
float cos_roll_x, sin_roll_y;
float cos_pitch_x, sin_pitch_y;
float sin_yaw_y, cos_yaw_x;
float cos_roll_x = 1;
float cos_pitch_x = 1;
float cos_yaw_x = 1;
float sin_pitch_y, sin_yaw_y, sin_roll_y;
// Airspeed
// --------
int airspeed; // m/s * 100
float airspeed_error; // m / s * 100
// Throttle Failsafe
// ------------------
boolean motor_armed = false;
boolean motor_auto_safe = false;
int airspeed; // m/s * 100
// Location Errors
// ---------------
long bearing_error; // deg * 100 : 0 to 36000
long altitude_error; // meters * 100 we are off in altitude
long bearing_error; // deg * 100 : 0 to 36000
long altitude_error; // meters * 100 we are off in altitude
float crosstrack_error; // meters we are off trackline
long distance_error; // distance to the WP
long yaw_error; // how off are we pointed
long long_error, lat_error; // temp for debugging
long long_error, lat_error; // temp fro debugging
// Sensors
// -------
// Battery Sensors
// ---------------
float battery_voltage = LOW_VOLTAGE * 1.05; // Battery Voltage of total battery, initialized above threshold for filter
float battery_voltage1 = LOW_VOLTAGE * 1.05; // Battery Voltage of cell 1, initialized above threshold for filter
float battery_voltage2 = LOW_VOLTAGE * 1.05; // Battery Voltage of cells 1 + 2, initialized above threshold for filter
@ -272,19 +276,9 @@ float battery_voltage4 = LOW_VOLTAGE * 1.05; // Battery Voltage of cells 1 +
@@ -272,19 +276,9 @@ float battery_voltage4 = LOW_VOLTAGE * 1.05; // Battery Voltage of cells 1 +
float current_voltage = LOW_VOLTAGE * 1.05; // Battery Voltage of cells 1 + 2+3 + 4, initialized above threshold for filter
float current_amps;
float current_total;
//int milliamp_hours;
//boolean current_enabled = false;
// Magnetometer variables
// ----------------------
//int magnetom_x;
//int magnetom_y;
//int magnetom_z;
//float mag_offset_x;
//float mag_offset_y;
//float mag_offset_z;
//float mag_declination;
// Airspeed Sensors
// ----------------
// Barometer Sensor variables
// --------------------------
@ -292,20 +286,18 @@ unsigned long abs_pressure;
@@ -292,20 +286,18 @@ unsigned long abs_pressure;
unsigned long ground_pressure;
int ground_temperature;
byte altitude_sensor = BARO; // used to know which sensor is active, BARO or SONAR
// Sonar Sensor variables
// Altitude Sensor variables
// ----------------------
long sonar_alt;
long baro_alt;
byte altitude_sensor = BARO; // used to know which sensor is active, BARO or SONAR
// flight mode specific
// --------------------
boolean takeoff_complete = false; // Flag for using take-off controls
boolean land_complete = false;
int takeoff_altitude;
int landing_distance; // meters;
boolean takeoff_complete; // Flag for using take-off controls
boolean land_complete;
int takeoff_altitude;
int landing_distance; // meters;
long old_alt; // used for managing altitude rates
int velocity_land;
@ -320,13 +312,13 @@ int loiter_time_max; // millis : how long to stay in LOITER mode
@@ -320,13 +312,13 @@ int loiter_time_max; // millis : how long to stay in LOITER mode
// these are the values for navigation control functions
//long GPS_wp_distance; // meters - distance between plane and next waypoint
long wp_distance; // meters - distance between plane and next waypoint
long wp_totalDistance; // meters - distance between old and next waypoint
//byte wp_total; // # of Commands total including way
//byte wp_index; // Current active command index
byte next_wp_index; // Current active command index
long wp_distance; // meters - distance between plane and next waypoint
long wp_totalDistance; // meters - distance between old and next waypoint
byte next_wp_index; // Current active command index
// repeating event control
// -----------------------
@ -376,14 +365,14 @@ boolean home_is_set; // Flag for if we have g_gps lock and have set the ho
@@ -376,14 +365,14 @@ boolean home_is_set; // Flag for if we have g_gps lock and have set the ho
// IMU variables
// -------------
float G_Dt = 0.02; // Integration time for the gyros (DCM algorithm)
float G_Dt = 0.02; // Integration time for the gyros (DCM algorithm)
// Performance monitoring
// ----------------------
long perf_mon_timer;
float imu_health; // Metric based on accel gain deweighting
int G_Dt_max; // Max main loop cycle time in milliseconds
float imu_health; // Metric based on accel gain deweighting
int G_Dt_max; // Max main loop cycle time in milliseconds
char display_PID = -1; // Flag used by DebugTerminal to indicate that the next PID calculation with this index should be displayed
char display_PID = -1; // Flag used by DebugTerminal to indicate that the next PID calculation with this index should be displayed
// System Timers
// --------------
@ -415,12 +404,12 @@ byte fbw_timer; // for limiting the execution of FBW input
@@ -415,12 +404,12 @@ byte fbw_timer; // for limiting the execution of FBW input
unsigned long nav_loopTimer; // used to track the elapsed ime for GPS nav
unsigned long nav2_loopTimer; // used to track the elapsed ime for GPS nav
unsigned long dTnav; // Delta Time in milliseconds for navigation computations
unsigned long dTnav2; // Delta Time in milliseconds for navigation computations
unsigned long elapsedTime; // for doing custom events