most functionality to splashdwon, find neutral and start mission. short timeouts still in code for testing, will adjust to go directly to sit_idle after splashdown
Dependencies: mbed MODSERIAL FATFileSystem
ConfigFileIO/ConfigFileIO.cpp@57:ec69651c8c21, 2018-06-14 (annotated)
- Committer:
- tnhnrl
- Date:
- Thu Jun 14 16:10:25 2018 +0000
- Revision:
- 57:ec69651c8c21
- Child:
- 73:f6f378311c8d
Working version with debug and simple menu
Who changed what in which revision?
User | Revision | Line number | New 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 | 57:ec69651c8c21 | 7 | } |
tnhnrl | 57:ec69651c8c21 | 8 | |
tnhnrl | 57:ec69651c8c21 | 9 | void ConfigFileIO::saveBattData(float p_gain, float i_gain, float d_gain) { |
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 | 57:ec69651c8c21 | 16 | sprintf(string_pgain, "%f", 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 | 57:ec69651c8c21 | 20 | sprintf(string_igain, "%f", 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 | 57:ec69651c8c21 | 24 | sprintf(string_dgain, "%f", d_gain); |
tnhnrl | 57:ec69651c8c21 | 25 | write_Batt_txt.setValue("DGain", string_dgain); |
tnhnrl | 57:ec69651c8c21 | 26 | |
tnhnrl | 57:ec69651c8c21 | 27 | write_Batt_txt.setValue("\n#string pot parameters\nzeroCounts", "610"); |
tnhnrl | 57:ec69651c8c21 | 28 | write_Batt_txt.setValue("PistonTravelLimit", "73.0"); |
tnhnrl | 57:ec69651c8c21 | 29 | write_Batt_txt.setValue("slope", "0.12176"); |
tnhnrl | 57:ec69651c8c21 | 30 | write_Batt_txt.setValue("filterWn", "6.0"); |
tnhnrl | 57:ec69651c8c21 | 31 | write_Batt_txt.setValue("deadband", "0.5"); |
tnhnrl | 57:ec69651c8c21 | 32 | |
tnhnrl | 57:ec69651c8c21 | 33 | //SAVE THE DATA! |
tnhnrl | 57:ec69651c8c21 | 34 | pc().printf("Saving BATTERY MOVER PID data!"); |
tnhnrl | 57:ec69651c8c21 | 35 | |
tnhnrl | 57:ec69651c8c21 | 36 | if (!write_Batt_txt.write("/local/batt.txt")) { |
tnhnrl | 57:ec69651c8c21 | 37 | pc().printf("\n\rERROR: (SAVE)Failure to write batt.txt file."); |
tnhnrl | 57:ec69651c8c21 | 38 | } |
tnhnrl | 57:ec69651c8c21 | 39 | else { |
tnhnrl | 57:ec69651c8c21 | 40 | pc().printf("\n\rFile batt.txt successful written.\n\r"); |
tnhnrl | 57:ec69651c8c21 | 41 | } |
tnhnrl | 57:ec69651c8c21 | 42 | } |
tnhnrl | 57:ec69651c8c21 | 43 | |
tnhnrl | 57:ec69651c8c21 | 44 | void ConfigFileIO::savePitchData(float p_gain, float i_gain, float d_gain, int batt_zeroOffset) { |
tnhnrl | 57:ec69651c8c21 | 45 | ConfigFile write_pitch_txt; //write to the config file |
tnhnrl | 57:ec69651c8c21 | 46 | |
tnhnrl | 57:ec69651c8c21 | 47 | char PGain_buffer[128]; |
tnhnrl | 57:ec69651c8c21 | 48 | sprintf(PGain_buffer,"# pitch outer loop parameters\n\n#Gains\nPGain"); |
tnhnrl | 57:ec69651c8c21 | 49 | |
tnhnrl | 57:ec69651c8c21 | 50 | char string_pgain[128]; |
tnhnrl | 57:ec69651c8c21 | 51 | sprintf(string_pgain, "%f", p_gain); |
tnhnrl | 57:ec69651c8c21 | 52 | write_pitch_txt.setValue(PGain_buffer, string_pgain); |
tnhnrl | 57:ec69651c8c21 | 53 | |
tnhnrl | 57:ec69651c8c21 | 54 | char string_igain[128]; |
tnhnrl | 57:ec69651c8c21 | 55 | sprintf(string_igain, "%f", i_gain); |
tnhnrl | 57:ec69651c8c21 | 56 | write_pitch_txt.setValue("IGain", string_igain); |
tnhnrl | 57:ec69651c8c21 | 57 | |
tnhnrl | 57:ec69651c8c21 | 58 | char string_dgain[128]; |
tnhnrl | 57:ec69651c8c21 | 59 | sprintf(string_dgain, "%f", d_gain); |
tnhnrl | 57:ec69651c8c21 | 60 | write_pitch_txt.setValue("DGain", string_dgain); |
tnhnrl | 57:ec69651c8c21 | 61 | |
tnhnrl | 57:ec69651c8c21 | 62 | write_pitch_txt.setValue("\n#Pitch sensor filter parameters\nfilterWn", "6.0"); |
tnhnrl | 57:ec69651c8c21 | 63 | write_pitch_txt.setValue("deadband", "0.5"); |
tnhnrl | 57:ec69651c8c21 | 64 | |
tnhnrl | 57:ec69651c8c21 | 65 | char string_zeroOffset[128]; |
tnhnrl | 57:ec69651c8c21 | 66 | sprintf(string_zeroOffset, "%d", batt_zeroOffset); |
tnhnrl | 57:ec69651c8c21 | 67 | //bce setting was 41 mm during LASR experiments |
tnhnrl | 57:ec69651c8c21 | 68 | write_pitch_txt.setValue("\n#Offset for neutral (default: 41)\nzeroOffset", string_zeroOffset); |
tnhnrl | 57:ec69651c8c21 | 69 | |
tnhnrl | 57:ec69651c8c21 | 70 | //SAVE THE DATA! |
tnhnrl | 57:ec69651c8c21 | 71 | pc().printf("Saving Buoyancy Engine Neutral Buoyancy Positions!"); |
tnhnrl | 57:ec69651c8c21 | 72 | |
tnhnrl | 57:ec69651c8c21 | 73 | if (!write_pitch_txt.write("/local/pitch.txt")) { |
tnhnrl | 57:ec69651c8c21 | 74 | pc().printf("\n\rERROR: (SAVE)Failure to write depth.txt file."); |
tnhnrl | 57:ec69651c8c21 | 75 | } |
tnhnrl | 57:ec69651c8c21 | 76 | else { |
tnhnrl | 57:ec69651c8c21 | 77 | pc().printf("\n\rFile pitch.txt successful written.\n\r"); |
tnhnrl | 57:ec69651c8c21 | 78 | } |
tnhnrl | 57:ec69651c8c21 | 79 | } |
tnhnrl | 57:ec69651c8c21 | 80 | |
tnhnrl | 57:ec69651c8c21 | 81 | void ConfigFileIO::saveBCEData(float p_gain, float i_gain, float d_gain) { |
tnhnrl | 57:ec69651c8c21 | 82 | ConfigFile write_BCE_txt; //write to the config file |
tnhnrl | 57:ec69651c8c21 | 83 | |
tnhnrl | 57:ec69651c8c21 | 84 | char PGain_buffer[128]; |
tnhnrl | 57:ec69651c8c21 | 85 | sprintf(PGain_buffer,"# configuration file for BCE parameters\n\n#Gains\nPGain"); |
tnhnrl | 57:ec69651c8c21 | 86 | |
tnhnrl | 57:ec69651c8c21 | 87 | char string_pgain[128]; |
tnhnrl | 57:ec69651c8c21 | 88 | sprintf(string_pgain, "%f", p_gain); |
tnhnrl | 57:ec69651c8c21 | 89 | write_BCE_txt.setValue(PGain_buffer, string_pgain); |
tnhnrl | 57:ec69651c8c21 | 90 | |
tnhnrl | 57:ec69651c8c21 | 91 | char string_igain[128]; |
tnhnrl | 57:ec69651c8c21 | 92 | sprintf(string_igain, "%f", i_gain); |
tnhnrl | 57:ec69651c8c21 | 93 | write_BCE_txt.setValue("IGain", string_igain); |
tnhnrl | 57:ec69651c8c21 | 94 | |
tnhnrl | 57:ec69651c8c21 | 95 | char string_dgain[128]; |
tnhnrl | 57:ec69651c8c21 | 96 | sprintf(string_dgain, "%f", d_gain); |
tnhnrl | 57:ec69651c8c21 | 97 | write_BCE_txt.setValue("DGain", string_dgain); |
tnhnrl | 57:ec69651c8c21 | 98 | |
tnhnrl | 57:ec69651c8c21 | 99 | write_BCE_txt.setValue("\n#string pot parameters\nzeroCounts", "253"); |
tnhnrl | 57:ec69651c8c21 | 100 | write_BCE_txt.setValue("PistonTravelLimit", "320.0"); |
tnhnrl | 57:ec69651c8c21 | 101 | write_BCE_txt.setValue("slope", "0.12176"); |
tnhnrl | 57:ec69651c8c21 | 102 | write_BCE_txt.setValue("filterWn", "6.0"); |
tnhnrl | 57:ec69651c8c21 | 103 | write_BCE_txt.setValue("deadband", "0.5"); |
tnhnrl | 57:ec69651c8c21 | 104 | |
tnhnrl | 57:ec69651c8c21 | 105 | //SAVE THE DATA! |
tnhnrl | 57:ec69651c8c21 | 106 | pc().printf("Saving BCE PID data!"); |
tnhnrl | 57:ec69651c8c21 | 107 | |
tnhnrl | 57:ec69651c8c21 | 108 | if (!write_BCE_txt.write("/local/bce.txt")) { |
tnhnrl | 57:ec69651c8c21 | 109 | pc().printf("\n\rERROR: (SAVE)Failure to write bce.txt file."); |
tnhnrl | 57:ec69651c8c21 | 110 | } |
tnhnrl | 57:ec69651c8c21 | 111 | else { |
tnhnrl | 57:ec69651c8c21 | 112 | pc().printf("\n\rFile bce.txt successful written.\n\r"); |
tnhnrl | 57:ec69651c8c21 | 113 | } |
tnhnrl | 57:ec69651c8c21 | 114 | } |
tnhnrl | 57:ec69651c8c21 | 115 | |
tnhnrl | 57:ec69651c8c21 | 116 | void ConfigFileIO::saveDepthData(float p_gain, float i_gain, float d_gain, int bce_zeroOffset) { |
tnhnrl | 57:ec69651c8c21 | 117 | ConfigFile write_depth_txt; //write to the config file |
tnhnrl | 57:ec69651c8c21 | 118 | |
tnhnrl | 57:ec69651c8c21 | 119 | char PGain_buffer[128]; |
tnhnrl | 57:ec69651c8c21 | 120 | sprintf(PGain_buffer,"# depth outer loop parameters\n\n#Gains\nPGain"); |
tnhnrl | 57:ec69651c8c21 | 121 | |
tnhnrl | 57:ec69651c8c21 | 122 | char string_pgain[128]; |
tnhnrl | 57:ec69651c8c21 | 123 | sprintf(string_pgain, "%f", p_gain); |
tnhnrl | 57:ec69651c8c21 | 124 | write_depth_txt.setValue(PGain_buffer, string_pgain); |
tnhnrl | 57:ec69651c8c21 | 125 | |
tnhnrl | 57:ec69651c8c21 | 126 | char string_igain[128]; |
tnhnrl | 57:ec69651c8c21 | 127 | sprintf(string_igain, "%f", i_gain); |
tnhnrl | 57:ec69651c8c21 | 128 | write_depth_txt.setValue("IGain", string_igain); |
tnhnrl | 57:ec69651c8c21 | 129 | |
tnhnrl | 57:ec69651c8c21 | 130 | char string_dgain[128]; |
tnhnrl | 57:ec69651c8c21 | 131 | sprintf(string_dgain, "%f", d_gain); |
tnhnrl | 57:ec69651c8c21 | 132 | write_depth_txt.setValue("DGain", string_dgain); |
tnhnrl | 57:ec69651c8c21 | 133 | |
tnhnrl | 57:ec69651c8c21 | 134 | write_depth_txt.setValue("\n#Depth sensor filter parameters\nfilterWn", "6.0"); |
tnhnrl | 57:ec69651c8c21 | 135 | write_depth_txt.setValue("deadband", "0.5"); |
tnhnrl | 57:ec69651c8c21 | 136 | |
tnhnrl | 57:ec69651c8c21 | 137 | char string_zeroOffset[128]; |
tnhnrl | 57:ec69651c8c21 | 138 | sprintf(string_zeroOffset, "%d", bce_zeroOffset); |
tnhnrl | 57:ec69651c8c21 | 139 | //bce setting was 240 mm during LASR experiments |
tnhnrl | 57:ec69651c8c21 | 140 | write_depth_txt.setValue("\n#Offset for neutral (default: 240)\nzeroOffset", string_zeroOffset); |
tnhnrl | 57:ec69651c8c21 | 141 | |
tnhnrl | 57:ec69651c8c21 | 142 | //SAVE THE DATA! |
tnhnrl | 57:ec69651c8c21 | 143 | pc().printf("Saving Buoyancy Engine Neutral Buoyancy Positions!"); |
tnhnrl | 57:ec69651c8c21 | 144 | |
tnhnrl | 57:ec69651c8c21 | 145 | if (!write_depth_txt.write("/local/depth.txt")) { |
tnhnrl | 57:ec69651c8c21 | 146 | pc().printf("\n\rERROR: (SAVE)Failure to write depth.txt file."); |
tnhnrl | 57:ec69651c8c21 | 147 | } |
tnhnrl | 57:ec69651c8c21 | 148 | else { |
tnhnrl | 57:ec69651c8c21 | 149 | pc().printf("\n\rFile depth.txt successful written.\n\r"); |
tnhnrl | 57:ec69651c8c21 | 150 | } |
tnhnrl | 57:ec69651c8c21 | 151 | } |
tnhnrl | 57:ec69651c8c21 | 152 | |
tnhnrl | 57:ec69651c8c21 | 153 | //write rudder (servo driver) file rudder.txt |
tnhnrl | 57:ec69651c8c21 | 154 | void ConfigFileIO::saveRudderData(float setMinDeg, float setMaxDeg, float setCenterPWM, float setMinPWM, float setMaxPWM) { |
tnhnrl | 57:ec69651c8c21 | 155 | ConfigFile rudder_txt; |
tnhnrl | 57:ec69651c8c21 | 156 | |
tnhnrl | 57:ec69651c8c21 | 157 | char header[128]; |
tnhnrl | 57:ec69651c8c21 | 158 | sprintf(header,"# rudder (servo) inner loop (heading outer loop uses this)"); |
tnhnrl | 57:ec69651c8c21 | 159 | |
tnhnrl | 57:ec69651c8c21 | 160 | char string_min_deg[128]; |
tnhnrl | 57:ec69651c8c21 | 161 | sprintf(string_min_deg, "%f", setMinDeg); |
tnhnrl | 57:ec69651c8c21 | 162 | rudder_txt.setValue("setMinDeg", string_min_deg); |
tnhnrl | 57:ec69651c8c21 | 163 | |
tnhnrl | 57:ec69651c8c21 | 164 | char string_max_deg[128]; |
tnhnrl | 57:ec69651c8c21 | 165 | sprintf(string_max_deg, "%f", setMaxDeg); |
tnhnrl | 57:ec69651c8c21 | 166 | rudder_txt.setValue("setMaxDeg", string_max_deg); |
tnhnrl | 57:ec69651c8c21 | 167 | |
tnhnrl | 57:ec69651c8c21 | 168 | char string_ctr_pwm[128]; |
tnhnrl | 57:ec69651c8c21 | 169 | sprintf(string_ctr_pwm, "%f", setCenterPWM); |
tnhnrl | 57:ec69651c8c21 | 170 | rudder_txt.setValue("setCenterPWM", string_ctr_pwm); |
tnhnrl | 57:ec69651c8c21 | 171 | |
tnhnrl | 57:ec69651c8c21 | 172 | char string_min_pwm[128]; |
tnhnrl | 57:ec69651c8c21 | 173 | sprintf(string_min_pwm, "%f", setMinPWM); |
tnhnrl | 57:ec69651c8c21 | 174 | rudder_txt.setValue("setMinPWM", string_min_pwm); |
tnhnrl | 57:ec69651c8c21 | 175 | |
tnhnrl | 57:ec69651c8c21 | 176 | char string_max_pwm[128]; |
tnhnrl | 57:ec69651c8c21 | 177 | sprintf(string_max_pwm, "%f", setMaxPWM); |
tnhnrl | 57:ec69651c8c21 | 178 | rudder_txt.setValue("setMaxPWM", string_max_pwm); |
tnhnrl | 57:ec69651c8c21 | 179 | |
tnhnrl | 57:ec69651c8c21 | 180 | //SAVE THE DATA! |
tnhnrl | 57:ec69651c8c21 | 181 | pc().printf("Saving RUDDER DATA!"); |
tnhnrl | 57:ec69651c8c21 | 182 | |
tnhnrl | 57:ec69651c8c21 | 183 | if (!rudder_txt.write("/local/rudder.txt")) { |
tnhnrl | 57:ec69651c8c21 | 184 | pc().printf("\n\rERROR: (SAVE)Failure to write rudder.txt file."); |
tnhnrl | 57:ec69651c8c21 | 185 | } |
tnhnrl | 57:ec69651c8c21 | 186 | else { |
tnhnrl | 57:ec69651c8c21 | 187 | pc().printf("\n\rFile rudder.txt successful written.\n\r"); |
tnhnrl | 57:ec69651c8c21 | 188 | } |
tnhnrl | 57:ec69651c8c21 | 189 | } |
tnhnrl | 57:ec69651c8c21 | 190 | |
tnhnrl | 57:ec69651c8c21 | 191 | int ConfigFileIO::load_BCE_config() { |
tnhnrl | 57:ec69651c8c21 | 192 | ConfigFile cfg; |
tnhnrl | 57:ec69651c8c21 | 193 | int count = 0; |
tnhnrl | 57:ec69651c8c21 | 194 | if (!cfg.read("/local/bce.txt")) { |
tnhnrl | 57:ec69651c8c21 | 195 | error("File Read Error"); |
tnhnrl | 57:ec69651c8c21 | 196 | } |
tnhnrl | 57:ec69651c8c21 | 197 | char value[BUFSIZ]; |
tnhnrl | 57:ec69651c8c21 | 198 | |
tnhnrl | 57:ec69651c8c21 | 199 | if (cfg.getValue("PGain", &value[0] , sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 200 | bce().setControllerP(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 201 | count++; |
tnhnrl | 57:ec69651c8c21 | 202 | } |
tnhnrl | 57:ec69651c8c21 | 203 | if (cfg.getValue("IGain", &value[0] ,sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 204 | bce().setControllerI(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 205 | count++; |
tnhnrl | 57:ec69651c8c21 | 206 | } |
tnhnrl | 57:ec69651c8c21 | 207 | if (cfg.getValue("DGain", &value[0] , sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 208 | bce().setControllerD(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 209 | count++; |
tnhnrl | 57:ec69651c8c21 | 210 | } |
tnhnrl | 57:ec69651c8c21 | 211 | if (cfg.getValue("zeroCounts", &value[0],sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 212 | bce().setZeroCounts(atoi(value)); |
tnhnrl | 57:ec69651c8c21 | 213 | count++; |
tnhnrl | 57:ec69651c8c21 | 214 | } |
tnhnrl | 57:ec69651c8c21 | 215 | if (cfg.getValue("PistonTravelLimit", &value[0], sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 216 | bce().setTravelLimit(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 217 | count++; |
tnhnrl | 57:ec69651c8c21 | 218 | } |
tnhnrl | 57:ec69651c8c21 | 219 | if (cfg.getValue("slope", &value[0], sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 220 | bce().setPotSlope(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 221 | count++; |
tnhnrl | 57:ec69651c8c21 | 222 | } |
tnhnrl | 57:ec69651c8c21 | 223 | if (cfg.getValue("filterWn", &value[0], sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 224 | bce().setFilterFrequency(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 225 | count++; |
tnhnrl | 57:ec69651c8c21 | 226 | } |
tnhnrl | 57:ec69651c8c21 | 227 | if (cfg.getValue("deadband", &value[0], sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 228 | bce().setDeadband(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 229 | count++; |
tnhnrl | 57:ec69651c8c21 | 230 | } |
tnhnrl | 57:ec69651c8c21 | 231 | |
tnhnrl | 57:ec69651c8c21 | 232 | return count; |
tnhnrl | 57:ec69651c8c21 | 233 | } |
tnhnrl | 57:ec69651c8c21 | 234 | |
tnhnrl | 57:ec69651c8c21 | 235 | //write to heading.txt |
tnhnrl | 57:ec69651c8c21 | 236 | void ConfigFileIO::saveHeadingData(float heading_p_gain, float heading_i_gain, float heading_d_gain, float heading_offset) { |
tnhnrl | 57:ec69651c8c21 | 237 | ConfigFile heading_txt; |
tnhnrl | 57:ec69651c8c21 | 238 | |
tnhnrl | 57:ec69651c8c21 | 239 | char PGain_buffer[128]; |
tnhnrl | 57:ec69651c8c21 | 240 | sprintf(PGain_buffer,"# HEADING (rudder outer loop) parameters\n\n#Gains\nPGain"); |
tnhnrl | 57:ec69651c8c21 | 241 | |
tnhnrl | 57:ec69651c8c21 | 242 | //convert input numbers into text and save them to text file |
tnhnrl | 57:ec69651c8c21 | 243 | char string_pgain[128]; |
tnhnrl | 57:ec69651c8c21 | 244 | sprintf(string_pgain, "%f", heading_p_gain); |
tnhnrl | 57:ec69651c8c21 | 245 | heading_txt.setValue(PGain_buffer, string_pgain); |
tnhnrl | 57:ec69651c8c21 | 246 | |
tnhnrl | 57:ec69651c8c21 | 247 | char string_igain[128]; |
tnhnrl | 57:ec69651c8c21 | 248 | sprintf(string_igain, "%f", heading_i_gain); |
tnhnrl | 57:ec69651c8c21 | 249 | heading_txt.setValue("IGain", string_igain); |
tnhnrl | 57:ec69651c8c21 | 250 | |
tnhnrl | 57:ec69651c8c21 | 251 | char string_dgain[128]; |
tnhnrl | 57:ec69651c8c21 | 252 | sprintf(string_dgain, "%f", heading_d_gain); |
tnhnrl | 57:ec69651c8c21 | 253 | heading_txt.setValue("DGain", string_dgain); |
tnhnrl | 57:ec69651c8c21 | 254 | |
tnhnrl | 57:ec69651c8c21 | 255 | heading_txt.setValue("\n# HEADING sensor filter parameters\nfilterWn", "6.0"); |
tnhnrl | 57:ec69651c8c21 | 256 | heading_txt.setValue("deadband", "0.5"); |
tnhnrl | 57:ec69651c8c21 | 257 | |
tnhnrl | 57:ec69651c8c21 | 258 | char string_zeroOffset[128]; |
tnhnrl | 57:ec69651c8c21 | 259 | sprintf(string_zeroOffset, "%f", heading_offset); |
tnhnrl | 57:ec69651c8c21 | 260 | heading_txt.setValue("\n#HEADING offset for dive (no default!)\nzeroOffset", string_zeroOffset); |
tnhnrl | 57:ec69651c8c21 | 261 | |
tnhnrl | 57:ec69651c8c21 | 262 | //SAVE THE DATA! |
tnhnrl | 57:ec69651c8c21 | 263 | pc().printf("(ConfigFileIO) Saving HEADING parameters!"); |
tnhnrl | 57:ec69651c8c21 | 264 | |
tnhnrl | 57:ec69651c8c21 | 265 | if (!heading_txt.write("/local/heading.txt")) { |
tnhnrl | 57:ec69651c8c21 | 266 | pc().printf("\n\rERROR: (SAVE) Failure to write heading.txt file."); |
tnhnrl | 57:ec69651c8c21 | 267 | } |
tnhnrl | 57:ec69651c8c21 | 268 | else { |
tnhnrl | 57:ec69651c8c21 | 269 | pc().printf("\n\rFile heading.txt successful written.\n\r"); |
tnhnrl | 57:ec69651c8c21 | 270 | } |
tnhnrl | 57:ec69651c8c21 | 271 | } |
tnhnrl | 57:ec69651c8c21 | 272 | |
tnhnrl | 57:ec69651c8c21 | 273 | int ConfigFileIO::load_BATT_config() { |
tnhnrl | 57:ec69651c8c21 | 274 | ConfigFile cfg; |
tnhnrl | 57:ec69651c8c21 | 275 | int count = 0; |
tnhnrl | 57:ec69651c8c21 | 276 | if (!cfg.read("/local/batt.txt")) { |
tnhnrl | 57:ec69651c8c21 | 277 | error("BATT File Read Error"); |
tnhnrl | 57:ec69651c8c21 | 278 | } |
tnhnrl | 57:ec69651c8c21 | 279 | char value[BUFSIZ]; |
tnhnrl | 57:ec69651c8c21 | 280 | |
tnhnrl | 57:ec69651c8c21 | 281 | |
tnhnrl | 57:ec69651c8c21 | 282 | if (cfg.getValue("PGain", &value[0] , sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 283 | batt().setControllerP(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 284 | count++; |
tnhnrl | 57:ec69651c8c21 | 285 | } |
tnhnrl | 57:ec69651c8c21 | 286 | if (cfg.getValue("IGain", &value[0] ,sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 287 | batt().setControllerI(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 288 | count++; |
tnhnrl | 57:ec69651c8c21 | 289 | } |
tnhnrl | 57:ec69651c8c21 | 290 | if (cfg.getValue("DGain", &value[0] , sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 291 | batt().setControllerD(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 292 | count++; |
tnhnrl | 57:ec69651c8c21 | 293 | } |
tnhnrl | 57:ec69651c8c21 | 294 | if (cfg.getValue("zeroCounts", &value[0],sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 295 | batt().setZeroCounts(atoi(value)); |
tnhnrl | 57:ec69651c8c21 | 296 | count++; |
tnhnrl | 57:ec69651c8c21 | 297 | } |
tnhnrl | 57:ec69651c8c21 | 298 | if (cfg.getValue("PistonTravelLimit", &value[0], sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 299 | batt().setTravelLimit(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 300 | count++; |
tnhnrl | 57:ec69651c8c21 | 301 | } |
tnhnrl | 57:ec69651c8c21 | 302 | if (cfg.getValue("slope", &value[0], sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 303 | batt().setPotSlope(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 304 | count++; |
tnhnrl | 57:ec69651c8c21 | 305 | } |
tnhnrl | 57:ec69651c8c21 | 306 | if (cfg.getValue("filterWn", &value[0], sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 307 | batt().setFilterFrequency(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 308 | count++; |
tnhnrl | 57:ec69651c8c21 | 309 | } |
tnhnrl | 57:ec69651c8c21 | 310 | if (cfg.getValue("deadband", &value[0], sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 311 | batt().setDeadband(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 312 | count++; |
tnhnrl | 57:ec69651c8c21 | 313 | } |
tnhnrl | 57:ec69651c8c21 | 314 | |
tnhnrl | 57:ec69651c8c21 | 315 | return count; |
tnhnrl | 57:ec69651c8c21 | 316 | } |
tnhnrl | 57:ec69651c8c21 | 317 | |
tnhnrl | 57:ec69651c8c21 | 318 | int ConfigFileIO::load_DEPTH_config() { |
tnhnrl | 57:ec69651c8c21 | 319 | ConfigFile cfg; |
tnhnrl | 57:ec69651c8c21 | 320 | int count = 0; |
tnhnrl | 57:ec69651c8c21 | 321 | if (!cfg.read("/local/depth.txt")) { |
tnhnrl | 57:ec69651c8c21 | 322 | error("DEPTH File Read Error"); |
tnhnrl | 57:ec69651c8c21 | 323 | } |
tnhnrl | 57:ec69651c8c21 | 324 | char value[BUFSIZ]; |
tnhnrl | 57:ec69651c8c21 | 325 | |
tnhnrl | 57:ec69651c8c21 | 326 | if (cfg.getValue("PGain", &value[0] , sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 327 | depthLoop().setControllerP(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 328 | count++; |
tnhnrl | 57:ec69651c8c21 | 329 | } |
tnhnrl | 57:ec69651c8c21 | 330 | if (cfg.getValue("IGain", &value[0] ,sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 331 | depthLoop().setControllerI(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 332 | count++; |
tnhnrl | 57:ec69651c8c21 | 333 | } |
tnhnrl | 57:ec69651c8c21 | 334 | if (cfg.getValue("DGain", &value[0] , sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 335 | depthLoop().setControllerD(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 336 | count++; |
tnhnrl | 57:ec69651c8c21 | 337 | } |
tnhnrl | 57:ec69651c8c21 | 338 | if (cfg.getValue("filterWn", &value[0], sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 339 | depthLoop().setFilterFrequency(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 340 | count++; |
tnhnrl | 57:ec69651c8c21 | 341 | } |
tnhnrl | 57:ec69651c8c21 | 342 | if (cfg.getValue("deadband", &value[0], sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 343 | depthLoop().setDeadband(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 344 | count++; |
tnhnrl | 57:ec69651c8c21 | 345 | } |
tnhnrl | 57:ec69651c8c21 | 346 | if (cfg.getValue("zeroOffset", &value[0], sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 347 | depthLoop().setOutputOffset(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 348 | count++; |
tnhnrl | 57:ec69651c8c21 | 349 | } |
tnhnrl | 57:ec69651c8c21 | 350 | return count; |
tnhnrl | 57:ec69651c8c21 | 351 | } |
tnhnrl | 57:ec69651c8c21 | 352 | |
tnhnrl | 57:ec69651c8c21 | 353 | int ConfigFileIO::load_PITCH_config() { |
tnhnrl | 57:ec69651c8c21 | 354 | ConfigFile cfg; |
tnhnrl | 57:ec69651c8c21 | 355 | int count = 0; |
tnhnrl | 57:ec69651c8c21 | 356 | if (!cfg.read("/local/pitch.txt")){ |
tnhnrl | 57:ec69651c8c21 | 357 | error("PITCH File Read Error"); |
tnhnrl | 57:ec69651c8c21 | 358 | } |
tnhnrl | 57:ec69651c8c21 | 359 | char value[BUFSIZ]; |
tnhnrl | 57:ec69651c8c21 | 360 | |
tnhnrl | 57:ec69651c8c21 | 361 | if (cfg.getValue("PGain", &value[0] , sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 362 | pitchLoop().setControllerP(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 363 | count++; |
tnhnrl | 57:ec69651c8c21 | 364 | } |
tnhnrl | 57:ec69651c8c21 | 365 | if (cfg.getValue("IGain", &value[0] ,sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 366 | pitchLoop().setControllerI(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 367 | count++; |
tnhnrl | 57:ec69651c8c21 | 368 | } |
tnhnrl | 57:ec69651c8c21 | 369 | if (cfg.getValue("DGain", &value[0] , sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 370 | pitchLoop().setControllerD(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 371 | count++; |
tnhnrl | 57:ec69651c8c21 | 372 | } |
tnhnrl | 57:ec69651c8c21 | 373 | if (cfg.getValue("filterWn", &value[0], sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 374 | pitchLoop().setFilterFrequency(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 375 | count++; |
tnhnrl | 57:ec69651c8c21 | 376 | } |
tnhnrl | 57:ec69651c8c21 | 377 | if (cfg.getValue("deadband", &value[0], sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 378 | pitchLoop().setDeadband(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 379 | count++; |
tnhnrl | 57:ec69651c8c21 | 380 | } |
tnhnrl | 57:ec69651c8c21 | 381 | |
tnhnrl | 57:ec69651c8c21 | 382 | if (cfg.getValue("zeroOffset", &value[0], sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 383 | pitchLoop().setOutputOffset(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 384 | count++; |
tnhnrl | 57:ec69651c8c21 | 385 | } |
tnhnrl | 57:ec69651c8c21 | 386 | return count; |
tnhnrl | 57:ec69651c8c21 | 387 | } |
tnhnrl | 57:ec69651c8c21 | 388 | |
tnhnrl | 57:ec69651c8c21 | 389 | int ConfigFileIO::load_HEADING_config() { |
tnhnrl | 57:ec69651c8c21 | 390 | ConfigFile cfg; |
tnhnrl | 57:ec69651c8c21 | 391 | int count = 0; |
tnhnrl | 57:ec69651c8c21 | 392 | if (!cfg.read("/local/heading.txt")){ |
tnhnrl | 57:ec69651c8c21 | 393 | error("HEADING File Read Error"); |
tnhnrl | 57:ec69651c8c21 | 394 | } |
tnhnrl | 57:ec69651c8c21 | 395 | char value[BUFSIZ]; |
tnhnrl | 57:ec69651c8c21 | 396 | |
tnhnrl | 57:ec69651c8c21 | 397 | if (cfg.getValue("PGain", &value[0] , sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 398 | headingLoop().setControllerP(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 399 | count++; |
tnhnrl | 57:ec69651c8c21 | 400 | } |
tnhnrl | 57:ec69651c8c21 | 401 | if (cfg.getValue("IGain", &value[0] ,sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 402 | headingLoop().setControllerI(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 403 | count++; |
tnhnrl | 57:ec69651c8c21 | 404 | } |
tnhnrl | 57:ec69651c8c21 | 405 | if (cfg.getValue("DGain", &value[0] , sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 406 | headingLoop().setControllerD(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 407 | count++; |
tnhnrl | 57:ec69651c8c21 | 408 | } |
tnhnrl | 57:ec69651c8c21 | 409 | if (cfg.getValue("filterWn", &value[0], sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 410 | headingLoop().setFilterFrequency(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 411 | count++; |
tnhnrl | 57:ec69651c8c21 | 412 | } |
tnhnrl | 57:ec69651c8c21 | 413 | if (cfg.getValue("deadband", &value[0], sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 414 | headingLoop().setDeadband(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 415 | count++; |
tnhnrl | 57:ec69651c8c21 | 416 | } |
tnhnrl | 57:ec69651c8c21 | 417 | |
tnhnrl | 57:ec69651c8c21 | 418 | if (cfg.getValue("zeroOffset", &value[0], sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 419 | headingLoop().setOutputOffset(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 420 | count++; |
tnhnrl | 57:ec69651c8c21 | 421 | } |
tnhnrl | 57:ec69651c8c21 | 422 | return count; |
tnhnrl | 57:ec69651c8c21 | 423 | } |
tnhnrl | 57:ec69651c8c21 | 424 | |
tnhnrl | 57:ec69651c8c21 | 425 | int ConfigFileIO::load_RUDDER_config() { |
tnhnrl | 57:ec69651c8c21 | 426 | ConfigFile cfg; |
tnhnrl | 57:ec69651c8c21 | 427 | int count = 0; |
tnhnrl | 57:ec69651c8c21 | 428 | if (!cfg.read("/local/rudder.txt")){ |
tnhnrl | 57:ec69651c8c21 | 429 | error("RUDDER File Read Error"); |
tnhnrl | 57:ec69651c8c21 | 430 | } |
tnhnrl | 57:ec69651c8c21 | 431 | char value[BUFSIZ]; |
tnhnrl | 57:ec69651c8c21 | 432 | |
tnhnrl | 57:ec69651c8c21 | 433 | //float values below |
tnhnrl | 57:ec69651c8c21 | 434 | if (cfg.getValue("setMinDeg", &value[0] , sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 435 | rudder().setMinDeg(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 436 | count++; |
tnhnrl | 57:ec69651c8c21 | 437 | } |
tnhnrl | 57:ec69651c8c21 | 438 | if (cfg.getValue("setMaxDeg", &value[0] ,sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 439 | rudder().setMaxDeg(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 440 | count++; |
tnhnrl | 57:ec69651c8c21 | 441 | } |
tnhnrl | 57:ec69651c8c21 | 442 | |
tnhnrl | 57:ec69651c8c21 | 443 | //integer values below |
tnhnrl | 57:ec69651c8c21 | 444 | if (cfg.getValue("setCenterPWM", &value[0] , sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 445 | rudder().setCenterPWM(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 446 | count++; |
tnhnrl | 57:ec69651c8c21 | 447 | } |
tnhnrl | 57:ec69651c8c21 | 448 | if (cfg.getValue("setMinPWM", &value[0], sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 449 | rudder().setMinPWM(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 450 | count++; |
tnhnrl | 57:ec69651c8c21 | 451 | } |
tnhnrl | 57:ec69651c8c21 | 452 | if (cfg.getValue("setMaxPWM", &value[0], sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 453 | rudder().setMaxPWM(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 454 | count++; |
tnhnrl | 57:ec69651c8c21 | 455 | } |
tnhnrl | 57:ec69651c8c21 | 456 | return count; |
tnhnrl | 57:ec69651c8c21 | 457 | } |