2011-02-17 03:09:13 -04:00
|
|
|
// -*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: t -*-
|
|
|
|
// ************************************************************************************
|
|
|
|
// This function gets critical data from EEPROM to get us underway if restarting in air
|
|
|
|
// ************************************************************************************
|
|
|
|
|
|
|
|
// Macro functions
|
|
|
|
// ---------------
|
2011-02-18 23:59:58 -04:00
|
|
|
/*void read_EEPROM_startup(void)
|
2011-02-17 03:09:13 -04:00
|
|
|
{
|
|
|
|
read_EEPROM_PID();
|
|
|
|
read_EEPROM_frame();
|
|
|
|
read_EEPROM_throttle();
|
|
|
|
read_EEPROM_logs();
|
|
|
|
read_EEPROM_flight_modes();
|
|
|
|
read_EEPROM_waypoint_info();
|
2011-02-18 23:59:58 -04:00
|
|
|
//imu.load_gyro_eeprom();
|
|
|
|
//imu.load_accel_eeprom();
|
2011-02-17 03:09:13 -04:00
|
|
|
read_EEPROM_alt_RTL();
|
|
|
|
read_EEPROM_current();
|
|
|
|
read_EEPROM_nav();
|
|
|
|
// magnatometer
|
|
|
|
read_EEPROM_compass();
|
2011-02-18 23:59:58 -04:00
|
|
|
//read_EEPROM_compass_declination();
|
2011-02-17 03:09:13 -04:00
|
|
|
read_EEPROM_compass_offset();
|
|
|
|
}
|
2011-02-18 23:59:58 -04:00
|
|
|
*/
|
2011-02-17 03:09:13 -04:00
|
|
|
|
|
|
|
|
|
|
|
/********************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
/********************************************************************************/
|
|
|
|
|
|
|
|
void save_EEPROM_alt_RTL(void)
|
|
|
|
{
|
2011-02-18 23:59:58 -04:00
|
|
|
g.RTL_altitude.save();
|
2011-02-19 22:03:01 -04:00
|
|
|
|
2011-02-17 03:09:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void read_EEPROM_alt_RTL(void)
|
|
|
|
{
|
2011-02-18 23:59:58 -04:00
|
|
|
g.RTL_altitude.load();
|
2011-02-17 03:09:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************************************************/
|
|
|
|
|
|
|
|
void read_EEPROM_waypoint_info(void)
|
|
|
|
{
|
2011-02-18 23:59:58 -04:00
|
|
|
g.waypoint_total.load();
|
|
|
|
g.waypoint_radius.load();
|
|
|
|
g.loiter_radius.load();
|
2011-02-17 03:09:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void save_EEPROM_waypoint_info(void)
|
|
|
|
{
|
2011-02-18 23:59:58 -04:00
|
|
|
g.waypoint_total.save();
|
|
|
|
g.waypoint_radius.save();
|
|
|
|
g.loiter_radius.save();
|
2011-02-17 03:09:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************************************************/
|
|
|
|
|
|
|
|
void read_EEPROM_nav(void)
|
|
|
|
{
|
2011-02-18 23:59:58 -04:00
|
|
|
g.crosstrack_gain.load();
|
|
|
|
g.crosstrack_entry_angle.load();
|
|
|
|
g.pitch_max.load();
|
2011-02-17 03:09:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void save_EEPROM_nav(void)
|
|
|
|
{
|
2011-02-18 23:59:58 -04:00
|
|
|
g.crosstrack_gain.save();
|
|
|
|
g.crosstrack_entry_angle.save();
|
|
|
|
g.pitch_max.save();
|
2011-02-17 03:09:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************************************************/
|
|
|
|
|
|
|
|
void read_EEPROM_PID(void)
|
|
|
|
{
|
|
|
|
g.pid_acro_rate_roll.load_gains();
|
|
|
|
g.pid_acro_rate_pitch.load_gains();
|
|
|
|
g.pid_acro_rate_yaw.load_gains();
|
2011-02-19 22:03:01 -04:00
|
|
|
|
2011-02-17 03:09:13 -04:00
|
|
|
g.pid_stabilize_roll.load_gains();
|
|
|
|
g.pid_stabilize_pitch.load_gains();
|
|
|
|
g.pid_yaw.load_gains();
|
2011-02-19 22:03:01 -04:00
|
|
|
|
2011-02-17 03:09:13 -04:00
|
|
|
g.pid_nav_lon.load_gains();
|
|
|
|
g.pid_nav_lat.load_gains();
|
|
|
|
g.pid_baro_throttle.load_gains();
|
|
|
|
g.pid_sonar_throttle.load_gains();
|
2011-02-19 22:03:01 -04:00
|
|
|
|
2011-02-17 03:09:13 -04:00
|
|
|
// roll pitch
|
2011-02-18 23:59:58 -04:00
|
|
|
g.stabilize_dampener.load();
|
2011-02-17 03:09:13 -04:00
|
|
|
|
|
|
|
// yaw
|
2011-02-18 23:59:58 -04:00
|
|
|
g.hold_yaw_dampener.load();
|
2011-02-17 03:09:13 -04:00
|
|
|
init_pids();
|
|
|
|
}
|
|
|
|
|
|
|
|
void save_EEPROM_PID(void)
|
|
|
|
{
|
2011-02-19 22:03:01 -04:00
|
|
|
|
|
|
|
g.pid_acro_rate_roll.save_gains();
|
2011-02-17 03:09:13 -04:00
|
|
|
g.pid_acro_rate_pitch.save_gains();
|
|
|
|
g.pid_acro_rate_yaw.save_gains();
|
2011-02-19 22:03:01 -04:00
|
|
|
|
2011-02-17 03:09:13 -04:00
|
|
|
g.pid_stabilize_roll.save_gains();
|
|
|
|
g.pid_stabilize_pitch.save_gains();
|
|
|
|
g.pid_yaw.save_gains();
|
2011-02-19 22:03:01 -04:00
|
|
|
|
2011-02-17 03:09:13 -04:00
|
|
|
g.pid_nav_lon.save_gains();
|
|
|
|
g.pid_nav_lat.save_gains();
|
|
|
|
g.pid_baro_throttle.save_gains();
|
|
|
|
g.pid_sonar_throttle.save_gains();
|
|
|
|
|
|
|
|
// roll pitch
|
2011-02-18 23:59:58 -04:00
|
|
|
g.stabilize_dampener.save();
|
2011-02-17 03:09:13 -04:00
|
|
|
// yaw
|
2011-02-18 23:59:58 -04:00
|
|
|
g.hold_yaw_dampener.save();
|
2011-02-17 03:09:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************************************************/
|
|
|
|
|
|
|
|
void save_EEPROM_frame(void)
|
|
|
|
{
|
2011-02-18 23:59:58 -04:00
|
|
|
g.frame_type.save();
|
2011-02-17 03:09:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void read_EEPROM_frame(void)
|
|
|
|
{
|
2011-02-18 23:59:58 -04:00
|
|
|
g.frame_type.load();
|
2011-02-17 03:09:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************************************************/
|
|
|
|
|
2011-02-18 23:59:58 -04:00
|
|
|
void save_EEPROM_throttle_cruise (void)
|
2011-02-17 03:09:13 -04:00
|
|
|
{
|
2011-02-18 23:59:58 -04:00
|
|
|
g.throttle_cruise.save();
|
2011-02-17 03:09:13 -04:00
|
|
|
}
|
|
|
|
|
2011-02-18 23:59:58 -04:00
|
|
|
void read_EEPROM_throttle_cruise(void)
|
2011-02-17 03:09:13 -04:00
|
|
|
{
|
2011-02-18 23:59:58 -04:00
|
|
|
g.throttle_cruise.load();
|
2011-02-17 03:09:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************************************************/
|
|
|
|
|
|
|
|
void save_EEPROM_current(void)
|
|
|
|
{
|
2011-02-18 23:59:58 -04:00
|
|
|
g.current_enabled.save();
|
|
|
|
g.milliamp_hours.save();
|
2011-02-17 03:09:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void read_EEPROM_current(void)
|
|
|
|
{
|
2011-02-18 23:59:58 -04:00
|
|
|
g.current_enabled.load();
|
|
|
|
g.milliamp_hours.load();
|
2011-02-17 03:09:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************************************************/
|
|
|
|
/*
|
|
|
|
void save_EEPROM_mag_offset(void)
|
|
|
|
{
|
|
|
|
write_EE_compressed_float(mag_offset_x, EE_MAG_X, 2);
|
|
|
|
write_EE_compressed_float(mag_offset_y, EE_MAG_Y, 2);
|
|
|
|
write_EE_compressed_float(mag_offset_z, EE_MAG_Z, 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
void read_EEPROM_compass_offset(void)
|
|
|
|
{
|
|
|
|
mag_offset_x = read_EE_compressed_float(EE_MAG_X, 2);
|
|
|
|
mag_offset_y = read_EE_compressed_float(EE_MAG_Y, 2);
|
|
|
|
mag_offset_z = read_EE_compressed_float(EE_MAG_Z, 2);
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
/********************************************************************************/
|
|
|
|
|
|
|
|
void read_EEPROM_compass(void)
|
|
|
|
{
|
2011-02-18 23:59:58 -04:00
|
|
|
g.compass_enabled.load();
|
2011-02-17 03:09:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void save_EEPROM_mag(void)
|
|
|
|
{
|
2011-02-18 23:59:58 -04:00
|
|
|
g.compass_enabled.save();
|
2011-02-17 03:09:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************************************************/
|
|
|
|
|
|
|
|
void save_command_index(void)
|
|
|
|
{
|
2011-02-18 23:59:58 -04:00
|
|
|
g.command_must_index.save();
|
2011-02-17 03:09:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void read_command_index(void)
|
|
|
|
{
|
2011-02-18 23:59:58 -04:00
|
|
|
g.command_must_index.load();
|
2011-02-17 03:09:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************************************************/
|
|
|
|
|
|
|
|
void save_EEPROM_pressure(void)
|
|
|
|
{
|
2011-02-18 23:59:58 -04:00
|
|
|
g.ground_pressure.save();
|
|
|
|
g.ground_temperature.save();
|
2011-02-17 03:09:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void read_EEPROM_pressure(void)
|
|
|
|
{
|
2011-02-18 23:59:58 -04:00
|
|
|
g.ground_pressure.load();
|
2011-02-19 22:03:01 -04:00
|
|
|
g.ground_temperature.load();
|
2011-02-18 23:59:58 -04:00
|
|
|
|
|
|
|
// to prime the filter
|
|
|
|
abs_pressure = g.ground_pressure;
|
2011-02-17 03:09:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************************************************/
|
|
|
|
|
|
|
|
void read_EEPROM_radio(void)
|
|
|
|
{
|
|
|
|
g.rc_1.load_eeprom();
|
|
|
|
g.rc_2.load_eeprom();
|
|
|
|
g.rc_3.load_eeprom();
|
|
|
|
g.rc_4.load_eeprom();
|
|
|
|
g.rc_5.load_eeprom();
|
|
|
|
g.rc_6.load_eeprom();
|
|
|
|
g.rc_7.load_eeprom();
|
|
|
|
g.rc_8.load_eeprom();
|
|
|
|
}
|
|
|
|
|
|
|
|
void save_EEPROM_radio(void)
|
2011-02-19 22:03:01 -04:00
|
|
|
{
|
2011-02-17 03:09:13 -04:00
|
|
|
g.rc_1.save_eeprom();
|
|
|
|
g.rc_2.save_eeprom();
|
|
|
|
g.rc_3.save_eeprom();
|
|
|
|
g.rc_4.save_eeprom();
|
|
|
|
g.rc_5.save_eeprom();
|
|
|
|
g.rc_6.save_eeprom();
|
|
|
|
g.rc_7.save_eeprom();
|
|
|
|
g.rc_8.save_eeprom();
|
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************************************************/
|
|
|
|
// configs are the basics
|
|
|
|
void read_EEPROM_throttle(void)
|
|
|
|
{
|
2011-02-18 23:59:58 -04:00
|
|
|
g.throttle_min.load();
|
|
|
|
g.throttle_max.load();
|
|
|
|
g.throttle_cruise.load();
|
2011-02-19 22:03:01 -04:00
|
|
|
g.throttle_fs_enabled.load();
|
|
|
|
g.throttle_fs_action.load();
|
|
|
|
g.throttle_fs_value.load();
|
2011-02-17 03:09:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void save_EEPROM_throttle(void)
|
|
|
|
{
|
2011-02-18 23:59:58 -04:00
|
|
|
g.throttle_min.load();
|
|
|
|
g.throttle_max.load();
|
|
|
|
g.throttle_cruise.save();
|
2011-02-19 22:03:01 -04:00
|
|
|
g.throttle_fs_enabled.load();
|
|
|
|
g.throttle_fs_action.load();
|
|
|
|
g.throttle_fs_value.load();
|
2011-02-17 03:09:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************************************************/
|
|
|
|
|
|
|
|
void read_EEPROM_logs(void)
|
|
|
|
{
|
2011-02-18 23:59:58 -04:00
|
|
|
g.log_bitmask.load();
|
2011-02-17 03:09:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void save_EEPROM_logs(void)
|
|
|
|
{
|
2011-02-18 23:59:58 -04:00
|
|
|
g.log_bitmask.save();
|
2011-02-17 03:09:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************************************************/
|
|
|
|
|
|
|
|
void read_EEPROM_flight_modes(void)
|
|
|
|
{
|
2011-02-18 23:59:58 -04:00
|
|
|
g.flight_modes.load();
|
2011-02-17 03:09:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void save_EEPROM_flight_modes(void)
|
|
|
|
{
|
2011-02-18 23:59:58 -04:00
|
|
|
g.flight_modes.save();
|
2011-02-19 22:03:01 -04:00
|
|
|
|
2011-02-17 03:09:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************************************************/
|
2011-02-18 23:59:58 -04:00
|
|
|
/*
|
2011-02-17 03:09:13 -04:00
|
|
|
float
|
|
|
|
read_EE_float(int address)
|
|
|
|
{
|
|
|
|
union {
|
|
|
|
byte bytes[4];
|
|
|
|
float value;
|
|
|
|
} _floatOut;
|
2011-02-19 22:03:01 -04:00
|
|
|
|
|
|
|
for (int i = 0; i < 4; i++)
|
2011-02-17 03:09:13 -04:00
|
|
|
_floatOut.bytes[i] = eeprom_read_byte((uint8_t *) (address + i));
|
|
|
|
return _floatOut.value;
|
|
|
|
}
|
|
|
|
|
|
|
|
void write_EE_float(float value, int address)
|
|
|
|
{
|
|
|
|
union {
|
|
|
|
byte bytes[4];
|
|
|
|
float value;
|
|
|
|
} _floatIn;
|
2011-02-19 22:03:01 -04:00
|
|
|
|
2011-02-17 03:09:13 -04:00
|
|
|
_floatIn.value = value;
|
2011-02-19 22:03:01 -04:00
|
|
|
for (int i = 0; i < 4; i++)
|
2011-02-17 03:09:13 -04:00
|
|
|
eeprom_write_byte((uint8_t *) (address + i), _floatIn.bytes[i]);
|
|
|
|
}
|
2011-02-18 23:59:58 -04:00
|
|
|
*/
|
2011-02-17 03:09:13 -04:00
|
|
|
/********************************************************************************/
|
2011-02-18 23:59:58 -04:00
|
|
|
/*
|
2011-02-17 03:09:13 -04:00
|
|
|
float
|
|
|
|
read_EE_compressed_float(int address, byte places)
|
|
|
|
{
|
|
|
|
float scale = pow(10, places);
|
2011-02-19 22:03:01 -04:00
|
|
|
|
2011-02-17 03:09:13 -04:00
|
|
|
int temp = eeprom_read_word((uint16_t *) address);
|
|
|
|
return ((float)temp / scale);
|
|
|
|
}
|
|
|
|
|
|
|
|
void write_EE_compressed_float(float value, int address, byte places)
|
|
|
|
{
|
|
|
|
float scale = pow(10, places);
|
|
|
|
int temp = value * scale;
|
|
|
|
eeprom_write_word((uint16_t *) address, temp);
|
|
|
|
}
|
2011-02-18 23:59:58 -04:00
|
|
|
*/
|