update with altimeter, swimfile.txt endleg.txt, etc see changes_13sep.txt also reset_PI()

Dependencies:   mbed MODSERIAL FATFileSystem

Committer:
joel_ssc
Date:
Fri Sep 13 19:15:40 2019 +0000
Revision:
104:426224a55f5f
Parent:
102:0f430de62447
slight change  includes reset_PI

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tnhnrl 57:ec69651c8c21 1 #include "ConfigFileIO.hpp"
tnhnrl 57:ec69651c8c21 2 #include "StaticDefs.hpp"
tnhnrl 57:ec69651c8c21 3
tnhnrl 57:ec69651c8c21 4 //configuration file io, both to read, set, and save
tnhnrl 57:ec69651c8c21 5
tnhnrl 57:ec69651c8c21 6 ConfigFileIO::ConfigFileIO() {
tnhnrl 73:f6f378311c8d 7 }
tnhnrl 57:ec69651c8c21 8
tnhnrl 76:c802e1da4179 9 void ConfigFileIO::saveBattData(float batt_p_gain, float batt_i_gain, float batt_d_gain, int batt_zeroOffset, float batt_filter_freq, float batt_deadband) {
tnhnrl 57:ec69651c8c21 10 ConfigFile write_Batt_txt; //write to the config file
tnhnrl 57:ec69651c8c21 11
tnhnrl 57:ec69651c8c21 12 char PGain_buffer[128];
tnhnrl 57:ec69651c8c21 13 sprintf(PGain_buffer,"# configuration file for battery mover parameters\n\n#Gains\nPGain");
tnhnrl 57:ec69651c8c21 14
tnhnrl 57:ec69651c8c21 15 char string_pgain[128];
tnhnrl 73:f6f378311c8d 16 sprintf(string_pgain, "%f", batt_p_gain);
tnhnrl 57:ec69651c8c21 17 write_Batt_txt.setValue(PGain_buffer, string_pgain);
tnhnrl 57:ec69651c8c21 18
tnhnrl 57:ec69651c8c21 19 char string_igain[128];
tnhnrl 73:f6f378311c8d 20 sprintf(string_igain, "%f", batt_i_gain);
tnhnrl 57:ec69651c8c21 21 write_Batt_txt.setValue("IGain", string_igain);
tnhnrl 57:ec69651c8c21 22
tnhnrl 57:ec69651c8c21 23 char string_dgain[128];
tnhnrl 73:f6f378311c8d 24 sprintf(string_dgain, "%f", batt_d_gain);
tnhnrl 57:ec69651c8c21 25 write_Batt_txt.setValue("DGain", string_dgain);
tnhnrl 73:f6f378311c8d 26
tnhnrl 73:f6f378311c8d 27 char string_zeroCounts[128];
tnhnrl 76:c802e1da4179 28 sprintf(string_zeroCounts, "%d", batt_zeroOffset);
tnhnrl 73:f6f378311c8d 29 write_Batt_txt.setValue("\n#string pot parameters\nzeroCounts", string_zeroCounts);
tnhnrl 73:f6f378311c8d 30
tnhnrl 79:3688c3a0d7f4 31 //modified this from hard-coded values to set to whatever is in the file on startup
tnhnrl 79:3688c3a0d7f4 32 char string_batt_travel_limit[128];
tnhnrl 79:3688c3a0d7f4 33 sprintf(string_batt_travel_limit, "%f", batt().getTravelLimit());
tnhnrl 79:3688c3a0d7f4 34 write_Batt_txt.setValue("PistonTravelLimit", string_batt_travel_limit);
tnhnrl 79:3688c3a0d7f4 35
tnhnrl 57:ec69651c8c21 36 write_Batt_txt.setValue("slope", "0.12176");
tnhnrl 73:f6f378311c8d 37
tnhnrl 73:f6f378311c8d 38 char string_filter_freq[128];
tnhnrl 73:f6f378311c8d 39 sprintf(string_filter_freq, "%f", batt_filter_freq);
tnhnrl 73:f6f378311c8d 40 write_Batt_txt.setValue("filterWn", string_filter_freq);
tnhnrl 73:f6f378311c8d 41
tnhnrl 73:f6f378311c8d 42 char string_deadband[128];
tnhnrl 73:f6f378311c8d 43 sprintf(string_deadband, "%f", batt_deadband);
tnhnrl 73:f6f378311c8d 44 write_Batt_txt.setValue("deadband", string_deadband);
tnhnrl 57:ec69651c8c21 45
tnhnrl 57:ec69651c8c21 46 //SAVE THE DATA!
tnhnrl 74:d281aaef9766 47 xbee().printf("Saving BATTERY MOVER PID data!");
tnhnrl 57:ec69651c8c21 48
tnhnrl 57:ec69651c8c21 49 if (!write_Batt_txt.write("/local/batt.txt")) {
tnhnrl 74:d281aaef9766 50 xbee().printf("\n\rERROR: (SAVE)Failure to write batt.txt file.");
tnhnrl 57:ec69651c8c21 51 }
tnhnrl 57:ec69651c8c21 52 else {
tnhnrl 74:d281aaef9766 53 xbee().printf("\n\rFile batt.txt successful written.\n\r");
tnhnrl 57:ec69651c8c21 54 }
tnhnrl 57:ec69651c8c21 55 }
joel_ssc 86:ba3a118b0080 56 int ConfigFileIO::load_StartTime() {
joel_ssc 86:ba3a118b0080 57 ConfigFile cfg;
joel_ssc 86:ba3a118b0080 58 int count = 0;
joel_ssc 86:ba3a118b0080 59 if (!cfg.read("/local/time.txt")) {
joel_ssc 86:ba3a118b0080 60 error("File Read Error");
joel_ssc 86:ba3a118b0080 61 }
joel_ssc 86:ba3a118b0080 62 char value[BUFSIZ];
joel_ssc 86:ba3a118b0080 63 if (cfg.getValue("TimeStamp", &value[0] , sizeof(value))) {
joel_ssc 86:ba3a118b0080 64 // bce().setControllerP(atoi(value));
joel_ssc 86:ba3a118b0080 65 mbedLogger().setLogTime(atol(value));
joel_ssc 86:ba3a118b0080 66 count++;
joel_ssc 86:ba3a118b0080 67 }
joel_ssc 86:ba3a118b0080 68 return count;
joel_ssc 86:ba3a118b0080 69 }
joel_ssc 82:0981b9ada820 70 void ConfigFileIO::saveLogVersData(int logversion, int diagversion) {
joel_ssc 82:0981b9ada820 71 ConfigFile write_logvers_txt; //write to the config file
joel_ssc 82:0981b9ada820 72
joel_ssc 82:0981b9ada820 73 char string_log[128];
joel_ssc 82:0981b9ada820 74 sprintf(string_log, "%d", logversion);
joel_ssc 82:0981b9ada820 75 write_logvers_txt.setValue("LogFileVers", string_log);
joel_ssc 82:0981b9ada820 76
joel_ssc 82:0981b9ada820 77 char string_diag[128];
joel_ssc 82:0981b9ada820 78 sprintf(string_diag, "%i", diagversion);
joel_ssc 82:0981b9ada820 79 write_logvers_txt.setValue("DiagFileVers", string_diag);
joel_ssc 82:0981b9ada820 80
joel_ssc 82:0981b9ada820 81
joel_ssc 82:0981b9ada820 82
joel_ssc 82:0981b9ada820 83 //SAVE THE DATA!
joel_ssc 82:0981b9ada820 84 xbee().printf("Saving logfile version numbers !");
CodyMarquardt 101:c24f70abb124 85 wait(1);
joel_ssc 82:0981b9ada820 86
joel_ssc 82:0981b9ada820 87 if (!write_logvers_txt.write("/local/logvers.txt")) {
joel_ssc 82:0981b9ada820 88 xbee().printf("\n\rERROR: (SAVE)Failure to write logvers.txt file.");
joel_ssc 82:0981b9ada820 89 }
joel_ssc 82:0981b9ada820 90 else {
joel_ssc 82:0981b9ada820 91 xbee().printf("\n\rFile logvvrs.txt successful written.\n\r");
joel_ssc 82:0981b9ada820 92 }
joel_ssc 82:0981b9ada820 93 }
tnhnrl 57:ec69651c8c21 94
tnhnrl 73:f6f378311c8d 95 void ConfigFileIO::savePitchData(float pitch_p_gain, float pitch_i_gain, float pitch_d_gain, float pitch_zeroOffset, float pitch_filter_freq, float pitch_deadband) {
tnhnrl 57:ec69651c8c21 96 ConfigFile write_pitch_txt; //write to the config file
tnhnrl 57:ec69651c8c21 97
tnhnrl 57:ec69651c8c21 98 char PGain_buffer[128];
tnhnrl 57:ec69651c8c21 99 sprintf(PGain_buffer,"# pitch outer loop parameters\n\n#Gains\nPGain");
tnhnrl 57:ec69651c8c21 100
tnhnrl 57:ec69651c8c21 101 char string_pgain[128];
tnhnrl 73:f6f378311c8d 102 sprintf(string_pgain, "%f", pitch_p_gain);
tnhnrl 57:ec69651c8c21 103 write_pitch_txt.setValue(PGain_buffer, string_pgain);
tnhnrl 57:ec69651c8c21 104
tnhnrl 57:ec69651c8c21 105 char string_igain[128];
tnhnrl 73:f6f378311c8d 106 sprintf(string_igain, "%f", pitch_i_gain);
tnhnrl 57:ec69651c8c21 107 write_pitch_txt.setValue("IGain", string_igain);
tnhnrl 57:ec69651c8c21 108
tnhnrl 57:ec69651c8c21 109 char string_dgain[128];
tnhnrl 73:f6f378311c8d 110 sprintf(string_dgain, "%f", pitch_d_gain);
tnhnrl 57:ec69651c8c21 111 write_pitch_txt.setValue("DGain", string_dgain);
tnhnrl 73:f6f378311c8d 112
tnhnrl 73:f6f378311c8d 113 char string_filter_freq[128];
tnhnrl 73:f6f378311c8d 114 sprintf(string_filter_freq, "%f", pitch_filter_freq);
tnhnrl 73:f6f378311c8d 115 write_pitch_txt.setValue("\n#Pitch sensor filter parameters\nfilterWn", string_filter_freq);
tnhnrl 73:f6f378311c8d 116
tnhnrl 73:f6f378311c8d 117 char string_deadband[128];
tnhnrl 73:f6f378311c8d 118 sprintf(string_deadband, "%f", pitch_deadband);
tnhnrl 73:f6f378311c8d 119 write_pitch_txt.setValue("deadband", string_deadband);
tnhnrl 57:ec69651c8c21 120
tnhnrl 57:ec69651c8c21 121 char string_zeroOffset[128];
tnhnrl 73:f6f378311c8d 122 sprintf(string_zeroOffset, "%f", pitch_zeroOffset);
tnhnrl 57:ec69651c8c21 123 //bce setting was 41 mm during LASR experiments
tnhnrl 57:ec69651c8c21 124 write_pitch_txt.setValue("\n#Offset for neutral (default: 41)\nzeroOffset", string_zeroOffset);
tnhnrl 57:ec69651c8c21 125
tnhnrl 57:ec69651c8c21 126 //SAVE THE DATA!
tnhnrl 74:d281aaef9766 127 xbee().printf("Saving Buoyancy Engine Neutral Buoyancy Positions!");
tnhnrl 57:ec69651c8c21 128
tnhnrl 57:ec69651c8c21 129 if (!write_pitch_txt.write("/local/pitch.txt")) {
tnhnrl 74:d281aaef9766 130 xbee().printf("\n\rERROR: (SAVE)Failure to write depth.txt file.");
tnhnrl 57:ec69651c8c21 131 }
tnhnrl 57:ec69651c8c21 132 else {
tnhnrl 74:d281aaef9766 133 xbee().printf("\n\rFile pitch.txt successful written.\n\r");
tnhnrl 57:ec69651c8c21 134 }
tnhnrl 57:ec69651c8c21 135 }
tnhnrl 57:ec69651c8c21 136
tnhnrl 76:c802e1da4179 137 void ConfigFileIO::saveBCEData(float bce_p_gain, float bce_i_gain, float bce_d_gain, int bce_zeroOffset, float bce_filter_freq, float bce_deadband) {
tnhnrl 57:ec69651c8c21 138 ConfigFile write_BCE_txt; //write to the config file
tnhnrl 57:ec69651c8c21 139
tnhnrl 57:ec69651c8c21 140 char PGain_buffer[128];
tnhnrl 57:ec69651c8c21 141 sprintf(PGain_buffer,"# configuration file for BCE parameters\n\n#Gains\nPGain");
tnhnrl 57:ec69651c8c21 142
tnhnrl 57:ec69651c8c21 143 char string_pgain[128];
tnhnrl 73:f6f378311c8d 144 sprintf(string_pgain, "%f", bce_p_gain);
tnhnrl 57:ec69651c8c21 145 write_BCE_txt.setValue(PGain_buffer, string_pgain);
tnhnrl 57:ec69651c8c21 146
tnhnrl 57:ec69651c8c21 147 char string_igain[128];
tnhnrl 73:f6f378311c8d 148 sprintf(string_igain, "%f", bce_i_gain);
tnhnrl 57:ec69651c8c21 149 write_BCE_txt.setValue("IGain", string_igain);
tnhnrl 57:ec69651c8c21 150
tnhnrl 57:ec69651c8c21 151 char string_dgain[128];
tnhnrl 73:f6f378311c8d 152 sprintf(string_dgain, "%f", bce_d_gain);
tnhnrl 57:ec69651c8c21 153 write_BCE_txt.setValue("DGain", string_dgain);
tnhnrl 73:f6f378311c8d 154
tnhnrl 73:f6f378311c8d 155 char string_zeroCounts[128];
tnhnrl 76:c802e1da4179 156 sprintf(string_zeroCounts, "%d", bce_zeroOffset);
tnhnrl 73:f6f378311c8d 157 write_BCE_txt.setValue("\n#string pot parameters\nzeroCounts", string_zeroCounts);
tnhnrl 73:f6f378311c8d 158
tnhnrl 79:3688c3a0d7f4 159 //modified this from hard-coded values to set to whatever is in the file on startup
tnhnrl 79:3688c3a0d7f4 160 char string_bce_travel_limit[128];
tnhnrl 79:3688c3a0d7f4 161 sprintf(string_bce_travel_limit, "%f", batt().getTravelLimit());
tnhnrl 79:3688c3a0d7f4 162 write_BCE_txt.setValue("PistonTravelLimit", string_bce_travel_limit);
tnhnrl 79:3688c3a0d7f4 163
tnhnrl 57:ec69651c8c21 164 write_BCE_txt.setValue("slope", "0.12176");
tnhnrl 73:f6f378311c8d 165
tnhnrl 73:f6f378311c8d 166 char string_filter_freq[128];
tnhnrl 73:f6f378311c8d 167 sprintf(string_filter_freq, "%f", bce_filter_freq);
tnhnrl 73:f6f378311c8d 168 write_BCE_txt.setValue("filterWn", string_filter_freq);
tnhnrl 73:f6f378311c8d 169
tnhnrl 73:f6f378311c8d 170 char string_deadband[128];
tnhnrl 73:f6f378311c8d 171 sprintf(string_deadband, "%f", bce_deadband);
tnhnrl 73:f6f378311c8d 172 write_BCE_txt.setValue("deadband", string_deadband);
tnhnrl 57:ec69651c8c21 173
tnhnrl 57:ec69651c8c21 174 //SAVE THE DATA!
tnhnrl 74:d281aaef9766 175 xbee().printf("Saving BCE PID data!");
tnhnrl 57:ec69651c8c21 176
tnhnrl 57:ec69651c8c21 177 if (!write_BCE_txt.write("/local/bce.txt")) {
tnhnrl 74:d281aaef9766 178 xbee().printf("\n\rERROR: (SAVE)Failure to write bce.txt file.");
tnhnrl 57:ec69651c8c21 179 }
tnhnrl 57:ec69651c8c21 180 else {
tnhnrl 74:d281aaef9766 181 xbee().printf("\n\rFile bce.txt successful written.\n\r");
tnhnrl 57:ec69651c8c21 182 }
tnhnrl 57:ec69651c8c21 183 }
tnhnrl 57:ec69651c8c21 184
tnhnrl 73:f6f378311c8d 185 void ConfigFileIO::saveDepthData(float depth_p_gain, float depth_i_gain, float depth_d_gain, float depth_zeroOffset, float depth_filter_freq, float depth_deadband) {
tnhnrl 57:ec69651c8c21 186 ConfigFile write_depth_txt; //write to the config file
tnhnrl 57:ec69651c8c21 187
tnhnrl 57:ec69651c8c21 188 char PGain_buffer[128];
tnhnrl 57:ec69651c8c21 189 sprintf(PGain_buffer,"# depth outer loop parameters\n\n#Gains\nPGain");
tnhnrl 57:ec69651c8c21 190
tnhnrl 57:ec69651c8c21 191 char string_pgain[128];
tnhnrl 73:f6f378311c8d 192 sprintf(string_pgain, "%f", depth_p_gain);
tnhnrl 57:ec69651c8c21 193 write_depth_txt.setValue(PGain_buffer, string_pgain);
tnhnrl 57:ec69651c8c21 194
tnhnrl 57:ec69651c8c21 195 char string_igain[128];
tnhnrl 73:f6f378311c8d 196 sprintf(string_igain, "%f", depth_i_gain);
tnhnrl 57:ec69651c8c21 197 write_depth_txt.setValue("IGain", string_igain);
tnhnrl 57:ec69651c8c21 198
tnhnrl 57:ec69651c8c21 199 char string_dgain[128];
tnhnrl 73:f6f378311c8d 200 sprintf(string_dgain, "%f", depth_d_gain);
tnhnrl 57:ec69651c8c21 201 write_depth_txt.setValue("DGain", string_dgain);
tnhnrl 73:f6f378311c8d 202
tnhnrl 73:f6f378311c8d 203 char string_filter_freq[128];
tnhnrl 73:f6f378311c8d 204 sprintf(string_filter_freq, "%f", depth_filter_freq);
tnhnrl 73:f6f378311c8d 205 write_depth_txt.setValue("\n#Depth sensor filter parameters\nfilterWn", string_filter_freq);
tnhnrl 73:f6f378311c8d 206
tnhnrl 73:f6f378311c8d 207 char string_deadband[128];
tnhnrl 73:f6f378311c8d 208 sprintf(string_deadband, "%f", depth_deadband);
tnhnrl 73:f6f378311c8d 209 write_depth_txt.setValue("deadband", string_deadband);
tnhnrl 57:ec69651c8c21 210
tnhnrl 57:ec69651c8c21 211 char string_zeroOffset[128];
tnhnrl 73:f6f378311c8d 212 sprintf(string_zeroOffset, "%f", depth_zeroOffset);
tnhnrl 57:ec69651c8c21 213 //bce setting was 240 mm during LASR experiments
tnhnrl 57:ec69651c8c21 214 write_depth_txt.setValue("\n#Offset for neutral (default: 240)\nzeroOffset", string_zeroOffset);
tnhnrl 57:ec69651c8c21 215
tnhnrl 57:ec69651c8c21 216 //SAVE THE DATA!
tnhnrl 74:d281aaef9766 217 xbee().printf("Saving Buoyancy Engine Neutral Buoyancy Positions!");
tnhnrl 57:ec69651c8c21 218
tnhnrl 57:ec69651c8c21 219 if (!write_depth_txt.write("/local/depth.txt")) {
tnhnrl 74:d281aaef9766 220 xbee().printf("\n\rERROR: (SAVE)Failure to write depth.txt file.");
tnhnrl 57:ec69651c8c21 221 }
tnhnrl 57:ec69651c8c21 222 else {
tnhnrl 74:d281aaef9766 223 xbee().printf("\n\rFile depth.txt successful written.\n\r");
tnhnrl 57:ec69651c8c21 224 }
tnhnrl 57:ec69651c8c21 225 }
tnhnrl 57:ec69651c8c21 226
tnhnrl 57:ec69651c8c21 227 //write rudder (servo driver) file rudder.txt
tnhnrl 57:ec69651c8c21 228 void ConfigFileIO::saveRudderData(float setMinDeg, float setMaxDeg, float setCenterPWM, float setMinPWM, float setMaxPWM) {
tnhnrl 57:ec69651c8c21 229 ConfigFile rudder_txt;
tnhnrl 57:ec69651c8c21 230
tnhnrl 57:ec69651c8c21 231 char header[128];
tnhnrl 57:ec69651c8c21 232 sprintf(header,"# rudder (servo) inner loop (heading outer loop uses this)");
tnhnrl 57:ec69651c8c21 233
tnhnrl 57:ec69651c8c21 234 char string_min_deg[128];
tnhnrl 57:ec69651c8c21 235 sprintf(string_min_deg, "%f", setMinDeg);
tnhnrl 57:ec69651c8c21 236 rudder_txt.setValue("setMinDeg", string_min_deg);
tnhnrl 57:ec69651c8c21 237
tnhnrl 57:ec69651c8c21 238 char string_max_deg[128];
tnhnrl 57:ec69651c8c21 239 sprintf(string_max_deg, "%f", setMaxDeg);
tnhnrl 57:ec69651c8c21 240 rudder_txt.setValue("setMaxDeg", string_max_deg);
tnhnrl 57:ec69651c8c21 241
tnhnrl 57:ec69651c8c21 242 char string_ctr_pwm[128];
tnhnrl 57:ec69651c8c21 243 sprintf(string_ctr_pwm, "%f", setCenterPWM);
tnhnrl 57:ec69651c8c21 244 rudder_txt.setValue("setCenterPWM", string_ctr_pwm);
tnhnrl 57:ec69651c8c21 245
tnhnrl 57:ec69651c8c21 246 char string_min_pwm[128];
tnhnrl 57:ec69651c8c21 247 sprintf(string_min_pwm, "%f", setMinPWM);
tnhnrl 57:ec69651c8c21 248 rudder_txt.setValue("setMinPWM", string_min_pwm);
tnhnrl 57:ec69651c8c21 249
tnhnrl 57:ec69651c8c21 250 char string_max_pwm[128];
tnhnrl 57:ec69651c8c21 251 sprintf(string_max_pwm, "%f", setMaxPWM);
tnhnrl 57:ec69651c8c21 252 rudder_txt.setValue("setMaxPWM", string_max_pwm);
tnhnrl 57:ec69651c8c21 253
tnhnrl 57:ec69651c8c21 254 //SAVE THE DATA!
tnhnrl 74:d281aaef9766 255 xbee().printf("Saving RUDDER DATA!");
tnhnrl 57:ec69651c8c21 256
tnhnrl 57:ec69651c8c21 257 if (!rudder_txt.write("/local/rudder.txt")) {
tnhnrl 74:d281aaef9766 258 xbee().printf("\n\rERROR: (SAVE)Failure to write rudder.txt file.");
tnhnrl 57:ec69651c8c21 259 }
tnhnrl 57:ec69651c8c21 260 else {
tnhnrl 74:d281aaef9766 261 xbee().printf("\n\rFile rudder.txt successful written.\n\r");
tnhnrl 57:ec69651c8c21 262 }
tnhnrl 57:ec69651c8c21 263 }
joel_ssc 102:0f430de62447 264 int ConfigFileIO::load_swim_config() {
joel_ssc 102:0f430de62447 265 ConfigFile cfg;
joel_ssc 102:0f430de62447 266 int count = 0;
joel_ssc 102:0f430de62447 267 char buf[256];
joel_ssc 102:0f430de62447 268
joel_ssc 102:0f430de62447 269 if (!cfg.read("/local/swimfile.txt")) {
joel_ssc 102:0f430de62447 270 error("File Read Error");
joel_ssc 102:0f430de62447 271 }
joel_ssc 102:0f430de62447 272 char value[BUFSIZ];
joel_ssc 102:0f430de62447 273
joel_ssc 102:0f430de62447 274 swimConstants.altim_abort_count = 0;
joel_ssc 102:0f430de62447 275 swimConstants.max_mbed_runtime_hr = 0.01;
joel_ssc 102:0f430de62447 276
joel_ssc 102:0f430de62447 277 if (cfg.getValue("bce_dive_mm", &value[0] , sizeof(value))) {
joel_ssc 102:0f430de62447 278 swimConstants.bce_dive_mm = (atof(value));
joel_ssc 102:0f430de62447 279 sprintf(buf, "in configFileIO: SWIM FILE bce_dive_mm = %.1f\n", swimConstants.bce_dive_mm);
joel_ssc 102:0f430de62447 280 mbedLogger().appendDiagFile(buf,3);
joel_ssc 102:0f430de62447 281 count++;
joel_ssc 102:0f430de62447 282 }
joel_ssc 102:0f430de62447 283 if (cfg.getValue("bce_rise_mm", &value[0] , sizeof(value))) {
joel_ssc 102:0f430de62447 284 swimConstants.bce_rise_mm = (atof(value));
joel_ssc 102:0f430de62447 285 count++;
joel_ssc 102:0f430de62447 286 }
joel_ssc 102:0f430de62447 287 if (cfg.getValue("bmm_dive_mm", &value[0] , sizeof(value))) {
joel_ssc 102:0f430de62447 288 swimConstants.bmm_dive_mm = (atof(value));
joel_ssc 102:0f430de62447 289 count++;
joel_ssc 102:0f430de62447 290 }
joel_ssc 102:0f430de62447 291 if (cfg.getValue("bce_rise_mm", &value[0] , sizeof(value))) {
joel_ssc 102:0f430de62447 292 swimConstants.bce_rise_mm = (atof(value));
joel_ssc 102:0f430de62447 293 count++;
joel_ssc 102:0f430de62447 294 }
joel_ssc 102:0f430de62447 295 if (cfg.getValue("altimeter_blank_m", &value[0] , sizeof(value))) {
joel_ssc 102:0f430de62447 296 swimConstants.altim_blank_m = (atof(value));
joel_ssc 102:0f430de62447 297 sprintf(buf, "in configfileIO: SWIM_config FILE altim_blank_m = %.1f\n", swimConstants.altim_blank_m);
joel_ssc 102:0f430de62447 298 mbedLogger().appendDiagFile(buf,3);
joel_ssc 102:0f430de62447 299 count++;
joel_ssc 102:0f430de62447 300 }
joel_ssc 102:0f430de62447 301 if (cfg.getValue("altimeter_abort_m", &value[0] , sizeof(value))) {
joel_ssc 102:0f430de62447 302 swimConstants.altim_abort_m = (atof(value));
joel_ssc 102:0f430de62447 303 count++;
joel_ssc 102:0f430de62447 304 }
joel_ssc 102:0f430de62447 305 if (cfg.getValue("fn_timeout", &value[0] , sizeof(value))) {
joel_ssc 102:0f430de62447 306 swimConstants.fn_timeout = (int) (atof(value)); // the python code is all floats in the config file, but mbed code is int here
joel_ssc 102:0f430de62447 307 sprintf(buf, "in configfileIO: SWIM_config FILE fn_timeout = %d\n", swimConstants.fn_timeout);
joel_ssc 102:0f430de62447 308 mbedLogger().appendDiagFile(buf,3);
joel_ssc 102:0f430de62447 309 count++;
joel_ssc 102:0f430de62447 310 }
joel_ssc 102:0f430de62447 311
joel_ssc 102:0f430de62447 312 if (cfg.getValue("max_mbed_runtime_hr", &value[0] , sizeof(value))) {
joel_ssc 102:0f430de62447 313 swimConstants.max_mbed_runtime_hr = (atof(value));
joel_ssc 102:0f430de62447 314 sprintf(buf, "in configfileIO: SWIM_config FILE max_mbed_runitme_hr = %.2f\n", swimConstants.max_mbed_runtime_hr);
joel_ssc 102:0f430de62447 315 mbedLogger().appendDiagFile(buf,3);
joel_ssc 102:0f430de62447 316 count++;
joel_ssc 102:0f430de62447 317 }
joel_ssc 102:0f430de62447 318
joel_ssc 102:0f430de62447 319 return count;
joel_ssc 102:0f430de62447 320 }
tnhnrl 57:ec69651c8c21 321
tnhnrl 57:ec69651c8c21 322 int ConfigFileIO::load_BCE_config() {
tnhnrl 57:ec69651c8c21 323 ConfigFile cfg;
tnhnrl 57:ec69651c8c21 324 int count = 0;
tnhnrl 57:ec69651c8c21 325 if (!cfg.read("/local/bce.txt")) {
tnhnrl 57:ec69651c8c21 326 error("File Read Error");
tnhnrl 57:ec69651c8c21 327 }
tnhnrl 57:ec69651c8c21 328 char value[BUFSIZ];
tnhnrl 57:ec69651c8c21 329
tnhnrl 57:ec69651c8c21 330 if (cfg.getValue("PGain", &value[0] , sizeof(value))) {
tnhnrl 57:ec69651c8c21 331 bce().setControllerP(atof(value));
tnhnrl 57:ec69651c8c21 332 count++;
tnhnrl 57:ec69651c8c21 333 }
tnhnrl 57:ec69651c8c21 334 if (cfg.getValue("IGain", &value[0] ,sizeof(value))) {
tnhnrl 57:ec69651c8c21 335 bce().setControllerI(atof(value));
tnhnrl 57:ec69651c8c21 336 count++;
tnhnrl 57:ec69651c8c21 337 }
tnhnrl 57:ec69651c8c21 338 if (cfg.getValue("DGain", &value[0] , sizeof(value))) {
tnhnrl 57:ec69651c8c21 339 bce().setControllerD(atof(value));
tnhnrl 57:ec69651c8c21 340 count++;
tnhnrl 57:ec69651c8c21 341 }
tnhnrl 57:ec69651c8c21 342 if (cfg.getValue("zeroCounts", &value[0],sizeof(value))) {
tnhnrl 57:ec69651c8c21 343 bce().setZeroCounts(atoi(value));
tnhnrl 57:ec69651c8c21 344 count++;
tnhnrl 57:ec69651c8c21 345 }
tnhnrl 57:ec69651c8c21 346 if (cfg.getValue("PistonTravelLimit", &value[0], sizeof(value))) {
tnhnrl 57:ec69651c8c21 347 bce().setTravelLimit(atof(value));
tnhnrl 57:ec69651c8c21 348 count++;
tnhnrl 57:ec69651c8c21 349 }
tnhnrl 57:ec69651c8c21 350 if (cfg.getValue("slope", &value[0], sizeof(value))) {
tnhnrl 57:ec69651c8c21 351 bce().setPotSlope(atof(value));
tnhnrl 57:ec69651c8c21 352 count++;
tnhnrl 57:ec69651c8c21 353 }
tnhnrl 57:ec69651c8c21 354 if (cfg.getValue("filterWn", &value[0], sizeof(value))) {
tnhnrl 57:ec69651c8c21 355 bce().setFilterFrequency(atof(value));
tnhnrl 57:ec69651c8c21 356 count++;
tnhnrl 57:ec69651c8c21 357 }
tnhnrl 57:ec69651c8c21 358 if (cfg.getValue("deadband", &value[0], sizeof(value))) {
tnhnrl 57:ec69651c8c21 359 bce().setDeadband(atof(value));
tnhnrl 57:ec69651c8c21 360 count++;
tnhnrl 57:ec69651c8c21 361 }
tnhnrl 57:ec69651c8c21 362
tnhnrl 57:ec69651c8c21 363 return count;
tnhnrl 57:ec69651c8c21 364 }
tnhnrl 57:ec69651c8c21 365
tnhnrl 57:ec69651c8c21 366 //write to heading.txt
tnhnrl 73:f6f378311c8d 367 void ConfigFileIO::saveHeadingData(float heading_p_gain, float heading_i_gain, float heading_d_gain, float heading_zeroOffset, float heading_filter_freq, float heading_deadband) {
tnhnrl 57:ec69651c8c21 368 ConfigFile heading_txt;
tnhnrl 57:ec69651c8c21 369
tnhnrl 57:ec69651c8c21 370 char PGain_buffer[128];
tnhnrl 57:ec69651c8c21 371 sprintf(PGain_buffer,"# HEADING (rudder outer loop) parameters\n\n#Gains\nPGain");
tnhnrl 57:ec69651c8c21 372
tnhnrl 57:ec69651c8c21 373 //convert input numbers into text and save them to text file
tnhnrl 57:ec69651c8c21 374 char string_pgain[128];
tnhnrl 57:ec69651c8c21 375 sprintf(string_pgain, "%f", heading_p_gain);
tnhnrl 57:ec69651c8c21 376 heading_txt.setValue(PGain_buffer, string_pgain);
tnhnrl 57:ec69651c8c21 377
tnhnrl 57:ec69651c8c21 378 char string_igain[128];
tnhnrl 57:ec69651c8c21 379 sprintf(string_igain, "%f", heading_i_gain);
tnhnrl 57:ec69651c8c21 380 heading_txt.setValue("IGain", string_igain);
tnhnrl 57:ec69651c8c21 381
tnhnrl 57:ec69651c8c21 382 char string_dgain[128];
tnhnrl 57:ec69651c8c21 383 sprintf(string_dgain, "%f", heading_d_gain);
tnhnrl 57:ec69651c8c21 384 heading_txt.setValue("DGain", string_dgain);
tnhnrl 74:d281aaef9766 385
tnhnrl 74:d281aaef9766 386 char string_heading_freq[128];
tnhnrl 74:d281aaef9766 387 sprintf(string_heading_freq, "%f", heading_filter_freq);
tnhnrl 74:d281aaef9766 388 heading_txt.setValue("\n# HEADING sensor filter parameters\nfilterWn", string_heading_freq);
tnhnrl 74:d281aaef9766 389
tnhnrl 74:d281aaef9766 390 char string_heading_db[128];
tnhnrl 74:d281aaef9766 391 sprintf(string_heading_db, "%f", heading_deadband);
tnhnrl 74:d281aaef9766 392 heading_txt.setValue("deadband",string_heading_db);
tnhnrl 57:ec69651c8c21 393
tnhnrl 57:ec69651c8c21 394 char string_zeroOffset[128];
tnhnrl 73:f6f378311c8d 395 sprintf(string_zeroOffset, "%f", heading_zeroOffset);
tnhnrl 74:d281aaef9766 396 heading_txt.setValue("\n#HEADING offset\nzeroOffset", string_zeroOffset);
tnhnrl 57:ec69651c8c21 397
tnhnrl 57:ec69651c8c21 398 //SAVE THE DATA!
tnhnrl 74:d281aaef9766 399 xbee().printf("(ConfigFileIO) Saving HEADING parameters!");
tnhnrl 57:ec69651c8c21 400
tnhnrl 57:ec69651c8c21 401 if (!heading_txt.write("/local/heading.txt")) {
tnhnrl 74:d281aaef9766 402 xbee().printf("\n\rERROR: (SAVE) Failure to write heading.txt file.");
tnhnrl 57:ec69651c8c21 403 }
tnhnrl 57:ec69651c8c21 404 else {
tnhnrl 74:d281aaef9766 405 xbee().printf("\n\rFile heading.txt successful written.\n\r");
tnhnrl 57:ec69651c8c21 406 }
tnhnrl 57:ec69651c8c21 407 }
joel_ssc 82:0981b9ada820 408 int ConfigFileIO::load_LogVers_config(int print_diag) { // I could copy this mode to read one line of a leg_mission file. One line or multiple lines?
tnhnrl 57:ec69651c8c21 409 ConfigFile cfg;
tnhnrl 57:ec69651c8c21 410 int count = 0;
joel_ssc 82:0981b9ada820 411 int version = 0;
joel_ssc 82:0981b9ada820 412 if (!cfg.read("/local/logvers.txt")) { // "/local/leg_mission.txt"
joel_ssc 82:0981b9ada820 413 error("Lognames version file logvers.txt File Read Error");
joel_ssc 82:0981b9ada820 414 }
joel_ssc 87:6d95f853dab3 415 char value[BUFSIZ]; // chang
joel_ssc 82:0981b9ada820 416
joel_ssc 82:0981b9ada820 417
joel_ssc 82:0981b9ada820 418 if (cfg.getValue("LogFileVers", &value[0] , sizeof(value))) {
joel_ssc 82:0981b9ada820 419 version = atoi(value);
joel_ssc 82:0981b9ada820 420 char buf[256];
joel_ssc 82:0981b9ada820 421 sprintf(buf, "LOG%03d.csv", version);
joel_ssc 82:0981b9ada820 422 logFilesStruct.logFileName = buf;
joel_ssc 82:0981b9ada820 423 logFilesStruct.logversion = version;
joel_ssc 82:0981b9ada820 424 count++;
joel_ssc 82:0981b9ada820 425 }
joel_ssc 82:0981b9ada820 426 if (cfg.getValue("DiagFileVers", &value[0] , sizeof(value))) {
joel_ssc 82:0981b9ada820 427 version = atoi(value);
joel_ssc 82:0981b9ada820 428 char buf[256];
joel_ssc 82:0981b9ada820 429
joel_ssc 82:0981b9ada820 430 sprintf(buf, "in configfileIO: diag file version number is %d\n", version);
joel_ssc 82:0981b9ada820 431 if(print_diag == 1) {mbedLogger().appendDiagFile(buf,3);}
joel_ssc 82:0981b9ada820 432 // buf[256]= {0};
joel_ssc 87:6d95f853dab3 433 sprintf(buf, "in ConfigFileIO: diag file string is DIAG%03d.txt\n", version);
joel_ssc 82:0981b9ada820 434 if(print_diag == 1) {mbedLogger().appendDiagFile(buf,3);}
joel_ssc 82:0981b9ada820 435 // buf[256]= {0};
joel_ssc 82:0981b9ada820 436 sprintf(buf, "DIAG%03d.txt", version);
joel_ssc 82:0981b9ada820 437 logFilesStruct.diagFileName = buf;
joel_ssc 82:0981b9ada820 438 logFilesStruct.diagversion = version;
joel_ssc 82:0981b9ada820 439 sprintf(buf, "in ConfigFileIO: diag info pulled from struct: filename = %s diagvernum = %d\n", logFilesStruct.diagFileName,
joel_ssc 82:0981b9ada820 440 logFilesStruct.diagversion);
joel_ssc 82:0981b9ada820 441 if(print_diag==1) {mbedLogger().appendDiagFile(buf,3);}
joel_ssc 82:0981b9ada820 442 count++;
joel_ssc 82:0981b9ada820 443 }
joel_ssc 82:0981b9ada820 444 return count;
joel_ssc 82:0981b9ada820 445 }
joel_ssc 102:0f430de62447 446 int ConfigFileIO::load_setneutral_status() { // so far these are not actually used except the setval found in the file.
joel_ssc 87:6d95f853dab3 447 ConfigFile cfg;
joel_ssc 87:6d95f853dab3 448 int count = 0;
joel_ssc 87:6d95f853dab3 449 int setval = 0;
joel_ssc 102:0f430de62447 450 float bce_mm = 240;
joel_ssc 102:0f430de62447 451 float batt_mm = 40;
joel_ssc 87:6d95f853dab3 452 if (!cfg.read("/local/neutral.txt")) {
joel_ssc 87:6d95f853dab3 453 error("setneutral file neutral.txt File Read Error");
joel_ssc 87:6d95f853dab3 454 // set values in struct to defaults??
joel_ssc 87:6d95f853dab3 455 }
joel_ssc 87:6d95f853dab3 456 char value[BUFSIZ];
joel_ssc 87:6d95f853dab3 457
joel_ssc 87:6d95f853dab3 458
joel_ssc 87:6d95f853dab3 459 if (cfg.getValue("neutral_set", &value[0] , sizeof(value))) {
joel_ssc 87:6d95f853dab3 460 setval = atoi(value);
joel_ssc 87:6d95f853dab3 461 neutralStruct.setval = setval;
joel_ssc 87:6d95f853dab3 462 count++;
joel_ssc 87:6d95f853dab3 463 }
joel_ssc 87:6d95f853dab3 464 if (cfg.getValue("bce_neutral_mm", &value[0] , sizeof(value))) {
joel_ssc 102:0f430de62447 465 bce_mm = atof(value);
joel_ssc 87:6d95f853dab3 466 char buf[256];
joel_ssc 102:0f430de62447 467 sprintf(buf, "in configfileIO: bce_neutral_mm is %f\n", bce_mm);
joel_ssc 87:6d95f853dab3 468 mbedLogger().appendDiagFile(buf,3);
joel_ssc 87:6d95f853dab3 469 // buf[256]= {0};
joel_ssc 87:6d95f853dab3 470 neutralStruct.bce_neutral_mm = bce_mm;
joel_ssc 87:6d95f853dab3 471 count++;
joel_ssc 87:6d95f853dab3 472 }
joel_ssc 87:6d95f853dab3 473 if (cfg.getValue("batt_neutral_mm", &value[0] , sizeof(value))) {
joel_ssc 102:0f430de62447 474 batt_mm = atof(value);
joel_ssc 87:6d95f853dab3 475 char buf[256];
joel_ssc 102:0f430de62447 476 sprintf(buf, "in configfileIO: batt_neutral_mm is %f\n", batt_mm);
joel_ssc 87:6d95f853dab3 477 mbedLogger().appendDiagFile(buf,3);
joel_ssc 87:6d95f853dab3 478 // buf[256]= {0};
joel_ssc 87:6d95f853dab3 479 neutralStruct.batt_neutral_mm = batt_mm;
joel_ssc 87:6d95f853dab3 480 count++;
joel_ssc 87:6d95f853dab3 481 }
joel_ssc 87:6d95f853dab3 482 return count;
joel_ssc 87:6d95f853dab3 483 }
joel_ssc 102:0f430de62447 484
joel_ssc 102:0f430de62447 485 void ConfigFileIO::saveNeutralStatus(int setval, float bce_neutral_mm, float batt_neutral_mm) {
joel_ssc 87:6d95f853dab3 486 ConfigFile neutral_txt;
joel_ssc 87:6d95f853dab3 487
joel_ssc 87:6d95f853dab3 488 //convert input numbers into text and save them to text file
joel_ssc 87:6d95f853dab3 489 char string_setval[128];
joel_ssc 87:6d95f853dab3 490 sprintf(string_setval, "%d", setval);
joel_ssc 87:6d95f853dab3 491 neutral_txt.setValue("# Neutral set status and values\nneutral_set", string_setval);
joel_ssc 87:6d95f853dab3 492
joel_ssc 87:6d95f853dab3 493 char string_bce[128];
joel_ssc 102:0f430de62447 494 sprintf(string_bce, "%.1f", bce_neutral_mm);
joel_ssc 87:6d95f853dab3 495 neutral_txt.setValue("bce_neutral_mm", string_bce);
joel_ssc 87:6d95f853dab3 496
joel_ssc 87:6d95f853dab3 497 char string_batt[128];
joel_ssc 102:0f430de62447 498 sprintf(string_batt, "%.1f", batt_neutral_mm);
joel_ssc 87:6d95f853dab3 499 neutral_txt.setValue("batt_neutral_mm", string_batt);
joel_ssc 87:6d95f853dab3 500
joel_ssc 87:6d95f853dab3 501
joel_ssc 95:1aac4086928a 502 //SAVE THE DATA! also put the data into the neutral struct
joel_ssc 87:6d95f853dab3 503 neutralStruct.batt_neutral_mm = batt_neutral_mm;
joel_ssc 87:6d95f853dab3 504 neutralStruct.bce_neutral_mm = bce_neutral_mm;
joel_ssc 87:6d95f853dab3 505 neutralStruct.setval = setval;
joel_ssc 87:6d95f853dab3 506 xbee().printf("(ConfigFileIO) Saving neutral set status parameters!");
joel_ssc 87:6d95f853dab3 507
joel_ssc 87:6d95f853dab3 508 if (!neutral_txt.write("/local/neutral.txt")) {
joel_ssc 87:6d95f853dab3 509 xbee().printf("\n\rERROR: (SAVE) Failure to write neutral.txt file.");
joel_ssc 87:6d95f853dab3 510 }
joel_ssc 87:6d95f853dab3 511 else {
joel_ssc 87:6d95f853dab3 512 xbee().printf("\n\rFile neutral.txt successful written.\n\r");
joel_ssc 87:6d95f853dab3 513 }
joel_ssc 87:6d95f853dab3 514 }
joel_ssc 102:0f430de62447 515 void ConfigFileIO::writeEndleg_reason() {
joel_ssc 102:0f430de62447 516 ConfigFile neutral_txt;
joel_ssc 102:0f430de62447 517
joel_ssc 102:0f430de62447 518 //convert input numbers into text and save them to text file
joel_ssc 102:0f430de62447 519 char string_setval[128];
joel_ssc 102:0f430de62447 520 char buf[256];
joel_ssc 102:0f430de62447 521 sprintf(string_setval, "%d", swimConstants.endleg_reason);
joel_ssc 102:0f430de62447 522 //neutral_txt.setValue("# EndLeg reason set here\n# 1=normal timeout 2=yo_timeout 3=altim_abort 4=no_find_neutral \n# 5=still inverted 6=yo_timeout+too slow 7=no_find_neutral+altim_abort 8=max_runtime\n[values]\nendleg_reason", string_setval);
joel_ssc 102:0f430de62447 523 neutral_txt.setValue("# EndLeg reason set here\n[values]\nendleg_reason", string_setval);
joel_ssc 102:0f430de62447 524
joel_ssc 102:0f430de62447 525
joel_ssc 102:0f430de62447 526 xbee().printf("(ConfigFileIO) Saving endleg reason to file");
joel_ssc 102:0f430de62447 527 sprintf(buf, "CONFIGFILEIO(): in write_endleg_reason writing out file\n");
joel_ssc 102:0f430de62447 528 mbedLogger().appendDiagFile(buf,3);
joel_ssc 102:0f430de62447 529
joel_ssc 102:0f430de62447 530 if (!neutral_txt.write("/local/endleg.txt")) {
joel_ssc 102:0f430de62447 531 xbee().printf("\n\rERROR: (SAVE) Failure to write endleg.txt file.");
joel_ssc 102:0f430de62447 532 }
joel_ssc 102:0f430de62447 533 else {
joel_ssc 102:0f430de62447 534 xbee().printf("\n\rFile endleg.txt successfully written.\n\r");
joel_ssc 102:0f430de62447 535 }
joel_ssc 102:0f430de62447 536 }
joel_ssc 82:0981b9ada820 537 int ConfigFileIO::load_BATT_config() { // I could copy this mode to read one line of a leg_mission file. One line or multiple lines?
joel_ssc 82:0981b9ada820 538 ConfigFile cfg;
joel_ssc 82:0981b9ada820 539 int count = 0;
joel_ssc 82:0981b9ada820 540 if (!cfg.read("/local/batt.txt")) { // "/local/leg_mission.txt"
tnhnrl 57:ec69651c8c21 541 error("BATT File Read Error");
tnhnrl 57:ec69651c8c21 542 }
tnhnrl 57:ec69651c8c21 543 char value[BUFSIZ];
tnhnrl 57:ec69651c8c21 544
tnhnrl 57:ec69651c8c21 545
tnhnrl 57:ec69651c8c21 546 if (cfg.getValue("PGain", &value[0] , sizeof(value))) {
joel_ssc 82:0981b9ada820 547 batt().setControllerP(atof(value)); // but I want values in a legStructLoaded, not a function
tnhnrl 57:ec69651c8c21 548 count++;
tnhnrl 57:ec69651c8c21 549 }
tnhnrl 57:ec69651c8c21 550 if (cfg.getValue("IGain", &value[0] ,sizeof(value))) {
tnhnrl 57:ec69651c8c21 551 batt().setControllerI(atof(value));
tnhnrl 57:ec69651c8c21 552 count++;
tnhnrl 57:ec69651c8c21 553 }
tnhnrl 57:ec69651c8c21 554 if (cfg.getValue("DGain", &value[0] , sizeof(value))) {
tnhnrl 57:ec69651c8c21 555 batt().setControllerD(atof(value));
tnhnrl 57:ec69651c8c21 556 count++;
tnhnrl 57:ec69651c8c21 557 }
tnhnrl 57:ec69651c8c21 558 if (cfg.getValue("zeroCounts", &value[0],sizeof(value))) {
tnhnrl 57:ec69651c8c21 559 batt().setZeroCounts(atoi(value));
tnhnrl 57:ec69651c8c21 560 count++;
tnhnrl 57:ec69651c8c21 561 }
tnhnrl 57:ec69651c8c21 562 if (cfg.getValue("PistonTravelLimit", &value[0], sizeof(value))) {
tnhnrl 57:ec69651c8c21 563 batt().setTravelLimit(atof(value));
tnhnrl 57:ec69651c8c21 564 count++;
tnhnrl 57:ec69651c8c21 565 }
tnhnrl 57:ec69651c8c21 566 if (cfg.getValue("slope", &value[0], sizeof(value))) {
tnhnrl 57:ec69651c8c21 567 batt().setPotSlope(atof(value));
tnhnrl 57:ec69651c8c21 568 count++;
tnhnrl 57:ec69651c8c21 569 }
tnhnrl 57:ec69651c8c21 570 if (cfg.getValue("filterWn", &value[0], sizeof(value))) {
tnhnrl 57:ec69651c8c21 571 batt().setFilterFrequency(atof(value));
tnhnrl 57:ec69651c8c21 572 count++;
tnhnrl 57:ec69651c8c21 573 }
tnhnrl 57:ec69651c8c21 574 if (cfg.getValue("deadband", &value[0], sizeof(value))) {
tnhnrl 57:ec69651c8c21 575 batt().setDeadband(atof(value));
tnhnrl 57:ec69651c8c21 576 count++;
tnhnrl 57:ec69651c8c21 577 }
tnhnrl 57:ec69651c8c21 578
tnhnrl 57:ec69651c8c21 579 return count;
tnhnrl 57:ec69651c8c21 580 }
joel_ssc 102:0f430de62447 581 int ConfigFileIO::load_Altimeter_config() { // I could copy this mode to read one line of a leg_mission file. One line or multiple lines?
joel_ssc 102:0f430de62447 582 ConfigFile cfg;
joel_ssc 102:0f430de62447 583 char buf[256];
joel_ssc 102:0f430de62447 584 int count = 0;
joel_ssc 102:0f430de62447 585 if (!cfg.read("/local/altim.txt")) { // "/local/leg_mission.txt"
joel_ssc 102:0f430de62447 586 error("ALT File Read Error");
joel_ssc 102:0f430de62447 587 }
joel_ssc 102:0f430de62447 588 char value[BUFSIZ];
joel_ssc 102:0f430de62447 589
joel_ssc 102:0f430de62447 590
joel_ssc 102:0f430de62447 591 if (cfg.getValue("slope", &value[0] , sizeof(value))) {
joel_ssc 102:0f430de62447 592 sensors().setAltimeterSlope(atof(value)); // but I want values in a legStructLoaded, not a function
joel_ssc 102:0f430de62447 593 count++;
joel_ssc 102:0f430de62447 594 }
joel_ssc 102:0f430de62447 595 sprintf(buf, "in configFileIO:load_altimeter constants: slope = %.4f\n", atof(value));
joel_ssc 102:0f430de62447 596 mbedLogger().appendDiagFile(buf,3);
joel_ssc 102:0f430de62447 597 if (cfg.getValue("intercept", &value[0] ,sizeof(value))) {
joel_ssc 102:0f430de62447 598 sensors().setAltimeterIntercept(atof(value));
joel_ssc 102:0f430de62447 599 count++;
joel_ssc 102:0f430de62447 600 }
joel_ssc 102:0f430de62447 601 sprintf(buf, "in configFileIO:load_altimeter constants: offset = %.4f\n", atof(value));
joel_ssc 102:0f430de62447 602 mbedLogger().appendDiagFile(buf,3);
joel_ssc 102:0f430de62447 603 return count;
joel_ssc 102:0f430de62447 604 }
joel_ssc 87:6d95f853dab3 605 void ConfigFileIO::report_still_inverted( float roll_value, int yotime) {
joel_ssc 87:6d95f853dab3 606 ConfigFile still_inverted;
joel_ssc 87:6d95f853dab3 607
joel_ssc 87:6d95f853dab3 608 char string_yotime[128];
joel_ssc 87:6d95f853dab3 609 sprintf(string_yotime, "%d", yotime);
joel_ssc 87:6d95f853dab3 610 still_inverted.setValue("# Still Inverted after START_SWIM yo timeout timeout\n yo_time", string_yotime);
joel_ssc 87:6d95f853dab3 611
joel_ssc 87:6d95f853dab3 612 char string_roll[128];
joel_ssc 87:6d95f853dab3 613 sprintf(string_roll, "%f", roll_value);
joel_ssc 87:6d95f853dab3 614 still_inverted.setValue("inverted_roll_value", string_roll);
joel_ssc 87:6d95f853dab3 615
joel_ssc 87:6d95f853dab3 616
joel_ssc 87:6d95f853dab3 617 //SAVE THE DATA!
joel_ssc 87:6d95f853dab3 618
joel_ssc 87:6d95f853dab3 619 xbee().printf("(ConfigFileIO) Saving still_inverted status after start_swim timeout!");
joel_ssc 87:6d95f853dab3 620
joel_ssc 87:6d95f853dab3 621 if (!still_inverted.write("/local/inverted.txt")) { // I assume this will build a new file if one is not already there
joel_ssc 87:6d95f853dab3 622 xbee().printf("\n\rERROR: (SAVE) Failure to write inverted.txt file.");
joel_ssc 87:6d95f853dab3 623 }
joel_ssc 87:6d95f853dab3 624 else {
joel_ssc 87:6d95f853dab3 625 xbee().printf("\n\rFile inverted.txt written.\n\r"); // raspberry Pi will need to delete this file on finding it
joel_ssc 87:6d95f853dab3 626 }
joel_ssc 87:6d95f853dab3 627
joel_ssc 87:6d95f853dab3 628 }
joel_ssc 102:0f430de62447 629 void ConfigFileIO::report_no_neutral_found(float bce_last_pos, float batt_last_pos) { // this will tell the Raspberry Pi that neutral was not found -- BAD
joel_ssc 87:6d95f853dab3 630 ConfigFile no_neutral;
joel_ssc 87:6d95f853dab3 631 int setval = 0;
joel_ssc 87:6d95f853dab3 632 //convert input numbers into text and save them to text file
joel_ssc 87:6d95f853dab3 633 char string_setval[128];
joel_ssc 87:6d95f853dab3 634 sprintf(string_setval, "%d", setval);
joel_ssc 87:6d95f853dab3 635 no_neutral.setValue("# Find_Neutral success or failure\nneutral_found", string_setval);
joel_ssc 87:6d95f853dab3 636
joel_ssc 87:6d95f853dab3 637 char string_batt[128];
joel_ssc 102:0f430de62447 638 sprintf(string_batt, "%.1f", batt_last_pos);
joel_ssc 87:6d95f853dab3 639 no_neutral.setValue("batt_last_position", string_batt);
joel_ssc 87:6d95f853dab3 640
joel_ssc 102:0f430de62447 641 sprintf(string_batt, "%.1f", bce_last_pos);
joel_ssc 87:6d95f853dab3 642 no_neutral.setValue("bce_last_position", string_batt);
joel_ssc 87:6d95f853dab3 643
joel_ssc 87:6d95f853dab3 644
joel_ssc 87:6d95f853dab3 645 //SAVE THE DATA! also put the data insto the neutral struct
joel_ssc 87:6d95f853dab3 646
joel_ssc 87:6d95f853dab3 647 xbee().printf("(ConfigFileIO) Saving find_neutral failure status!");
joel_ssc 87:6d95f853dab3 648
joel_ssc 87:6d95f853dab3 649 if (!no_neutral.write("/local/no_float.txt")) { // I assume this will build a new file if one is not already there
joel_ssc 87:6d95f853dab3 650 xbee().printf("\n\rERROR: (SAVE) Failure to write no_float.txt file.");
joel_ssc 87:6d95f853dab3 651 }
joel_ssc 87:6d95f853dab3 652 else {
joel_ssc 87:6d95f853dab3 653 xbee().printf("\n\rFile no_float.txt written.\n\r");
joel_ssc 87:6d95f853dab3 654 }
joel_ssc 87:6d95f853dab3 655 }
joel_ssc 88:1813f583cee9 656 void ConfigFileIO::save_FinalTime() {
joel_ssc 88:1813f583cee9 657 ConfigFile timefile_txt;
joel_ssc 88:1813f583cee9 658 int last_time;
joel_ssc 88:1813f583cee9 659 char header[128];
joel_ssc 88:1813f583cee9 660 sprintf(header,"# Timestamp at last moment before closing shop\n");
joel_ssc 88:1813f583cee9 661
joel_ssc 88:1813f583cee9 662 char string_end_time[128];
joel_ssc 88:1813f583cee9 663 last_time = mbedLogger().getSystemTime();
joel_ssc 88:1813f583cee9 664 sprintf(string_end_time, "%d", last_time);
joel_ssc 88:1813f583cee9 665 timefile_txt.setValue("TimeStamp", string_end_time);
joel_ssc 88:1813f583cee9 666
joel_ssc 88:1813f583cee9 667
joel_ssc 88:1813f583cee9 668 //SAVE THE DATA!
joel_ssc 88:1813f583cee9 669 xbee().printf("Saving timestamp value!");
joel_ssc 88:1813f583cee9 670
joel_ssc 88:1813f583cee9 671 if (!timefile_txt.write("/local/newtime.txt")) {
joel_ssc 88:1813f583cee9 672 xbee().printf("\n\rERROR: (SAVE)Failure to write time.txt file.");
joel_ssc 88:1813f583cee9 673 }
joel_ssc 88:1813f583cee9 674 else {
joel_ssc 88:1813f583cee9 675 xbee().printf("\n\rFile newtime.txt successfully written.\n\r");
joel_ssc 88:1813f583cee9 676 }
joel_ssc 88:1813f583cee9 677 }
tnhnrl 57:ec69651c8c21 678 int ConfigFileIO::load_DEPTH_config() {
tnhnrl 57:ec69651c8c21 679 ConfigFile cfg;
tnhnrl 57:ec69651c8c21 680 int count = 0;
tnhnrl 57:ec69651c8c21 681 if (!cfg.read("/local/depth.txt")) {
tnhnrl 57:ec69651c8c21 682 error("DEPTH File Read Error");
tnhnrl 57:ec69651c8c21 683 }
tnhnrl 57:ec69651c8c21 684 char value[BUFSIZ];
tnhnrl 57:ec69651c8c21 685
tnhnrl 57:ec69651c8c21 686 if (cfg.getValue("PGain", &value[0] , sizeof(value))) {
tnhnrl 57:ec69651c8c21 687 depthLoop().setControllerP(atof(value));
tnhnrl 57:ec69651c8c21 688 count++;
tnhnrl 57:ec69651c8c21 689 }
tnhnrl 57:ec69651c8c21 690 if (cfg.getValue("IGain", &value[0] ,sizeof(value))) {
tnhnrl 57:ec69651c8c21 691 depthLoop().setControllerI(atof(value));
tnhnrl 57:ec69651c8c21 692 count++;
tnhnrl 57:ec69651c8c21 693 }
tnhnrl 57:ec69651c8c21 694 if (cfg.getValue("DGain", &value[0] , sizeof(value))) {
tnhnrl 57:ec69651c8c21 695 depthLoop().setControllerD(atof(value));
tnhnrl 57:ec69651c8c21 696 count++;
tnhnrl 57:ec69651c8c21 697 }
tnhnrl 57:ec69651c8c21 698 if (cfg.getValue("filterWn", &value[0], sizeof(value))) {
tnhnrl 57:ec69651c8c21 699 depthLoop().setFilterFrequency(atof(value));
tnhnrl 57:ec69651c8c21 700 count++;
tnhnrl 57:ec69651c8c21 701 }
tnhnrl 57:ec69651c8c21 702 if (cfg.getValue("deadband", &value[0], sizeof(value))) {
tnhnrl 57:ec69651c8c21 703 depthLoop().setDeadband(atof(value));
tnhnrl 57:ec69651c8c21 704 count++;
tnhnrl 57:ec69651c8c21 705 }
tnhnrl 57:ec69651c8c21 706 if (cfg.getValue("zeroOffset", &value[0], sizeof(value))) {
tnhnrl 57:ec69651c8c21 707 depthLoop().setOutputOffset(atof(value));
tnhnrl 57:ec69651c8c21 708 count++;
tnhnrl 57:ec69651c8c21 709 }
tnhnrl 57:ec69651c8c21 710 return count;
tnhnrl 57:ec69651c8c21 711 }
tnhnrl 57:ec69651c8c21 712
tnhnrl 57:ec69651c8c21 713 int ConfigFileIO::load_PITCH_config() {
tnhnrl 57:ec69651c8c21 714 ConfigFile cfg;
tnhnrl 57:ec69651c8c21 715 int count = 0;
tnhnrl 57:ec69651c8c21 716 if (!cfg.read("/local/pitch.txt")){
tnhnrl 57:ec69651c8c21 717 error("PITCH File Read Error");
tnhnrl 57:ec69651c8c21 718 }
tnhnrl 57:ec69651c8c21 719 char value[BUFSIZ];
tnhnrl 57:ec69651c8c21 720
tnhnrl 57:ec69651c8c21 721 if (cfg.getValue("PGain", &value[0] , sizeof(value))) {
tnhnrl 57:ec69651c8c21 722 pitchLoop().setControllerP(atof(value));
tnhnrl 57:ec69651c8c21 723 count++;
tnhnrl 57:ec69651c8c21 724 }
tnhnrl 57:ec69651c8c21 725 if (cfg.getValue("IGain", &value[0] ,sizeof(value))) {
tnhnrl 57:ec69651c8c21 726 pitchLoop().setControllerI(atof(value));
tnhnrl 57:ec69651c8c21 727 count++;
tnhnrl 57:ec69651c8c21 728 }
tnhnrl 57:ec69651c8c21 729 if (cfg.getValue("DGain", &value[0] , sizeof(value))) {
tnhnrl 57:ec69651c8c21 730 pitchLoop().setControllerD(atof(value));
tnhnrl 57:ec69651c8c21 731 count++;
tnhnrl 57:ec69651c8c21 732 }
tnhnrl 57:ec69651c8c21 733 if (cfg.getValue("filterWn", &value[0], sizeof(value))) {
tnhnrl 57:ec69651c8c21 734 pitchLoop().setFilterFrequency(atof(value));
tnhnrl 57:ec69651c8c21 735 count++;
tnhnrl 57:ec69651c8c21 736 }
tnhnrl 57:ec69651c8c21 737 if (cfg.getValue("deadband", &value[0], sizeof(value))) {
tnhnrl 57:ec69651c8c21 738 pitchLoop().setDeadband(atof(value));
tnhnrl 57:ec69651c8c21 739 count++;
tnhnrl 57:ec69651c8c21 740 }
tnhnrl 57:ec69651c8c21 741
tnhnrl 57:ec69651c8c21 742 if (cfg.getValue("zeroOffset", &value[0], sizeof(value))) {
tnhnrl 57:ec69651c8c21 743 pitchLoop().setOutputOffset(atof(value));
tnhnrl 57:ec69651c8c21 744 count++;
tnhnrl 57:ec69651c8c21 745 }
tnhnrl 57:ec69651c8c21 746 return count;
tnhnrl 57:ec69651c8c21 747 }
tnhnrl 57:ec69651c8c21 748
tnhnrl 57:ec69651c8c21 749 int ConfigFileIO::load_HEADING_config() {
tnhnrl 57:ec69651c8c21 750 ConfigFile cfg;
tnhnrl 57:ec69651c8c21 751 int count = 0;
tnhnrl 57:ec69651c8c21 752 if (!cfg.read("/local/heading.txt")){
tnhnrl 57:ec69651c8c21 753 error("HEADING File Read Error");
tnhnrl 57:ec69651c8c21 754 }
tnhnrl 57:ec69651c8c21 755 char value[BUFSIZ];
tnhnrl 57:ec69651c8c21 756
tnhnrl 57:ec69651c8c21 757 if (cfg.getValue("PGain", &value[0] , sizeof(value))) {
tnhnrl 57:ec69651c8c21 758 headingLoop().setControllerP(atof(value));
tnhnrl 57:ec69651c8c21 759 count++;
tnhnrl 57:ec69651c8c21 760 }
tnhnrl 57:ec69651c8c21 761 if (cfg.getValue("IGain", &value[0] ,sizeof(value))) {
tnhnrl 57:ec69651c8c21 762 headingLoop().setControllerI(atof(value));
tnhnrl 57:ec69651c8c21 763 count++;
tnhnrl 57:ec69651c8c21 764 }
tnhnrl 57:ec69651c8c21 765 if (cfg.getValue("DGain", &value[0] , sizeof(value))) {
tnhnrl 57:ec69651c8c21 766 headingLoop().setControllerD(atof(value));
tnhnrl 57:ec69651c8c21 767 count++;
tnhnrl 57:ec69651c8c21 768 }
tnhnrl 57:ec69651c8c21 769 if (cfg.getValue("filterWn", &value[0], sizeof(value))) {
tnhnrl 57:ec69651c8c21 770 headingLoop().setFilterFrequency(atof(value));
tnhnrl 57:ec69651c8c21 771 count++;
tnhnrl 57:ec69651c8c21 772 }
tnhnrl 57:ec69651c8c21 773 if (cfg.getValue("deadband", &value[0], sizeof(value))) {
tnhnrl 57:ec69651c8c21 774 headingLoop().setDeadband(atof(value));
tnhnrl 57:ec69651c8c21 775 count++;
tnhnrl 57:ec69651c8c21 776 }
tnhnrl 57:ec69651c8c21 777
tnhnrl 57:ec69651c8c21 778 if (cfg.getValue("zeroOffset", &value[0], sizeof(value))) {
tnhnrl 57:ec69651c8c21 779 headingLoop().setOutputOffset(atof(value));
tnhnrl 57:ec69651c8c21 780 count++;
tnhnrl 57:ec69651c8c21 781 }
tnhnrl 57:ec69651c8c21 782 return count;
tnhnrl 57:ec69651c8c21 783 }
tnhnrl 57:ec69651c8c21 784
tnhnrl 57:ec69651c8c21 785 int ConfigFileIO::load_RUDDER_config() {
tnhnrl 57:ec69651c8c21 786 ConfigFile cfg;
tnhnrl 57:ec69651c8c21 787 int count = 0;
tnhnrl 57:ec69651c8c21 788 if (!cfg.read("/local/rudder.txt")){
tnhnrl 57:ec69651c8c21 789 error("RUDDER File Read Error");
tnhnrl 57:ec69651c8c21 790 }
tnhnrl 57:ec69651c8c21 791 char value[BUFSIZ];
tnhnrl 57:ec69651c8c21 792
tnhnrl 57:ec69651c8c21 793 //float values below
tnhnrl 57:ec69651c8c21 794 if (cfg.getValue("setMinDeg", &value[0] , sizeof(value))) {
tnhnrl 57:ec69651c8c21 795 rudder().setMinDeg(atof(value));
tnhnrl 57:ec69651c8c21 796 count++;
tnhnrl 57:ec69651c8c21 797 }
tnhnrl 57:ec69651c8c21 798 if (cfg.getValue("setMaxDeg", &value[0] ,sizeof(value))) {
tnhnrl 57:ec69651c8c21 799 rudder().setMaxDeg(atof(value));
tnhnrl 57:ec69651c8c21 800 count++;
tnhnrl 57:ec69651c8c21 801 }
tnhnrl 57:ec69651c8c21 802
tnhnrl 57:ec69651c8c21 803 //integer values below
tnhnrl 57:ec69651c8c21 804 if (cfg.getValue("setCenterPWM", &value[0] , sizeof(value))) {
tnhnrl 57:ec69651c8c21 805 rudder().setCenterPWM(atof(value));
tnhnrl 57:ec69651c8c21 806 count++;
tnhnrl 57:ec69651c8c21 807 }
tnhnrl 57:ec69651c8c21 808 if (cfg.getValue("setMinPWM", &value[0], sizeof(value))) {
tnhnrl 57:ec69651c8c21 809 rudder().setMinPWM(atof(value));
tnhnrl 57:ec69651c8c21 810 count++;
tnhnrl 57:ec69651c8c21 811 }
tnhnrl 57:ec69651c8c21 812 if (cfg.getValue("setMaxPWM", &value[0], sizeof(value))) {
tnhnrl 57:ec69651c8c21 813 rudder().setMaxPWM(atof(value));
tnhnrl 57:ec69651c8c21 814 count++;
tnhnrl 57:ec69651c8c21 815 }
tnhnrl 57:ec69651c8c21 816 return count;
tnhnrl 57:ec69651c8c21 817 }