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
Config_File_IO/ConfigFileIO.cpp@17:7c16b5671d0e, 2017-11-21 (annotated)
- Committer:
- tnhnrl
- Date:
- Tue Nov 21 22:03:26 2017 +0000
- Revision:
- 17:7c16b5671d0e
FSG code commit 11/21
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tnhnrl | 17:7c16b5671d0e | 1 | #include "ConfigFileIO.hpp" |
tnhnrl | 17:7c16b5671d0e | 2 | #include "StaticDefs.hpp" |
tnhnrl | 17:7c16b5671d0e | 3 | |
tnhnrl | 17:7c16b5671d0e | 4 | // This set of functions is all about the configuration file io, both to read, set, and save |
tnhnrl | 17:7c16b5671d0e | 5 | |
tnhnrl | 17:7c16b5671d0e | 6 | // todo: update write PID because there are now more gains |
tnhnrl | 17:7c16b5671d0e | 7 | // todo: back-check this file matches the list of parameters |
tnhnrl | 17:7c16b5671d0e | 8 | |
tnhnrl | 17:7c16b5671d0e | 9 | //Files that are present on the MBED are cleared and rewritten |
tnhnrl | 17:7c16b5671d0e | 10 | |
tnhnrl | 17:7c16b5671d0e | 11 | /* ************************** SETUP FILE SYSTEM ************************** */ |
tnhnrl | 17:7c16b5671d0e | 12 | |
tnhnrl | 17:7c16b5671d0e | 13 | // constructor |
tnhnrl | 17:7c16b5671d0e | 14 | ConfigFileIO::ConfigFileIO() { |
tnhnrl | 17:7c16b5671d0e | 15 | //LocalFileSystem local("local"); //not working in the class |
tnhnrl | 17:7c16b5671d0e | 16 | } |
tnhnrl | 17:7c16b5671d0e | 17 | |
tnhnrl | 17:7c16b5671d0e | 18 | void ConfigFileIO::saveNeutralPositions(float float_nbp_value, float float_nb_battpos_value) { |
tnhnrl | 17:7c16b5671d0e | 19 | ConfigFile write_neutral_cfg; //write to the config file |
tnhnrl | 17:7c16b5671d0e | 20 | |
tnhnrl | 17:7c16b5671d0e | 21 | char nbp_buffer[50]; |
tnhnrl | 17:7c16b5671d0e | 22 | sprintf(nbp_buffer, "%f", float_nbp_value); |
tnhnrl | 17:7c16b5671d0e | 23 | |
tnhnrl | 17:7c16b5671d0e | 24 | if (!write_neutral_cfg.setValue("neutral_buoyancy_engine_position_mm", nbp_buffer)) { |
tnhnrl | 17:7c16b5671d0e | 25 | pc().printf("\nFailure to set a value!"); |
tnhnrl | 17:7c16b5671d0e | 26 | } |
tnhnrl | 17:7c16b5671d0e | 27 | else { |
tnhnrl | 17:7c16b5671d0e | 28 | pc().printf("NET BUOYANCY (buoyancy engine position) CONFIG written!. \n\r"); |
tnhnrl | 17:7c16b5671d0e | 29 | } |
tnhnrl | 17:7c16b5671d0e | 30 | |
tnhnrl | 17:7c16b5671d0e | 31 | char nb_battpos_value[50]; |
tnhnrl | 17:7c16b5671d0e | 32 | sprintf(nb_battpos_value, "%f", float_nb_battpos_value); |
tnhnrl | 17:7c16b5671d0e | 33 | |
tnhnrl | 17:7c16b5671d0e | 34 | if (!write_neutral_cfg.setValue("neutral_buoyancy_battery_motor_position_mm", nb_battpos_value)) { |
tnhnrl | 17:7c16b5671d0e | 35 | pc().printf("\nFailure to set a value!"); |
tnhnrl | 17:7c16b5671d0e | 36 | } |
tnhnrl | 17:7c16b5671d0e | 37 | else { |
tnhnrl | 17:7c16b5671d0e | 38 | pc().printf("NET BUOYANCY (batt motor position) CONFIG written!. \n\r"); |
tnhnrl | 17:7c16b5671d0e | 39 | } |
tnhnrl | 17:7c16b5671d0e | 40 | |
tnhnrl | 17:7c16b5671d0e | 41 | //SAVE THE DATA! |
tnhnrl | 17:7c16b5671d0e | 42 | pc().printf("Saving Neutral Buoyancy Positions!"); |
tnhnrl | 17:7c16b5671d0e | 43 | |
tnhnrl | 17:7c16b5671d0e | 44 | if (!write_neutral_cfg.write("/local/neutral.cfg")) { |
tnhnrl | 17:7c16b5671d0e | 45 | pc().printf("\n\rERROR: (SAVE)Failure to write neutral.cfg file."); |
tnhnrl | 17:7c16b5671d0e | 46 | } |
tnhnrl | 17:7c16b5671d0e | 47 | else { |
tnhnrl | 17:7c16b5671d0e | 48 | pc().printf("\n\r(SAVE) Successful save."); |
tnhnrl | 17:7c16b5671d0e | 49 | } |
tnhnrl | 17:7c16b5671d0e | 50 | } |
tnhnrl | 17:7c16b5671d0e | 51 | |
tnhnrl | 17:7c16b5671d0e | 52 | void ConfigFileIO::loadNeutralPositions() { //reads neutral.cfg |
tnhnrl | 17:7c16b5671d0e | 53 | ConfigFile read_neutral_cfg; //create this object (KEEP THIS LOCAL, do not mess with other config object) |
tnhnrl | 17:7c16b5671d0e | 54 | |
tnhnrl | 17:7c16b5671d0e | 55 | char * string_neutral_buoyancy_engine_position_mm = "neutral_buoyancy_engine_position_mm"; |
tnhnrl | 17:7c16b5671d0e | 56 | char * string_neutral_buoyancy_battery_motor_position_mm = "neutral_buoyancy_battery_motor_position_mm"; |
tnhnrl | 17:7c16b5671d0e | 57 | char * startup_delay_config = "startup_delay_neutral"; //not using this 10/11/2017 |
tnhnrl | 17:7c16b5671d0e | 58 | char * string_config_neutral_depth_ft = "neutral_dive_depth_ft"; |
tnhnrl | 17:7c16b5671d0e | 59 | |
tnhnrl | 17:7c16b5671d0e | 60 | char value[BUFSIZ]; //something like size 4096 |
tnhnrl | 17:7c16b5671d0e | 61 | |
tnhnrl | 17:7c16b5671d0e | 62 | float config_file_wait_setting_neutral; //you can set the delay in the config file! |
tnhnrl | 17:7c16b5671d0e | 63 | |
tnhnrl | 17:7c16b5671d0e | 64 | //read configuration file stored on MBED |
tnhnrl | 17:7c16b5671d0e | 65 | if (!read_neutral_cfg.read("/local/neutral.cfg")) { |
tnhnrl | 17:7c16b5671d0e | 66 | pc().printf("\n\rERROR:Failure to read neutral.cfg file."); |
tnhnrl | 17:7c16b5671d0e | 67 | } |
tnhnrl | 17:7c16b5671d0e | 68 | else |
tnhnrl | 17:7c16b5671d0e | 69 | pc().printf("Successfully read neutral.cfg file.\n\r"); |
tnhnrl | 17:7c16b5671d0e | 70 | |
tnhnrl | 17:7c16b5671d0e | 71 | //Read values from config file |
tnhnrl | 17:7c16b5671d0e | 72 | if (read_neutral_cfg.getValue(string_neutral_buoyancy_engine_position_mm, &value[0], sizeof(value))) { |
tnhnrl | 17:7c16b5671d0e | 73 | pc().printf("\n\r%s = %s", string_neutral_buoyancy_engine_position_mm, value); |
tnhnrl | 17:7c16b5671d0e | 74 | ////xbee().printf("\n\r%s = %s", string_neutral_buoyancy_engine_position_mm, value); |
tnhnrl | 17:7c16b5671d0e | 75 | _neutral_bce_pos_mm = atof(value); //global for now |
tnhnrl | 17:7c16b5671d0e | 76 | } |
tnhnrl | 17:7c16b5671d0e | 77 | if (read_neutral_cfg.getValue(string_neutral_buoyancy_battery_motor_position_mm, &value[0], sizeof(value))) { |
tnhnrl | 17:7c16b5671d0e | 78 | pc().printf("\n\r%s = %s", string_neutral_buoyancy_battery_motor_position_mm, value); |
tnhnrl | 17:7c16b5671d0e | 79 | ////xbee().printf("\n\r%s = %s", string_neutral_buoyancy_battery_motor_position_mm, value); |
tnhnrl | 17:7c16b5671d0e | 80 | _neutral_batt_pos_mm = atof(value); //global for now |
tnhnrl | 17:7c16b5671d0e | 81 | } |
tnhnrl | 17:7c16b5671d0e | 82 | } |
tnhnrl | 17:7c16b5671d0e | 83 | |
tnhnrl | 17:7c16b5671d0e | 84 | float ConfigFileIO::getBattPos() { |
tnhnrl | 17:7c16b5671d0e | 85 | return _neutral_batt_pos_mm; |
tnhnrl | 17:7c16b5671d0e | 86 | } |
tnhnrl | 17:7c16b5671d0e | 87 | |
tnhnrl | 17:7c16b5671d0e | 88 | float ConfigFileIO::getBCEPos() { |
tnhnrl | 17:7c16b5671d0e | 89 | return _neutral_bce_pos_mm; |
tnhnrl | 17:7c16b5671d0e | 90 | } |
tnhnrl | 17:7c16b5671d0e | 91 | |
tnhnrl | 17:7c16b5671d0e | 92 | //// load data on command |
tnhnrl | 17:7c16b5671d0e | 93 | //void ConfigFileIO::load() { |
tnhnrl | 17:7c16b5671d0e | 94 | // load_manual_position_PID_gains_from_config_file(); |
tnhnrl | 17:7c16b5671d0e | 95 | // load_auto_PID_gains_from_config_file(); |
tnhnrl | 17:7c16b5671d0e | 96 | // load_timers_from_config_file(); |
tnhnrl | 17:7c16b5671d0e | 97 | // |
tnhnrl | 17:7c16b5671d0e | 98 | // //add rest of loading functions |
tnhnrl | 17:7c16b5671d0e | 99 | // //load_initial_config_position |
tnhnrl | 17:7c16b5671d0e | 100 | //} |
tnhnrl | 17:7c16b5671d0e | 101 | // |
tnhnrl | 17:7c16b5671d0e | 102 | //void ConfigFileIO::write_to_config_neutral_buoyancy_position_mm(float float_nbp_value, float float_nb_battpos_value) { |
tnhnrl | 17:7c16b5671d0e | 103 | // ConfigFile write_neutral_cfg; //write to the config file |
tnhnrl | 17:7c16b5671d0e | 104 | // |
tnhnrl | 17:7c16b5671d0e | 105 | // char nbp_buffer[50]; |
tnhnrl | 17:7c16b5671d0e | 106 | // sprintf(nbp_buffer, "%f", float_nbp_value); |
tnhnrl | 17:7c16b5671d0e | 107 | // |
tnhnrl | 17:7c16b5671d0e | 108 | // if (!write_neutral_cfg.setValue("neutral_buoyancy_engine_position_mm", nbp_buffer)) { |
tnhnrl | 17:7c16b5671d0e | 109 | // pc().printf("\nFailure to set a value!"); |
tnhnrl | 17:7c16b5671d0e | 110 | // ////////xbee().printf("\nFailure to set a value!"); |
tnhnrl | 17:7c16b5671d0e | 111 | // } |
tnhnrl | 17:7c16b5671d0e | 112 | // else { |
tnhnrl | 17:7c16b5671d0e | 113 | // pc().printf("\n*********** NET BUOYANCY (buoyancy engine position) CONFIG written!. *****************"); |
tnhnrl | 17:7c16b5671d0e | 114 | // ////xbee().printf("\n*********** NET BUOYANCY (buoyancy engine position) CONFIG written!. *****************"); |
tnhnrl | 17:7c16b5671d0e | 115 | // } |
tnhnrl | 17:7c16b5671d0e | 116 | // |
tnhnrl | 17:7c16b5671d0e | 117 | // char nb_battpos_value[50]; |
tnhnrl | 17:7c16b5671d0e | 118 | // sprintf(nb_battpos_value, "%f", float_nb_battpos_value); |
tnhnrl | 17:7c16b5671d0e | 119 | // |
tnhnrl | 17:7c16b5671d0e | 120 | // if (!write_neutral_cfg.setValue("neutral_buoyancy_battery_motor_position_mm", nb_battpos_value)) { |
tnhnrl | 17:7c16b5671d0e | 121 | // pc().printf("\nFailure to set a value!"); |
tnhnrl | 17:7c16b5671d0e | 122 | // ////xbee().printf("\nFailure to set a value!"); |
tnhnrl | 17:7c16b5671d0e | 123 | // } |
tnhnrl | 17:7c16b5671d0e | 124 | // else { |
tnhnrl | 17:7c16b5671d0e | 125 | // pc().printf("\n*********** NET BUOYANCY (batt motor position) CONFIG written!. *****************"); |
tnhnrl | 17:7c16b5671d0e | 126 | // ////xbee().printf("\n*********** NET BUOYANCY (batt motor position) CONFIG written!. *****************"); |
tnhnrl | 17:7c16b5671d0e | 127 | // } |
tnhnrl | 17:7c16b5671d0e | 128 | // |
tnhnrl | 17:7c16b5671d0e | 129 | // //SAVE THE DATA! |
tnhnrl | 17:7c16b5671d0e | 130 | // |
tnhnrl | 17:7c16b5671d0e | 131 | // pc().printf("$$$$$$$$$$$$$$ SAVING THE DATA NOW! $$$$$$$$$$$$$$"); |
tnhnrl | 17:7c16b5671d0e | 132 | // //xbee().printf("$$$$$$$$$$$$$$ SAVING THE DATA NOW! $$$$$$$$$$$$$$"); |
tnhnrl | 17:7c16b5671d0e | 133 | // |
tnhnrl | 17:7c16b5671d0e | 134 | // if (!write_neutral_cfg.write("/local/neutral.cfg")) { |
tnhnrl | 17:7c16b5671d0e | 135 | // pc().printf("\n\rERROR: (SAVE)Failure to write neutral.cfg file."); |
tnhnrl | 17:7c16b5671d0e | 136 | // ////xbee().printf("\n\rERROR: (SAVE)Failure to write neutral.cfg file."); |
tnhnrl | 17:7c16b5671d0e | 137 | // } |
tnhnrl | 17:7c16b5671d0e | 138 | // else { |
tnhnrl | 17:7c16b5671d0e | 139 | // pc().printf("\n\r(SAVE) Successful save."); |
tnhnrl | 17:7c16b5671d0e | 140 | // ////xbee().printf("\n\r(SAVE) Successful save."); |
tnhnrl | 17:7c16b5671d0e | 141 | // } |
tnhnrl | 17:7c16b5671d0e | 142 | //} |
tnhnrl | 17:7c16b5671d0e | 143 | // |
tnhnrl | 17:7c16b5671d0e | 144 | //void ConfigFileIO::load_neutral_config() { //reads neutral.cfg |
tnhnrl | 17:7c16b5671d0e | 145 | // ConfigFile read_neutral_cfg; //create this object (KEEP THIS LOCAL, do not mess with other config object) |
tnhnrl | 17:7c16b5671d0e | 146 | // |
tnhnrl | 17:7c16b5671d0e | 147 | // pc().printf("\n\rRead NEUTRAL Config File Function"); |
tnhnrl | 17:7c16b5671d0e | 148 | // //xbee().printf("\n\rRead NEUTRAL Config File Function"); |
tnhnrl | 17:7c16b5671d0e | 149 | // |
tnhnrl | 17:7c16b5671d0e | 150 | // char * string_neutral_buoyancy_engine_position_mm = "neutral_buoyancy_engine_position_mm"; |
tnhnrl | 17:7c16b5671d0e | 151 | // char * string_neutral_buoyancy_battery_motor_position_mm = "neutral_buoyancy_battery_motor_position_mm"; |
tnhnrl | 17:7c16b5671d0e | 152 | // char * startup_delay_config = "startup_delay_neutral"; //not using this 10/11/2017 |
tnhnrl | 17:7c16b5671d0e | 153 | // char * string_config_neutral_depth_ft = "neutral_dive_depth_ft"; |
tnhnrl | 17:7c16b5671d0e | 154 | // |
tnhnrl | 17:7c16b5671d0e | 155 | // char value[BUFSIZ]; //something like size 4096 |
tnhnrl | 17:7c16b5671d0e | 156 | // |
tnhnrl | 17:7c16b5671d0e | 157 | // float config_file_wait_setting_neutral; //you can set the delay in the config file! |
tnhnrl | 17:7c16b5671d0e | 158 | // |
tnhnrl | 17:7c16b5671d0e | 159 | // //read configuration file stored on MBED |
tnhnrl | 17:7c16b5671d0e | 160 | // if (!read_neutral_cfg.read("/local/neutral.cfg")) { |
tnhnrl | 17:7c16b5671d0e | 161 | // pc().printf("\n\rERROR:Failure to read neutral.cfg file."); |
tnhnrl | 17:7c16b5671d0e | 162 | // ////xbee().printf("\n\rERROR:Failure to read neutral.cfg file."); |
tnhnrl | 17:7c16b5671d0e | 163 | // } |
tnhnrl | 17:7c16b5671d0e | 164 | // |
tnhnrl | 17:7c16b5671d0e | 165 | // //READ THE VALUES FROM THE FILES |
tnhnrl | 17:7c16b5671d0e | 166 | // if (read_neutral_cfg.getValue(string_neutral_buoyancy_engine_position_mm, &value[0], sizeof(value))) { |
tnhnrl | 17:7c16b5671d0e | 167 | // pc().printf("\n\r%s = %s", string_neutral_buoyancy_engine_position_mm, value); |
tnhnrl | 17:7c16b5671d0e | 168 | // ////xbee().printf("\n\r%s = %s", string_neutral_buoyancy_engine_position_mm, value); |
tnhnrl | 17:7c16b5671d0e | 169 | // neutral_bce_position_mm = atof(value); //global for now |
tnhnrl | 17:7c16b5671d0e | 170 | // } |
tnhnrl | 17:7c16b5671d0e | 171 | // |
tnhnrl | 17:7c16b5671d0e | 172 | // if (read_neutral_cfg.getValue(string_neutral_buoyancy_battery_motor_position_mm, &value[0], sizeof(value))) { |
tnhnrl | 17:7c16b5671d0e | 173 | // pc().printf("\n\r%s = %s", string_neutral_buoyancy_battery_motor_position_mm, value); |
tnhnrl | 17:7c16b5671d0e | 174 | // ////xbee().printf("\n\r%s = %s", string_neutral_buoyancy_battery_motor_position_mm, value); |
tnhnrl | 17:7c16b5671d0e | 175 | // neutral_batt_position_mm = atof(value); //global for now |
tnhnrl | 17:7c16b5671d0e | 176 | // } |
tnhnrl | 17:7c16b5671d0e | 177 | // |
tnhnrl | 17:7c16b5671d0e | 178 | // if (read_neutral_cfg.getValue(string_config_neutral_depth_ft, &value[0], sizeof(value))) { |
tnhnrl | 17:7c16b5671d0e | 179 | // pc().printf("\n\r%s = %s", string_config_neutral_depth_ft, value); |
tnhnrl | 17:7c16b5671d0e | 180 | // ////xbee().printf("\n\r%s = %s", string_config_neutral_depth_ft, value); |
tnhnrl | 17:7c16b5671d0e | 181 | // neutral_depth_cmd = atof(value); //global for now |
tnhnrl | 17:7c16b5671d0e | 182 | // } |
tnhnrl | 17:7c16b5671d0e | 183 | // |
tnhnrl | 17:7c16b5671d0e | 184 | // if (read_neutral_cfg.getValue(startup_delay_config, &value[0], sizeof(value))) { |
tnhnrl | 17:7c16b5671d0e | 185 | // pc().printf("\n\r%s = %s", startup_delay_config, value); |
tnhnrl | 17:7c16b5671d0e | 186 | // ////xbee().printf("\n\r%s = %s", startup_delay_config, value); |
tnhnrl | 17:7c16b5671d0e | 187 | // config_file_wait_setting_neutral = atof(value); //global for now |
tnhnrl | 17:7c16b5671d0e | 188 | // } |
tnhnrl | 17:7c16b5671d0e | 189 | // |
tnhnrl | 17:7c16b5671d0e | 190 | // wait(config_file_wait_setting_neutral); //delay the rest of the program so user can check data |
tnhnrl | 17:7c16b5671d0e | 191 | //} |
tnhnrl | 17:7c16b5671d0e | 192 | // |
tnhnrl | 17:7c16b5671d0e | 193 | ////this depth is manually changed by the user |
tnhnrl | 17:7c16b5671d0e | 194 | ////write the neutral dive depth to the neutral.cfg or neutral config file |
tnhnrl | 17:7c16b5671d0e | 195 | ////not allowing modification of position FOR NOW 10/11/2017 |
tnhnrl | 17:7c16b5671d0e | 196 | //void ConfigFileIO::write_neutral_dive_depth_in_ft_to_config(float write_neutral_depth_ft) { |
tnhnrl | 17:7c16b5671d0e | 197 | // ConfigFile write_neutral_cfg; //write to the config file |
tnhnrl | 17:7c16b5671d0e | 198 | // |
tnhnrl | 17:7c16b5671d0e | 199 | // char buffer_depth_ft[50]; |
tnhnrl | 17:7c16b5671d0e | 200 | // sprintf(buffer_depth_ft, "%f", write_neutral_depth_ft); |
tnhnrl | 17:7c16b5671d0e | 201 | // |
tnhnrl | 17:7c16b5671d0e | 202 | // /* ***************** convert existing data ***************** */ |
tnhnrl | 17:7c16b5671d0e | 203 | // char buffer_buoyancy_position[50]; |
tnhnrl | 17:7c16b5671d0e | 204 | // sprintf(buffer_buoyancy_position, "%f", neutral_bce_position_mm); |
tnhnrl | 17:7c16b5671d0e | 205 | // |
tnhnrl | 17:7c16b5671d0e | 206 | // char buffer_battery_position[50]; |
tnhnrl | 17:7c16b5671d0e | 207 | // sprintf(buffer_battery_position, "%f", neutral_batt_position_mm); |
tnhnrl | 17:7c16b5671d0e | 208 | // /* ***************** convert existing data ***************** */ |
tnhnrl | 17:7c16b5671d0e | 209 | // |
tnhnrl | 17:7c16b5671d0e | 210 | // //write to the file (print error if it didn't work) |
tnhnrl | 17:7c16b5671d0e | 211 | // |
tnhnrl | 17:7c16b5671d0e | 212 | // if (!write_neutral_cfg.setValue("neutral_buoyancy_engine_position_mm", buffer_buoyancy_position)) { //writes Neutral_Buoyancy=4.0 //psi |
tnhnrl | 17:7c16b5671d0e | 213 | // pc().printf("\nFailure to set a value!"); |
tnhnrl | 17:7c16b5671d0e | 214 | // } |
tnhnrl | 17:7c16b5671d0e | 215 | // |
tnhnrl | 17:7c16b5671d0e | 216 | // if (!write_neutral_cfg.setValue("neutral_buoyancy_battery_motor_position_mm", buffer_battery_position)) { //writes Neutral_Buoyancy=4.0 //psi |
tnhnrl | 17:7c16b5671d0e | 217 | // pc().printf("\nFailure to set a value!"); |
tnhnrl | 17:7c16b5671d0e | 218 | // } |
tnhnrl | 17:7c16b5671d0e | 219 | // |
tnhnrl | 17:7c16b5671d0e | 220 | // if (!write_neutral_cfg.setValue("neutral_dive_depth_ft", buffer_depth_ft)) { //writes Neutral_Buoyancy=4.0 //psi |
tnhnrl | 17:7c16b5671d0e | 221 | // pc().printf("\nFailure to set a value!"); |
tnhnrl | 17:7c16b5671d0e | 222 | // } |
tnhnrl | 17:7c16b5671d0e | 223 | // |
tnhnrl | 17:7c16b5671d0e | 224 | // //SAVE THE DATA! |
tnhnrl | 17:7c16b5671d0e | 225 | // if (!write_neutral_cfg.write("/local/neutral.cfg")) |
tnhnrl | 17:7c16b5671d0e | 226 | // { |
tnhnrl | 17:7c16b5671d0e | 227 | // pc().printf("\nERROR: (SAVE) Failure to write neutral.cfg file."); |
tnhnrl | 17:7c16b5671d0e | 228 | // ////xbee().printf("\nERROR: (SAVE) Failure to write neutral.cfg file."); |
tnhnrl | 17:7c16b5671d0e | 229 | // } |
tnhnrl | 17:7c16b5671d0e | 230 | // else |
tnhnrl | 17:7c16b5671d0e | 231 | // { |
tnhnrl | 17:7c16b5671d0e | 232 | // pc().printf("\n(SAVE) Successful save."); |
tnhnrl | 17:7c16b5671d0e | 233 | // } |
tnhnrl | 17:7c16b5671d0e | 234 | //} |
tnhnrl | 17:7c16b5671d0e | 235 | // |
tnhnrl | 17:7c16b5671d0e | 236 | //// write_dive_cycle_config(max_dive_depth_in_feet,pitch_angle,net_buoyancy,dive_time_force); |
tnhnrl | 17:7c16b5671d0e | 237 | //void ConfigFileIO::write_dive_cycle_config(float depth_feet, float pitch_deg, float buoyancy, float dive_time) { |
tnhnrl | 17:7c16b5671d0e | 238 | // ConfigFile write_divecyc_cfg; //write to the config file |
tnhnrl | 17:7c16b5671d0e | 239 | // |
tnhnrl | 17:7c16b5671d0e | 240 | // char char_depth_feet[50]; |
tnhnrl | 17:7c16b5671d0e | 241 | // sprintf(char_depth_feet, "%f", depth_feet); |
tnhnrl | 17:7c16b5671d0e | 242 | // |
tnhnrl | 17:7c16b5671d0e | 243 | // char char_pitch_deg[50]; |
tnhnrl | 17:7c16b5671d0e | 244 | // sprintf(char_pitch_deg, "%f", pitch_deg); |
tnhnrl | 17:7c16b5671d0e | 245 | // |
tnhnrl | 17:7c16b5671d0e | 246 | // char char_buoyancy[50]; |
tnhnrl | 17:7c16b5671d0e | 247 | // sprintf(char_buoyancy, "%f", buoyancy); |
tnhnrl | 17:7c16b5671d0e | 248 | // |
tnhnrl | 17:7c16b5671d0e | 249 | // char char_dive_time[50]; |
tnhnrl | 17:7c16b5671d0e | 250 | // sprintf(char_dive_time, "%f", dive_time); |
tnhnrl | 17:7c16b5671d0e | 251 | // |
tnhnrl | 17:7c16b5671d0e | 252 | // float startup_delay = 0.1; |
tnhnrl | 17:7c16b5671d0e | 253 | // char char_startup_delay[50]; |
tnhnrl | 17:7c16b5671d0e | 254 | // sprintf(char_startup_delay, "%f", startup_delay); |
tnhnrl | 17:7c16b5671d0e | 255 | // |
tnhnrl | 17:7c16b5671d0e | 256 | // //write to the file (print error if it didn't work) |
tnhnrl | 17:7c16b5671d0e | 257 | // |
tnhnrl | 17:7c16b5671d0e | 258 | // if (!write_divecyc_cfg.setValue("dive_cycle_depth_cmd", char_depth_feet)) { //writes Neutral_Buoyancy=4.0 //psi |
tnhnrl | 17:7c16b5671d0e | 259 | // pc().printf("\nFailure to set dive_cycle_depth_cmd value!"); |
tnhnrl | 17:7c16b5671d0e | 260 | // } |
tnhnrl | 17:7c16b5671d0e | 261 | // |
tnhnrl | 17:7c16b5671d0e | 262 | // if (!write_divecyc_cfg.setValue("dive_cycle_pitch_cmd", char_pitch_deg)) { //writes Neutral_Buoyancy=4.0 //psi |
tnhnrl | 17:7c16b5671d0e | 263 | // pc().printf("\nFailure to set dive_cycle_pitch_cmd value!"); |
tnhnrl | 17:7c16b5671d0e | 264 | // } |
tnhnrl | 17:7c16b5671d0e | 265 | // |
tnhnrl | 17:7c16b5671d0e | 266 | // if (!write_divecyc_cfg.setValue("dive_cycle_net_buoyancy_cmd", char_buoyancy)) { //writes Neutral_Buoyancy=4.0 //psi |
tnhnrl | 17:7c16b5671d0e | 267 | // pc().printf("\nFailure to set dive_cycle_net_buoyancy_cmd value!"); |
tnhnrl | 17:7c16b5671d0e | 268 | // } |
tnhnrl | 17:7c16b5671d0e | 269 | // |
tnhnrl | 17:7c16b5671d0e | 270 | // if (!write_divecyc_cfg.setValue("emergency_surface_delay", char_dive_time)) { //writes Neutral_Buoyancy=4.0 //psi |
tnhnrl | 17:7c16b5671d0e | 271 | // pc().printf("\nFailure to set emergency_surface_delay value!"); |
tnhnrl | 17:7c16b5671d0e | 272 | // } |
tnhnrl | 17:7c16b5671d0e | 273 | // |
tnhnrl | 17:7c16b5671d0e | 274 | // if (!write_divecyc_cfg.setValue("startup_delay_dive", char_startup_delay)) { //writes Neutral_Buoyancy=4.0 //psi |
tnhnrl | 17:7c16b5671d0e | 275 | // pc().printf("\nFailure to set startup_delay_dive value!"); |
tnhnrl | 17:7c16b5671d0e | 276 | // } |
tnhnrl | 17:7c16b5671d0e | 277 | // |
tnhnrl | 17:7c16b5671d0e | 278 | // //SAVE THE DATA! |
tnhnrl | 17:7c16b5671d0e | 279 | // if (!write_divecyc_cfg.write("/local/neutral.cfg")) |
tnhnrl | 17:7c16b5671d0e | 280 | // { |
tnhnrl | 17:7c16b5671d0e | 281 | // pc().printf("\nERROR: (SAVE) Failure to write neutral.cfg file."); |
tnhnrl | 17:7c16b5671d0e | 282 | // ////xbee().printf("\nERROR: (SAVE) Failure to write neutral.cfg file."); |
tnhnrl | 17:7c16b5671d0e | 283 | // } |
tnhnrl | 17:7c16b5671d0e | 284 | // else |
tnhnrl | 17:7c16b5671d0e | 285 | // { |
tnhnrl | 17:7c16b5671d0e | 286 | // pc().printf("\n(SAVE) Successful save."); |
tnhnrl | 17:7c16b5671d0e | 287 | // } |
tnhnrl | 17:7c16b5671d0e | 288 | //} |
tnhnrl | 17:7c16b5671d0e | 289 | // |
tnhnrl | 17:7c16b5671d0e | 290 | //void ConfigFileIO::load_dive_cycle_config() { //reads divecyc.cfg |
tnhnrl | 17:7c16b5671d0e | 291 | // ConfigFile dive_cfg; //create this object (KEEP THIS LOCAL, do not mess with other config object) |
tnhnrl | 17:7c16b5671d0e | 292 | // |
tnhnrl | 17:7c16b5671d0e | 293 | // pc().printf("\n\rRead DIVE CYCLE Config File Function"); |
tnhnrl | 17:7c16b5671d0e | 294 | // //xbee().printf("\n\rRead DIVE CYCLE Config File Function"); |
tnhnrl | 17:7c16b5671d0e | 295 | // |
tnhnrl | 17:7c16b5671d0e | 296 | // char * string_max_depth_config_value = "dive_cycle_depth_cmd"; |
tnhnrl | 17:7c16b5671d0e | 297 | // char * string_dive_cycle_pitch_angle_config_value = "dive_cycle_pitch_cmd"; |
tnhnrl | 17:7c16b5671d0e | 298 | // char * string_dive_cycle_net_buoyancy_input_mL = "dive_cycle_net_buoyancy_cmd"; |
tnhnrl | 17:7c16b5671d0e | 299 | // char * startup_delay_config = "startup_delay_dive"; |
tnhnrl | 17:7c16b5671d0e | 300 | // |
tnhnrl | 17:7c16b5671d0e | 301 | // char value1[BUFSIZ]; //something like size 4096 |
tnhnrl | 17:7c16b5671d0e | 302 | // char value2[BUFSIZ]; //something like size 4096 |
tnhnrl | 17:7c16b5671d0e | 303 | // char value3[BUFSIZ]; //something like size 4096 |
tnhnrl | 17:7c16b5671d0e | 304 | // char value4[BUFSIZ]; //something like size 4096 |
tnhnrl | 17:7c16b5671d0e | 305 | // char value5[BUFSIZ]; //something like size 4096 |
tnhnrl | 17:7c16b5671d0e | 306 | // |
tnhnrl | 17:7c16b5671d0e | 307 | // float config_file_wait_setting_dive; //you can set the delay in the config file! |
tnhnrl | 17:7c16b5671d0e | 308 | // |
tnhnrl | 17:7c16b5671d0e | 309 | // //read configuration file stored on MBED |
tnhnrl | 17:7c16b5671d0e | 310 | // if (!dive_cfg.read("/local/divecyc.cfg")) { |
tnhnrl | 17:7c16b5671d0e | 311 | // pc().printf("\nERROR:Failure to read a configuration file."); |
tnhnrl | 17:7c16b5671d0e | 312 | // ////xbee().printf("\nERROR:Failure to read a configuration file."); |
tnhnrl | 17:7c16b5671d0e | 313 | // } |
tnhnrl | 17:7c16b5671d0e | 314 | // |
tnhnrl | 17:7c16b5671d0e | 315 | // //READ THE VALUES FROM THE FILES |
tnhnrl | 17:7c16b5671d0e | 316 | // if (dive_cfg.getValue(string_max_depth_config_value, &value1[0], sizeof(value1))) { |
tnhnrl | 17:7c16b5671d0e | 317 | // pc().printf("\n\r%s = %s", string_max_depth_config_value, value1); |
tnhnrl | 17:7c16b5671d0e | 318 | // ////xbee().printf("\n\r%s = %s", string_max_depth_config_value, value1); |
tnhnrl | 17:7c16b5671d0e | 319 | // dive_cycle_depth_cmd = atof(value1); |
tnhnrl | 17:7c16b5671d0e | 320 | // } |
tnhnrl | 17:7c16b5671d0e | 321 | // |
tnhnrl | 17:7c16b5671d0e | 322 | // if (dive_cfg.getValue(string_dive_cycle_pitch_angle_config_value, &value2[0], sizeof(value2))) { |
tnhnrl | 17:7c16b5671d0e | 323 | // pc().printf("\n\r%s = %s", string_dive_cycle_pitch_angle_config_value, value2); |
tnhnrl | 17:7c16b5671d0e | 324 | // ////xbee().printf("\n\r%s = %s", string_dive_cycle_pitch_angle_config_value, value2); |
tnhnrl | 17:7c16b5671d0e | 325 | // dive_cycle_pitch_cmd = atof(value2); |
tnhnrl | 17:7c16b5671d0e | 326 | // } |
tnhnrl | 17:7c16b5671d0e | 327 | // |
tnhnrl | 17:7c16b5671d0e | 328 | // if (dive_cfg.getValue(string_dive_cycle_net_buoyancy_input_mL, &value3[0], sizeof(value3))) { |
tnhnrl | 17:7c16b5671d0e | 329 | // pc().printf("\n\r%s = %s", string_dive_cycle_net_buoyancy_input_mL, value3); |
tnhnrl | 17:7c16b5671d0e | 330 | // ////xbee().printf("\n\r%s = %s", string_dive_cycle_net_buoyancy_input_mL, value3); |
tnhnrl | 17:7c16b5671d0e | 331 | // dive_cycle_net_buoyancy_cmd = atof(value3); |
tnhnrl | 17:7c16b5671d0e | 332 | // } |
tnhnrl | 17:7c16b5671d0e | 333 | //} |
tnhnrl | 17:7c16b5671d0e | 334 | // |
tnhnrl | 17:7c16b5671d0e | 335 | //void ConfigFileIO::load_initial_config_position() { //reads starting.cfg |
tnhnrl | 17:7c16b5671d0e | 336 | // ConfigFile starting_cfg; //create this object (KEEP THIS LOCAL, do not mess with other config object) |
tnhnrl | 17:7c16b5671d0e | 337 | // |
tnhnrl | 17:7c16b5671d0e | 338 | // pc().printf("\n\rRead Starting Config File Function"); |
tnhnrl | 17:7c16b5671d0e | 339 | // //xbee().printf("\n\rRead Starting Config File Function"); |
tnhnrl | 17:7c16b5671d0e | 340 | // |
tnhnrl | 17:7c16b5671d0e | 341 | // /* values that the motors go to when they start */ |
tnhnrl | 17:7c16b5671d0e | 342 | // char * positionCmd_config = "bce_setPoint"; |
tnhnrl | 17:7c16b5671d0e | 343 | // char * battery_positionCmd_config = "batt_setPoint"; |
tnhnrl | 17:7c16b5671d0e | 344 | // /* values that the motors go to when they start */ |
tnhnrl | 17:7c16b5671d0e | 345 | // |
tnhnrl | 17:7c16b5671d0e | 346 | // char * depth_setPoint_config = "depth_setPoint"; //pressure_PSI_setPoint |
tnhnrl | 17:7c16b5671d0e | 347 | // char * depth_controller_deadband_config = "depth_deadband"; |
tnhnrl | 17:7c16b5671d0e | 348 | // char * DIVE_DEPTH_config = "DIVE_DEPTH"; //config file has DIVE_DEPTH=0.0 |
tnhnrl | 17:7c16b5671d0e | 349 | // |
tnhnrl | 17:7c16b5671d0e | 350 | // char value[BUFSIZ]; //something like size 4096 |
tnhnrl | 17:7c16b5671d0e | 351 | // |
tnhnrl | 17:7c16b5671d0e | 352 | // //read configuration file stored on MBED |
tnhnrl | 17:7c16b5671d0e | 353 | // if (!starting_cfg.read("/local/starting.cfg")) { |
tnhnrl | 17:7c16b5671d0e | 354 | // pc().printf("\n\rERROR:Failure to read starting.cfg file."); |
tnhnrl | 17:7c16b5671d0e | 355 | // ////xbee().printf("\n\rERROR:Failure to read starting.cfg file."); |
tnhnrl | 17:7c16b5671d0e | 356 | // } |
tnhnrl | 17:7c16b5671d0e | 357 | // |
tnhnrl | 17:7c16b5671d0e | 358 | // //READ THE VALUES FROM THE FILES |
tnhnrl | 17:7c16b5671d0e | 359 | // if (starting_cfg.getValue(positionCmd_config, &value[0], sizeof(value))) { |
tnhnrl | 17:7c16b5671d0e | 360 | // pc().printf("%\n\rs=%s", positionCmd_config, value); |
tnhnrl | 17:7c16b5671d0e | 361 | // ////xbee().printf("\n\r%s = %s", positionCmd_config, value); |
tnhnrl | 17:7c16b5671d0e | 362 | // bce_setPoint = atof(value); |
tnhnrl | 17:7c16b5671d0e | 363 | // } |
tnhnrl | 17:7c16b5671d0e | 364 | // |
tnhnrl | 17:7c16b5671d0e | 365 | // if (starting_cfg.getValue(battery_positionCmd_config, &value[0], sizeof(value))) { |
tnhnrl | 17:7c16b5671d0e | 366 | // pc().printf("\n\r%s = %s", battery_positionCmd_config, value); |
tnhnrl | 17:7c16b5671d0e | 367 | // ////xbee().printf("\n\r%s = %s", battery_positionCmd_config, value); |
tnhnrl | 17:7c16b5671d0e | 368 | // batt_setPoint = atof(value); //THIS IS WHERE YOU SET THE STUFF IN THE STARTUP |
tnhnrl | 17:7c16b5671d0e | 369 | // } |
tnhnrl | 17:7c16b5671d0e | 370 | // |
tnhnrl | 17:7c16b5671d0e | 371 | // if (starting_cfg.getValue(depth_setPoint_config, &value[0], sizeof(value))) { |
tnhnrl | 17:7c16b5671d0e | 372 | // pc().printf("\n\r%s = %s", depth_setPoint_config, value); |
tnhnrl | 17:7c16b5671d0e | 373 | // ////xbee().printf("\n\r%s = %s", depth_setPoint_config, value); |
tnhnrl | 17:7c16b5671d0e | 374 | // depth_setPoint = atof(value); |
tnhnrl | 17:7c16b5671d0e | 375 | // } |
tnhnrl | 17:7c16b5671d0e | 376 | // |
tnhnrl | 17:7c16b5671d0e | 377 | // if (starting_cfg.getValue(depth_controller_deadband_config, &value[0], sizeof(value))) { |
tnhnrl | 17:7c16b5671d0e | 378 | // pc().printf("\n\r%s = %s", depth_controller_deadband_config, value); |
tnhnrl | 17:7c16b5671d0e | 379 | // ////xbee().printf("\n\r%s = %s", depth_controller_deadband_config, value); |
tnhnrl | 17:7c16b5671d0e | 380 | // depth_deadband = atof(value); |
tnhnrl | 17:7c16b5671d0e | 381 | // //this is not coverted to PSI, do that later |
tnhnrl | 17:7c16b5671d0e | 382 | // } |
tnhnrl | 17:7c16b5671d0e | 383 | // |
tnhnrl | 17:7c16b5671d0e | 384 | // if (starting_cfg.getValue(DIVE_DEPTH_config, &value[0], sizeof(value))) { |
tnhnrl | 17:7c16b5671d0e | 385 | // pc().printf("\n\r%s = %s", DIVE_DEPTH_config, value); |
tnhnrl | 17:7c16b5671d0e | 386 | // ////xbee().printf("\n\r%s = %s", DIVE_DEPTH_config, value); |
tnhnrl | 17:7c16b5671d0e | 387 | // dive_cycle_depth_cmd = atof(value); //write this from the config file |
tnhnrl | 17:7c16b5671d0e | 388 | // } |
tnhnrl | 17:7c16b5671d0e | 389 | // |
tnhnrl | 17:7c16b5671d0e | 390 | // //READ THE VALUES FROM THE FILES |
tnhnrl | 17:7c16b5671d0e | 391 | // pc().printf("\n\n\rReading from starting.cfg"); |
tnhnrl | 17:7c16b5671d0e | 392 | // pc().printf("\n\r(STARTING) Buoyancy_Engine_pos: %3.3f BATT_pos: %3.3f", bce_setPoint, batt_setPoint); |
tnhnrl | 17:7c16b5671d0e | 393 | // pc().printf("\n\r(STARTING) Pressure setPoint: %3.3f (deadband: %3.3f)(STARTING)", depth_setPoint, depth_deadband); |
tnhnrl | 17:7c16b5671d0e | 394 | // |
tnhnrl | 17:7c16b5671d0e | 395 | // //xbee().printf("\n\n\rReading from starting.cfg"); |
tnhnrl | 17:7c16b5671d0e | 396 | // //xbee().printf("\n\r(STARTING) Buoyancy_Engine_pos: %3.3f BATT_pos: %3.3f", bce_setPoint, batt_setPoint); |
tnhnrl | 17:7c16b5671d0e | 397 | // //xbee().printf("\n\r(STARTING) Pressure setPoint: %3.3f (deadband: %3.3f)(STARTING)", depth_setPoint, depth_deadband); |
tnhnrl | 17:7c16b5671d0e | 398 | //} |
tnhnrl | 17:7c16b5671d0e | 399 | // |
tnhnrl | 17:7c16b5671d0e | 400 | //void ConfigFileIO::load_auto_PID_gains_from_config_file() { |
tnhnrl | 17:7c16b5671d0e | 401 | // int gain_counter = 0; |
tnhnrl | 17:7c16b5671d0e | 402 | // |
tnhnrl | 17:7c16b5671d0e | 403 | // //PID.cfg |
tnhnrl | 17:7c16b5671d0e | 404 | // ConfigFile read_PID_cfg; //create this object (KEEP THIS LOCAL, do not mess with other config object) |
tnhnrl | 17:7c16b5671d0e | 405 | // |
tnhnrl | 17:7c16b5671d0e | 406 | // pc().printf("\n\n\rReading AUTO_PID.cfg File Function"); |
tnhnrl | 17:7c16b5671d0e | 407 | // //xbee().printf("\n\n\rReading AUTO_PID.cfg File Function"); |
tnhnrl | 17:7c16b5671d0e | 408 | // |
tnhnrl | 17:7c16b5671d0e | 409 | // char * string_BE_P_value = "depth_controller_P"; |
tnhnrl | 17:7c16b5671d0e | 410 | // char * string_BE_I_value = "depth_controller_I"; |
tnhnrl | 17:7c16b5671d0e | 411 | // char * string_BE_D_value = "depth_controller_D"; |
tnhnrl | 17:7c16b5671d0e | 412 | // |
tnhnrl | 17:7c16b5671d0e | 413 | // char * string_BATT_P_value = "pitch_controller_P"; |
tnhnrl | 17:7c16b5671d0e | 414 | // char * string_BATT_I_value = "pitch_controller_I"; |
tnhnrl | 17:7c16b5671d0e | 415 | // char * string_BATT_D_value = "pitch_controller_D"; |
tnhnrl | 17:7c16b5671d0e | 416 | // |
tnhnrl | 17:7c16b5671d0e | 417 | // char value[BUFSIZ]; //something like size 4096 |
tnhnrl | 17:7c16b5671d0e | 418 | // |
tnhnrl | 17:7c16b5671d0e | 419 | // float float_BE_P_value; |
tnhnrl | 17:7c16b5671d0e | 420 | // float float_BE_I_value; |
tnhnrl | 17:7c16b5671d0e | 421 | // float float_BE_D_value; |
tnhnrl | 17:7c16b5671d0e | 422 | // |
tnhnrl | 17:7c16b5671d0e | 423 | // float float_BATT_P_value; |
tnhnrl | 17:7c16b5671d0e | 424 | // float float_BATT_I_value; |
tnhnrl | 17:7c16b5671d0e | 425 | // float float_BATT_D_value; |
tnhnrl | 17:7c16b5671d0e | 426 | // |
tnhnrl | 17:7c16b5671d0e | 427 | // //read configuration file stored on MBED |
tnhnrl | 17:7c16b5671d0e | 428 | // if (!read_PID_cfg.read("/local/AUTO_PID.cfg")) |
tnhnrl | 17:7c16b5671d0e | 429 | // { |
tnhnrl | 17:7c16b5671d0e | 430 | // pc().printf("\n\rERROR: Failure to read AUTO_PID.cfg file."); |
tnhnrl | 17:7c16b5671d0e | 431 | // ////xbee().printf("\n\rERROR: Failure to read AUTO_PID.cfg file."); |
tnhnrl | 17:7c16b5671d0e | 432 | // gain_counter++; |
tnhnrl | 17:7c16b5671d0e | 433 | // } |
tnhnrl | 17:7c16b5671d0e | 434 | // |
tnhnrl | 17:7c16b5671d0e | 435 | // //READ THE VALUES FROM THE FILES |
tnhnrl | 17:7c16b5671d0e | 436 | // if (read_PID_cfg.getValue(string_BE_P_value, &value[0], sizeof(value))) |
tnhnrl | 17:7c16b5671d0e | 437 | // { |
tnhnrl | 17:7c16b5671d0e | 438 | // pc().printf("\n\r%s = %s", string_BE_P_value, value); |
tnhnrl | 17:7c16b5671d0e | 439 | // ////xbee().printf("\n\r%s = %s", string_BE_P_value, value); |
tnhnrl | 17:7c16b5671d0e | 440 | // float_BE_P_value = atof(value); |
tnhnrl | 17:7c16b5671d0e | 441 | // gain_counter++; |
tnhnrl | 17:7c16b5671d0e | 442 | // } |
tnhnrl | 17:7c16b5671d0e | 443 | // |
tnhnrl | 17:7c16b5671d0e | 444 | // if (read_PID_cfg.getValue(string_BE_I_value, &value[0], sizeof(value))) |
tnhnrl | 17:7c16b5671d0e | 445 | // { |
tnhnrl | 17:7c16b5671d0e | 446 | // pc().printf("\n\r%s = %s", string_BE_I_value, value); |
tnhnrl | 17:7c16b5671d0e | 447 | // ////xbee().printf("\n\r%s = %s", string_BE_I_value, value); |
tnhnrl | 17:7c16b5671d0e | 448 | // float_BE_I_value = atof(value); |
tnhnrl | 17:7c16b5671d0e | 449 | // gain_counter++; |
tnhnrl | 17:7c16b5671d0e | 450 | // } |
tnhnrl | 17:7c16b5671d0e | 451 | // |
tnhnrl | 17:7c16b5671d0e | 452 | // if (read_PID_cfg.getValue(string_BE_D_value, &value[0], sizeof(value))) |
tnhnrl | 17:7c16b5671d0e | 453 | // { |
tnhnrl | 17:7c16b5671d0e | 454 | // pc().printf("\n\r%s = %s", string_BE_D_value, value); |
tnhnrl | 17:7c16b5671d0e | 455 | // ////xbee().printf("\n\r%s = %s", string_BE_D_value, value); |
tnhnrl | 17:7c16b5671d0e | 456 | // float_BE_D_value = atof(value); |
tnhnrl | 17:7c16b5671d0e | 457 | // gain_counter++; |
tnhnrl | 17:7c16b5671d0e | 458 | // } |
tnhnrl | 17:7c16b5671d0e | 459 | // |
tnhnrl | 17:7c16b5671d0e | 460 | // if (read_PID_cfg.getValue(string_BATT_P_value, &value[0], sizeof(value))) |
tnhnrl | 17:7c16b5671d0e | 461 | // { |
tnhnrl | 17:7c16b5671d0e | 462 | // pc().printf("\n\r%s = %s", string_BATT_P_value, value); |
tnhnrl | 17:7c16b5671d0e | 463 | // ////xbee().printf("\n\r%s = %s", string_BATT_P_value, value); |
tnhnrl | 17:7c16b5671d0e | 464 | // float_BATT_P_value = atof(value); |
tnhnrl | 17:7c16b5671d0e | 465 | // gain_counter++; |
tnhnrl | 17:7c16b5671d0e | 466 | // } |
tnhnrl | 17:7c16b5671d0e | 467 | // |
tnhnrl | 17:7c16b5671d0e | 468 | // if (read_PID_cfg.getValue(string_BATT_I_value, &value[0], sizeof(value))) |
tnhnrl | 17:7c16b5671d0e | 469 | // { |
tnhnrl | 17:7c16b5671d0e | 470 | // pc().printf("\n\r%s = %s", string_BATT_I_value, value); |
tnhnrl | 17:7c16b5671d0e | 471 | // ////xbee().printf("\n\r%s = %s", string_BATT_I_value, value); |
tnhnrl | 17:7c16b5671d0e | 472 | // float_BATT_I_value = atof(value); |
tnhnrl | 17:7c16b5671d0e | 473 | // gain_counter++; |
tnhnrl | 17:7c16b5671d0e | 474 | // } |
tnhnrl | 17:7c16b5671d0e | 475 | // |
tnhnrl | 17:7c16b5671d0e | 476 | // if (read_PID_cfg.getValue(string_BATT_D_value, &value[0], sizeof(value))) |
tnhnrl | 17:7c16b5671d0e | 477 | // { |
tnhnrl | 17:7c16b5671d0e | 478 | // pc().printf("\n\r%s = %s", string_BATT_D_value, value); |
tnhnrl | 17:7c16b5671d0e | 479 | // ////xbee().printf("\n\r%s = %s", string_BATT_D_value, value); |
tnhnrl | 17:7c16b5671d0e | 480 | // float_BATT_D_value = atof(value); |
tnhnrl | 17:7c16b5671d0e | 481 | // gain_counter++; |
tnhnrl | 17:7c16b5671d0e | 482 | // } |
tnhnrl | 17:7c16b5671d0e | 483 | // |
tnhnrl | 17:7c16b5671d0e | 484 | // /* set these global parameters from the config file */ |
tnhnrl | 17:7c16b5671d0e | 485 | // depth_controller_P = float_BE_P_value; |
tnhnrl | 17:7c16b5671d0e | 486 | // depth_controller_I = float_BE_I_value; |
tnhnrl | 17:7c16b5671d0e | 487 | // depth_controller_D = float_BE_D_value; |
tnhnrl | 17:7c16b5671d0e | 488 | // |
tnhnrl | 17:7c16b5671d0e | 489 | // pitch_controller_P = float_BATT_P_value; |
tnhnrl | 17:7c16b5671d0e | 490 | // pitch_controller_I = float_BATT_I_value; |
tnhnrl | 17:7c16b5671d0e | 491 | // pitch_controller_D = float_BATT_D_value; |
tnhnrl | 17:7c16b5671d0e | 492 | // |
tnhnrl | 17:7c16b5671d0e | 493 | // if (gain_counter != 6) { |
tnhnrl | 17:7c16b5671d0e | 494 | // pc().printf("\b\rAUTO_PID gain settings have not been properly loaded!"); |
tnhnrl | 17:7c16b5671d0e | 495 | // ////xbee().printf("\n\rAUTO_PID gain settings have not been properly loaded!"); |
tnhnrl | 17:7c16b5671d0e | 496 | // wait(3); //test against watchdog... |
tnhnrl | 17:7c16b5671d0e | 497 | // } |
tnhnrl | 17:7c16b5671d0e | 498 | // |
tnhnrl | 17:7c16b5671d0e | 499 | // else { |
tnhnrl | 17:7c16b5671d0e | 500 | // pc().printf("\n\rAUTO_PID gain settings loaded."); |
tnhnrl | 17:7c16b5671d0e | 501 | // ////xbee().printf("\n\rAUTO_PID gain settings loaded."); |
tnhnrl | 17:7c16b5671d0e | 502 | // } |
tnhnrl | 17:7c16b5671d0e | 503 | //} |
tnhnrl | 17:7c16b5671d0e | 504 | // |
tnhnrl | 17:7c16b5671d0e | 505 | //// from "PID.cfg" |
tnhnrl | 17:7c16b5671d0e | 506 | //void ConfigFileIO::load_manual_position_PID_gains_from_config_file() { |
tnhnrl | 17:7c16b5671d0e | 507 | // int gain_counter = 0; |
tnhnrl | 17:7c16b5671d0e | 508 | // |
tnhnrl | 17:7c16b5671d0e | 509 | // //PID.cfg |
tnhnrl | 17:7c16b5671d0e | 510 | // ConfigFile read_PID_cfg; //create this object (KEEP THIS LOCAL, do not mess with other config object) |
tnhnrl | 17:7c16b5671d0e | 511 | // |
tnhnrl | 17:7c16b5671d0e | 512 | // pc().printf("\n\n\rReading MAN_PID.cfg File Function"); |
tnhnrl | 17:7c16b5671d0e | 513 | // //xbee().printf("\n\n\rReading MAN_PID.cfg File Function"); |
tnhnrl | 17:7c16b5671d0e | 514 | // |
tnhnrl | 17:7c16b5671d0e | 515 | // char * string_BE_P_value = "buoyancy_engine_P"; |
tnhnrl | 17:7c16b5671d0e | 516 | // char * string_BE_I_value = "buoyancy_engine_I"; |
tnhnrl | 17:7c16b5671d0e | 517 | // char * string_BE_D_value = "buoyancy_engine_D"; |
tnhnrl | 17:7c16b5671d0e | 518 | // |
tnhnrl | 17:7c16b5671d0e | 519 | // char * string_BATT_P_value = "battery_P"; |
tnhnrl | 17:7c16b5671d0e | 520 | // char * string_BATT_I_value = "battery_I"; |
tnhnrl | 17:7c16b5671d0e | 521 | // char * string_BATT_D_value = "battery_D"; |
tnhnrl | 17:7c16b5671d0e | 522 | // |
tnhnrl | 17:7c16b5671d0e | 523 | // char value[BUFSIZ]; //something like size 4096 |
tnhnrl | 17:7c16b5671d0e | 524 | // |
tnhnrl | 17:7c16b5671d0e | 525 | // float float_BE_P_value; |
tnhnrl | 17:7c16b5671d0e | 526 | // float float_BE_I_value; |
tnhnrl | 17:7c16b5671d0e | 527 | // float float_BE_D_value; |
tnhnrl | 17:7c16b5671d0e | 528 | // |
tnhnrl | 17:7c16b5671d0e | 529 | // float float_BATT_P_value; |
tnhnrl | 17:7c16b5671d0e | 530 | // float float_BATT_I_value; |
tnhnrl | 17:7c16b5671d0e | 531 | // float float_BATT_D_value; |
tnhnrl | 17:7c16b5671d0e | 532 | // |
tnhnrl | 17:7c16b5671d0e | 533 | // //read configuration file stored on MBED |
tnhnrl | 17:7c16b5671d0e | 534 | // if (!read_PID_cfg.read("/local/MAN_PID.cfg")) |
tnhnrl | 17:7c16b5671d0e | 535 | // { |
tnhnrl | 17:7c16b5671d0e | 536 | // pc().printf("\n\rERROR: Failure to read MAN_PID.cfg file."); |
tnhnrl | 17:7c16b5671d0e | 537 | // ////xbee().printf("\n\rERROR: Failure to read MAN_PID.cfg file."); |
tnhnrl | 17:7c16b5671d0e | 538 | // gain_counter++; |
tnhnrl | 17:7c16b5671d0e | 539 | // } |
tnhnrl | 17:7c16b5671d0e | 540 | // |
tnhnrl | 17:7c16b5671d0e | 541 | // //READ THE VALUES FROM THE FILES |
tnhnrl | 17:7c16b5671d0e | 542 | // if (read_PID_cfg.getValue(string_BE_P_value, &value[0], sizeof(value))) |
tnhnrl | 17:7c16b5671d0e | 543 | // { |
tnhnrl | 17:7c16b5671d0e | 544 | // pc().printf("\n\r%s = %s", string_BE_P_value, value); |
tnhnrl | 17:7c16b5671d0e | 545 | // ////xbee().printf("\n\r%s = %s", string_BE_P_value, value); |
tnhnrl | 17:7c16b5671d0e | 546 | // float_BE_P_value = atof(value); |
tnhnrl | 17:7c16b5671d0e | 547 | // gain_counter++; |
tnhnrl | 17:7c16b5671d0e | 548 | // } |
tnhnrl | 17:7c16b5671d0e | 549 | // |
tnhnrl | 17:7c16b5671d0e | 550 | // if (read_PID_cfg.getValue(string_BE_I_value, &value[0], sizeof(value))) |
tnhnrl | 17:7c16b5671d0e | 551 | // { |
tnhnrl | 17:7c16b5671d0e | 552 | // pc().printf("\n\r%s = %s", string_BE_I_value, value); |
tnhnrl | 17:7c16b5671d0e | 553 | // ////xbee().printf("\n\r%s = %s", string_BE_I_value, value); |
tnhnrl | 17:7c16b5671d0e | 554 | // float_BE_I_value = atof(value); |
tnhnrl | 17:7c16b5671d0e | 555 | // gain_counter++; |
tnhnrl | 17:7c16b5671d0e | 556 | // } |
tnhnrl | 17:7c16b5671d0e | 557 | // |
tnhnrl | 17:7c16b5671d0e | 558 | // if (read_PID_cfg.getValue(string_BE_D_value, &value[0], sizeof(value))) |
tnhnrl | 17:7c16b5671d0e | 559 | // { |
tnhnrl | 17:7c16b5671d0e | 560 | // pc().printf("\n\r%s = %s", string_BE_D_value, value); |
tnhnrl | 17:7c16b5671d0e | 561 | // ////xbee().printf("\n\r%s = %s", string_BE_D_value, value); |
tnhnrl | 17:7c16b5671d0e | 562 | // float_BE_D_value = atof(value); |
tnhnrl | 17:7c16b5671d0e | 563 | // gain_counter++; |
tnhnrl | 17:7c16b5671d0e | 564 | // } |
tnhnrl | 17:7c16b5671d0e | 565 | // |
tnhnrl | 17:7c16b5671d0e | 566 | // if (read_PID_cfg.getValue(string_BATT_P_value, &value[0], sizeof(value))) |
tnhnrl | 17:7c16b5671d0e | 567 | // { |
tnhnrl | 17:7c16b5671d0e | 568 | // pc().printf("\n\r%s = %s", string_BATT_P_value, value); |
tnhnrl | 17:7c16b5671d0e | 569 | // ////xbee().printf("\n\r%s = %s", string_BATT_P_value, value); |
tnhnrl | 17:7c16b5671d0e | 570 | // float_BATT_P_value = atof(value); |
tnhnrl | 17:7c16b5671d0e | 571 | // gain_counter++; |
tnhnrl | 17:7c16b5671d0e | 572 | // } |
tnhnrl | 17:7c16b5671d0e | 573 | // |
tnhnrl | 17:7c16b5671d0e | 574 | // if (read_PID_cfg.getValue(string_BATT_I_value, &value[0], sizeof(value))) |
tnhnrl | 17:7c16b5671d0e | 575 | // { |
tnhnrl | 17:7c16b5671d0e | 576 | // pc().printf("\n\r%s = %s", string_BATT_I_value, value); |
tnhnrl | 17:7c16b5671d0e | 577 | // ////xbee().printf("\n\r%s = %s", string_BATT_I_value, value); |
tnhnrl | 17:7c16b5671d0e | 578 | // float_BATT_I_value = atof(value); |
tnhnrl | 17:7c16b5671d0e | 579 | // gain_counter++; |
tnhnrl | 17:7c16b5671d0e | 580 | // } |
tnhnrl | 17:7c16b5671d0e | 581 | // |
tnhnrl | 17:7c16b5671d0e | 582 | // if (read_PID_cfg.getValue(string_BATT_D_value, &value[0], sizeof(value))) |
tnhnrl | 17:7c16b5671d0e | 583 | // { |
tnhnrl | 17:7c16b5671d0e | 584 | // pc().printf("\n\r%s = %s", string_BATT_D_value, value); |
tnhnrl | 17:7c16b5671d0e | 585 | // ////xbee().printf("\n\r%s = %s", string_BATT_D_value, value); |
tnhnrl | 17:7c16b5671d0e | 586 | // float_BATT_D_value = atof(value); |
tnhnrl | 17:7c16b5671d0e | 587 | // gain_counter++; |
tnhnrl | 17:7c16b5671d0e | 588 | // } |
tnhnrl | 17:7c16b5671d0e | 589 | // |
tnhnrl | 17:7c16b5671d0e | 590 | // /* set these global parameters from the config file */ |
tnhnrl | 17:7c16b5671d0e | 591 | // bce_position_P = float_BE_P_value; |
tnhnrl | 17:7c16b5671d0e | 592 | // bce_position_I = float_BE_I_value; |
tnhnrl | 17:7c16b5671d0e | 593 | // bce_position_D = float_BE_D_value; |
tnhnrl | 17:7c16b5671d0e | 594 | // |
tnhnrl | 17:7c16b5671d0e | 595 | // batt_position_P = float_BATT_P_value; |
tnhnrl | 17:7c16b5671d0e | 596 | // batt_position_I = float_BATT_I_value; |
tnhnrl | 17:7c16b5671d0e | 597 | // batt_position_D = float_BATT_D_value; |
tnhnrl | 17:7c16b5671d0e | 598 | // |
tnhnrl | 17:7c16b5671d0e | 599 | // if (gain_counter != 6) { |
tnhnrl | 17:7c16b5671d0e | 600 | // pc().printf("\b\rMAN_PID gain settings have not been properly loaded!"); |
tnhnrl | 17:7c16b5671d0e | 601 | // ////xbee().printf("\n\rMAN_PID gain settings have not been properly loaded!"); |
tnhnrl | 17:7c16b5671d0e | 602 | // wait(3); //test against watchdog... |
tnhnrl | 17:7c16b5671d0e | 603 | // } |
tnhnrl | 17:7c16b5671d0e | 604 | // |
tnhnrl | 17:7c16b5671d0e | 605 | // else { |
tnhnrl | 17:7c16b5671d0e | 606 | // pc().printf("\n\rMAN_PID gain settings loaded."); |
tnhnrl | 17:7c16b5671d0e | 607 | // ////xbee().printf("\n\rMAN_PID gain settings loaded."); |
tnhnrl | 17:7c16b5671d0e | 608 | // } |
tnhnrl | 17:7c16b5671d0e | 609 | //} |
tnhnrl | 17:7c16b5671d0e | 610 | // |
tnhnrl | 17:7c16b5671d0e | 611 | // |
tnhnrl | 17:7c16b5671d0e | 612 | ////write only the automated PID control gains |
tnhnrl | 17:7c16b5671d0e | 613 | //void ConfigFileIO::write_manual_position_PID_values_to_config(float battP, float battI, float battD, float beP, float beI, float beD) { |
tnhnrl | 17:7c16b5671d0e | 614 | // ConfigFile write_PID_cfg; //write to pid.cfg file |
tnhnrl | 17:7c16b5671d0e | 615 | // |
tnhnrl | 17:7c16b5671d0e | 616 | // pc().printf("\n\rCONFIG FILE IO write_manual_position_PID_values_to_config\n"); |
tnhnrl | 17:7c16b5671d0e | 617 | // |
tnhnrl | 17:7c16b5671d0e | 618 | // char char_battP[50]; |
tnhnrl | 17:7c16b5671d0e | 619 | // sprintf(char_battP, "%0.5f", battP); |
tnhnrl | 17:7c16b5671d0e | 620 | // char char_battI[50]; |
tnhnrl | 17:7c16b5671d0e | 621 | // sprintf(char_battI, "%0.5f", battI); |
tnhnrl | 17:7c16b5671d0e | 622 | // char char_battD[50]; |
tnhnrl | 17:7c16b5671d0e | 623 | // sprintf(char_battD, "%0.5f", battD); |
tnhnrl | 17:7c16b5671d0e | 624 | // |
tnhnrl | 17:7c16b5671d0e | 625 | // char char_beP[50]; |
tnhnrl | 17:7c16b5671d0e | 626 | // sprintf(char_beP, "%0.5f", beP); |
tnhnrl | 17:7c16b5671d0e | 627 | // char char_beI[50]; |
tnhnrl | 17:7c16b5671d0e | 628 | // sprintf(char_beI, "%0.5f", beI); |
tnhnrl | 17:7c16b5671d0e | 629 | // char char_beD[50]; |
tnhnrl | 17:7c16b5671d0e | 630 | // sprintf(char_beD, "%0.5f", beD); |
tnhnrl | 17:7c16b5671d0e | 631 | // |
tnhnrl | 17:7c16b5671d0e | 632 | // if (!write_PID_cfg.setValue("buoyancy_engine_P", char_beP)) |
tnhnrl | 17:7c16b5671d0e | 633 | // { |
tnhnrl | 17:7c16b5671d0e | 634 | // pc().printf("\nFailure to set buoyancy_engine_P value!"); |
tnhnrl | 17:7c16b5671d0e | 635 | // } |
tnhnrl | 17:7c16b5671d0e | 636 | // |
tnhnrl | 17:7c16b5671d0e | 637 | // if (!write_PID_cfg.setValue("buoyancy_engine_I", char_beI)) |
tnhnrl | 17:7c16b5671d0e | 638 | // { |
tnhnrl | 17:7c16b5671d0e | 639 | // pc().printf("\nFailure to set buoyancy_engine_I value!"); |
tnhnrl | 17:7c16b5671d0e | 640 | // } |
tnhnrl | 17:7c16b5671d0e | 641 | // |
tnhnrl | 17:7c16b5671d0e | 642 | // if (!write_PID_cfg.setValue("buoyancy_engine_D", char_beD)) |
tnhnrl | 17:7c16b5671d0e | 643 | // { |
tnhnrl | 17:7c16b5671d0e | 644 | // pc().printf("\nFailure to set buoyancy_engine_D value!"); |
tnhnrl | 17:7c16b5671d0e | 645 | // } |
tnhnrl | 17:7c16b5671d0e | 646 | // |
tnhnrl | 17:7c16b5671d0e | 647 | // if (!write_PID_cfg.setValue("battery_P", char_battP)) |
tnhnrl | 17:7c16b5671d0e | 648 | // { |
tnhnrl | 17:7c16b5671d0e | 649 | // pc().printf("\nFailure to set battery_P value!"); |
tnhnrl | 17:7c16b5671d0e | 650 | // } |
tnhnrl | 17:7c16b5671d0e | 651 | // |
tnhnrl | 17:7c16b5671d0e | 652 | // if (!write_PID_cfg.setValue("battery_I", char_battI)) |
tnhnrl | 17:7c16b5671d0e | 653 | // { |
tnhnrl | 17:7c16b5671d0e | 654 | // pc().printf("\nFailure to set battery_I value!"); |
tnhnrl | 17:7c16b5671d0e | 655 | // } |
tnhnrl | 17:7c16b5671d0e | 656 | // |
tnhnrl | 17:7c16b5671d0e | 657 | // if (!write_PID_cfg.setValue("battery_D", char_battD)) |
tnhnrl | 17:7c16b5671d0e | 658 | // { |
tnhnrl | 17:7c16b5671d0e | 659 | // pc().printf("\nFailure to set battery_D value!"); |
tnhnrl | 17:7c16b5671d0e | 660 | // } |
tnhnrl | 17:7c16b5671d0e | 661 | // |
tnhnrl | 17:7c16b5671d0e | 662 | // /* ************** SAVE TO PID.cfg ************** */ |
tnhnrl | 17:7c16b5671d0e | 663 | // if (!write_PID_cfg.write("/local/MAN_PID.cfg")) { |
tnhnrl | 17:7c16b5671d0e | 664 | // pc().printf("\nERROR: (SAVE) Failure to write MAN_PID.cfg file."); |
tnhnrl | 17:7c16b5671d0e | 665 | // ////xbee().printf("\nERROR: (SAVE) Failure to write MAN_PID.cfg file."); |
tnhnrl | 17:7c16b5671d0e | 666 | // } |
tnhnrl | 17:7c16b5671d0e | 667 | // |
tnhnrl | 17:7c16b5671d0e | 668 | // else { |
tnhnrl | 17:7c16b5671d0e | 669 | // pc().printf("\nMAN_PID.cfg save successful."); |
tnhnrl | 17:7c16b5671d0e | 670 | // ////xbee().printf("\nMAN_PID.cfg save successful."); |
tnhnrl | 17:7c16b5671d0e | 671 | // } |
tnhnrl | 17:7c16b5671d0e | 672 | // /* ************** SAVE TO PID.cfg ************** */ |
tnhnrl | 17:7c16b5671d0e | 673 | //} |
tnhnrl | 17:7c16b5671d0e | 674 | // |
tnhnrl | 17:7c16b5671d0e | 675 | //void ConfigFileIO::write_auto_PID_values_to_config(float battP, float battI, float battD, float beP, float beI, float beD) { |
tnhnrl | 17:7c16b5671d0e | 676 | // ConfigFile write_PID_cfg; //write to pid.cfg file |
tnhnrl | 17:7c16b5671d0e | 677 | // |
tnhnrl | 17:7c16b5671d0e | 678 | // pc().printf("\n\rCONFIG FILE IO write_auto_PID_values_to_config\n"); |
tnhnrl | 17:7c16b5671d0e | 679 | // |
tnhnrl | 17:7c16b5671d0e | 680 | // char char_battP[50]; |
tnhnrl | 17:7c16b5671d0e | 681 | // sprintf(char_battP, "%0.5f", battP); |
tnhnrl | 17:7c16b5671d0e | 682 | // char char_battI[50]; |
tnhnrl | 17:7c16b5671d0e | 683 | // sprintf(char_battI, "%0.5f", battI); |
tnhnrl | 17:7c16b5671d0e | 684 | // char char_battD[50]; |
tnhnrl | 17:7c16b5671d0e | 685 | // sprintf(char_battD, "%0.5f", battD); |
tnhnrl | 17:7c16b5671d0e | 686 | // |
tnhnrl | 17:7c16b5671d0e | 687 | // char char_beP[50]; |
tnhnrl | 17:7c16b5671d0e | 688 | // sprintf(char_beP, "%0.5f", beP); |
tnhnrl | 17:7c16b5671d0e | 689 | // char char_beI[50]; |
tnhnrl | 17:7c16b5671d0e | 690 | // sprintf(char_beI, "%0.5f", beI); |
tnhnrl | 17:7c16b5671d0e | 691 | // char char_beD[50]; |
tnhnrl | 17:7c16b5671d0e | 692 | // sprintf(char_beD, "%0.5f", beD); |
tnhnrl | 17:7c16b5671d0e | 693 | // |
tnhnrl | 17:7c16b5671d0e | 694 | // if (!write_PID_cfg.setValue("depth_controller_P", char_beP)) |
tnhnrl | 17:7c16b5671d0e | 695 | // { |
tnhnrl | 17:7c16b5671d0e | 696 | // pc().printf("\nFailure to set depth_controller_P value!"); |
tnhnrl | 17:7c16b5671d0e | 697 | // } |
tnhnrl | 17:7c16b5671d0e | 698 | // |
tnhnrl | 17:7c16b5671d0e | 699 | // if (!write_PID_cfg.setValue("depth_controller_I", char_beI)) |
tnhnrl | 17:7c16b5671d0e | 700 | // { |
tnhnrl | 17:7c16b5671d0e | 701 | // pc().printf("\nFailure to set depth_controller_I value!"); |
tnhnrl | 17:7c16b5671d0e | 702 | // } |
tnhnrl | 17:7c16b5671d0e | 703 | // |
tnhnrl | 17:7c16b5671d0e | 704 | // if (!write_PID_cfg.setValue("depth_controller_D", char_beD)) |
tnhnrl | 17:7c16b5671d0e | 705 | // { |
tnhnrl | 17:7c16b5671d0e | 706 | // pc().printf("\nFailure to set depth_controller_D value!"); |
tnhnrl | 17:7c16b5671d0e | 707 | // } |
tnhnrl | 17:7c16b5671d0e | 708 | // |
tnhnrl | 17:7c16b5671d0e | 709 | // if (!write_PID_cfg.setValue("pitch_controller_P", char_battP)) |
tnhnrl | 17:7c16b5671d0e | 710 | // { |
tnhnrl | 17:7c16b5671d0e | 711 | // pc().printf("\nFailure to set pitch_controller_P value!"); |
tnhnrl | 17:7c16b5671d0e | 712 | // } |
tnhnrl | 17:7c16b5671d0e | 713 | // |
tnhnrl | 17:7c16b5671d0e | 714 | // if (!write_PID_cfg.setValue("pitch_controller_I", char_battI)) |
tnhnrl | 17:7c16b5671d0e | 715 | // { |
tnhnrl | 17:7c16b5671d0e | 716 | // pc().printf("\nFailure to set pitch_controller_I value!"); |
tnhnrl | 17:7c16b5671d0e | 717 | // } |
tnhnrl | 17:7c16b5671d0e | 718 | // |
tnhnrl | 17:7c16b5671d0e | 719 | // if (!write_PID_cfg.setValue("pitch_controller_D", char_battD)) |
tnhnrl | 17:7c16b5671d0e | 720 | // { |
tnhnrl | 17:7c16b5671d0e | 721 | // pc().printf("\nFailure to set pitch_controller_D value!"); |
tnhnrl | 17:7c16b5671d0e | 722 | // } |
tnhnrl | 17:7c16b5671d0e | 723 | // |
tnhnrl | 17:7c16b5671d0e | 724 | // /* ************** SAVE TO PID.cfg ************** */ |
tnhnrl | 17:7c16b5671d0e | 725 | // if (!write_PID_cfg.write("/local/AUTO_PID.cfg")) { |
tnhnrl | 17:7c16b5671d0e | 726 | // pc().printf("\n\rERROR: (SAVE) Failure to write AUTO_PID.cfg file."); |
tnhnrl | 17:7c16b5671d0e | 727 | // ////xbee().printf("\n\rERROR: (SAVE) Failure to write AUTO_PID.cfg file."); |
tnhnrl | 17:7c16b5671d0e | 728 | // } |
tnhnrl | 17:7c16b5671d0e | 729 | // |
tnhnrl | 17:7c16b5671d0e | 730 | // else { |
tnhnrl | 17:7c16b5671d0e | 731 | // pc().printf("\n\rAUTO_PID.cfg save successful."); |
tnhnrl | 17:7c16b5671d0e | 732 | // ////xbee().printf("\n\rAUTO_PID.cfg save successful."); |
tnhnrl | 17:7c16b5671d0e | 733 | // } |
tnhnrl | 17:7c16b5671d0e | 734 | // /* ************** SAVE TO PID.cfg ************** */ |
tnhnrl | 17:7c16b5671d0e | 735 | //} |
tnhnrl | 17:7c16b5671d0e | 736 | // |
tnhnrl | 17:7c16b5671d0e | 737 | //void ConfigFileIO::write_timers_to_config_file(float force, float neutral, float dive) { |
tnhnrl | 17:7c16b5671d0e | 738 | // //timers.cfg file |
tnhnrl | 17:7c16b5671d0e | 739 | // ConfigFile write_TIMERS_cfg; //create this object (KEEP THIS LOCAL, do not mess with other config object) |
tnhnrl | 17:7c16b5671d0e | 740 | // |
tnhnrl | 17:7c16b5671d0e | 741 | // char char_force[50]; |
tnhnrl | 17:7c16b5671d0e | 742 | // sprintf(char_force, "%0.5f", force); //convert the float values into char values |
tnhnrl | 17:7c16b5671d0e | 743 | // |
tnhnrl | 17:7c16b5671d0e | 744 | // char char_neutral[50]; |
tnhnrl | 17:7c16b5671d0e | 745 | // sprintf(char_neutral, "%0.5f", neutral); //convert the float values into char values |
tnhnrl | 17:7c16b5671d0e | 746 | // |
tnhnrl | 17:7c16b5671d0e | 747 | // char char_dive[50]; |
tnhnrl | 17:7c16b5671d0e | 748 | // sprintf(char_dive, "%0.5f", dive); //convert the float values into char values |
tnhnrl | 17:7c16b5671d0e | 749 | // |
tnhnrl | 17:7c16b5671d0e | 750 | // if (!write_TIMERS_cfg.setValue("timed_emergency_surface_seconds", char_force)) |
tnhnrl | 17:7c16b5671d0e | 751 | // { |
tnhnrl | 17:7c16b5671d0e | 752 | // pc().printf("\n\rFailure to set timed_emergency_surface_seconds value!"); |
tnhnrl | 17:7c16b5671d0e | 753 | // ////xbee().printf("\n\rFailure to set timed_emergency_surface_seconds value!"); |
tnhnrl | 17:7c16b5671d0e | 754 | // } |
tnhnrl | 17:7c16b5671d0e | 755 | // |
tnhnrl | 17:7c16b5671d0e | 756 | // if (!write_TIMERS_cfg.setValue("timed_neutral_emergency_surface_seconds", char_neutral)) |
tnhnrl | 17:7c16b5671d0e | 757 | // { |
tnhnrl | 17:7c16b5671d0e | 758 | // pc().printf("\n\rFailure to set timed_neutral_emergency_surface_seconds value!"); |
tnhnrl | 17:7c16b5671d0e | 759 | // ////xbee().printf("\n\rFailure to set timed_neutral_emergency_surface_seconds value!"); |
tnhnrl | 17:7c16b5671d0e | 760 | // } |
tnhnrl | 17:7c16b5671d0e | 761 | // |
tnhnrl | 17:7c16b5671d0e | 762 | // if (!write_TIMERS_cfg.setValue("timed_dive_emergency_surface_seconds", char_dive)) |
tnhnrl | 17:7c16b5671d0e | 763 | // { |
tnhnrl | 17:7c16b5671d0e | 764 | // pc().printf("\n\rFailure to set timed_dive_emergency_surface_seconds value!"); |
tnhnrl | 17:7c16b5671d0e | 765 | // ////xbee().printf("\n\rFailure to set timed_dive_emergency_surface_seconds value!"); |
tnhnrl | 17:7c16b5671d0e | 766 | // } |
tnhnrl | 17:7c16b5671d0e | 767 | // |
tnhnrl | 17:7c16b5671d0e | 768 | // /* ************** SAVE TO timers.cfg ************** */ |
tnhnrl | 17:7c16b5671d0e | 769 | // if (!write_TIMERS_cfg.write("/local/timers.cfg")) { |
tnhnrl | 17:7c16b5671d0e | 770 | // pc().printf("\n\rERROR: (SAVE) Failure to write timers.cfg file."); |
tnhnrl | 17:7c16b5671d0e | 771 | // ////xbee().printf("\n\rERROR: (SAVE) Failure to write timers.cfg file."); |
tnhnrl | 17:7c16b5671d0e | 772 | // wait(3); //debugging |
tnhnrl | 17:7c16b5671d0e | 773 | // } |
tnhnrl | 17:7c16b5671d0e | 774 | // |
tnhnrl | 17:7c16b5671d0e | 775 | // else { |
tnhnrl | 17:7c16b5671d0e | 776 | // pc().printf("\n\rtimers.cfg save successful."); |
tnhnrl | 17:7c16b5671d0e | 777 | // ////xbee().printf("\n\rtimers.cfg save successful."); |
tnhnrl | 17:7c16b5671d0e | 778 | // } |
tnhnrl | 17:7c16b5671d0e | 779 | // /* ************** SAVE TO timers.cfg ************** */ |
tnhnrl | 17:7c16b5671d0e | 780 | //} |
tnhnrl | 17:7c16b5671d0e | 781 | // |
tnhnrl | 17:7c16b5671d0e | 782 | //void ConfigFileIO::load_timers_from_config_file() { |
tnhnrl | 17:7c16b5671d0e | 783 | // //timers.cfg file |
tnhnrl | 17:7c16b5671d0e | 784 | // ConfigFile read_TIMERS_cfg; //create this object (KEEP THIS LOCAL, do not mess with other config object) |
tnhnrl | 17:7c16b5671d0e | 785 | // |
tnhnrl | 17:7c16b5671d0e | 786 | // pc().printf("\n\n\rReading timers.cfg file"); |
tnhnrl | 17:7c16b5671d0e | 787 | // //xbee().printf("\n\n\rReading timers.cfg file"); |
tnhnrl | 17:7c16b5671d0e | 788 | // |
tnhnrl | 17:7c16b5671d0e | 789 | // char * timed_emergency_surface_seconds_config = "timed_emergency_surface_seconds"; |
tnhnrl | 17:7c16b5671d0e | 790 | // char * timed_neutral_emergency_surface_config = "timed_neutral_emergency_surface_seconds"; |
tnhnrl | 17:7c16b5671d0e | 791 | // char * timed_dive_emergency_surface_config = "timed_dive_emergency_surface_seconds"; |
tnhnrl | 17:7c16b5671d0e | 792 | // |
tnhnrl | 17:7c16b5671d0e | 793 | // char value[BUFSIZ]; //set a buffer value, 4096 |
tnhnrl | 17:7c16b5671d0e | 794 | // |
tnhnrl | 17:7c16b5671d0e | 795 | // //read configuration file stored on MBED |
tnhnrl | 17:7c16b5671d0e | 796 | // if (!read_TIMERS_cfg.read("/local/timers.cfg")) |
tnhnrl | 17:7c16b5671d0e | 797 | // { |
tnhnrl | 17:7c16b5671d0e | 798 | // pc().printf("\n\rERROR: Failure to read timers.cfg file."); |
tnhnrl | 17:7c16b5671d0e | 799 | // ////xbee().printf("\n\rERROR: Failure to read timers.cfg file."); |
tnhnrl | 17:7c16b5671d0e | 800 | // } |
tnhnrl | 17:7c16b5671d0e | 801 | // else { |
tnhnrl | 17:7c16b5671d0e | 802 | // pc().printf("\n\rTimers.cfg loaded!"); |
tnhnrl | 17:7c16b5671d0e | 803 | // ////xbee().printf("\n\rTimers.cfg loaded!"); |
tnhnrl | 17:7c16b5671d0e | 804 | // } |
tnhnrl | 17:7c16b5671d0e | 805 | // |
tnhnrl | 17:7c16b5671d0e | 806 | // int timers_counter = 0; |
tnhnrl | 17:7c16b5671d0e | 807 | // |
tnhnrl | 17:7c16b5671d0e | 808 | // if (read_TIMERS_cfg.getValue(timed_emergency_surface_seconds_config, &value[0], sizeof(value))) |
tnhnrl | 17:7c16b5671d0e | 809 | // { |
tnhnrl | 17:7c16b5671d0e | 810 | // pc().printf("\n\r%s=%s", timed_emergency_surface_seconds_config, value); |
tnhnrl | 17:7c16b5671d0e | 811 | // ////xbee().printf("\n\r%s=%s", timed_emergency_surface_seconds_config, value); |
tnhnrl | 17:7c16b5671d0e | 812 | // emergency_timeout = atof(value); //write this from the config file |
tnhnrl | 17:7c16b5671d0e | 813 | // timers_counter++; |
tnhnrl | 17:7c16b5671d0e | 814 | // } |
tnhnrl | 17:7c16b5671d0e | 815 | // |
tnhnrl | 17:7c16b5671d0e | 816 | // if (read_TIMERS_cfg.getValue(timed_neutral_emergency_surface_config, &value[0], sizeof(value))) |
tnhnrl | 17:7c16b5671d0e | 817 | // { |
tnhnrl | 17:7c16b5671d0e | 818 | // pc().printf("\n\r%s = %s", timed_neutral_emergency_surface_config, value); |
tnhnrl | 17:7c16b5671d0e | 819 | // ////xbee().printf("\n\r%s = %s", timed_neutral_emergency_surface_config, value); |
tnhnrl | 17:7c16b5671d0e | 820 | // neutral_timeout = atof(value); //write this from the config file |
tnhnrl | 17:7c16b5671d0e | 821 | // timers_counter++; |
tnhnrl | 17:7c16b5671d0e | 822 | // } |
tnhnrl | 17:7c16b5671d0e | 823 | // |
tnhnrl | 17:7c16b5671d0e | 824 | // if (read_TIMERS_cfg.getValue(timed_dive_emergency_surface_config, &value[0], sizeof(value))) |
tnhnrl | 17:7c16b5671d0e | 825 | // { |
tnhnrl | 17:7c16b5671d0e | 826 | // pc().printf("\n\r%s = %s", timed_dive_emergency_surface_config, value); |
tnhnrl | 17:7c16b5671d0e | 827 | // ////xbee().printf("\n\r%s = %s", timed_dive_emergency_surface_config, value); |
tnhnrl | 17:7c16b5671d0e | 828 | // dive_cycle_timeout = atof(value); //write this from the config file |
tnhnrl | 17:7c16b5671d0e | 829 | // timers_counter++; |
tnhnrl | 17:7c16b5671d0e | 830 | // } |
tnhnrl | 17:7c16b5671d0e | 831 | // |
tnhnrl | 17:7c16b5671d0e | 832 | // if (timers_counter == 3) { |
tnhnrl | 17:7c16b5671d0e | 833 | // pc().printf("\n\rAll timers loaded successfully!"); |
tnhnrl | 17:7c16b5671d0e | 834 | // ////xbee().printf("\n\rAll timers loaded successfully!"); |
tnhnrl | 17:7c16b5671d0e | 835 | // } |
tnhnrl | 17:7c16b5671d0e | 836 | // else { |
tnhnrl | 17:7c16b5671d0e | 837 | // pc().printf("\n\rTIMERS NOT LOADED!"); |
tnhnrl | 17:7c16b5671d0e | 838 | // ////xbee().printf("\n\rTIMERS NOT LOADED!"); |
tnhnrl | 17:7c16b5671d0e | 839 | // } |
tnhnrl | 17:7c16b5671d0e | 840 | //} |
tnhnrl | 17:7c16b5671d0e | 841 | // |
tnhnrl | 17:7c16b5671d0e | 842 | // |
tnhnrl | 17:7c16b5671d0e | 843 | //void ConfigFileIO::read_config_file() |
tnhnrl | 17:7c16b5671d0e | 844 | //{ |
tnhnrl | 17:7c16b5671d0e | 845 | // ConfigFile read_cfg; //create this object (KEEP THIS LOCAL, do not mess with other config object) |
tnhnrl | 17:7c16b5671d0e | 846 | // |
tnhnrl | 17:7c16b5671d0e | 847 | // pc().printf("\n\rRead input.cfg File"); |
tnhnrl | 17:7c16b5671d0e | 848 | // //xbee().printf("\n\rRead input.cfg File"); |
tnhnrl | 17:7c16b5671d0e | 849 | // |
tnhnrl | 17:7c16b5671d0e | 850 | // //Ignore comments in a configuration file. |
tnhnrl | 17:7c16b5671d0e | 851 | // //Ignore empty lines in a configuration file. |
tnhnrl | 17:7c16b5671d0e | 852 | // //Keep spaces in side of keys and values. |
tnhnrl | 17:7c16b5671d0e | 853 | // |
tnhnrl | 17:7c16b5671d0e | 854 | // char * key1 = "depth_config"; |
tnhnrl | 17:7c16b5671d0e | 855 | // char * key2 = "pitch_angle_config"; |
tnhnrl | 17:7c16b5671d0e | 856 | // char * key3 = "net_buoyancy_config"; |
tnhnrl | 17:7c16b5671d0e | 857 | //// char * key4 = "MyKey"; |
tnhnrl | 17:7c16b5671d0e | 858 | // |
tnhnrl | 17:7c16b5671d0e | 859 | // char value[BUFSIZ]; //something like size 4096 |
tnhnrl | 17:7c16b5671d0e | 860 | // |
tnhnrl | 17:7c16b5671d0e | 861 | // //read configuration file stored on MBED |
tnhnrl | 17:7c16b5671d0e | 862 | // if (!read_cfg.read("/local/input.cfg")) |
tnhnrl | 17:7c16b5671d0e | 863 | // { |
tnhnrl | 17:7c16b5671d0e | 864 | // pc().printf("\nERROR:Failure to read input.cfg configuration file."); |
tnhnrl | 17:7c16b5671d0e | 865 | // ////xbee().printf("\nERROR:Failure to read input.cfg configuration file."); |
tnhnrl | 17:7c16b5671d0e | 866 | // } |
tnhnrl | 17:7c16b5671d0e | 867 | // |
tnhnrl | 17:7c16b5671d0e | 868 | // //read the values from the file |
tnhnrl | 17:7c16b5671d0e | 869 | // if (read_cfg.getValue(key1, &value[0], sizeof(value))) |
tnhnrl | 17:7c16b5671d0e | 870 | // { |
tnhnrl | 17:7c16b5671d0e | 871 | // pc().printf("\n\r%s = %s", key1, value); |
tnhnrl | 17:7c16b5671d0e | 872 | // ////xbee().printf("\n\r%s = %s", key1, value); |
tnhnrl | 17:7c16b5671d0e | 873 | // depth_setPoint = atof(value); |
tnhnrl | 17:7c16b5671d0e | 874 | // } |
tnhnrl | 17:7c16b5671d0e | 875 | // else |
tnhnrl | 17:7c16b5671d0e | 876 | // { |
tnhnrl | 17:7c16b5671d0e | 877 | // ////xbee().printf("\n\rERROR: File is blank!"); |
tnhnrl | 17:7c16b5671d0e | 878 | // pc().printf("\n\rERROR: File is blank!"); |
tnhnrl | 17:7c16b5671d0e | 879 | // } |
tnhnrl | 17:7c16b5671d0e | 880 | // |
tnhnrl | 17:7c16b5671d0e | 881 | // //test the first key, if there is nothing present then the rest will not print either |
tnhnrl | 17:7c16b5671d0e | 882 | // if (read_cfg.getValue(key2, &value[0], sizeof(value))) |
tnhnrl | 17:7c16b5671d0e | 883 | // { |
tnhnrl | 17:7c16b5671d0e | 884 | // pc().printf("\n\r%s = %s", key2, value); |
tnhnrl | 17:7c16b5671d0e | 885 | // ////xbee().printf("\n\r%s = %s", key2, value); |
tnhnrl | 17:7c16b5671d0e | 886 | // pitch_setPoint = atof(value); |
tnhnrl | 17:7c16b5671d0e | 887 | // } |
tnhnrl | 17:7c16b5671d0e | 888 | // |
tnhnrl | 17:7c16b5671d0e | 889 | // if (read_cfg.getValue(key3, &value[0], sizeof(value))) |
tnhnrl | 17:7c16b5671d0e | 890 | // { |
tnhnrl | 17:7c16b5671d0e | 891 | // pc().printf("\n\r%s = %s", key3, value); |
tnhnrl | 17:7c16b5671d0e | 892 | // ////xbee().printf("\n\r%s = %s", key3, value); |
tnhnrl | 17:7c16b5671d0e | 893 | // neutral_bce_position_mm = atof(value); |
tnhnrl | 17:7c16b5671d0e | 894 | // } |
tnhnrl | 17:7c16b5671d0e | 895 | //} |
tnhnrl | 17:7c16b5671d0e | 896 | |
tnhnrl | 17:7c16b5671d0e | 897 |