Flying Sea Glider / Mbed 2 deprecated 2019_13sep_jcw_nosd

Dependencies:   mbed MODSERIAL FATFileSystem

Committer:
CodyMarquardt
Date:
Fri Jun 28 15:07:41 2019 +0000
Revision:
101:c24f70abb124
Parent:
95:1aac4086928a
Child:
102:0f430de62447
k

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 }
tnhnrl 57:ec69651c8c21 264
tnhnrl 57:ec69651c8c21 265 int ConfigFileIO::load_BCE_config() {
tnhnrl 57:ec69651c8c21 266 ConfigFile cfg;
tnhnrl 57:ec69651c8c21 267 int count = 0;
tnhnrl 57:ec69651c8c21 268 if (!cfg.read("/local/bce.txt")) {
tnhnrl 57:ec69651c8c21 269 error("File Read Error");
tnhnrl 57:ec69651c8c21 270 }
tnhnrl 57:ec69651c8c21 271 char value[BUFSIZ];
tnhnrl 57:ec69651c8c21 272
tnhnrl 57:ec69651c8c21 273 if (cfg.getValue("PGain", &value[0] , sizeof(value))) {
tnhnrl 57:ec69651c8c21 274 bce().setControllerP(atof(value));
tnhnrl 57:ec69651c8c21 275 count++;
tnhnrl 57:ec69651c8c21 276 }
tnhnrl 57:ec69651c8c21 277 if (cfg.getValue("IGain", &value[0] ,sizeof(value))) {
tnhnrl 57:ec69651c8c21 278 bce().setControllerI(atof(value));
tnhnrl 57:ec69651c8c21 279 count++;
tnhnrl 57:ec69651c8c21 280 }
tnhnrl 57:ec69651c8c21 281 if (cfg.getValue("DGain", &value[0] , sizeof(value))) {
tnhnrl 57:ec69651c8c21 282 bce().setControllerD(atof(value));
tnhnrl 57:ec69651c8c21 283 count++;
tnhnrl 57:ec69651c8c21 284 }
tnhnrl 57:ec69651c8c21 285 if (cfg.getValue("zeroCounts", &value[0],sizeof(value))) {
tnhnrl 57:ec69651c8c21 286 bce().setZeroCounts(atoi(value));
tnhnrl 57:ec69651c8c21 287 count++;
tnhnrl 57:ec69651c8c21 288 }
tnhnrl 57:ec69651c8c21 289 if (cfg.getValue("PistonTravelLimit", &value[0], sizeof(value))) {
tnhnrl 57:ec69651c8c21 290 bce().setTravelLimit(atof(value));
tnhnrl 57:ec69651c8c21 291 count++;
tnhnrl 57:ec69651c8c21 292 }
tnhnrl 57:ec69651c8c21 293 if (cfg.getValue("slope", &value[0], sizeof(value))) {
tnhnrl 57:ec69651c8c21 294 bce().setPotSlope(atof(value));
tnhnrl 57:ec69651c8c21 295 count++;
tnhnrl 57:ec69651c8c21 296 }
tnhnrl 57:ec69651c8c21 297 if (cfg.getValue("filterWn", &value[0], sizeof(value))) {
tnhnrl 57:ec69651c8c21 298 bce().setFilterFrequency(atof(value));
tnhnrl 57:ec69651c8c21 299 count++;
tnhnrl 57:ec69651c8c21 300 }
tnhnrl 57:ec69651c8c21 301 if (cfg.getValue("deadband", &value[0], sizeof(value))) {
tnhnrl 57:ec69651c8c21 302 bce().setDeadband(atof(value));
tnhnrl 57:ec69651c8c21 303 count++;
tnhnrl 57:ec69651c8c21 304 }
tnhnrl 57:ec69651c8c21 305
tnhnrl 57:ec69651c8c21 306 return count;
tnhnrl 57:ec69651c8c21 307 }
tnhnrl 57:ec69651c8c21 308
tnhnrl 57:ec69651c8c21 309 //write to heading.txt
tnhnrl 73:f6f378311c8d 310 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 311 ConfigFile heading_txt;
tnhnrl 57:ec69651c8c21 312
tnhnrl 57:ec69651c8c21 313 char PGain_buffer[128];
tnhnrl 57:ec69651c8c21 314 sprintf(PGain_buffer,"# HEADING (rudder outer loop) parameters\n\n#Gains\nPGain");
tnhnrl 57:ec69651c8c21 315
tnhnrl 57:ec69651c8c21 316 //convert input numbers into text and save them to text file
tnhnrl 57:ec69651c8c21 317 char string_pgain[128];
tnhnrl 57:ec69651c8c21 318 sprintf(string_pgain, "%f", heading_p_gain);
tnhnrl 57:ec69651c8c21 319 heading_txt.setValue(PGain_buffer, string_pgain);
tnhnrl 57:ec69651c8c21 320
tnhnrl 57:ec69651c8c21 321 char string_igain[128];
tnhnrl 57:ec69651c8c21 322 sprintf(string_igain, "%f", heading_i_gain);
tnhnrl 57:ec69651c8c21 323 heading_txt.setValue("IGain", string_igain);
tnhnrl 57:ec69651c8c21 324
tnhnrl 57:ec69651c8c21 325 char string_dgain[128];
tnhnrl 57:ec69651c8c21 326 sprintf(string_dgain, "%f", heading_d_gain);
tnhnrl 57:ec69651c8c21 327 heading_txt.setValue("DGain", string_dgain);
tnhnrl 74:d281aaef9766 328
tnhnrl 74:d281aaef9766 329 char string_heading_freq[128];
tnhnrl 74:d281aaef9766 330 sprintf(string_heading_freq, "%f", heading_filter_freq);
tnhnrl 74:d281aaef9766 331 heading_txt.setValue("\n# HEADING sensor filter parameters\nfilterWn", string_heading_freq);
tnhnrl 74:d281aaef9766 332
tnhnrl 74:d281aaef9766 333 char string_heading_db[128];
tnhnrl 74:d281aaef9766 334 sprintf(string_heading_db, "%f", heading_deadband);
tnhnrl 74:d281aaef9766 335 heading_txt.setValue("deadband",string_heading_db);
tnhnrl 57:ec69651c8c21 336
tnhnrl 57:ec69651c8c21 337 char string_zeroOffset[128];
tnhnrl 73:f6f378311c8d 338 sprintf(string_zeroOffset, "%f", heading_zeroOffset);
tnhnrl 74:d281aaef9766 339 heading_txt.setValue("\n#HEADING offset\nzeroOffset", string_zeroOffset);
tnhnrl 57:ec69651c8c21 340
tnhnrl 57:ec69651c8c21 341 //SAVE THE DATA!
tnhnrl 74:d281aaef9766 342 xbee().printf("(ConfigFileIO) Saving HEADING parameters!");
tnhnrl 57:ec69651c8c21 343
tnhnrl 57:ec69651c8c21 344 if (!heading_txt.write("/local/heading.txt")) {
tnhnrl 74:d281aaef9766 345 xbee().printf("\n\rERROR: (SAVE) Failure to write heading.txt file.");
tnhnrl 57:ec69651c8c21 346 }
tnhnrl 57:ec69651c8c21 347 else {
tnhnrl 74:d281aaef9766 348 xbee().printf("\n\rFile heading.txt successful written.\n\r");
tnhnrl 57:ec69651c8c21 349 }
tnhnrl 57:ec69651c8c21 350 }
joel_ssc 82:0981b9ada820 351 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 352 ConfigFile cfg;
tnhnrl 57:ec69651c8c21 353 int count = 0;
joel_ssc 82:0981b9ada820 354 int version = 0;
joel_ssc 82:0981b9ada820 355 if (!cfg.read("/local/logvers.txt")) { // "/local/leg_mission.txt"
joel_ssc 82:0981b9ada820 356 error("Lognames version file logvers.txt File Read Error");
joel_ssc 82:0981b9ada820 357 }
joel_ssc 87:6d95f853dab3 358 char value[BUFSIZ]; // chang
joel_ssc 82:0981b9ada820 359
joel_ssc 82:0981b9ada820 360
joel_ssc 82:0981b9ada820 361 if (cfg.getValue("LogFileVers", &value[0] , sizeof(value))) {
joel_ssc 82:0981b9ada820 362 version = atoi(value);
joel_ssc 82:0981b9ada820 363 char buf[256];
joel_ssc 82:0981b9ada820 364 sprintf(buf, "LOG%03d.csv", version);
joel_ssc 82:0981b9ada820 365 logFilesStruct.logFileName = buf;
joel_ssc 82:0981b9ada820 366 logFilesStruct.logversion = version;
joel_ssc 82:0981b9ada820 367 count++;
joel_ssc 82:0981b9ada820 368 }
joel_ssc 82:0981b9ada820 369 if (cfg.getValue("DiagFileVers", &value[0] , sizeof(value))) {
joel_ssc 82:0981b9ada820 370 version = atoi(value);
joel_ssc 82:0981b9ada820 371 char buf[256];
joel_ssc 82:0981b9ada820 372
joel_ssc 82:0981b9ada820 373 sprintf(buf, "in configfileIO: diag file version number is %d\n", version);
joel_ssc 82:0981b9ada820 374 if(print_diag == 1) {mbedLogger().appendDiagFile(buf,3);}
joel_ssc 82:0981b9ada820 375 // buf[256]= {0};
joel_ssc 87:6d95f853dab3 376 sprintf(buf, "in ConfigFileIO: diag file string is DIAG%03d.txt\n", version);
joel_ssc 82:0981b9ada820 377 if(print_diag == 1) {mbedLogger().appendDiagFile(buf,3);}
joel_ssc 82:0981b9ada820 378 // buf[256]= {0};
joel_ssc 82:0981b9ada820 379 sprintf(buf, "DIAG%03d.txt", version);
joel_ssc 82:0981b9ada820 380 logFilesStruct.diagFileName = buf;
joel_ssc 82:0981b9ada820 381 logFilesStruct.diagversion = version;
joel_ssc 82:0981b9ada820 382 sprintf(buf, "in ConfigFileIO: diag info pulled from struct: filename = %s diagvernum = %d\n", logFilesStruct.diagFileName,
joel_ssc 82:0981b9ada820 383 logFilesStruct.diagversion);
joel_ssc 82:0981b9ada820 384 if(print_diag==1) {mbedLogger().appendDiagFile(buf,3);}
joel_ssc 82:0981b9ada820 385 count++;
joel_ssc 82:0981b9ada820 386 }
joel_ssc 82:0981b9ada820 387 return count;
joel_ssc 82:0981b9ada820 388 }
joel_ssc 87:6d95f853dab3 389 int ConfigFileIO::load_setneutral_status() {
joel_ssc 87:6d95f853dab3 390 ConfigFile cfg;
joel_ssc 87:6d95f853dab3 391 int count = 0;
joel_ssc 87:6d95f853dab3 392 int setval = 0;
joel_ssc 87:6d95f853dab3 393 int bce_mm = 240;
joel_ssc 87:6d95f853dab3 394 int batt_mm = 40;
joel_ssc 87:6d95f853dab3 395 if (!cfg.read("/local/neutral.txt")) {
joel_ssc 87:6d95f853dab3 396 error("setneutral file neutral.txt File Read Error");
joel_ssc 87:6d95f853dab3 397 // set values in struct to defaults??
joel_ssc 87:6d95f853dab3 398 }
joel_ssc 87:6d95f853dab3 399 char value[BUFSIZ];
joel_ssc 87:6d95f853dab3 400
joel_ssc 87:6d95f853dab3 401
joel_ssc 87:6d95f853dab3 402 if (cfg.getValue("neutral_set", &value[0] , sizeof(value))) {
joel_ssc 87:6d95f853dab3 403 setval = atoi(value);
joel_ssc 87:6d95f853dab3 404 neutralStruct.setval = setval;
joel_ssc 87:6d95f853dab3 405 count++;
joel_ssc 87:6d95f853dab3 406 }
joel_ssc 87:6d95f853dab3 407 if (cfg.getValue("bce_neutral_mm", &value[0] , sizeof(value))) {
joel_ssc 87:6d95f853dab3 408 bce_mm = atoi(value);
joel_ssc 87:6d95f853dab3 409 char buf[256];
joel_ssc 87:6d95f853dab3 410 sprintf(buf, "in configfileIO: bce_neutral_mm is %d\n", bce_mm);
joel_ssc 87:6d95f853dab3 411 mbedLogger().appendDiagFile(buf,3);
joel_ssc 87:6d95f853dab3 412 // buf[256]= {0};
joel_ssc 87:6d95f853dab3 413 neutralStruct.bce_neutral_mm = bce_mm;
joel_ssc 87:6d95f853dab3 414 count++;
joel_ssc 87:6d95f853dab3 415 }
joel_ssc 87:6d95f853dab3 416 if (cfg.getValue("batt_neutral_mm", &value[0] , sizeof(value))) {
joel_ssc 87:6d95f853dab3 417 batt_mm = atoi(value);
joel_ssc 87:6d95f853dab3 418 char buf[256];
joel_ssc 87:6d95f853dab3 419 sprintf(buf, "in configfileIO: batt_neutral_mm is %d\n", batt_mm);
joel_ssc 87:6d95f853dab3 420 mbedLogger().appendDiagFile(buf,3);
joel_ssc 87:6d95f853dab3 421 // buf[256]= {0};
joel_ssc 87:6d95f853dab3 422 neutralStruct.batt_neutral_mm = batt_mm;
joel_ssc 87:6d95f853dab3 423 count++;
joel_ssc 87:6d95f853dab3 424 }
joel_ssc 87:6d95f853dab3 425 return count;
joel_ssc 87:6d95f853dab3 426 }
joel_ssc 87:6d95f853dab3 427 void ConfigFileIO::saveNeutralStatus(int setval, int bce_neutral_mm, int batt_neutral_mm) {
joel_ssc 87:6d95f853dab3 428 ConfigFile neutral_txt;
joel_ssc 87:6d95f853dab3 429
joel_ssc 87:6d95f853dab3 430 //convert input numbers into text and save them to text file
joel_ssc 87:6d95f853dab3 431 char string_setval[128];
joel_ssc 87:6d95f853dab3 432 sprintf(string_setval, "%d", setval);
joel_ssc 87:6d95f853dab3 433 neutral_txt.setValue("# Neutral set status and values\nneutral_set", string_setval);
joel_ssc 87:6d95f853dab3 434
joel_ssc 87:6d95f853dab3 435 char string_bce[128];
joel_ssc 87:6d95f853dab3 436 sprintf(string_bce, "%d", bce_neutral_mm);
joel_ssc 87:6d95f853dab3 437 neutral_txt.setValue("bce_neutral_mm", string_bce);
joel_ssc 87:6d95f853dab3 438
joel_ssc 87:6d95f853dab3 439 char string_batt[128];
joel_ssc 87:6d95f853dab3 440 sprintf(string_batt, "%d", batt_neutral_mm);
joel_ssc 87:6d95f853dab3 441 neutral_txt.setValue("batt_neutral_mm", string_batt);
joel_ssc 87:6d95f853dab3 442
joel_ssc 87:6d95f853dab3 443
joel_ssc 95:1aac4086928a 444 //SAVE THE DATA! also put the data into the neutral struct
joel_ssc 87:6d95f853dab3 445 neutralStruct.batt_neutral_mm = batt_neutral_mm;
joel_ssc 87:6d95f853dab3 446 neutralStruct.bce_neutral_mm = bce_neutral_mm;
joel_ssc 87:6d95f853dab3 447 neutralStruct.setval = setval;
joel_ssc 87:6d95f853dab3 448 xbee().printf("(ConfigFileIO) Saving neutral set status parameters!");
joel_ssc 87:6d95f853dab3 449
joel_ssc 87:6d95f853dab3 450 if (!neutral_txt.write("/local/neutral.txt")) {
joel_ssc 87:6d95f853dab3 451 xbee().printf("\n\rERROR: (SAVE) Failure to write neutral.txt file.");
joel_ssc 87:6d95f853dab3 452 }
joel_ssc 87:6d95f853dab3 453 else {
joel_ssc 87:6d95f853dab3 454 xbee().printf("\n\rFile neutral.txt successful written.\n\r");
joel_ssc 87:6d95f853dab3 455 }
joel_ssc 87:6d95f853dab3 456 }
joel_ssc 82:0981b9ada820 457 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 458 ConfigFile cfg;
joel_ssc 82:0981b9ada820 459 int count = 0;
joel_ssc 82:0981b9ada820 460 if (!cfg.read("/local/batt.txt")) { // "/local/leg_mission.txt"
tnhnrl 57:ec69651c8c21 461 error("BATT File Read Error");
tnhnrl 57:ec69651c8c21 462 }
tnhnrl 57:ec69651c8c21 463 char value[BUFSIZ];
tnhnrl 57:ec69651c8c21 464
tnhnrl 57:ec69651c8c21 465
tnhnrl 57:ec69651c8c21 466 if (cfg.getValue("PGain", &value[0] , sizeof(value))) {
joel_ssc 82:0981b9ada820 467 batt().setControllerP(atof(value)); // but I want values in a legStructLoaded, not a function
tnhnrl 57:ec69651c8c21 468 count++;
tnhnrl 57:ec69651c8c21 469 }
tnhnrl 57:ec69651c8c21 470 if (cfg.getValue("IGain", &value[0] ,sizeof(value))) {
tnhnrl 57:ec69651c8c21 471 batt().setControllerI(atof(value));
tnhnrl 57:ec69651c8c21 472 count++;
tnhnrl 57:ec69651c8c21 473 }
tnhnrl 57:ec69651c8c21 474 if (cfg.getValue("DGain", &value[0] , sizeof(value))) {
tnhnrl 57:ec69651c8c21 475 batt().setControllerD(atof(value));
tnhnrl 57:ec69651c8c21 476 count++;
tnhnrl 57:ec69651c8c21 477 }
tnhnrl 57:ec69651c8c21 478 if (cfg.getValue("zeroCounts", &value[0],sizeof(value))) {
tnhnrl 57:ec69651c8c21 479 batt().setZeroCounts(atoi(value));
tnhnrl 57:ec69651c8c21 480 count++;
tnhnrl 57:ec69651c8c21 481 }
tnhnrl 57:ec69651c8c21 482 if (cfg.getValue("PistonTravelLimit", &value[0], sizeof(value))) {
tnhnrl 57:ec69651c8c21 483 batt().setTravelLimit(atof(value));
tnhnrl 57:ec69651c8c21 484 count++;
tnhnrl 57:ec69651c8c21 485 }
tnhnrl 57:ec69651c8c21 486 if (cfg.getValue("slope", &value[0], sizeof(value))) {
tnhnrl 57:ec69651c8c21 487 batt().setPotSlope(atof(value));
tnhnrl 57:ec69651c8c21 488 count++;
tnhnrl 57:ec69651c8c21 489 }
tnhnrl 57:ec69651c8c21 490 if (cfg.getValue("filterWn", &value[0], sizeof(value))) {
tnhnrl 57:ec69651c8c21 491 batt().setFilterFrequency(atof(value));
tnhnrl 57:ec69651c8c21 492 count++;
tnhnrl 57:ec69651c8c21 493 }
tnhnrl 57:ec69651c8c21 494 if (cfg.getValue("deadband", &value[0], sizeof(value))) {
tnhnrl 57:ec69651c8c21 495 batt().setDeadband(atof(value));
tnhnrl 57:ec69651c8c21 496 count++;
tnhnrl 57:ec69651c8c21 497 }
tnhnrl 57:ec69651c8c21 498
tnhnrl 57:ec69651c8c21 499 return count;
tnhnrl 57:ec69651c8c21 500 }
joel_ssc 87:6d95f853dab3 501 void ConfigFileIO::report_still_inverted( float roll_value, int yotime) {
joel_ssc 87:6d95f853dab3 502 ConfigFile still_inverted;
joel_ssc 87:6d95f853dab3 503
joel_ssc 87:6d95f853dab3 504 char string_yotime[128];
joel_ssc 87:6d95f853dab3 505 sprintf(string_yotime, "%d", yotime);
joel_ssc 87:6d95f853dab3 506 still_inverted.setValue("# Still Inverted after START_SWIM yo timeout timeout\n yo_time", string_yotime);
joel_ssc 87:6d95f853dab3 507
joel_ssc 87:6d95f853dab3 508 char string_roll[128];
joel_ssc 87:6d95f853dab3 509 sprintf(string_roll, "%f", roll_value);
joel_ssc 87:6d95f853dab3 510 still_inverted.setValue("inverted_roll_value", string_roll);
joel_ssc 87:6d95f853dab3 511
joel_ssc 87:6d95f853dab3 512
joel_ssc 87:6d95f853dab3 513 //SAVE THE DATA!
joel_ssc 87:6d95f853dab3 514
joel_ssc 87:6d95f853dab3 515 xbee().printf("(ConfigFileIO) Saving still_inverted status after start_swim timeout!");
joel_ssc 87:6d95f853dab3 516
joel_ssc 87:6d95f853dab3 517 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 518 xbee().printf("\n\rERROR: (SAVE) Failure to write inverted.txt file.");
joel_ssc 87:6d95f853dab3 519 }
joel_ssc 87:6d95f853dab3 520 else {
joel_ssc 87:6d95f853dab3 521 xbee().printf("\n\rFile inverted.txt written.\n\r"); // raspberry Pi will need to delete this file on finding it
joel_ssc 87:6d95f853dab3 522 }
joel_ssc 87:6d95f853dab3 523
joel_ssc 87:6d95f853dab3 524 }
joel_ssc 87:6d95f853dab3 525 void ConfigFileIO::report_no_neutral_found(int bce_last_pos, int batt_last_pos) { // this will tell the Raspberry Pi that neutral was not found -- BAD
joel_ssc 87:6d95f853dab3 526 ConfigFile no_neutral;
joel_ssc 87:6d95f853dab3 527 int setval = 0;
joel_ssc 87:6d95f853dab3 528 //convert input numbers into text and save them to text file
joel_ssc 87:6d95f853dab3 529 char string_setval[128];
joel_ssc 87:6d95f853dab3 530 sprintf(string_setval, "%d", setval);
joel_ssc 87:6d95f853dab3 531 no_neutral.setValue("# Find_Neutral success or failure\nneutral_found", string_setval);
joel_ssc 87:6d95f853dab3 532
joel_ssc 87:6d95f853dab3 533 char string_batt[128];
joel_ssc 87:6d95f853dab3 534 sprintf(string_batt, "%d", batt_last_pos);
joel_ssc 87:6d95f853dab3 535 no_neutral.setValue("batt_last_position", string_batt);
joel_ssc 87:6d95f853dab3 536
joel_ssc 87:6d95f853dab3 537 sprintf(string_batt, "%d", bce_last_pos);
joel_ssc 87:6d95f853dab3 538 no_neutral.setValue("bce_last_position", string_batt);
joel_ssc 87:6d95f853dab3 539
joel_ssc 87:6d95f853dab3 540
joel_ssc 87:6d95f853dab3 541 //SAVE THE DATA! also put the data insto the neutral struct
joel_ssc 87:6d95f853dab3 542
joel_ssc 87:6d95f853dab3 543 xbee().printf("(ConfigFileIO) Saving find_neutral failure status!");
joel_ssc 87:6d95f853dab3 544
joel_ssc 87:6d95f853dab3 545 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 546 xbee().printf("\n\rERROR: (SAVE) Failure to write no_float.txt file.");
joel_ssc 87:6d95f853dab3 547 }
joel_ssc 87:6d95f853dab3 548 else {
joel_ssc 87:6d95f853dab3 549 xbee().printf("\n\rFile no_float.txt written.\n\r");
joel_ssc 87:6d95f853dab3 550 }
joel_ssc 87:6d95f853dab3 551 }
joel_ssc 88:1813f583cee9 552 void ConfigFileIO::save_FinalTime() {
joel_ssc 88:1813f583cee9 553 ConfigFile timefile_txt;
joel_ssc 88:1813f583cee9 554 int last_time;
joel_ssc 88:1813f583cee9 555 char header[128];
joel_ssc 88:1813f583cee9 556 sprintf(header,"# Timestamp at last moment before closing shop\n");
joel_ssc 88:1813f583cee9 557
joel_ssc 88:1813f583cee9 558 char string_end_time[128];
joel_ssc 88:1813f583cee9 559 last_time = mbedLogger().getSystemTime();
joel_ssc 88:1813f583cee9 560 sprintf(string_end_time, "%d", last_time);
joel_ssc 88:1813f583cee9 561 timefile_txt.setValue("TimeStamp", string_end_time);
joel_ssc 88:1813f583cee9 562
joel_ssc 88:1813f583cee9 563
joel_ssc 88:1813f583cee9 564 //SAVE THE DATA!
joel_ssc 88:1813f583cee9 565 xbee().printf("Saving timestamp value!");
joel_ssc 88:1813f583cee9 566
joel_ssc 88:1813f583cee9 567 if (!timefile_txt.write("/local/newtime.txt")) {
joel_ssc 88:1813f583cee9 568 xbee().printf("\n\rERROR: (SAVE)Failure to write time.txt file.");
joel_ssc 88:1813f583cee9 569 }
joel_ssc 88:1813f583cee9 570 else {
joel_ssc 88:1813f583cee9 571 xbee().printf("\n\rFile newtime.txt successfully written.\n\r");
joel_ssc 88:1813f583cee9 572 }
joel_ssc 88:1813f583cee9 573 }
tnhnrl 57:ec69651c8c21 574 int ConfigFileIO::load_DEPTH_config() {
tnhnrl 57:ec69651c8c21 575 ConfigFile cfg;
tnhnrl 57:ec69651c8c21 576 int count = 0;
tnhnrl 57:ec69651c8c21 577 if (!cfg.read("/local/depth.txt")) {
tnhnrl 57:ec69651c8c21 578 error("DEPTH File Read Error");
tnhnrl 57:ec69651c8c21 579 }
tnhnrl 57:ec69651c8c21 580 char value[BUFSIZ];
tnhnrl 57:ec69651c8c21 581
tnhnrl 57:ec69651c8c21 582 if (cfg.getValue("PGain", &value[0] , sizeof(value))) {
tnhnrl 57:ec69651c8c21 583 depthLoop().setControllerP(atof(value));
tnhnrl 57:ec69651c8c21 584 count++;
tnhnrl 57:ec69651c8c21 585 }
tnhnrl 57:ec69651c8c21 586 if (cfg.getValue("IGain", &value[0] ,sizeof(value))) {
tnhnrl 57:ec69651c8c21 587 depthLoop().setControllerI(atof(value));
tnhnrl 57:ec69651c8c21 588 count++;
tnhnrl 57:ec69651c8c21 589 }
tnhnrl 57:ec69651c8c21 590 if (cfg.getValue("DGain", &value[0] , sizeof(value))) {
tnhnrl 57:ec69651c8c21 591 depthLoop().setControllerD(atof(value));
tnhnrl 57:ec69651c8c21 592 count++;
tnhnrl 57:ec69651c8c21 593 }
tnhnrl 57:ec69651c8c21 594 if (cfg.getValue("filterWn", &value[0], sizeof(value))) {
tnhnrl 57:ec69651c8c21 595 depthLoop().setFilterFrequency(atof(value));
tnhnrl 57:ec69651c8c21 596 count++;
tnhnrl 57:ec69651c8c21 597 }
tnhnrl 57:ec69651c8c21 598 if (cfg.getValue("deadband", &value[0], sizeof(value))) {
tnhnrl 57:ec69651c8c21 599 depthLoop().setDeadband(atof(value));
tnhnrl 57:ec69651c8c21 600 count++;
tnhnrl 57:ec69651c8c21 601 }
tnhnrl 57:ec69651c8c21 602 if (cfg.getValue("zeroOffset", &value[0], sizeof(value))) {
tnhnrl 57:ec69651c8c21 603 depthLoop().setOutputOffset(atof(value));
tnhnrl 57:ec69651c8c21 604 count++;
tnhnrl 57:ec69651c8c21 605 }
tnhnrl 57:ec69651c8c21 606 return count;
tnhnrl 57:ec69651c8c21 607 }
tnhnrl 57:ec69651c8c21 608
tnhnrl 57:ec69651c8c21 609 int ConfigFileIO::load_PITCH_config() {
tnhnrl 57:ec69651c8c21 610 ConfigFile cfg;
tnhnrl 57:ec69651c8c21 611 int count = 0;
tnhnrl 57:ec69651c8c21 612 if (!cfg.read("/local/pitch.txt")){
tnhnrl 57:ec69651c8c21 613 error("PITCH File Read Error");
tnhnrl 57:ec69651c8c21 614 }
tnhnrl 57:ec69651c8c21 615 char value[BUFSIZ];
tnhnrl 57:ec69651c8c21 616
tnhnrl 57:ec69651c8c21 617 if (cfg.getValue("PGain", &value[0] , sizeof(value))) {
tnhnrl 57:ec69651c8c21 618 pitchLoop().setControllerP(atof(value));
tnhnrl 57:ec69651c8c21 619 count++;
tnhnrl 57:ec69651c8c21 620 }
tnhnrl 57:ec69651c8c21 621 if (cfg.getValue("IGain", &value[0] ,sizeof(value))) {
tnhnrl 57:ec69651c8c21 622 pitchLoop().setControllerI(atof(value));
tnhnrl 57:ec69651c8c21 623 count++;
tnhnrl 57:ec69651c8c21 624 }
tnhnrl 57:ec69651c8c21 625 if (cfg.getValue("DGain", &value[0] , sizeof(value))) {
tnhnrl 57:ec69651c8c21 626 pitchLoop().setControllerD(atof(value));
tnhnrl 57:ec69651c8c21 627 count++;
tnhnrl 57:ec69651c8c21 628 }
tnhnrl 57:ec69651c8c21 629 if (cfg.getValue("filterWn", &value[0], sizeof(value))) {
tnhnrl 57:ec69651c8c21 630 pitchLoop().setFilterFrequency(atof(value));
tnhnrl 57:ec69651c8c21 631 count++;
tnhnrl 57:ec69651c8c21 632 }
tnhnrl 57:ec69651c8c21 633 if (cfg.getValue("deadband", &value[0], sizeof(value))) {
tnhnrl 57:ec69651c8c21 634 pitchLoop().setDeadband(atof(value));
tnhnrl 57:ec69651c8c21 635 count++;
tnhnrl 57:ec69651c8c21 636 }
tnhnrl 57:ec69651c8c21 637
tnhnrl 57:ec69651c8c21 638 if (cfg.getValue("zeroOffset", &value[0], sizeof(value))) {
tnhnrl 57:ec69651c8c21 639 pitchLoop().setOutputOffset(atof(value));
tnhnrl 57:ec69651c8c21 640 count++;
tnhnrl 57:ec69651c8c21 641 }
tnhnrl 57:ec69651c8c21 642 return count;
tnhnrl 57:ec69651c8c21 643 }
tnhnrl 57:ec69651c8c21 644
tnhnrl 57:ec69651c8c21 645 int ConfigFileIO::load_HEADING_config() {
tnhnrl 57:ec69651c8c21 646 ConfigFile cfg;
tnhnrl 57:ec69651c8c21 647 int count = 0;
tnhnrl 57:ec69651c8c21 648 if (!cfg.read("/local/heading.txt")){
tnhnrl 57:ec69651c8c21 649 error("HEADING File Read Error");
tnhnrl 57:ec69651c8c21 650 }
tnhnrl 57:ec69651c8c21 651 char value[BUFSIZ];
tnhnrl 57:ec69651c8c21 652
tnhnrl 57:ec69651c8c21 653 if (cfg.getValue("PGain", &value[0] , sizeof(value))) {
tnhnrl 57:ec69651c8c21 654 headingLoop().setControllerP(atof(value));
tnhnrl 57:ec69651c8c21 655 count++;
tnhnrl 57:ec69651c8c21 656 }
tnhnrl 57:ec69651c8c21 657 if (cfg.getValue("IGain", &value[0] ,sizeof(value))) {
tnhnrl 57:ec69651c8c21 658 headingLoop().setControllerI(atof(value));
tnhnrl 57:ec69651c8c21 659 count++;
tnhnrl 57:ec69651c8c21 660 }
tnhnrl 57:ec69651c8c21 661 if (cfg.getValue("DGain", &value[0] , sizeof(value))) {
tnhnrl 57:ec69651c8c21 662 headingLoop().setControllerD(atof(value));
tnhnrl 57:ec69651c8c21 663 count++;
tnhnrl 57:ec69651c8c21 664 }
tnhnrl 57:ec69651c8c21 665 if (cfg.getValue("filterWn", &value[0], sizeof(value))) {
tnhnrl 57:ec69651c8c21 666 headingLoop().setFilterFrequency(atof(value));
tnhnrl 57:ec69651c8c21 667 count++;
tnhnrl 57:ec69651c8c21 668 }
tnhnrl 57:ec69651c8c21 669 if (cfg.getValue("deadband", &value[0], sizeof(value))) {
tnhnrl 57:ec69651c8c21 670 headingLoop().setDeadband(atof(value));
tnhnrl 57:ec69651c8c21 671 count++;
tnhnrl 57:ec69651c8c21 672 }
tnhnrl 57:ec69651c8c21 673
tnhnrl 57:ec69651c8c21 674 if (cfg.getValue("zeroOffset", &value[0], sizeof(value))) {
tnhnrl 57:ec69651c8c21 675 headingLoop().setOutputOffset(atof(value));
tnhnrl 57:ec69651c8c21 676 count++;
tnhnrl 57:ec69651c8c21 677 }
tnhnrl 57:ec69651c8c21 678 return count;
tnhnrl 57:ec69651c8c21 679 }
tnhnrl 57:ec69651c8c21 680
tnhnrl 57:ec69651c8c21 681 int ConfigFileIO::load_RUDDER_config() {
tnhnrl 57:ec69651c8c21 682 ConfigFile cfg;
tnhnrl 57:ec69651c8c21 683 int count = 0;
tnhnrl 57:ec69651c8c21 684 if (!cfg.read("/local/rudder.txt")){
tnhnrl 57:ec69651c8c21 685 error("RUDDER File Read Error");
tnhnrl 57:ec69651c8c21 686 }
tnhnrl 57:ec69651c8c21 687 char value[BUFSIZ];
tnhnrl 57:ec69651c8c21 688
tnhnrl 57:ec69651c8c21 689 //float values below
tnhnrl 57:ec69651c8c21 690 if (cfg.getValue("setMinDeg", &value[0] , sizeof(value))) {
tnhnrl 57:ec69651c8c21 691 rudder().setMinDeg(atof(value));
tnhnrl 57:ec69651c8c21 692 count++;
tnhnrl 57:ec69651c8c21 693 }
tnhnrl 57:ec69651c8c21 694 if (cfg.getValue("setMaxDeg", &value[0] ,sizeof(value))) {
tnhnrl 57:ec69651c8c21 695 rudder().setMaxDeg(atof(value));
tnhnrl 57:ec69651c8c21 696 count++;
tnhnrl 57:ec69651c8c21 697 }
tnhnrl 57:ec69651c8c21 698
tnhnrl 57:ec69651c8c21 699 //integer values below
tnhnrl 57:ec69651c8c21 700 if (cfg.getValue("setCenterPWM", &value[0] , sizeof(value))) {
tnhnrl 57:ec69651c8c21 701 rudder().setCenterPWM(atof(value));
tnhnrl 57:ec69651c8c21 702 count++;
tnhnrl 57:ec69651c8c21 703 }
tnhnrl 57:ec69651c8c21 704 if (cfg.getValue("setMinPWM", &value[0], sizeof(value))) {
tnhnrl 57:ec69651c8c21 705 rudder().setMinPWM(atof(value));
tnhnrl 57:ec69651c8c21 706 count++;
tnhnrl 57:ec69651c8c21 707 }
tnhnrl 57:ec69651c8c21 708 if (cfg.getValue("setMaxPWM", &value[0], sizeof(value))) {
tnhnrl 57:ec69651c8c21 709 rudder().setMaxPWM(atof(value));
tnhnrl 57:ec69651c8c21 710 count++;
tnhnrl 57:ec69651c8c21 711 }
tnhnrl 57:ec69651c8c21 712 return count;
tnhnrl 57:ec69651c8c21 713 }