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