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@86:ba3a118b0080, 2019-05-02 (annotated)
- Committer:
- joel_ssc
- Date:
- Thu May 02 20:34:16 2019 +0000
- Revision:
- 86:ba3a118b0080
- Parent:
- 82:0981b9ada820
- Child:
- 87:6d95f853dab3
works and gives led signals of life
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 | 82:0981b9ada820 | 357 | char value[BUFSIZ]; |
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 | 82:0981b9ada820 | 375 | sprintf(buf, "in ConfigFileIO: diag file string is DIAG%03d.txt", 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 | 82:0981b9ada820 | 388 | 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 | 389 | ConfigFile cfg; |
joel_ssc | 82:0981b9ada820 | 390 | int count = 0; |
joel_ssc | 82:0981b9ada820 | 391 | if (!cfg.read("/local/batt.txt")) { // "/local/leg_mission.txt" |
tnhnrl | 57:ec69651c8c21 | 392 | error("BATT File Read Error"); |
tnhnrl | 57:ec69651c8c21 | 393 | } |
tnhnrl | 57:ec69651c8c21 | 394 | char value[BUFSIZ]; |
tnhnrl | 57:ec69651c8c21 | 395 | |
tnhnrl | 57:ec69651c8c21 | 396 | |
tnhnrl | 57:ec69651c8c21 | 397 | if (cfg.getValue("PGain", &value[0] , sizeof(value))) { |
joel_ssc | 82:0981b9ada820 | 398 | batt().setControllerP(atof(value)); // but I want values in a legStructLoaded, not a function |
tnhnrl | 57:ec69651c8c21 | 399 | count++; |
tnhnrl | 57:ec69651c8c21 | 400 | } |
tnhnrl | 57:ec69651c8c21 | 401 | if (cfg.getValue("IGain", &value[0] ,sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 402 | batt().setControllerI(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 403 | count++; |
tnhnrl | 57:ec69651c8c21 | 404 | } |
tnhnrl | 57:ec69651c8c21 | 405 | if (cfg.getValue("DGain", &value[0] , sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 406 | batt().setControllerD(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 407 | count++; |
tnhnrl | 57:ec69651c8c21 | 408 | } |
tnhnrl | 57:ec69651c8c21 | 409 | if (cfg.getValue("zeroCounts", &value[0],sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 410 | batt().setZeroCounts(atoi(value)); |
tnhnrl | 57:ec69651c8c21 | 411 | count++; |
tnhnrl | 57:ec69651c8c21 | 412 | } |
tnhnrl | 57:ec69651c8c21 | 413 | if (cfg.getValue("PistonTravelLimit", &value[0], sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 414 | batt().setTravelLimit(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 415 | count++; |
tnhnrl | 57:ec69651c8c21 | 416 | } |
tnhnrl | 57:ec69651c8c21 | 417 | if (cfg.getValue("slope", &value[0], sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 418 | batt().setPotSlope(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 419 | count++; |
tnhnrl | 57:ec69651c8c21 | 420 | } |
tnhnrl | 57:ec69651c8c21 | 421 | if (cfg.getValue("filterWn", &value[0], sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 422 | batt().setFilterFrequency(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 423 | count++; |
tnhnrl | 57:ec69651c8c21 | 424 | } |
tnhnrl | 57:ec69651c8c21 | 425 | if (cfg.getValue("deadband", &value[0], sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 426 | batt().setDeadband(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 427 | count++; |
tnhnrl | 57:ec69651c8c21 | 428 | } |
tnhnrl | 57:ec69651c8c21 | 429 | |
tnhnrl | 57:ec69651c8c21 | 430 | return count; |
tnhnrl | 57:ec69651c8c21 | 431 | } |
tnhnrl | 57:ec69651c8c21 | 432 | |
tnhnrl | 57:ec69651c8c21 | 433 | int ConfigFileIO::load_DEPTH_config() { |
tnhnrl | 57:ec69651c8c21 | 434 | ConfigFile cfg; |
tnhnrl | 57:ec69651c8c21 | 435 | int count = 0; |
tnhnrl | 57:ec69651c8c21 | 436 | if (!cfg.read("/local/depth.txt")) { |
tnhnrl | 57:ec69651c8c21 | 437 | error("DEPTH File Read Error"); |
tnhnrl | 57:ec69651c8c21 | 438 | } |
tnhnrl | 57:ec69651c8c21 | 439 | char value[BUFSIZ]; |
tnhnrl | 57:ec69651c8c21 | 440 | |
tnhnrl | 57:ec69651c8c21 | 441 | if (cfg.getValue("PGain", &value[0] , sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 442 | depthLoop().setControllerP(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 443 | count++; |
tnhnrl | 57:ec69651c8c21 | 444 | } |
tnhnrl | 57:ec69651c8c21 | 445 | if (cfg.getValue("IGain", &value[0] ,sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 446 | depthLoop().setControllerI(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 447 | count++; |
tnhnrl | 57:ec69651c8c21 | 448 | } |
tnhnrl | 57:ec69651c8c21 | 449 | if (cfg.getValue("DGain", &value[0] , sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 450 | depthLoop().setControllerD(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 451 | count++; |
tnhnrl | 57:ec69651c8c21 | 452 | } |
tnhnrl | 57:ec69651c8c21 | 453 | if (cfg.getValue("filterWn", &value[0], sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 454 | depthLoop().setFilterFrequency(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 455 | count++; |
tnhnrl | 57:ec69651c8c21 | 456 | } |
tnhnrl | 57:ec69651c8c21 | 457 | if (cfg.getValue("deadband", &value[0], sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 458 | depthLoop().setDeadband(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 459 | count++; |
tnhnrl | 57:ec69651c8c21 | 460 | } |
tnhnrl | 57:ec69651c8c21 | 461 | if (cfg.getValue("zeroOffset", &value[0], sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 462 | depthLoop().setOutputOffset(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 463 | count++; |
tnhnrl | 57:ec69651c8c21 | 464 | } |
tnhnrl | 57:ec69651c8c21 | 465 | return count; |
tnhnrl | 57:ec69651c8c21 | 466 | } |
tnhnrl | 57:ec69651c8c21 | 467 | |
tnhnrl | 57:ec69651c8c21 | 468 | int ConfigFileIO::load_PITCH_config() { |
tnhnrl | 57:ec69651c8c21 | 469 | ConfigFile cfg; |
tnhnrl | 57:ec69651c8c21 | 470 | int count = 0; |
tnhnrl | 57:ec69651c8c21 | 471 | if (!cfg.read("/local/pitch.txt")){ |
tnhnrl | 57:ec69651c8c21 | 472 | error("PITCH File Read Error"); |
tnhnrl | 57:ec69651c8c21 | 473 | } |
tnhnrl | 57:ec69651c8c21 | 474 | char value[BUFSIZ]; |
tnhnrl | 57:ec69651c8c21 | 475 | |
tnhnrl | 57:ec69651c8c21 | 476 | if (cfg.getValue("PGain", &value[0] , sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 477 | pitchLoop().setControllerP(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 478 | count++; |
tnhnrl | 57:ec69651c8c21 | 479 | } |
tnhnrl | 57:ec69651c8c21 | 480 | if (cfg.getValue("IGain", &value[0] ,sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 481 | pitchLoop().setControllerI(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 482 | count++; |
tnhnrl | 57:ec69651c8c21 | 483 | } |
tnhnrl | 57:ec69651c8c21 | 484 | if (cfg.getValue("DGain", &value[0] , sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 485 | pitchLoop().setControllerD(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 486 | count++; |
tnhnrl | 57:ec69651c8c21 | 487 | } |
tnhnrl | 57:ec69651c8c21 | 488 | if (cfg.getValue("filterWn", &value[0], sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 489 | pitchLoop().setFilterFrequency(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 490 | count++; |
tnhnrl | 57:ec69651c8c21 | 491 | } |
tnhnrl | 57:ec69651c8c21 | 492 | if (cfg.getValue("deadband", &value[0], sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 493 | pitchLoop().setDeadband(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 494 | count++; |
tnhnrl | 57:ec69651c8c21 | 495 | } |
tnhnrl | 57:ec69651c8c21 | 496 | |
tnhnrl | 57:ec69651c8c21 | 497 | if (cfg.getValue("zeroOffset", &value[0], sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 498 | pitchLoop().setOutputOffset(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 499 | count++; |
tnhnrl | 57:ec69651c8c21 | 500 | } |
tnhnrl | 57:ec69651c8c21 | 501 | return count; |
tnhnrl | 57:ec69651c8c21 | 502 | } |
tnhnrl | 57:ec69651c8c21 | 503 | |
tnhnrl | 57:ec69651c8c21 | 504 | int ConfigFileIO::load_HEADING_config() { |
tnhnrl | 57:ec69651c8c21 | 505 | ConfigFile cfg; |
tnhnrl | 57:ec69651c8c21 | 506 | int count = 0; |
tnhnrl | 57:ec69651c8c21 | 507 | if (!cfg.read("/local/heading.txt")){ |
tnhnrl | 57:ec69651c8c21 | 508 | error("HEADING File Read Error"); |
tnhnrl | 57:ec69651c8c21 | 509 | } |
tnhnrl | 57:ec69651c8c21 | 510 | char value[BUFSIZ]; |
tnhnrl | 57:ec69651c8c21 | 511 | |
tnhnrl | 57:ec69651c8c21 | 512 | if (cfg.getValue("PGain", &value[0] , sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 513 | headingLoop().setControllerP(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 514 | count++; |
tnhnrl | 57:ec69651c8c21 | 515 | } |
tnhnrl | 57:ec69651c8c21 | 516 | if (cfg.getValue("IGain", &value[0] ,sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 517 | headingLoop().setControllerI(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 518 | count++; |
tnhnrl | 57:ec69651c8c21 | 519 | } |
tnhnrl | 57:ec69651c8c21 | 520 | if (cfg.getValue("DGain", &value[0] , sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 521 | headingLoop().setControllerD(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 522 | count++; |
tnhnrl | 57:ec69651c8c21 | 523 | } |
tnhnrl | 57:ec69651c8c21 | 524 | if (cfg.getValue("filterWn", &value[0], sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 525 | headingLoop().setFilterFrequency(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 526 | count++; |
tnhnrl | 57:ec69651c8c21 | 527 | } |
tnhnrl | 57:ec69651c8c21 | 528 | if (cfg.getValue("deadband", &value[0], sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 529 | headingLoop().setDeadband(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 530 | count++; |
tnhnrl | 57:ec69651c8c21 | 531 | } |
tnhnrl | 57:ec69651c8c21 | 532 | |
tnhnrl | 57:ec69651c8c21 | 533 | if (cfg.getValue("zeroOffset", &value[0], sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 534 | headingLoop().setOutputOffset(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 535 | count++; |
tnhnrl | 57:ec69651c8c21 | 536 | } |
tnhnrl | 57:ec69651c8c21 | 537 | return count; |
tnhnrl | 57:ec69651c8c21 | 538 | } |
tnhnrl | 57:ec69651c8c21 | 539 | |
tnhnrl | 57:ec69651c8c21 | 540 | int ConfigFileIO::load_RUDDER_config() { |
tnhnrl | 57:ec69651c8c21 | 541 | ConfigFile cfg; |
tnhnrl | 57:ec69651c8c21 | 542 | int count = 0; |
tnhnrl | 57:ec69651c8c21 | 543 | if (!cfg.read("/local/rudder.txt")){ |
tnhnrl | 57:ec69651c8c21 | 544 | error("RUDDER File Read Error"); |
tnhnrl | 57:ec69651c8c21 | 545 | } |
tnhnrl | 57:ec69651c8c21 | 546 | char value[BUFSIZ]; |
tnhnrl | 57:ec69651c8c21 | 547 | |
tnhnrl | 57:ec69651c8c21 | 548 | //float values below |
tnhnrl | 57:ec69651c8c21 | 549 | if (cfg.getValue("setMinDeg", &value[0] , sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 550 | rudder().setMinDeg(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 551 | count++; |
tnhnrl | 57:ec69651c8c21 | 552 | } |
tnhnrl | 57:ec69651c8c21 | 553 | if (cfg.getValue("setMaxDeg", &value[0] ,sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 554 | rudder().setMaxDeg(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 555 | count++; |
tnhnrl | 57:ec69651c8c21 | 556 | } |
tnhnrl | 57:ec69651c8c21 | 557 | |
tnhnrl | 57:ec69651c8c21 | 558 | //integer values below |
tnhnrl | 57:ec69651c8c21 | 559 | if (cfg.getValue("setCenterPWM", &value[0] , sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 560 | rudder().setCenterPWM(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 561 | count++; |
tnhnrl | 57:ec69651c8c21 | 562 | } |
tnhnrl | 57:ec69651c8c21 | 563 | if (cfg.getValue("setMinPWM", &value[0], sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 564 | rudder().setMinPWM(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 565 | count++; |
tnhnrl | 57:ec69651c8c21 | 566 | } |
tnhnrl | 57:ec69651c8c21 | 567 | if (cfg.getValue("setMaxPWM", &value[0], sizeof(value))) { |
tnhnrl | 57:ec69651c8c21 | 568 | rudder().setMaxPWM(atof(value)); |
tnhnrl | 57:ec69651c8c21 | 569 | count++; |
tnhnrl | 57:ec69651c8c21 | 570 | } |
tnhnrl | 57:ec69651c8c21 | 571 | return count; |
tnhnrl | 57:ec69651c8c21 | 572 | } |