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@92:52a91656458a, 2019-05-13 (annotated)
- Committer:
- joel_ssc
- Date:
- Mon May 13 19:25:26 2019 +0000
- Revision:
- 92:52a91656458a
- Parent:
- 88:1813f583cee9
version for first flight test, timeouts not yet set correctly
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 | 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 !"); |
joel_ssc | 82:0981b9ada820 | 85 | |
joel_ssc | 82:0981b9ada820 | 86 | if (!write_logvers_txt.write("/local/logvers.txt")) { |
joel_ssc | 82:0981b9ada820 | 87 | xbee().printf("\n\rERROR: (SAVE)Failure to write logvers.txt file."); |
joel_ssc | 82:0981b9ada820 | 88 | } |
joel_ssc | 82:0981b9ada820 | 89 | else { |
joel_ssc | 82:0981b9ada820 | 90 | xbee().printf("\n\rFile logvvrs.txt successful written.\n\r"); |
joel_ssc | 82:0981b9ada820 | 91 | } |
joel_ssc | 82:0981b9ada820 | 92 | } |
tnhnrl | 57:ec69651c8c21 | 93 | |
tnhnrl | 73:f6f378311c8d | 94 | 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 | 95 | ConfigFile write_pitch_txt; //write to the config file |
tnhnrl | 57:ec69651c8c21 | 96 | |
tnhnrl | 57:ec69651c8c21 | 97 | char PGain_buffer[128]; |
tnhnrl | 57:ec69651c8c21 | 98 | sprintf(PGain_buffer,"# pitch outer loop parameters\n\n#Gains\nPGain"); |
tnhnrl | 57:ec69651c8c21 | 99 | |
tnhnrl | 57:ec69651c8c21 | 100 | char string_pgain[128]; |
tnhnrl | 73:f6f378311c8d | 101 | sprintf(string_pgain, "%f", pitch_p_gain); |
tnhnrl | 57:ec69651c8c21 | 102 | write_pitch_txt.setValue(PGain_buffer, string_pgain); |
tnhnrl | 57:ec69651c8c21 | 103 | |
tnhnrl | 57:ec69651c8c21 | 104 | char string_igain[128]; |
tnhnrl | 73:f6f378311c8d | 105 | sprintf(string_igain, "%f", pitch_i_gain); |
tnhnrl | 57:ec69651c8c21 | 106 | write_pitch_txt.setValue("IGain", string_igain); |
tnhnrl | 57:ec69651c8c21 | 107 | |
tnhnrl | 57:ec69651c8c21 | 108 | char string_dgain[128]; |
tnhnrl | 73:f6f378311c8d | 109 | sprintf(string_dgain, "%f", pitch_d_gain); |
tnhnrl | 57:ec69651c8c21 | 110 | write_pitch_txt.setValue("DGain", string_dgain); |
tnhnrl | 73:f6f378311c8d | 111 | |
tnhnrl | 73:f6f378311c8d | 112 | char string_filter_freq[128]; |
tnhnrl | 73:f6f378311c8d | 113 | sprintf(string_filter_freq, "%f", pitch_filter_freq); |
tnhnrl | 73:f6f378311c8d | 114 | write_pitch_txt.setValue("\n#Pitch sensor filter parameters\nfilterWn", string_filter_freq); |
tnhnrl | 73:f6f378311c8d | 115 | |
tnhnrl | 73:f6f378311c8d | 116 | char string_deadband[128]; |
tnhnrl | 73:f6f378311c8d | 117 | sprintf(string_deadband, "%f", pitch_deadband); |
tnhnrl | 73:f6f378311c8d | 118 | write_pitch_txt.setValue("deadband", string_deadband); |
tnhnrl | 57:ec69651c8c21 | 119 | |
tnhnrl | 57:ec69651c8c21 | 120 | char string_zeroOffset[128]; |
tnhnrl | 73:f6f378311c8d | 121 | sprintf(string_zeroOffset, "%f", pitch_zeroOffset); |
tnhnrl | 57:ec69651c8c21 | 122 | //bce setting was 41 mm during LASR experiments |
tnhnrl | 57:ec69651c8c21 | 123 | write_pitch_txt.setValue("\n#Offset for neutral (default: 41)\nzeroOffset", string_zeroOffset); |
tnhnrl | 57:ec69651c8c21 | 124 | |
tnhnrl | 57:ec69651c8c21 | 125 | //SAVE THE DATA! |
tnhnrl | 74:d281aaef9766 | 126 | xbee().printf("Saving Buoyancy Engine Neutral Buoyancy Positions!"); |
tnhnrl | 57:ec69651c8c21 | 127 | |
tnhnrl | 57:ec69651c8c21 | 128 | if (!write_pitch_txt.write("/local/pitch.txt")) { |
tnhnrl | 74:d281aaef9766 | 129 | xbee().printf("\n\rERROR: (SAVE)Failure to write depth.txt file."); |
tnhnrl | 57:ec69651c8c21 | 130 | } |
tnhnrl | 57:ec69651c8c21 | 131 | else { |
tnhnrl | 74:d281aaef9766 | 132 | xbee().printf("\n\rFile pitch.txt successful written.\n\r"); |
tnhnrl | 57:ec69651c8c21 | 133 | } |
tnhnrl | 57:ec69651c8c21 | 134 | } |
tnhnrl | 57:ec69651c8c21 | 135 | |
tnhnrl | 76:c802e1da4179 | 136 | 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 | 137 | ConfigFile write_BCE_txt; //write to the config file |
tnhnrl | 57:ec69651c8c21 | 138 | |
tnhnrl | 57:ec69651c8c21 | 139 | char PGain_buffer[128]; |
tnhnrl | 57:ec69651c8c21 | 140 | sprintf(PGain_buffer,"# configuration file for BCE parameters\n\n#Gains\nPGain"); |
tnhnrl | 57:ec69651c8c21 | 141 | |
tnhnrl | 57:ec69651c8c21 | 142 | char string_pgain[128]; |
tnhnrl | 73:f6f378311c8d | 143 | sprintf(string_pgain, "%f", bce_p_gain); |
tnhnrl | 57:ec69651c8c21 | 144 | write_BCE_txt.setValue(PGain_buffer, string_pgain); |
tnhnrl | 57:ec69651c8c21 | 145 | |
tnhnrl | 57:ec69651c8c21 | 146 | char string_igain[128]; |
tnhnrl | 73:f6f378311c8d | 147 | sprintf(string_igain, "%f", bce_i_gain); |
tnhnrl | 57:ec69651c8c21 | 148 | write_BCE_txt.setValue("IGain", string_igain); |
tnhnrl | 57:ec69651c8c21 | 149 | |
tnhnrl | 57:ec69651c8c21 | 150 | char string_dgain[128]; |
tnhnrl | 73:f6f378311c8d | 151 | sprintf(string_dgain, "%f", bce_d_gain); |
tnhnrl | 57:ec69651c8c21 | 152 | write_BCE_txt.setValue("DGain", string_dgain); |
tnhnrl | 73:f6f378311c8d | 153 | |
tnhnrl | 73:f6f378311c8d | 154 | char string_zeroCounts[128]; |
tnhnrl | 76:c802e1da4179 | 155 | sprintf(string_zeroCounts, "%d", bce_zeroOffset); |
tnhnrl | 73:f6f378311c8d | 156 | write_BCE_txt.setValue("\n#string pot parameters\nzeroCounts", string_zeroCounts); |
tnhnrl | 73:f6f378311c8d | 157 | |
tnhnrl | 79:3688c3a0d7f4 | 158 | //modified this from hard-coded values to set to whatever is in the file on startup |
tnhnrl | 79:3688c3a0d7f4 | 159 | char string_bce_travel_limit[128]; |
tnhnrl | 79:3688c3a0d7f4 | 160 | sprintf(string_bce_travel_limit, "%f", batt().getTravelLimit()); |
tnhnrl | 79:3688c3a0d7f4 | 161 | write_BCE_txt.setValue("PistonTravelLimit", string_bce_travel_limit); |
tnhnrl | 79:3688c3a0d7f4 | 162 | |
tnhnrl | 57:ec69651c8c21 | 163 | write_BCE_txt.setValue("slope", "0.12176"); |
tnhnrl | 73:f6f378311c8d | 164 | |
tnhnrl | 73:f6f378311c8d | 165 | char string_filter_freq[128]; |
tnhnrl | 73:f6f378311c8d | 166 | sprintf(string_filter_freq, "%f", bce_filter_freq); |
tnhnrl | 73:f6f378311c8d | 167 | write_BCE_txt.setValue("filterWn", string_filter_freq); |
tnhnrl | 73:f6f378311c8d | 168 | |
tnhnrl | 73:f6f378311c8d | 169 | char string_deadband[128]; |
tnhnrl | 73:f6f378311c8d | 170 | sprintf(string_deadband, "%f", bce_deadband); |
tnhnrl | 73:f6f378311c8d | 171 | write_BCE_txt.setValue("deadband", string_deadband); |
tnhnrl | 57:ec69651c8c21 | 172 | |
tnhnrl | 57:ec69651c8c21 | 173 | //SAVE THE DATA! |
tnhnrl | 74:d281aaef9766 | 174 | xbee().printf("Saving BCE PID data!"); |
tnhnrl | 57:ec69651c8c21 | 175 | |
tnhnrl | 57:ec69651c8c21 | 176 | if (!write_BCE_txt.write("/local/bce.txt")) { |
tnhnrl | 74:d281aaef9766 | 177 | xbee().printf("\n\rERROR: (SAVE)Failure to write bce.txt file."); |
tnhnrl | 57:ec69651c8c21 | 178 | } |
tnhnrl | 57:ec69651c8c21 | 179 | else { |
tnhnrl | 74:d281aaef9766 | 180 | xbee().printf("\n\rFile bce.txt successful written.\n\r"); |
tnhnrl | 57:ec69651c8c21 | 181 | } |
tnhnrl | 57:ec69651c8c21 | 182 | } |
tnhnrl | 57:ec69651c8c21 | 183 | |
tnhnrl | 73:f6f378311c8d | 184 | 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 | 185 | ConfigFile write_depth_txt; //write to the config file |
tnhnrl | 57:ec69651c8c21 | 186 | |
tnhnrl | 57:ec69651c8c21 | 187 | char PGain_buffer[128]; |
tnhnrl | 57:ec69651c8c21 | 188 | sprintf(PGain_buffer,"# depth outer loop parameters\n\n#Gains\nPGain"); |
tnhnrl | 57:ec69651c8c21 | 189 | |
tnhnrl | 57:ec69651c8c21 | 190 | char string_pgain[128]; |
tnhnrl | 73:f6f378311c8d | 191 | sprintf(string_pgain, "%f", depth_p_gain); |
tnhnrl | 57:ec69651c8c21 | 192 | write_depth_txt.setValue(PGain_buffer, string_pgain); |
tnhnrl | 57:ec69651c8c21 | 193 | |
tnhnrl | 57:ec69651c8c21 | 194 | char string_igain[128]; |
tnhnrl | 73:f6f378311c8d | 195 | sprintf(string_igain, "%f", depth_i_gain); |
tnhnrl | 57:ec69651c8c21 | 196 | write_depth_txt.setValue("IGain", string_igain); |
tnhnrl | 57:ec69651c8c21 | 197 | |
tnhnrl | 57:ec69651c8c21 | 198 | char string_dgain[128]; |
tnhnrl | 73:f6f378311c8d | 199 | sprintf(string_dgain, "%f", depth_d_gain); |
tnhnrl | 57:ec69651c8c21 | 200 | write_depth_txt.setValue("DGain", string_dgain); |
tnhnrl | 73:f6f378311c8d | 201 | |
tnhnrl | 73:f6f378311c8d | 202 | char string_filter_freq[128]; |
tnhnrl | 73:f6f378311c8d | 203 | sprintf(string_filter_freq, "%f", depth_filter_freq); |
tnhnrl | 73:f6f378311c8d | 204 | write_depth_txt.setValue("\n#Depth sensor filter parameters\nfilterWn", string_filter_freq); |
tnhnrl | 73:f6f378311c8d | 205 | |
tnhnrl | 73:f6f378311c8d | 206 | char string_deadband[128]; |
tnhnrl | 73:f6f378311c8d | 207 | sprintf(string_deadband, "%f", depth_deadband); |
tnhnrl | 73:f6f378311c8d | 208 | write_depth_txt.setValue("deadband", string_deadband); |
tnhnrl | 57:ec69651c8c21 | 209 | |
tnhnrl | 57:ec69651c8c21 | 210 | char string_zeroOffset[128]; |
tnhnrl | 73:f6f378311c8d | 211 | sprintf(string_zeroOffset, "%f", depth_zeroOffset); |
tnhnrl | 57:ec69651c8c21 | 212 | //bce setting was 240 mm during LASR experiments |
tnhnrl | 57:ec69651c8c21 | 213 | write_depth_txt.setValue("\n#Offset for neutral (default: 240)\nzeroOffset", string_zeroOffset); |
tnhnrl | 57:ec69651c8c21 | 214 | |
tnhnrl | 57:ec69651c8c21 | 215 | //SAVE THE DATA! |
tnhnrl | 74:d281aaef9766 | 216 | xbee().printf("Saving Buoyancy Engine Neutral Buoyancy Positions!"); |
tnhnrl | 57:ec69651c8c21 | 217 | |
tnhnrl | 57:ec69651c8c21 | 218 | if (!write_depth_txt.write("/local/depth.txt")) { |
tnhnrl | 74:d281aaef9766 | 219 | xbee().printf("\n\rERROR: (SAVE)Failure to write depth.txt file."); |
tnhnrl | 57:ec69651c8c21 | 220 | } |
tnhnrl | 57:ec69651c8c21 | 221 | else { |
tnhnrl | 74:d281aaef9766 | 222 | xbee().printf("\n\rFile depth.txt successful written.\n\r"); |
tnhnrl | 57:ec69651c8c21 | 223 | } |
tnhnrl | 57:ec69651c8c21 | 224 | } |
tnhnrl | 57:ec69651c8c21 | 225 | |
tnhnrl | 57:ec69651c8c21 | 226 | //write rudder (servo driver) file rudder.txt |
tnhnrl | 57:ec69651c8c21 | 227 | void ConfigFileIO::saveRudderData(float setMinDeg, float setMaxDeg, float setCenterPWM, float setMinPWM, float setMaxPWM) { |
tnhnrl | 57:ec69651c8c21 | 228 | ConfigFile rudder_txt; |
tnhnrl | 57:ec69651c8c21 | 229 | |
tnhnrl | 57:ec69651c8c21 | 230 | char header[128]; |
tnhnrl | 57:ec69651c8c21 | 231 | sprintf(header,"# rudder (servo) inner loop (heading outer loop uses this)"); |
tnhnrl | 57:ec69651c8c21 | 232 | |
tnhnrl | 57:ec69651c8c21 | 233 | char string_min_deg[128]; |
tnhnrl | 57:ec69651c8c21 | 234 | sprintf(string_min_deg, "%f", setMinDeg); |
tnhnrl | 57:ec69651c8c21 | 235 | rudder_txt.setValue("setMinDeg", string_min_deg); |
tnhnrl | 57:ec69651c8c21 | 236 | |
tnhnrl | 57:ec69651c8c21 | 237 | char string_max_deg[128]; |
tnhnrl | 57:ec69651c8c21 | 238 | sprintf(string_max_deg, "%f", setMaxDeg); |
tnhnrl | 57:ec69651c8c21 | 239 | rudder_txt.setValue("setMaxDeg", string_max_deg); |
tnhnrl | 57:ec69651c8c21 | 240 | |
tnhnrl | 57:ec69651c8c21 | 241 | char string_ctr_pwm[128]; |
tnhnrl | 57:ec69651c8c21 | 242 | sprintf(string_ctr_pwm, "%f", setCenterPWM); |
tnhnrl | 57:ec69651c8c21 | 243 | rudder_txt.setValue("setCenterPWM", string_ctr_pwm); |
tnhnrl | 57:ec69651c8c21 | 244 | |
tnhnrl | 57:ec69651c8c21 | 245 | char string_min_pwm[128]; |
tnhnrl | 57:ec69651c8c21 | 246 | sprintf(string_min_pwm, "%f", setMinPWM); |
tnhnrl | 57:ec69651c8c21 | 247 | rudder_txt.setValue("setMinPWM", string_min_pwm); |
tnhnrl | 57:ec69651c8c21 | 248 | |
tnhnrl | 57:ec69651c8c21 | 249 | char string_max_pwm[128]; |
tnhnrl | 57:ec69651c8c21 | 250 | sprintf(string_max_pwm, "%f", setMaxPWM); |
tnhnrl | 57:ec69651c8c21 | 251 | rudder_txt.setValue("setMaxPWM", string_max_pwm); |
tnhnrl | 57:ec69651c8c21 | 252 | |
tnhnrl | 57:ec69651c8c21 | 253 | //SAVE THE DATA! |
tnhnrl | 74:d281aaef9766 | 254 | xbee().printf("Saving RUDDER DATA!"); |
tnhnrl | 57:ec69651c8c21 | 255 | |
tnhnrl | 57:ec69651c8c21 | 256 | if (!rudder_txt.write("/local/rudder.txt")) { |
tnhnrl | 74:d281aaef9766 | 257 | xbee().printf("\n\rERROR: (SAVE)Failure to write rudder.txt file."); |
tnhnrl | 57:ec69651c8c21 | 258 | } |
tnhnrl | 57:ec69651c8c21 | 259 | else { |
tnhnrl | 74:d281aaef9766 | 260 | xbee().printf("\n\rFile rudder.txt successful written.\n\r"); |
tnhnrl | 57:ec69651c8c21 | 261 | } |
tnhnrl | 57:ec69651c8c21 | 262 | } |
tnhnrl | 57:ec69651c8c21 | 263 | |
tnhnrl | 57:ec69651c8c21 | 264 | int ConfigFileIO::load_BCE_config() { |
tnhnrl | 57:ec69651c8c21 | 265 | ConfigFile cfg; |
tnhnrl | 57:ec69651c8c21 | 266 | int count = 0; |
tnhnrl | 57:ec69651c8c21 | 267 | if (!cfg.read("/local/bce.txt")) { |
tnhnrl | 57:ec69651c8c21 | 268 | error("File Read Error"); |
tnhnrl | 57:ec69651c8c21 | 269 | } |
tnhnrl | 57:ec69651c8c21 | 270 | char value[BUFSIZ]; |
tnhnrl | 57:ec69651c8c21 | 271 | |
tnhnrl | 57:ec69651c8c21 | 272 | if (cfg.getValue("PGain", &value[0] , sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 273 | bce().setControllerP(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 274 | count++; |
tnhnrl | 57:ec69651c8c21 | 275 | } |
tnhnrl | 57:ec69651c8c21 | 276 | if (cfg.getValue("IGain", &value[0] ,sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 277 | bce().setControllerI(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 278 | count++; |
tnhnrl | 57:ec69651c8c21 | 279 | } |
tnhnrl | 57:ec69651c8c21 | 280 | if (cfg.getValue("DGain", &value[0] , sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 281 | bce().setControllerD(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 282 | count++; |
tnhnrl | 57:ec69651c8c21 | 283 | } |
tnhnrl | 57:ec69651c8c21 | 284 | if (cfg.getValue("zeroCounts", &value[0],sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 285 | bce().setZeroCounts(atoi(value)); |
tnhnrl | 57:ec69651c8c21 | 286 | count++; |
tnhnrl | 57:ec69651c8c21 | 287 | } |
tnhnrl | 57:ec69651c8c21 | 288 | if (cfg.getValue("PistonTravelLimit", &value[0], sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 289 | bce().setTravelLimit(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 290 | count++; |
tnhnrl | 57:ec69651c8c21 | 291 | } |
tnhnrl | 57:ec69651c8c21 | 292 | if (cfg.getValue("slope", &value[0], sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 293 | bce().setPotSlope(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 294 | count++; |
tnhnrl | 57:ec69651c8c21 | 295 | } |
tnhnrl | 57:ec69651c8c21 | 296 | if (cfg.getValue("filterWn", &value[0], sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 297 | bce().setFilterFrequency(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 298 | count++; |
tnhnrl | 57:ec69651c8c21 | 299 | } |
tnhnrl | 57:ec69651c8c21 | 300 | if (cfg.getValue("deadband", &value[0], sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 301 | bce().setDeadband(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 302 | count++; |
tnhnrl | 57:ec69651c8c21 | 303 | } |
tnhnrl | 57:ec69651c8c21 | 304 | |
tnhnrl | 57:ec69651c8c21 | 305 | return count; |
tnhnrl | 57:ec69651c8c21 | 306 | } |
tnhnrl | 57:ec69651c8c21 | 307 | |
tnhnrl | 57:ec69651c8c21 | 308 | //write to heading.txt |
tnhnrl | 73:f6f378311c8d | 309 | 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 | 310 | ConfigFile heading_txt; |
tnhnrl | 57:ec69651c8c21 | 311 | |
tnhnrl | 57:ec69651c8c21 | 312 | char PGain_buffer[128]; |
tnhnrl | 57:ec69651c8c21 | 313 | sprintf(PGain_buffer,"# HEADING (rudder outer loop) parameters\n\n#Gains\nPGain"); |
tnhnrl | 57:ec69651c8c21 | 314 | |
tnhnrl | 57:ec69651c8c21 | 315 | //convert input numbers into text and save them to text file |
tnhnrl | 57:ec69651c8c21 | 316 | char string_pgain[128]; |
tnhnrl | 57:ec69651c8c21 | 317 | sprintf(string_pgain, "%f", heading_p_gain); |
tnhnrl | 57:ec69651c8c21 | 318 | heading_txt.setValue(PGain_buffer, string_pgain); |
tnhnrl | 57:ec69651c8c21 | 319 | |
tnhnrl | 57:ec69651c8c21 | 320 | char string_igain[128]; |
tnhnrl | 57:ec69651c8c21 | 321 | sprintf(string_igain, "%f", heading_i_gain); |
tnhnrl | 57:ec69651c8c21 | 322 | heading_txt.setValue("IGain", string_igain); |
tnhnrl | 57:ec69651c8c21 | 323 | |
tnhnrl | 57:ec69651c8c21 | 324 | char string_dgain[128]; |
tnhnrl | 57:ec69651c8c21 | 325 | sprintf(string_dgain, "%f", heading_d_gain); |
tnhnrl | 57:ec69651c8c21 | 326 | heading_txt.setValue("DGain", string_dgain); |
tnhnrl | 74:d281aaef9766 | 327 | |
tnhnrl | 74:d281aaef9766 | 328 | char string_heading_freq[128]; |
tnhnrl | 74:d281aaef9766 | 329 | sprintf(string_heading_freq, "%f", heading_filter_freq); |
tnhnrl | 74:d281aaef9766 | 330 | heading_txt.setValue("\n# HEADING sensor filter parameters\nfilterWn", string_heading_freq); |
tnhnrl | 74:d281aaef9766 | 331 | |
tnhnrl | 74:d281aaef9766 | 332 | char string_heading_db[128]; |
tnhnrl | 74:d281aaef9766 | 333 | sprintf(string_heading_db, "%f", heading_deadband); |
tnhnrl | 74:d281aaef9766 | 334 | heading_txt.setValue("deadband",string_heading_db); |
tnhnrl | 57:ec69651c8c21 | 335 | |
tnhnrl | 57:ec69651c8c21 | 336 | char string_zeroOffset[128]; |
tnhnrl | 73:f6f378311c8d | 337 | sprintf(string_zeroOffset, "%f", heading_zeroOffset); |
tnhnrl | 74:d281aaef9766 | 338 | heading_txt.setValue("\n#HEADING offset\nzeroOffset", string_zeroOffset); |
tnhnrl | 57:ec69651c8c21 | 339 | |
tnhnrl | 57:ec69651c8c21 | 340 | //SAVE THE DATA! |
tnhnrl | 74:d281aaef9766 | 341 | xbee().printf("(ConfigFileIO) Saving HEADING parameters!"); |
tnhnrl | 57:ec69651c8c21 | 342 | |
tnhnrl | 57:ec69651c8c21 | 343 | if (!heading_txt.write("/local/heading.txt")) { |
tnhnrl | 74:d281aaef9766 | 344 | xbee().printf("\n\rERROR: (SAVE) Failure to write heading.txt file."); |
tnhnrl | 57:ec69651c8c21 | 345 | } |
tnhnrl | 57:ec69651c8c21 | 346 | else { |
tnhnrl | 74:d281aaef9766 | 347 | xbee().printf("\n\rFile heading.txt successful written.\n\r"); |
tnhnrl | 57:ec69651c8c21 | 348 | } |
tnhnrl | 57:ec69651c8c21 | 349 | } |
joel_ssc | 82:0981b9ada820 | 350 | 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 | 351 | ConfigFile cfg; |
tnhnrl | 57:ec69651c8c21 | 352 | int count = 0; |
joel_ssc | 82:0981b9ada820 | 353 | int version = 0; |
joel_ssc | 82:0981b9ada820 | 354 | if (!cfg.read("/local/logvers.txt")) { // "/local/leg_mission.txt" |
joel_ssc | 82:0981b9ada820 | 355 | error("Lognames version file logvers.txt File Read Error"); |
joel_ssc | 82:0981b9ada820 | 356 | } |
joel_ssc | 87:6d95f853dab3 | 357 | char value[BUFSIZ]; // chang |
joel_ssc | 82:0981b9ada820 | 358 | |
joel_ssc | 82:0981b9ada820 | 359 | |
joel_ssc | 82:0981b9ada820 | 360 | if (cfg.getValue("LogFileVers", &value[0] , sizeof(value))) { |
joel_ssc | 82:0981b9ada820 | 361 | version = atoi(value); |
joel_ssc | 82:0981b9ada820 | 362 | char buf[256]; |
joel_ssc | 82:0981b9ada820 | 363 | sprintf(buf, "LOG%03d.csv", version); |
joel_ssc | 82:0981b9ada820 | 364 | logFilesStruct.logFileName = buf; |
joel_ssc | 82:0981b9ada820 | 365 | logFilesStruct.logversion = version; |
joel_ssc | 82:0981b9ada820 | 366 | count++; |
joel_ssc | 82:0981b9ada820 | 367 | } |
joel_ssc | 82:0981b9ada820 | 368 | if (cfg.getValue("DiagFileVers", &value[0] , sizeof(value))) { |
joel_ssc | 82:0981b9ada820 | 369 | version = atoi(value); |
joel_ssc | 82:0981b9ada820 | 370 | char buf[256]; |
joel_ssc | 82:0981b9ada820 | 371 | |
joel_ssc | 82:0981b9ada820 | 372 | sprintf(buf, "in configfileIO: diag file version number is %d\n", version); |
joel_ssc | 82:0981b9ada820 | 373 | if(print_diag == 1) {mbedLogger().appendDiagFile(buf,3);} |
joel_ssc | 82:0981b9ada820 | 374 | // buf[256]= {0}; |
joel_ssc | 87:6d95f853dab3 | 375 | sprintf(buf, "in ConfigFileIO: diag file string is DIAG%03d.txt\n", version); |
joel_ssc | 82:0981b9ada820 | 376 | if(print_diag == 1) {mbedLogger().appendDiagFile(buf,3);} |
joel_ssc | 82:0981b9ada820 | 377 | // buf[256]= {0}; |
joel_ssc | 82:0981b9ada820 | 378 | sprintf(buf, "DIAG%03d.txt", version); |
joel_ssc | 82:0981b9ada820 | 379 | logFilesStruct.diagFileName = buf; |
joel_ssc | 82:0981b9ada820 | 380 | logFilesStruct.diagversion = version; |
joel_ssc | 82:0981b9ada820 | 381 | sprintf(buf, "in ConfigFileIO: diag info pulled from struct: filename = %s diagvernum = %d\n", logFilesStruct.diagFileName, |
joel_ssc | 82:0981b9ada820 | 382 | logFilesStruct.diagversion); |
joel_ssc | 82:0981b9ada820 | 383 | if(print_diag==1) {mbedLogger().appendDiagFile(buf,3);} |
joel_ssc | 82:0981b9ada820 | 384 | count++; |
joel_ssc | 82:0981b9ada820 | 385 | } |
joel_ssc | 82:0981b9ada820 | 386 | return count; |
joel_ssc | 82:0981b9ada820 | 387 | } |
joel_ssc | 87:6d95f853dab3 | 388 | int ConfigFileIO::load_setneutral_status() { |
joel_ssc | 87:6d95f853dab3 | 389 | ConfigFile cfg; |
joel_ssc | 87:6d95f853dab3 | 390 | int count = 0; |
joel_ssc | 87:6d95f853dab3 | 391 | int setval = 0; |
joel_ssc | 87:6d95f853dab3 | 392 | int bce_mm = 240; |
joel_ssc | 87:6d95f853dab3 | 393 | int batt_mm = 40; |
joel_ssc | 87:6d95f853dab3 | 394 | if (!cfg.read("/local/neutral.txt")) { |
joel_ssc | 87:6d95f853dab3 | 395 | error("setneutral file neutral.txt File Read Error"); |
joel_ssc | 87:6d95f853dab3 | 396 | // set values in struct to defaults?? |
joel_ssc | 87:6d95f853dab3 | 397 | } |
joel_ssc | 87:6d95f853dab3 | 398 | char value[BUFSIZ]; |
joel_ssc | 87:6d95f853dab3 | 399 | |
joel_ssc | 87:6d95f853dab3 | 400 | |
joel_ssc | 87:6d95f853dab3 | 401 | if (cfg.getValue("neutral_set", &value[0] , sizeof(value))) { |
joel_ssc | 87:6d95f853dab3 | 402 | setval = atoi(value); |
joel_ssc | 87:6d95f853dab3 | 403 | neutralStruct.setval = setval; |
joel_ssc | 87:6d95f853dab3 | 404 | count++; |
joel_ssc | 87:6d95f853dab3 | 405 | } |
joel_ssc | 87:6d95f853dab3 | 406 | if (cfg.getValue("bce_neutral_mm", &value[0] , sizeof(value))) { |
joel_ssc | 87:6d95f853dab3 | 407 | bce_mm = atoi(value); |
joel_ssc | 87:6d95f853dab3 | 408 | char buf[256]; |
joel_ssc | 87:6d95f853dab3 | 409 | sprintf(buf, "in configfileIO: bce_neutral_mm is %d\n", bce_mm); |
joel_ssc | 87:6d95f853dab3 | 410 | mbedLogger().appendDiagFile(buf,3); |
joel_ssc | 87:6d95f853dab3 | 411 | // buf[256]= {0}; |
joel_ssc | 87:6d95f853dab3 | 412 | neutralStruct.bce_neutral_mm = bce_mm; |
joel_ssc | 87:6d95f853dab3 | 413 | count++; |
joel_ssc | 87:6d95f853dab3 | 414 | } |
joel_ssc | 87:6d95f853dab3 | 415 | if (cfg.getValue("batt_neutral_mm", &value[0] , sizeof(value))) { |
joel_ssc | 87:6d95f853dab3 | 416 | batt_mm = atoi(value); |
joel_ssc | 87:6d95f853dab3 | 417 | char buf[256]; |
joel_ssc | 87:6d95f853dab3 | 418 | sprintf(buf, "in configfileIO: batt_neutral_mm is %d\n", batt_mm); |
joel_ssc | 87:6d95f853dab3 | 419 | mbedLogger().appendDiagFile(buf,3); |
joel_ssc | 87:6d95f853dab3 | 420 | // buf[256]= {0}; |
joel_ssc | 87:6d95f853dab3 | 421 | neutralStruct.batt_neutral_mm = batt_mm; |
joel_ssc | 87:6d95f853dab3 | 422 | count++; |
joel_ssc | 87:6d95f853dab3 | 423 | } |
joel_ssc | 87:6d95f853dab3 | 424 | return count; |
joel_ssc | 87:6d95f853dab3 | 425 | } |
joel_ssc | 87:6d95f853dab3 | 426 | void ConfigFileIO::saveNeutralStatus(int setval, int bce_neutral_mm, int batt_neutral_mm) { |
joel_ssc | 87:6d95f853dab3 | 427 | ConfigFile neutral_txt; |
joel_ssc | 87:6d95f853dab3 | 428 | |
joel_ssc | 87:6d95f853dab3 | 429 | //convert input numbers into text and save them to text file |
joel_ssc | 87:6d95f853dab3 | 430 | char string_setval[128]; |
joel_ssc | 87:6d95f853dab3 | 431 | sprintf(string_setval, "%d", setval); |
joel_ssc | 87:6d95f853dab3 | 432 | neutral_txt.setValue("# Neutral set status and values\nneutral_set", string_setval); |
joel_ssc | 87:6d95f853dab3 | 433 | |
joel_ssc | 87:6d95f853dab3 | 434 | char string_bce[128]; |
joel_ssc | 87:6d95f853dab3 | 435 | sprintf(string_bce, "%d", bce_neutral_mm); |
joel_ssc | 87:6d95f853dab3 | 436 | neutral_txt.setValue("bce_neutral_mm", string_bce); |
joel_ssc | 87:6d95f853dab3 | 437 | |
joel_ssc | 87:6d95f853dab3 | 438 | char string_batt[128]; |
joel_ssc | 87:6d95f853dab3 | 439 | sprintf(string_batt, "%d", batt_neutral_mm); |
joel_ssc | 87:6d95f853dab3 | 440 | neutral_txt.setValue("batt_neutral_mm", string_batt); |
joel_ssc | 87:6d95f853dab3 | 441 | |
joel_ssc | 87:6d95f853dab3 | 442 | |
joel_ssc | 87:6d95f853dab3 | 443 | //SAVE THE DATA! also put the data insto the neutral struct |
joel_ssc | 87:6d95f853dab3 | 444 | neutralStruct.batt_neutral_mm = batt_neutral_mm; |
joel_ssc | 87:6d95f853dab3 | 445 | neutralStruct.bce_neutral_mm = bce_neutral_mm; |
joel_ssc | 87:6d95f853dab3 | 446 | neutralStruct.setval = setval; |
joel_ssc | 87:6d95f853dab3 | 447 | xbee().printf("(ConfigFileIO) Saving neutral set status parameters!"); |
joel_ssc | 87:6d95f853dab3 | 448 | |
joel_ssc | 87:6d95f853dab3 | 449 | if (!neutral_txt.write("/local/neutral.txt")) { |
joel_ssc | 87:6d95f853dab3 | 450 | xbee().printf("\n\rERROR: (SAVE) Failure to write neutral.txt file."); |
joel_ssc | 87:6d95f853dab3 | 451 | } |
joel_ssc | 87:6d95f853dab3 | 452 | else { |
joel_ssc | 87:6d95f853dab3 | 453 | xbee().printf("\n\rFile neutral.txt successful written.\n\r"); |
joel_ssc | 87:6d95f853dab3 | 454 | } |
joel_ssc | 87:6d95f853dab3 | 455 | } |
joel_ssc | 82:0981b9ada820 | 456 | 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 | 457 | ConfigFile cfg; |
joel_ssc | 82:0981b9ada820 | 458 | int count = 0; |
joel_ssc | 82:0981b9ada820 | 459 | if (!cfg.read("/local/batt.txt")) { // "/local/leg_mission.txt" |
tnhnrl | 57:ec69651c8c21 | 460 | error("BATT File Read Error"); |
tnhnrl | 57:ec69651c8c21 | 461 | } |
tnhnrl | 57:ec69651c8c21 | 462 | char value[BUFSIZ]; |
tnhnrl | 57:ec69651c8c21 | 463 | |
tnhnrl | 57:ec69651c8c21 | 464 | |
tnhnrl | 57:ec69651c8c21 | 465 | if (cfg.getValue("PGain", &value[0] , sizeof(value))) { |
joel_ssc | 82:0981b9ada820 | 466 | batt().setControllerP(atof(value)); // but I want values in a legStructLoaded, not a function |
tnhnrl | 57:ec69651c8c21 | 467 | count++; |
tnhnrl | 57:ec69651c8c21 | 468 | } |
tnhnrl | 57:ec69651c8c21 | 469 | if (cfg.getValue("IGain", &value[0] ,sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 470 | batt().setControllerI(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 471 | count++; |
tnhnrl | 57:ec69651c8c21 | 472 | } |
tnhnrl | 57:ec69651c8c21 | 473 | if (cfg.getValue("DGain", &value[0] , sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 474 | batt().setControllerD(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 475 | count++; |
tnhnrl | 57:ec69651c8c21 | 476 | } |
tnhnrl | 57:ec69651c8c21 | 477 | if (cfg.getValue("zeroCounts", &value[0],sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 478 | batt().setZeroCounts(atoi(value)); |
tnhnrl | 57:ec69651c8c21 | 479 | count++; |
tnhnrl | 57:ec69651c8c21 | 480 | } |
tnhnrl | 57:ec69651c8c21 | 481 | if (cfg.getValue("PistonTravelLimit", &value[0], sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 482 | batt().setTravelLimit(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 483 | count++; |
tnhnrl | 57:ec69651c8c21 | 484 | } |
tnhnrl | 57:ec69651c8c21 | 485 | if (cfg.getValue("slope", &value[0], sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 486 | batt().setPotSlope(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 487 | count++; |
tnhnrl | 57:ec69651c8c21 | 488 | } |
tnhnrl | 57:ec69651c8c21 | 489 | if (cfg.getValue("filterWn", &value[0], sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 490 | batt().setFilterFrequency(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 491 | count++; |
tnhnrl | 57:ec69651c8c21 | 492 | } |
tnhnrl | 57:ec69651c8c21 | 493 | if (cfg.getValue("deadband", &value[0], sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 494 | batt().setDeadband(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 495 | count++; |
tnhnrl | 57:ec69651c8c21 | 496 | } |
tnhnrl | 57:ec69651c8c21 | 497 | |
tnhnrl | 57:ec69651c8c21 | 498 | return count; |
tnhnrl | 57:ec69651c8c21 | 499 | } |
joel_ssc | 87:6d95f853dab3 | 500 | void ConfigFileIO::report_still_inverted( float roll_value, int yotime) { |
joel_ssc | 87:6d95f853dab3 | 501 | ConfigFile still_inverted; |
joel_ssc | 87:6d95f853dab3 | 502 | |
joel_ssc | 87:6d95f853dab3 | 503 | char string_yotime[128]; |
joel_ssc | 87:6d95f853dab3 | 504 | sprintf(string_yotime, "%d", yotime); |
joel_ssc | 87:6d95f853dab3 | 505 | still_inverted.setValue("# Still Inverted after START_SWIM yo timeout timeout\n yo_time", string_yotime); |
joel_ssc | 87:6d95f853dab3 | 506 | |
joel_ssc | 87:6d95f853dab3 | 507 | char string_roll[128]; |
joel_ssc | 87:6d95f853dab3 | 508 | sprintf(string_roll, "%f", roll_value); |
joel_ssc | 87:6d95f853dab3 | 509 | still_inverted.setValue("inverted_roll_value", string_roll); |
joel_ssc | 87:6d95f853dab3 | 510 | |
joel_ssc | 87:6d95f853dab3 | 511 | |
joel_ssc | 87:6d95f853dab3 | 512 | //SAVE THE DATA! |
joel_ssc | 87:6d95f853dab3 | 513 | |
joel_ssc | 87:6d95f853dab3 | 514 | xbee().printf("(ConfigFileIO) Saving still_inverted status after start_swim timeout!"); |
joel_ssc | 87:6d95f853dab3 | 515 | |
joel_ssc | 87:6d95f853dab3 | 516 | 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 | 517 | xbee().printf("\n\rERROR: (SAVE) Failure to write inverted.txt file."); |
joel_ssc | 87:6d95f853dab3 | 518 | } |
joel_ssc | 87:6d95f853dab3 | 519 | else { |
joel_ssc | 87:6d95f853dab3 | 520 | xbee().printf("\n\rFile inverted.txt written.\n\r"); // raspberry Pi will need to delete this file on finding it |
joel_ssc | 87:6d95f853dab3 | 521 | } |
joel_ssc | 87:6d95f853dab3 | 522 | |
joel_ssc | 87:6d95f853dab3 | 523 | } |
joel_ssc | 87:6d95f853dab3 | 524 | 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 | 525 | ConfigFile no_neutral; |
joel_ssc | 87:6d95f853dab3 | 526 | int setval = 0; |
joel_ssc | 87:6d95f853dab3 | 527 | //convert input numbers into text and save them to text file |
joel_ssc | 87:6d95f853dab3 | 528 | char string_setval[128]; |
joel_ssc | 87:6d95f853dab3 | 529 | sprintf(string_setval, "%d", setval); |
joel_ssc | 87:6d95f853dab3 | 530 | no_neutral.setValue("# Find_Neutral success or failure\nneutral_found", string_setval); |
joel_ssc | 87:6d95f853dab3 | 531 | |
joel_ssc | 87:6d95f853dab3 | 532 | char string_batt[128]; |
joel_ssc | 87:6d95f853dab3 | 533 | sprintf(string_batt, "%d", batt_last_pos); |
joel_ssc | 87:6d95f853dab3 | 534 | no_neutral.setValue("batt_last_position", string_batt); |
joel_ssc | 87:6d95f853dab3 | 535 | |
joel_ssc | 87:6d95f853dab3 | 536 | sprintf(string_batt, "%d", bce_last_pos); |
joel_ssc | 87:6d95f853dab3 | 537 | no_neutral.setValue("bce_last_position", string_batt); |
joel_ssc | 87:6d95f853dab3 | 538 | |
joel_ssc | 87:6d95f853dab3 | 539 | |
joel_ssc | 87:6d95f853dab3 | 540 | //SAVE THE DATA! also put the data insto the neutral struct |
joel_ssc | 87:6d95f853dab3 | 541 | |
joel_ssc | 87:6d95f853dab3 | 542 | xbee().printf("(ConfigFileIO) Saving find_neutral failure status!"); |
joel_ssc | 87:6d95f853dab3 | 543 | |
joel_ssc | 87:6d95f853dab3 | 544 | 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 | 545 | xbee().printf("\n\rERROR: (SAVE) Failure to write no_float.txt file."); |
joel_ssc | 87:6d95f853dab3 | 546 | } |
joel_ssc | 87:6d95f853dab3 | 547 | else { |
joel_ssc | 87:6d95f853dab3 | 548 | xbee().printf("\n\rFile no_float.txt written.\n\r"); |
joel_ssc | 87:6d95f853dab3 | 549 | } |
joel_ssc | 87:6d95f853dab3 | 550 | } |
joel_ssc | 88:1813f583cee9 | 551 | void ConfigFileIO::save_FinalTime() { |
joel_ssc | 88:1813f583cee9 | 552 | ConfigFile timefile_txt; |
joel_ssc | 88:1813f583cee9 | 553 | int last_time; |
joel_ssc | 88:1813f583cee9 | 554 | char header[128]; |
joel_ssc | 88:1813f583cee9 | 555 | sprintf(header,"# Timestamp at last moment before closing shop\n"); |
joel_ssc | 88:1813f583cee9 | 556 | |
joel_ssc | 88:1813f583cee9 | 557 | char string_end_time[128]; |
joel_ssc | 88:1813f583cee9 | 558 | last_time = mbedLogger().getSystemTime(); |
joel_ssc | 88:1813f583cee9 | 559 | sprintf(string_end_time, "%d", last_time); |
joel_ssc | 88:1813f583cee9 | 560 | timefile_txt.setValue("TimeStamp", string_end_time); |
joel_ssc | 88:1813f583cee9 | 561 | |
joel_ssc | 88:1813f583cee9 | 562 | |
joel_ssc | 88:1813f583cee9 | 563 | //SAVE THE DATA! |
joel_ssc | 88:1813f583cee9 | 564 | xbee().printf("Saving timestamp value!"); |
joel_ssc | 88:1813f583cee9 | 565 | |
joel_ssc | 88:1813f583cee9 | 566 | if (!timefile_txt.write("/local/newtime.txt")) { |
joel_ssc | 88:1813f583cee9 | 567 | xbee().printf("\n\rERROR: (SAVE)Failure to write time.txt file."); |
joel_ssc | 88:1813f583cee9 | 568 | } |
joel_ssc | 88:1813f583cee9 | 569 | else { |
joel_ssc | 88:1813f583cee9 | 570 | xbee().printf("\n\rFile newtime.txt successfully written.\n\r"); |
joel_ssc | 88:1813f583cee9 | 571 | } |
joel_ssc | 88:1813f583cee9 | 572 | } |
tnhnrl | 57:ec69651c8c21 | 573 | int ConfigFileIO::load_DEPTH_config() { |
tnhnrl | 57:ec69651c8c21 | 574 | ConfigFile cfg; |
tnhnrl | 57:ec69651c8c21 | 575 | int count = 0; |
tnhnrl | 57:ec69651c8c21 | 576 | if (!cfg.read("/local/depth.txt")) { |
tnhnrl | 57:ec69651c8c21 | 577 | error("DEPTH File Read Error"); |
tnhnrl | 57:ec69651c8c21 | 578 | } |
tnhnrl | 57:ec69651c8c21 | 579 | char value[BUFSIZ]; |
tnhnrl | 57:ec69651c8c21 | 580 | |
tnhnrl | 57:ec69651c8c21 | 581 | if (cfg.getValue("PGain", &value[0] , sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 582 | depthLoop().setControllerP(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 583 | count++; |
tnhnrl | 57:ec69651c8c21 | 584 | } |
tnhnrl | 57:ec69651c8c21 | 585 | if (cfg.getValue("IGain", &value[0] ,sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 586 | depthLoop().setControllerI(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 587 | count++; |
tnhnrl | 57:ec69651c8c21 | 588 | } |
tnhnrl | 57:ec69651c8c21 | 589 | if (cfg.getValue("DGain", &value[0] , sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 590 | depthLoop().setControllerD(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 591 | count++; |
tnhnrl | 57:ec69651c8c21 | 592 | } |
tnhnrl | 57:ec69651c8c21 | 593 | if (cfg.getValue("filterWn", &value[0], sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 594 | depthLoop().setFilterFrequency(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 595 | count++; |
tnhnrl | 57:ec69651c8c21 | 596 | } |
tnhnrl | 57:ec69651c8c21 | 597 | if (cfg.getValue("deadband", &value[0], sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 598 | depthLoop().setDeadband(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 599 | count++; |
tnhnrl | 57:ec69651c8c21 | 600 | } |
tnhnrl | 57:ec69651c8c21 | 601 | if (cfg.getValue("zeroOffset", &value[0], sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 602 | depthLoop().setOutputOffset(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 603 | count++; |
tnhnrl | 57:ec69651c8c21 | 604 | } |
tnhnrl | 57:ec69651c8c21 | 605 | return count; |
tnhnrl | 57:ec69651c8c21 | 606 | } |
tnhnrl | 57:ec69651c8c21 | 607 | |
tnhnrl | 57:ec69651c8c21 | 608 | int ConfigFileIO::load_PITCH_config() { |
tnhnrl | 57:ec69651c8c21 | 609 | ConfigFile cfg; |
tnhnrl | 57:ec69651c8c21 | 610 | int count = 0; |
tnhnrl | 57:ec69651c8c21 | 611 | if (!cfg.read("/local/pitch.txt")){ |
tnhnrl | 57:ec69651c8c21 | 612 | error("PITCH File Read Error"); |
tnhnrl | 57:ec69651c8c21 | 613 | } |
tnhnrl | 57:ec69651c8c21 | 614 | char value[BUFSIZ]; |
tnhnrl | 57:ec69651c8c21 | 615 | |
tnhnrl | 57:ec69651c8c21 | 616 | if (cfg.getValue("PGain", &value[0] , sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 617 | pitchLoop().setControllerP(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 618 | count++; |
tnhnrl | 57:ec69651c8c21 | 619 | } |
tnhnrl | 57:ec69651c8c21 | 620 | if (cfg.getValue("IGain", &value[0] ,sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 621 | pitchLoop().setControllerI(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 622 | count++; |
tnhnrl | 57:ec69651c8c21 | 623 | } |
tnhnrl | 57:ec69651c8c21 | 624 | if (cfg.getValue("DGain", &value[0] , sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 625 | pitchLoop().setControllerD(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 626 | count++; |
tnhnrl | 57:ec69651c8c21 | 627 | } |
tnhnrl | 57:ec69651c8c21 | 628 | if (cfg.getValue("filterWn", &value[0], sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 629 | pitchLoop().setFilterFrequency(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 630 | count++; |
tnhnrl | 57:ec69651c8c21 | 631 | } |
tnhnrl | 57:ec69651c8c21 | 632 | if (cfg.getValue("deadband", &value[0], sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 633 | pitchLoop().setDeadband(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 634 | count++; |
tnhnrl | 57:ec69651c8c21 | 635 | } |
tnhnrl | 57:ec69651c8c21 | 636 | |
tnhnrl | 57:ec69651c8c21 | 637 | if (cfg.getValue("zeroOffset", &value[0], sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 638 | pitchLoop().setOutputOffset(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 639 | count++; |
tnhnrl | 57:ec69651c8c21 | 640 | } |
tnhnrl | 57:ec69651c8c21 | 641 | return count; |
tnhnrl | 57:ec69651c8c21 | 642 | } |
tnhnrl | 57:ec69651c8c21 | 643 | |
tnhnrl | 57:ec69651c8c21 | 644 | int ConfigFileIO::load_HEADING_config() { |
tnhnrl | 57:ec69651c8c21 | 645 | ConfigFile cfg; |
tnhnrl | 57:ec69651c8c21 | 646 | int count = 0; |
tnhnrl | 57:ec69651c8c21 | 647 | if (!cfg.read("/local/heading.txt")){ |
tnhnrl | 57:ec69651c8c21 | 648 | error("HEADING File Read Error"); |
tnhnrl | 57:ec69651c8c21 | 649 | } |
tnhnrl | 57:ec69651c8c21 | 650 | char value[BUFSIZ]; |
tnhnrl | 57:ec69651c8c21 | 651 | |
tnhnrl | 57:ec69651c8c21 | 652 | if (cfg.getValue("PGain", &value[0] , sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 653 | headingLoop().setControllerP(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 654 | count++; |
tnhnrl | 57:ec69651c8c21 | 655 | } |
tnhnrl | 57:ec69651c8c21 | 656 | if (cfg.getValue("IGain", &value[0] ,sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 657 | headingLoop().setControllerI(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 658 | count++; |
tnhnrl | 57:ec69651c8c21 | 659 | } |
tnhnrl | 57:ec69651c8c21 | 660 | if (cfg.getValue("DGain", &value[0] , sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 661 | headingLoop().setControllerD(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 662 | count++; |
tnhnrl | 57:ec69651c8c21 | 663 | } |
tnhnrl | 57:ec69651c8c21 | 664 | if (cfg.getValue("filterWn", &value[0], sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 665 | headingLoop().setFilterFrequency(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 666 | count++; |
tnhnrl | 57:ec69651c8c21 | 667 | } |
tnhnrl | 57:ec69651c8c21 | 668 | if (cfg.getValue("deadband", &value[0], sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 669 | headingLoop().setDeadband(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 670 | count++; |
tnhnrl | 57:ec69651c8c21 | 671 | } |
tnhnrl | 57:ec69651c8c21 | 672 | |
tnhnrl | 57:ec69651c8c21 | 673 | if (cfg.getValue("zeroOffset", &value[0], sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 674 | headingLoop().setOutputOffset(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 675 | count++; |
tnhnrl | 57:ec69651c8c21 | 676 | } |
tnhnrl | 57:ec69651c8c21 | 677 | return count; |
tnhnrl | 57:ec69651c8c21 | 678 | } |
tnhnrl | 57:ec69651c8c21 | 679 | |
tnhnrl | 57:ec69651c8c21 | 680 | int ConfigFileIO::load_RUDDER_config() { |
tnhnrl | 57:ec69651c8c21 | 681 | ConfigFile cfg; |
tnhnrl | 57:ec69651c8c21 | 682 | int count = 0; |
tnhnrl | 57:ec69651c8c21 | 683 | if (!cfg.read("/local/rudder.txt")){ |
tnhnrl | 57:ec69651c8c21 | 684 | error("RUDDER File Read Error"); |
tnhnrl | 57:ec69651c8c21 | 685 | } |
tnhnrl | 57:ec69651c8c21 | 686 | char value[BUFSIZ]; |
tnhnrl | 57:ec69651c8c21 | 687 | |
tnhnrl | 57:ec69651c8c21 | 688 | //float values below |
tnhnrl | 57:ec69651c8c21 | 689 | if (cfg.getValue("setMinDeg", &value[0] , sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 690 | rudder().setMinDeg(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 691 | count++; |
tnhnrl | 57:ec69651c8c21 | 692 | } |
tnhnrl | 57:ec69651c8c21 | 693 | if (cfg.getValue("setMaxDeg", &value[0] ,sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 694 | rudder().setMaxDeg(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 695 | count++; |
tnhnrl | 57:ec69651c8c21 | 696 | } |
tnhnrl | 57:ec69651c8c21 | 697 | |
tnhnrl | 57:ec69651c8c21 | 698 | //integer values below |
tnhnrl | 57:ec69651c8c21 | 699 | if (cfg.getValue("setCenterPWM", &value[0] , sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 700 | rudder().setCenterPWM(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 701 | count++; |
tnhnrl | 57:ec69651c8c21 | 702 | } |
tnhnrl | 57:ec69651c8c21 | 703 | if (cfg.getValue("setMinPWM", &value[0], sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 704 | rudder().setMinPWM(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 705 | count++; |
tnhnrl | 57:ec69651c8c21 | 706 | } |
tnhnrl | 57:ec69651c8c21 | 707 | if (cfg.getValue("setMaxPWM", &value[0], sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 708 | rudder().setMaxPWM(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 709 | count++; |
tnhnrl | 57:ec69651c8c21 | 710 | } |
tnhnrl | 57:ec69651c8c21 | 711 | return count; |
tnhnrl | 57:ec69651c8c21 | 712 | } |