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 filter mbed-rtos ConfigFile PID PPM FreeIMU_external_magnetometer TinyGPS
Global/ConfigFileWrapper/ConfigFileWrapper.cpp@2:969dfa4f2436, 2015-04-01 (annotated)
- Committer:
- joe4465
- Date:
- Wed Apr 01 11:19:21 2015 +0000
- Revision:
- 2:969dfa4f2436
- Parent:
- ConfigFileWrapper/ConfigFileWrapper.cpp@0:c6a85bb2a827
Altitude hold with 2 PID's working. Exported to offline compiler
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| joe4465 | 0:c6a85bb2a827 | 1 | #include "ConfigFileWrapper.h" |
| joe4465 | 0:c6a85bb2a827 | 2 | |
| joe4465 | 2:969dfa4f2436 | 3 | ConfigFileWrapper::ConfigFileWrapper() |
| joe4465 | 0:c6a85bb2a827 | 4 | { |
| joe4465 | 0:c6a85bb2a827 | 5 | _str = new char[1024]; |
| joe4465 | 0:c6a85bb2a827 | 6 | loadSettings(); |
| joe4465 | 0:c6a85bb2a827 | 7 | |
| joe4465 | 2:969dfa4f2436 | 8 | DEBUG("Config file wrapper initialised\r\n"); |
| joe4465 | 0:c6a85bb2a827 | 9 | } |
| joe4465 | 0:c6a85bb2a827 | 10 | |
| joe4465 | 2:969dfa4f2436 | 11 | ConfigFileWrapper::~ConfigFileWrapper(){} |
| joe4465 | 2:969dfa4f2436 | 12 | |
| joe4465 | 2:969dfa4f2436 | 13 | PidWrapper::PidParameter ConfigFileWrapper::getYawRateParameters() |
| joe4465 | 0:c6a85bb2a827 | 14 | { |
| joe4465 | 0:c6a85bb2a827 | 15 | return _yawRateParameters; |
| joe4465 | 0:c6a85bb2a827 | 16 | } |
| joe4465 | 0:c6a85bb2a827 | 17 | |
| joe4465 | 2:969dfa4f2436 | 18 | PidWrapper::PidParameter ConfigFileWrapper::getPitchRateParameters() |
| joe4465 | 0:c6a85bb2a827 | 19 | { |
| joe4465 | 0:c6a85bb2a827 | 20 | return _pitchRateParameters; |
| joe4465 | 0:c6a85bb2a827 | 21 | } |
| joe4465 | 0:c6a85bb2a827 | 22 | |
| joe4465 | 2:969dfa4f2436 | 23 | PidWrapper::PidParameter ConfigFileWrapper::getRollRateParameters() |
| joe4465 | 0:c6a85bb2a827 | 24 | { |
| joe4465 | 0:c6a85bb2a827 | 25 | return _rollRateParameters; |
| joe4465 | 0:c6a85bb2a827 | 26 | } |
| joe4465 | 0:c6a85bb2a827 | 27 | |
| joe4465 | 2:969dfa4f2436 | 28 | PidWrapper::PidParameter ConfigFileWrapper::getYawStabParameters() |
| joe4465 | 0:c6a85bb2a827 | 29 | { |
| joe4465 | 0:c6a85bb2a827 | 30 | return _yawStabParameters; |
| joe4465 | 0:c6a85bb2a827 | 31 | } |
| joe4465 | 0:c6a85bb2a827 | 32 | |
| joe4465 | 2:969dfa4f2436 | 33 | PidWrapper::PidParameter ConfigFileWrapper::getPitchStabParameters() |
| joe4465 | 0:c6a85bb2a827 | 34 | { |
| joe4465 | 0:c6a85bb2a827 | 35 | return _pitchStabParameters; |
| joe4465 | 0:c6a85bb2a827 | 36 | } |
| joe4465 | 0:c6a85bb2a827 | 37 | |
| joe4465 | 2:969dfa4f2436 | 38 | PidWrapper::PidParameter ConfigFileWrapper::getRollStabParameters() |
| joe4465 | 0:c6a85bb2a827 | 39 | { |
| joe4465 | 0:c6a85bb2a827 | 40 | return _rollStabParameters; |
| joe4465 | 0:c6a85bb2a827 | 41 | } |
| joe4465 | 0:c6a85bb2a827 | 42 | |
| joe4465 | 2:969dfa4f2436 | 43 | PidWrapper::PidParameter ConfigFileWrapper::getAltitudeRateParameters() |
| joe4465 | 2:969dfa4f2436 | 44 | { |
| joe4465 | 2:969dfa4f2436 | 45 | return _altitudeRateParameters; |
| joe4465 | 2:969dfa4f2436 | 46 | } |
| joe4465 | 2:969dfa4f2436 | 47 | |
| joe4465 | 2:969dfa4f2436 | 48 | PidWrapper::PidParameter ConfigFileWrapper::getAltitudeStabParameters() |
| joe4465 | 0:c6a85bb2a827 | 49 | { |
| joe4465 | 2:969dfa4f2436 | 50 | return _altitudeStabParameters; |
| joe4465 | 2:969dfa4f2436 | 51 | } |
| joe4465 | 2:969dfa4f2436 | 52 | |
| joe4465 | 2:969dfa4f2436 | 53 | bool ConfigFileWrapper::setYawRateParameters(PidWrapper::PidParameter pidParameters) |
| joe4465 | 2:969dfa4f2436 | 54 | { |
| joe4465 | 2:969dfa4f2436 | 55 | _yawRateParameters = pidParameters; |
| joe4465 | 0:c6a85bb2a827 | 56 | return true; |
| joe4465 | 0:c6a85bb2a827 | 57 | } |
| joe4465 | 0:c6a85bb2a827 | 58 | |
| joe4465 | 2:969dfa4f2436 | 59 | bool ConfigFileWrapper::setPitchRateParameters(PidWrapper::PidParameter pidParameters) |
| joe4465 | 0:c6a85bb2a827 | 60 | { |
| joe4465 | 2:969dfa4f2436 | 61 | _pitchRateParameters = pidParameters; |
| joe4465 | 0:c6a85bb2a827 | 62 | return true; |
| joe4465 | 0:c6a85bb2a827 | 63 | } |
| joe4465 | 0:c6a85bb2a827 | 64 | |
| joe4465 | 2:969dfa4f2436 | 65 | bool ConfigFileWrapper::setRollRateParameters(PidWrapper::PidParameter pidParameters) |
| joe4465 | 2:969dfa4f2436 | 66 | { |
| joe4465 | 2:969dfa4f2436 | 67 | _rollRateParameters = pidParameters; |
| joe4465 | 2:969dfa4f2436 | 68 | return true; |
| joe4465 | 2:969dfa4f2436 | 69 | } |
| joe4465 | 2:969dfa4f2436 | 70 | |
| joe4465 | 2:969dfa4f2436 | 71 | bool ConfigFileWrapper::setYawStabParameters(PidWrapper::PidParameter pidParameters) |
| joe4465 | 0:c6a85bb2a827 | 72 | { |
| joe4465 | 2:969dfa4f2436 | 73 | _yawStabParameters = pidParameters; |
| joe4465 | 2:969dfa4f2436 | 74 | return true; |
| joe4465 | 2:969dfa4f2436 | 75 | } |
| joe4465 | 2:969dfa4f2436 | 76 | |
| joe4465 | 2:969dfa4f2436 | 77 | bool ConfigFileWrapper::setPitchStabParameters(PidWrapper::PidParameter pidParameters) |
| joe4465 | 2:969dfa4f2436 | 78 | { |
| joe4465 | 2:969dfa4f2436 | 79 | _pitchStabParameters = pidParameters; |
| joe4465 | 0:c6a85bb2a827 | 80 | return true; |
| joe4465 | 0:c6a85bb2a827 | 81 | } |
| joe4465 | 0:c6a85bb2a827 | 82 | |
| joe4465 | 2:969dfa4f2436 | 83 | bool ConfigFileWrapper::setRollStabParameters(PidWrapper::PidParameter pidParameters) |
| joe4465 | 2:969dfa4f2436 | 84 | { |
| joe4465 | 2:969dfa4f2436 | 85 | _rollStabParameters = pidParameters; |
| joe4465 | 2:969dfa4f2436 | 86 | return true; |
| joe4465 | 2:969dfa4f2436 | 87 | } |
| joe4465 | 2:969dfa4f2436 | 88 | |
| joe4465 | 2:969dfa4f2436 | 89 | bool ConfigFileWrapper::setAltitudeRateParameters(PidWrapper::PidParameter pidParameters) |
| joe4465 | 0:c6a85bb2a827 | 90 | { |
| joe4465 | 2:969dfa4f2436 | 91 | _altitudeRateParameters = pidParameters; |
| joe4465 | 2:969dfa4f2436 | 92 | return true; |
| joe4465 | 2:969dfa4f2436 | 93 | } |
| joe4465 | 2:969dfa4f2436 | 94 | |
| joe4465 | 2:969dfa4f2436 | 95 | bool ConfigFileWrapper::setAltitudeStabParameters(PidWrapper::PidParameter pidParameters) |
| joe4465 | 2:969dfa4f2436 | 96 | { |
| joe4465 | 2:969dfa4f2436 | 97 | _altitudeStabParameters = pidParameters; |
| joe4465 | 0:c6a85bb2a827 | 98 | return true; |
| joe4465 | 0:c6a85bb2a827 | 99 | } |
| joe4465 | 0:c6a85bb2a827 | 100 | |
| joe4465 | 2:969dfa4f2436 | 101 | float ConfigFileWrapper::getAccelZeroPitch() |
| joe4465 | 2:969dfa4f2436 | 102 | { |
| joe4465 | 2:969dfa4f2436 | 103 | return _accelZeroPitch; |
| joe4465 | 2:969dfa4f2436 | 104 | } |
| joe4465 | 2:969dfa4f2436 | 105 | |
| joe4465 | 2:969dfa4f2436 | 106 | float ConfigFileWrapper::getAccelZeroRoll() |
| joe4465 | 0:c6a85bb2a827 | 107 | { |
| joe4465 | 2:969dfa4f2436 | 108 | return _accelZeroRoll; |
| joe4465 | 2:969dfa4f2436 | 109 | } |
| joe4465 | 2:969dfa4f2436 | 110 | |
| joe4465 | 2:969dfa4f2436 | 111 | bool ConfigFileWrapper::setAccelZeroPitch(float value) |
| joe4465 | 2:969dfa4f2436 | 112 | { |
| joe4465 | 2:969dfa4f2436 | 113 | _accelZeroPitch = value; |
| joe4465 | 0:c6a85bb2a827 | 114 | return true; |
| joe4465 | 0:c6a85bb2a827 | 115 | } |
| joe4465 | 0:c6a85bb2a827 | 116 | |
| joe4465 | 2:969dfa4f2436 | 117 | bool ConfigFileWrapper::setAccelZeroRoll(float value) |
| joe4465 | 0:c6a85bb2a827 | 118 | { |
| joe4465 | 2:969dfa4f2436 | 119 | _accelZeroRoll = value; |
| joe4465 | 0:c6a85bb2a827 | 120 | return true; |
| joe4465 | 0:c6a85bb2a827 | 121 | } |
| joe4465 | 0:c6a85bb2a827 | 122 | |
| joe4465 | 2:969dfa4f2436 | 123 | void ConfigFileWrapper::convertToCharArray(double number) |
| joe4465 | 0:c6a85bb2a827 | 124 | { |
| joe4465 | 0:c6a85bb2a827 | 125 | sprintf(_str, "%1.8f", number ); |
| joe4465 | 0:c6a85bb2a827 | 126 | } |
| joe4465 | 0:c6a85bb2a827 | 127 | |
| joe4465 | 0:c6a85bb2a827 | 128 | void ConfigFileWrapper::convertToCharArray(int number) |
| joe4465 | 0:c6a85bb2a827 | 129 | { |
| joe4465 | 0:c6a85bb2a827 | 130 | sprintf(_str, "%d", number ); |
| joe4465 | 0:c6a85bb2a827 | 131 | } |
| joe4465 | 0:c6a85bb2a827 | 132 | |
| joe4465 | 0:c6a85bb2a827 | 133 | void ConfigFileWrapper::loadSettings() |
| joe4465 | 0:c6a85bb2a827 | 134 | { |
| joe4465 | 0:c6a85bb2a827 | 135 | char value[BUFSIZ]; |
| joe4465 | 0:c6a85bb2a827 | 136 | |
| joe4465 | 2:969dfa4f2436 | 137 | DEBUG("Loading settings from config file\n\r"); |
| joe4465 | 2:969dfa4f2436 | 138 | |
| joe4465 | 0:c6a85bb2a827 | 139 | //Read a configuration file from a mbed. |
| joe4465 | 2:969dfa4f2436 | 140 | LocalFileSystem local("local"); |
| joe4465 | 2:969dfa4f2436 | 141 | if (!_configFile.read("/local/CONFIG.CFG")) |
| joe4465 | 0:c6a85bb2a827 | 142 | { |
| joe4465 | 0:c6a85bb2a827 | 143 | DEBUG("Config file does not exist\n\r"); |
| joe4465 | 2:969dfa4f2436 | 144 | return; |
| joe4465 | 0:c6a85bb2a827 | 145 | } |
| joe4465 | 0:c6a85bb2a827 | 146 | else |
| joe4465 | 0:c6a85bb2a827 | 147 | { |
| joe4465 | 0:c6a85bb2a827 | 148 | //Get values |
| joe4465 | 0:c6a85bb2a827 | 149 | if (_configFile.getValue("yawRatePIDControllerP", &value[0], sizeof(value))) _yawRateParameters.p = atof(value); |
| joe4465 | 0:c6a85bb2a827 | 150 | else DEBUG("Failed to get value for yawRatePIDControllerP\n\r"); |
| joe4465 | 0:c6a85bb2a827 | 151 | |
| joe4465 | 0:c6a85bb2a827 | 152 | if (_configFile.getValue("yawRatePIDControllerI", &value[0], sizeof(value))) _yawRateParameters.i = atof(value); |
| joe4465 | 0:c6a85bb2a827 | 153 | else DEBUG("Failed to get value for yawRatePIDControllerI\n\r"); |
| joe4465 | 0:c6a85bb2a827 | 154 | |
| joe4465 | 0:c6a85bb2a827 | 155 | if (_configFile.getValue("yawRatePIDControllerD", &value[0], sizeof(value))) _yawRateParameters.d = atof(value); |
| joe4465 | 0:c6a85bb2a827 | 156 | else DEBUG("Failed to get value for yawRatePIDControllerD\n\r"); |
| joe4465 | 0:c6a85bb2a827 | 157 | |
| joe4465 | 0:c6a85bb2a827 | 158 | if (_configFile.getValue("pitchRatePIDControllerP", &value[0], sizeof(value))) _pitchRateParameters.p = atof(value); |
| joe4465 | 0:c6a85bb2a827 | 159 | else DEBUG("Failed to get value for pitchRatePIDControllerP\n\r"); |
| joe4465 | 0:c6a85bb2a827 | 160 | |
| joe4465 | 0:c6a85bb2a827 | 161 | if (_configFile.getValue("pitchRatePIDControllerI", &value[0], sizeof(value))) _pitchRateParameters.i = atof(value); |
| joe4465 | 0:c6a85bb2a827 | 162 | else DEBUG("Failed to get value for pitchRatePIDControllerI\n\r"); |
| joe4465 | 0:c6a85bb2a827 | 163 | |
| joe4465 | 0:c6a85bb2a827 | 164 | if (_configFile.getValue("pitchRatePIDControllerD", &value[0], sizeof(value))) _pitchRateParameters.d = atof(value); |
| joe4465 | 0:c6a85bb2a827 | 165 | else DEBUG("Failed to get value for pitchRatePIDControllerD\n\r"); |
| joe4465 | 0:c6a85bb2a827 | 166 | |
| joe4465 | 0:c6a85bb2a827 | 167 | if (_configFile.getValue("rollRatePIDControllerP", &value[0], sizeof(value))) _rollRateParameters.p = atof(value); |
| joe4465 | 0:c6a85bb2a827 | 168 | else DEBUG("Failed to get value for rollRatePIDControllerP\n\r"); |
| joe4465 | 0:c6a85bb2a827 | 169 | |
| joe4465 | 0:c6a85bb2a827 | 170 | if (_configFile.getValue("rollRatePIDControllerI", &value[0], sizeof(value))) _rollRateParameters.i = atof(value); |
| joe4465 | 0:c6a85bb2a827 | 171 | else DEBUG("Failed to get value for rollRatePIDControllerI\n\r"); |
| joe4465 | 0:c6a85bb2a827 | 172 | |
| joe4465 | 0:c6a85bb2a827 | 173 | if (_configFile.getValue("rollRatePIDControllerD", &value[0], sizeof(value))) _rollRateParameters.d = atof(value); |
| joe4465 | 0:c6a85bb2a827 | 174 | else DEBUG("Failed to get value for rollRatePIDControllerD\n\r"); |
| joe4465 | 0:c6a85bb2a827 | 175 | |
| joe4465 | 0:c6a85bb2a827 | 176 | if (_configFile.getValue("yawStabPIDControllerP", &value[0], sizeof(value))) _yawStabParameters.p = atof(value); |
| joe4465 | 0:c6a85bb2a827 | 177 | else DEBUG("Failed to get value for yawStabPIDControllerP\n\r"); |
| joe4465 | 0:c6a85bb2a827 | 178 | |
| joe4465 | 0:c6a85bb2a827 | 179 | if (_configFile.getValue("yawStabPIDControllerI", &value[0], sizeof(value))) _yawStabParameters.i = atof(value); |
| joe4465 | 0:c6a85bb2a827 | 180 | else DEBUG("Failed to get value for yawStabPIDControllerI\n\r"); |
| joe4465 | 0:c6a85bb2a827 | 181 | |
| joe4465 | 0:c6a85bb2a827 | 182 | if (_configFile.getValue("yawStabPIDControllerD", &value[0], sizeof(value))) _yawStabParameters.d = atof(value); |
| joe4465 | 0:c6a85bb2a827 | 183 | else DEBUG("Failed to get value for yawStabPIDControllerD\n\r"); |
| joe4465 | 0:c6a85bb2a827 | 184 | |
| joe4465 | 0:c6a85bb2a827 | 185 | if (_configFile.getValue("pitchStabPIDControllerP", &value[0], sizeof(value))) _pitchStabParameters.p = atof(value); |
| joe4465 | 0:c6a85bb2a827 | 186 | else DEBUG("Failed to get value for pitchStabPIDControllerP\n\r"); |
| joe4465 | 0:c6a85bb2a827 | 187 | |
| joe4465 | 0:c6a85bb2a827 | 188 | if (_configFile.getValue("pitchStabPIDControllerI", &value[0], sizeof(value))) _pitchStabParameters.i = atof(value); |
| joe4465 | 0:c6a85bb2a827 | 189 | else DEBUG("Failed to get value for pitchStabPIDControllerI\n\r"); |
| joe4465 | 0:c6a85bb2a827 | 190 | |
| joe4465 | 0:c6a85bb2a827 | 191 | if (_configFile.getValue("pitchStabPIDControllerD", &value[0], sizeof(value))) _pitchStabParameters.d = atof(value); |
| joe4465 | 0:c6a85bb2a827 | 192 | else DEBUG("Failed to get value for pitchStabPIDControllerD\n\r"); |
| joe4465 | 0:c6a85bb2a827 | 193 | |
| joe4465 | 0:c6a85bb2a827 | 194 | if (_configFile.getValue("rollStabPIDControllerP", &value[0], sizeof(value))) _rollStabParameters.p = atof(value); |
| joe4465 | 0:c6a85bb2a827 | 195 | else DEBUG("Failed to get value for rollStabPIDControllerP\n\r"); |
| joe4465 | 0:c6a85bb2a827 | 196 | |
| joe4465 | 0:c6a85bb2a827 | 197 | if (_configFile.getValue("rollStabPIDControllerI", &value[0], sizeof(value))) _rollStabParameters.i = atof(value); |
| joe4465 | 0:c6a85bb2a827 | 198 | else DEBUG("Failed to get value for rollStabPIDControllerI\n\r"); |
| joe4465 | 0:c6a85bb2a827 | 199 | |
| joe4465 | 0:c6a85bb2a827 | 200 | if (_configFile.getValue("rollStabPIDControllerD", &value[0], sizeof(value))) _rollStabParameters.d = atof(value); |
| joe4465 | 0:c6a85bb2a827 | 201 | else DEBUG("Failed to get value for rollStabPIDControllerD\n\r"); |
| joe4465 | 2:969dfa4f2436 | 202 | |
| joe4465 | 2:969dfa4f2436 | 203 | if (_configFile.getValue("altitudeRatePIDControllerP", &value[0], sizeof(value))) _altitudeRateParameters.p = atof(value); |
| joe4465 | 2:969dfa4f2436 | 204 | else DEBUG("Failed to get value for altitudeRatePIDControllerP\n\r"); |
| joe4465 | 2:969dfa4f2436 | 205 | |
| joe4465 | 2:969dfa4f2436 | 206 | if (_configFile.getValue("altitudeRatePIDControllerI", &value[0], sizeof(value))) _altitudeRateParameters.i = atof(value); |
| joe4465 | 2:969dfa4f2436 | 207 | else DEBUG("Failed to get value for altitudeRatePIDControllerI\n\r"); |
| joe4465 | 2:969dfa4f2436 | 208 | |
| joe4465 | 2:969dfa4f2436 | 209 | if (_configFile.getValue("altitudeRatePIDControllerD", &value[0], sizeof(value))) _altitudeRateParameters.d = atof(value); |
| joe4465 | 2:969dfa4f2436 | 210 | else DEBUG("Failed to get value for altitudeRatePIDControllerD\n\r"); |
| joe4465 | 2:969dfa4f2436 | 211 | |
| joe4465 | 2:969dfa4f2436 | 212 | if (_configFile.getValue("altitudeStabPIDControllerP", &value[0], sizeof(value))) _altitudeStabParameters.p = atof(value); |
| joe4465 | 2:969dfa4f2436 | 213 | else DEBUG("Failed to get value for altitudeStabPIDControllerP\n\r"); |
| joe4465 | 2:969dfa4f2436 | 214 | |
| joe4465 | 2:969dfa4f2436 | 215 | if (_configFile.getValue("altitudeStabPIDControllerI", &value[0], sizeof(value))) _altitudeStabParameters.i = atof(value); |
| joe4465 | 2:969dfa4f2436 | 216 | else DEBUG("Failed to get value for altitudeStabPIDControllerI\n\r"); |
| joe4465 | 2:969dfa4f2436 | 217 | |
| joe4465 | 2:969dfa4f2436 | 218 | if (_configFile.getValue("altitudeStabPIDControllerD", &value[0], sizeof(value))) _altitudeStabParameters.d = atof(value); |
| joe4465 | 2:969dfa4f2436 | 219 | else DEBUG("Failed to get value for altitudeStabPIDControllerD\n\r"); |
| joe4465 | 2:969dfa4f2436 | 220 | |
| joe4465 | 2:969dfa4f2436 | 221 | if (_configFile.getValue("accelZeroPitch", &value[0], sizeof(value))) _accelZeroPitch = atof(value); |
| joe4465 | 2:969dfa4f2436 | 222 | else DEBUG("Failed to get value for accelZeroPitch\n\r"); |
| joe4465 | 2:969dfa4f2436 | 223 | |
| joe4465 | 2:969dfa4f2436 | 224 | if (_configFile.getValue("accelZeroRoll", &value[0], sizeof(value))) _accelZeroRoll = atof(value); |
| joe4465 | 2:969dfa4f2436 | 225 | else DEBUG("Failed to get value for accelZeroRoll\n\r"); |
| joe4465 | 0:c6a85bb2a827 | 226 | |
| joe4465 | 0:c6a85bb2a827 | 227 | /*if (_configFile.getValue("zeroPitch", &value[0], sizeof(value))) _zeroValues[1] = atof(value); |
| joe4465 | 0:c6a85bb2a827 | 228 | else DEBUG("Failed to get value for zero pitch\n\r"); |
| joe4465 | 0:c6a85bb2a827 | 229 | |
| joe4465 | 0:c6a85bb2a827 | 230 | if (_configFile.getValue("zeroRoll", &value[0], sizeof(value))) _zeroValues[2] = atof(value); |
| joe4465 | 0:c6a85bb2a827 | 231 | else printf("Failed to get value for zero roll\n\r");*/ |
| joe4465 | 0:c6a85bb2a827 | 232 | } |
| joe4465 | 0:c6a85bb2a827 | 233 | |
| joe4465 | 0:c6a85bb2a827 | 234 | DEBUG("Finished loading settings from config file\n\r"); |
| joe4465 | 0:c6a85bb2a827 | 235 | } |
| joe4465 | 2:969dfa4f2436 | 236 | |
| joe4465 | 2:969dfa4f2436 | 237 | bool ConfigFileWrapper::saveSettings() |
| joe4465 | 2:969dfa4f2436 | 238 | { |
| joe4465 | 2:969dfa4f2436 | 239 | DEBUG("Writing settings to config file\n\r"); |
| joe4465 | 2:969dfa4f2436 | 240 | |
| joe4465 | 2:969dfa4f2436 | 241 | LocalFileSystem local("local"); |
| joe4465 | 2:969dfa4f2436 | 242 | if (!_configFile.read("/local/CONFIG.CFG")) |
| joe4465 | 2:969dfa4f2436 | 243 | { |
| joe4465 | 2:969dfa4f2436 | 244 | DEBUG("Config file does not exist\n\r"); |
| joe4465 | 2:969dfa4f2436 | 245 | return false; |
| joe4465 | 2:969dfa4f2436 | 246 | } |
| joe4465 | 2:969dfa4f2436 | 247 | else |
| joe4465 | 2:969dfa4f2436 | 248 | { |
| joe4465 | 2:969dfa4f2436 | 249 | //Write values |
| joe4465 | 2:969dfa4f2436 | 250 | convertToCharArray(_yawRateParameters.p); |
| joe4465 | 2:969dfa4f2436 | 251 | if (!_configFile.setValue("yawRatePIDControllerP", _str)) DEBUG("Failed to write value for yawRatePIDControllerP\n\r"); |
| joe4465 | 2:969dfa4f2436 | 252 | |
| joe4465 | 2:969dfa4f2436 | 253 | convertToCharArray(_yawRateParameters.i); |
| joe4465 | 2:969dfa4f2436 | 254 | if (!_configFile.setValue("yawRatePIDControllerI", _str)) DEBUG("Failed to write value for yawRatePIDControllerI\n\r"); |
| joe4465 | 2:969dfa4f2436 | 255 | |
| joe4465 | 2:969dfa4f2436 | 256 | convertToCharArray(_yawRateParameters.d); |
| joe4465 | 2:969dfa4f2436 | 257 | if (!_configFile.setValue("yawRatePIDControllerD", _str)) DEBUG("Failed to write value for yawRatePIDControllerD\n\r"); |
| joe4465 | 2:969dfa4f2436 | 258 | |
| joe4465 | 2:969dfa4f2436 | 259 | convertToCharArray(_pitchRateParameters.p); |
| joe4465 | 2:969dfa4f2436 | 260 | if (!_configFile.setValue("pitchRatePIDControllerP", _str)) DEBUG("Failed to write value for pitchRatePIDControllerP\n\r"); |
| joe4465 | 2:969dfa4f2436 | 261 | |
| joe4465 | 2:969dfa4f2436 | 262 | convertToCharArray(_pitchRateParameters.i); |
| joe4465 | 2:969dfa4f2436 | 263 | if (!_configFile.setValue("pitchRatePIDControllerI", _str)) DEBUG("Failed to write value for pitchRatePIDControllerI\n\r"); |
| joe4465 | 2:969dfa4f2436 | 264 | |
| joe4465 | 2:969dfa4f2436 | 265 | convertToCharArray(_pitchRateParameters.d); |
| joe4465 | 2:969dfa4f2436 | 266 | if (!_configFile.setValue("pitchRatePIDControllerD", _str)) DEBUG("Failed to write value for pitchRatePIDControllerD\n\r"); |
| joe4465 | 2:969dfa4f2436 | 267 | |
| joe4465 | 2:969dfa4f2436 | 268 | convertToCharArray(_rollRateParameters.p); |
| joe4465 | 2:969dfa4f2436 | 269 | if (!_configFile.setValue("rollRatePIDControllerP", _str)) DEBUG("Failed to write value for rollRatePIDControllerP\n\r"); |
| joe4465 | 2:969dfa4f2436 | 270 | |
| joe4465 | 2:969dfa4f2436 | 271 | convertToCharArray(_rollRateParameters.i); |
| joe4465 | 2:969dfa4f2436 | 272 | if (!_configFile.setValue("rollRatePIDControllerI", _str)) DEBUG("Failed to write value for rollRatePIDControllerI\n\r"); |
| joe4465 | 2:969dfa4f2436 | 273 | |
| joe4465 | 2:969dfa4f2436 | 274 | convertToCharArray(_rollRateParameters.d); |
| joe4465 | 2:969dfa4f2436 | 275 | if (!_configFile.setValue("rollRatePIDControllerD", _str)) DEBUG("Failed to write value for rollRatePIDControllerD\n\r"); |
| joe4465 | 2:969dfa4f2436 | 276 | |
| joe4465 | 2:969dfa4f2436 | 277 | convertToCharArray(_yawStabParameters.p); |
| joe4465 | 2:969dfa4f2436 | 278 | if (!_configFile.setValue("yawStabPIDControllerP", _str)) DEBUG("Failed to write value for yawStabPIDControllerP\n\r"); |
| joe4465 | 2:969dfa4f2436 | 279 | |
| joe4465 | 2:969dfa4f2436 | 280 | convertToCharArray(_yawStabParameters.i); |
| joe4465 | 2:969dfa4f2436 | 281 | if (!_configFile.setValue("yawStabPIDControllerI", _str)) DEBUG("Failed to write value for yawStabPIDControllerI\n\r"); |
| joe4465 | 2:969dfa4f2436 | 282 | |
| joe4465 | 2:969dfa4f2436 | 283 | convertToCharArray(_yawStabParameters.d); |
| joe4465 | 2:969dfa4f2436 | 284 | if (!_configFile.setValue("yawStabPIDControllerD", _str)) DEBUG("Failed to write value for yawStabPIDControllerD\n\r"); |
| joe4465 | 2:969dfa4f2436 | 285 | |
| joe4465 | 2:969dfa4f2436 | 286 | convertToCharArray(_pitchStabParameters.p); |
| joe4465 | 2:969dfa4f2436 | 287 | if (!_configFile.setValue("pitchStabPIDControllerP", _str)) DEBUG("Failed to write value for pitchStabPIDControllerP\n\r"); |
| joe4465 | 2:969dfa4f2436 | 288 | |
| joe4465 | 2:969dfa4f2436 | 289 | convertToCharArray(_pitchStabParameters.i); |
| joe4465 | 2:969dfa4f2436 | 290 | if (!_configFile.setValue("pitchStabPIDControllerI", _str)) DEBUG("Failed to write value for pitchStabPIDControllerI\n\r"); |
| joe4465 | 2:969dfa4f2436 | 291 | |
| joe4465 | 2:969dfa4f2436 | 292 | convertToCharArray(_pitchStabParameters.d); |
| joe4465 | 2:969dfa4f2436 | 293 | if (!_configFile.setValue("pitchStabPIDControllerD", _str)) DEBUG("Failed to write value for pitchStabPIDControllerD\n\r"); |
| joe4465 | 2:969dfa4f2436 | 294 | |
| joe4465 | 2:969dfa4f2436 | 295 | convertToCharArray(_rollStabParameters.p); |
| joe4465 | 2:969dfa4f2436 | 296 | if (!_configFile.setValue("rollStabPIDControllerP", _str)) DEBUG("Failed to write value for rollStabPIDControllerP\n\r"); |
| joe4465 | 2:969dfa4f2436 | 297 | |
| joe4465 | 2:969dfa4f2436 | 298 | convertToCharArray(_rollStabParameters.i); |
| joe4465 | 2:969dfa4f2436 | 299 | if (!_configFile.setValue("rollStabPIDControllerI", _str)) DEBUG("Failed to write value for _rollStabPIDControllerI\n\r"); |
| joe4465 | 2:969dfa4f2436 | 300 | |
| joe4465 | 2:969dfa4f2436 | 301 | convertToCharArray(_rollStabParameters.d); |
| joe4465 | 2:969dfa4f2436 | 302 | if (!_configFile.setValue("rollStabPIDControllerD", _str)) DEBUG("Failed to write value for rollStabPIDControllerD\n\r"); |
| joe4465 | 2:969dfa4f2436 | 303 | |
| joe4465 | 2:969dfa4f2436 | 304 | convertToCharArray(_altitudeRateParameters.p); |
| joe4465 | 2:969dfa4f2436 | 305 | if (!_configFile.setValue("altitudeRatePIDControllerP", _str)) DEBUG("Failed to write value for altitudeRatePIDControllerP\n\r"); |
| joe4465 | 2:969dfa4f2436 | 306 | |
| joe4465 | 2:969dfa4f2436 | 307 | convertToCharArray(_altitudeRateParameters.i); |
| joe4465 | 2:969dfa4f2436 | 308 | if (!_configFile.setValue("altitudeRatePIDControllerI", _str)) DEBUG("Failed to write value for altitudeRatePIDControllerI\n\r"); |
| joe4465 | 2:969dfa4f2436 | 309 | |
| joe4465 | 2:969dfa4f2436 | 310 | convertToCharArray(_altitudeRateParameters.d); |
| joe4465 | 2:969dfa4f2436 | 311 | if (!_configFile.setValue("altitudeRatePIDControllerD", _str)) DEBUG("Failed to write value for altitudeRatePIDControllerD\n\r"); |
| joe4465 | 2:969dfa4f2436 | 312 | |
| joe4465 | 2:969dfa4f2436 | 313 | convertToCharArray(_altitudeStabParameters.p); |
| joe4465 | 2:969dfa4f2436 | 314 | if (!_configFile.setValue("altitudeStabPIDControllerP", _str)) DEBUG("Failed to write value for altitudeStabPIDControllerP\n\r"); |
| joe4465 | 2:969dfa4f2436 | 315 | |
| joe4465 | 2:969dfa4f2436 | 316 | convertToCharArray(_altitudeStabParameters.i); |
| joe4465 | 2:969dfa4f2436 | 317 | if (!_configFile.setValue("altitudeStabPIDControllerI", _str)) DEBUG("Failed to write value for altitudeStabPIDControllerI\n\r"); |
| joe4465 | 2:969dfa4f2436 | 318 | |
| joe4465 | 2:969dfa4f2436 | 319 | convertToCharArray(_altitudeStabParameters.d); |
| joe4465 | 2:969dfa4f2436 | 320 | if (!_configFile.setValue("altitudeStabPIDControllerD", _str)) DEBUG("Failed to write value for altitudeStabPIDControllerD\n\r"); |
| joe4465 | 2:969dfa4f2436 | 321 | |
| joe4465 | 2:969dfa4f2436 | 322 | convertToCharArray(_accelZeroPitch); |
| joe4465 | 2:969dfa4f2436 | 323 | if (!_configFile.setValue("accelZeroPitch", _str)) DEBUG("Failed to write value for accelZeroPitch\n\r"); |
| joe4465 | 2:969dfa4f2436 | 324 | |
| joe4465 | 2:969dfa4f2436 | 325 | convertToCharArray(_accelZeroRoll); |
| joe4465 | 2:969dfa4f2436 | 326 | if (!_configFile.setValue("accelZeroRoll", _str)) DEBUG("Failed to write value for accelZeroRoll\n\r"); |
| joe4465 | 2:969dfa4f2436 | 327 | |
| joe4465 | 2:969dfa4f2436 | 328 | |
| joe4465 | 2:969dfa4f2436 | 329 | //convertToCharArray(_zeroValues[1]); |
| joe4465 | 2:969dfa4f2436 | 330 | //if (!_configFile.setValue("_zeroPitch", _str)) DEBUG("Failed to write value for zero pitch\n\r"); |
| joe4465 | 2:969dfa4f2436 | 331 | |
| joe4465 | 2:969dfa4f2436 | 332 | //convertToCharArray(_zeroValues[2]); |
| joe4465 | 2:969dfa4f2436 | 333 | //if (!_configFile.setValue("_zeroRoll", _str)) DEBUG("Failed to write value for zero roll\n\r"); |
| joe4465 | 2:969dfa4f2436 | 334 | |
| joe4465 | 2:969dfa4f2436 | 335 | if (!_configFile.write("/local/CONFIG.CFG")) |
| joe4465 | 2:969dfa4f2436 | 336 | { |
| joe4465 | 2:969dfa4f2436 | 337 | DEBUG("Failure to write settings to configuration file.\n\r"); |
| joe4465 | 2:969dfa4f2436 | 338 | return false; |
| joe4465 | 2:969dfa4f2436 | 339 | } |
| joe4465 | 2:969dfa4f2436 | 340 | else |
| joe4465 | 2:969dfa4f2436 | 341 | { |
| joe4465 | 2:969dfa4f2436 | 342 | DEBUG("Successfully wrote settings to configuration file.\n\r"); |
| joe4465 | 2:969dfa4f2436 | 343 | return true; |
| joe4465 | 2:969dfa4f2436 | 344 | } |
| joe4465 | 2:969dfa4f2436 | 345 | } |
| joe4465 | 2:969dfa4f2436 | 346 | } |