From 268874fdb7d3f5396a0ddf7731681afb42c01ec2 Mon Sep 17 00:00:00 2001 From: Julian Oes Date: Tue, 25 Sep 2012 10:31:19 +0200 Subject: [PATCH 1/2] auto save after calibration (however the rest is reset to stock) --- apps/commander/commander.c | 48 +++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/apps/commander/commander.c b/apps/commander/commander.c index c8564792f8..18dd0ceb65 100644 --- a/apps/commander/commander.c +++ b/apps/commander/commander.c @@ -71,7 +71,7 @@ #include #include #include - + #include #include #include @@ -136,6 +136,7 @@ static void led_deinit(void); static int led_toggle(int led); static int led_on(int led); static int led_off(int led); +static int pm_save_eeprom(bool only_unsaved); static void do_gyro_calibration(int status_pub, struct vehicle_status_s *status); static void do_mag_calibration(int status_pub, struct vehicle_status_s *status); static void do_accel_calibration(int status_pub, struct vehicle_status_s *status); @@ -266,6 +267,33 @@ static void cal_bsort(float a[], int n) } } +static const char *parameter_file = "/eeprom/parameters"; + +static int pm_save_eeprom(bool only_unsaved) +{ + /* delete the file in case it exists */ + unlink(parameter_file); + + /* create the file */ + int fd = open(parameter_file, O_WRONLY | O_CREAT | O_EXCL); + + if (fd < 0) { + warn("opening '%s' for writing failed", parameter_file); + return -1; + } + + int result = param_export(fd, only_unsaved); + close(fd); + + if (result != 0) { + unlink(parameter_file); + warn("error exporting parameters to '%s'", parameter_file); + return -2; + } + + return 0; +} + void do_mag_calibration(int status_pub, struct vehicle_status_s *status) { /* set to mag calibration mode */ @@ -487,6 +515,12 @@ void do_mag_calibration(int status_pub, struct vehicle_status_s *status) free(mag_minima[1]); free(mag_minima[2]); + /* auto-save to EEPROM */ + int save_ret = pm_save_eeprom(true); + if(save_ret != 0) { + warn("WARNING: auto-save of params to EEPROM failed"); + } + close(sub_sensor_combined); } @@ -566,6 +600,12 @@ void do_gyro_calibration(int status_pub, struct vehicle_status_s *status) warn("WARNING: failed to set scale / offsets for gyro"); close(fd); + /* auto-save to EEPROM */ + int save_ret = pm_save_eeprom(true); + if(save_ret != 0) { + warn("WARNING: auto-save of params to EEPROM failed"); + } + /* exit to gyro calibration mode */ status->flag_preflight_gyro_calibration = false; state_machine_publish(status_pub, status, mavlink_fd); @@ -675,6 +715,12 @@ void do_accel_calibration(int status_pub, struct vehicle_status_s *status) warn("WARNING: failed to set scale / offsets for accel"); close(fd); + /* auto-save to EEPROM */ + int save_ret = pm_save_eeprom(true); + if(save_ret != 0) { + warn("WARNING: auto-save of params to EEPROM failed"); + } + /* exit to gyro calibration mode */ status->flag_preflight_accel_calibration = false; state_machine_publish(status_pub, status, mavlink_fd); From e217540e013aaa4162c95b361f511c7eb76bc7ad Mon Sep 17 00:00:00 2001 From: Julian Oes Date: Tue, 25 Sep 2012 10:51:13 +0200 Subject: [PATCH 2/2] write all params to EEPROM for now (workaround to prevent standard values being written) --- apps/commander/commander.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/apps/commander/commander.c b/apps/commander/commander.c index 18dd0ceb65..7535b90469 100644 --- a/apps/commander/commander.c +++ b/apps/commander/commander.c @@ -516,11 +516,13 @@ void do_mag_calibration(int status_pub, struct vehicle_status_s *status) free(mag_minima[2]); /* auto-save to EEPROM */ - int save_ret = pm_save_eeprom(true); + int save_ret = pm_save_eeprom(false); if(save_ret != 0) { warn("WARNING: auto-save of params to EEPROM failed"); } + mavlink_log_info(mavlink_fd, "[commander] magnetometer calibration finished"); + close(sub_sensor_combined); } @@ -601,7 +603,7 @@ void do_gyro_calibration(int status_pub, struct vehicle_status_s *status) close(fd); /* auto-save to EEPROM */ - int save_ret = pm_save_eeprom(true); + int save_ret = pm_save_eeprom(false); if(save_ret != 0) { warn("WARNING: auto-save of params to EEPROM failed"); } @@ -610,6 +612,8 @@ void do_gyro_calibration(int status_pub, struct vehicle_status_s *status) status->flag_preflight_gyro_calibration = false; state_machine_publish(status_pub, status, mavlink_fd); + mavlink_log_info(mavlink_fd, "[commander] gyro calibration finished"); + // char offset_output[50]; // sprintf(offset_output, "[commander] gyro cal: x:%8.4f y:%8.4f z:%8.4f", (double)gyro_offset[0], (double)gyro_offset[1], (double)gyro_offset[2]); // mavlink_log_info(mavlink_fd, offset_output); @@ -716,7 +720,7 @@ void do_accel_calibration(int status_pub, struct vehicle_status_s *status) close(fd); /* auto-save to EEPROM */ - int save_ret = pm_save_eeprom(true); + int save_ret = pm_save_eeprom(false); if(save_ret != 0) { warn("WARNING: auto-save of params to EEPROM failed"); } @@ -725,6 +729,8 @@ void do_accel_calibration(int status_pub, struct vehicle_status_s *status) status->flag_preflight_accel_calibration = false; state_machine_publish(status_pub, status, mavlink_fd); + mavlink_log_info(mavlink_fd, "[commander] acceleration calibration finished"); + // char offset_output[50]; // sprintf(offset_output, "[commander] accel cal: x:%8.4f y:%8.4f z:%8.4f", (double)accel_offset[0], // (double)accel_offset[1], (double)accel_offset[2]);