Joseph Roberts / Mbed 2 deprecated Quadcopter_mk2

Dependencies:   mbed MODSERIAL filter mbed-rtos ConfigFile PID PPM FreeIMU_external_magnetometer TinyGPS

Committer:
joe4465
Date:
Wed Mar 04 18:50:37 2015 +0000
Revision:
0:c6a85bb2a827
New version of quadcopter software, written following OO principles

Who changed what in which revision?

UserRevisionLine numberNew contents of line
joe4465 0:c6a85bb2a827 1 #include "ConfigFileWrapper.h"
joe4465 0:c6a85bb2a827 2
joe4465 0:c6a85bb2a827 3 ConfigFileWrapper::ConfigFileWrapper(){}
joe4465 0:c6a85bb2a827 4
joe4465 0:c6a85bb2a827 5 ConfigFileWrapper::~ConfigFileWrapper(){}
joe4465 0:c6a85bb2a827 6
joe4465 0:c6a85bb2a827 7 bool PidWrapper::initialise()
joe4465 0:c6a85bb2a827 8 {
joe4465 0:c6a85bb2a827 9 _str = new char[1024];
joe4465 0:c6a85bb2a827 10 loadSettings();
joe4465 0:c6a85bb2a827 11
joe4465 0:c6a85bb2a827 12 DEBUG("Config file wrapper initialised");
joe4465 0:c6a85bb2a827 13 return true;
joe4465 0:c6a85bb2a827 14 }
joe4465 0:c6a85bb2a827 15
joe4465 0:c6a85bb2a827 16 pidWrapper::PidParameters ConfigFileWrapper::getYawRateParameters()
joe4465 0:c6a85bb2a827 17 {
joe4465 0:c6a85bb2a827 18 return _yawRateParameters;
joe4465 0:c6a85bb2a827 19 }
joe4465 0:c6a85bb2a827 20
joe4465 0:c6a85bb2a827 21 pidWrapper::PidParameters ConfigFileWrapper::getPitchRateParameters()
joe4465 0:c6a85bb2a827 22 {
joe4465 0:c6a85bb2a827 23 return _pitchRateParameters;
joe4465 0:c6a85bb2a827 24 }
joe4465 0:c6a85bb2a827 25
joe4465 0:c6a85bb2a827 26 pidWrapper::PidParameters ConfigFileWrapper::getRollRateParameters()
joe4465 0:c6a85bb2a827 27 {
joe4465 0:c6a85bb2a827 28 return _rollRateParameters;
joe4465 0:c6a85bb2a827 29 }
joe4465 0:c6a85bb2a827 30
joe4465 0:c6a85bb2a827 31 pidWrapper::PidParameters ConfigFileWrapper::getYawStabParameters()
joe4465 0:c6a85bb2a827 32 {
joe4465 0:c6a85bb2a827 33 return _yawStabParameters;
joe4465 0:c6a85bb2a827 34 }
joe4465 0:c6a85bb2a827 35
joe4465 0:c6a85bb2a827 36 pidWrapper::PidParameters ConfigFileWrapper::getPitchStabParameters()
joe4465 0:c6a85bb2a827 37 {
joe4465 0:c6a85bb2a827 38 return _pitchStabParameters;
joe4465 0:c6a85bb2a827 39 }
joe4465 0:c6a85bb2a827 40
joe4465 0:c6a85bb2a827 41 pidWrapper::PidParameters ConfigFileWrapper::getRollStabParameters()
joe4465 0:c6a85bb2a827 42 {
joe4465 0:c6a85bb2a827 43 return _rollStabParameters;
joe4465 0:c6a85bb2a827 44 }
joe4465 0:c6a85bb2a827 45
joe4465 0:c6a85bb2a827 46 bool ConfigFileWrapper::setYawRateParameters(pidWrapper::PidParameters)
joe4465 0:c6a85bb2a827 47 {
joe4465 0:c6a85bb2a827 48 return true;
joe4465 0:c6a85bb2a827 49 }
joe4465 0:c6a85bb2a827 50
joe4465 0:c6a85bb2a827 51 bool ConfigFileWrapper::setPitchRateParameters(pidWrapper::PidParameters)
joe4465 0:c6a85bb2a827 52 {
joe4465 0:c6a85bb2a827 53 return true;
joe4465 0:c6a85bb2a827 54 }
joe4465 0:c6a85bb2a827 55
joe4465 0:c6a85bb2a827 56 bool ConfigFileWrapper::setRollRateParameters(pidWrapper::PidParameters)
joe4465 0:c6a85bb2a827 57 {
joe4465 0:c6a85bb2a827 58 return true;
joe4465 0:c6a85bb2a827 59 }
joe4465 0:c6a85bb2a827 60
joe4465 0:c6a85bb2a827 61 bool ConfigFileWrapper::setYawStabParameters(pidWrapper::PidParameters)
joe4465 0:c6a85bb2a827 62 {
joe4465 0:c6a85bb2a827 63 return true;
joe4465 0:c6a85bb2a827 64 }
joe4465 0:c6a85bb2a827 65
joe4465 0:c6a85bb2a827 66 bool ConfigFileWrapper::setPitchStabParameters(pidWrapper::PidParameters)
joe4465 0:c6a85bb2a827 67 {
joe4465 0:c6a85bb2a827 68 return true;
joe4465 0:c6a85bb2a827 69 }
joe4465 0:c6a85bb2a827 70
joe4465 0:c6a85bb2a827 71 bool ConfigFileWrapper::setRollStabParameters(pidWrapper::PidParameters)
joe4465 0:c6a85bb2a827 72 {
joe4465 0:c6a85bb2a827 73 return true;
joe4465 0:c6a85bb2a827 74 }
joe4465 0:c6a85bb2a827 75
joe4465 0:c6a85bb2a827 76 void ConfigFileWrapper::convertToCharArray(float number)
joe4465 0:c6a85bb2a827 77 {
joe4465 0:c6a85bb2a827 78 sprintf(_str, "%1.8f", number );
joe4465 0:c6a85bb2a827 79 }
joe4465 0:c6a85bb2a827 80
joe4465 0:c6a85bb2a827 81 void ConfigFileWrapper::convertToCharArray(int number)
joe4465 0:c6a85bb2a827 82 {
joe4465 0:c6a85bb2a827 83 sprintf(_str, "%d", number );
joe4465 0:c6a85bb2a827 84 }
joe4465 0:c6a85bb2a827 85
joe4465 0:c6a85bb2a827 86 void ConfigFileWrapper::loadSettings()
joe4465 0:c6a85bb2a827 87 {
joe4465 0:c6a85bb2a827 88 char value[BUFSIZ];
joe4465 0:c6a85bb2a827 89
joe4465 0:c6a85bb2a827 90 //Read a configuration file from a mbed.
joe4465 0:c6a85bb2a827 91 if (!_configFile.read("/local/config.cfg"))
joe4465 0:c6a85bb2a827 92 {
joe4465 0:c6a85bb2a827 93 DEBUG("Config file does not exist\n\r");
joe4465 0:c6a85bb2a827 94 }
joe4465 0:c6a85bb2a827 95 else
joe4465 0:c6a85bb2a827 96 {
joe4465 0:c6a85bb2a827 97 //Get values
joe4465 0:c6a85bb2a827 98 if (_configFile.getValue("yawRatePIDControllerP", &value[0], sizeof(value))) _yawRateParameters.p = atof(value);
joe4465 0:c6a85bb2a827 99 else DEBUG("Failed to get value for yawRatePIDControllerP\n\r");
joe4465 0:c6a85bb2a827 100
joe4465 0:c6a85bb2a827 101 if (_configFile.getValue("yawRatePIDControllerI", &value[0], sizeof(value))) _yawRateParameters.i = atof(value);
joe4465 0:c6a85bb2a827 102 else DEBUG("Failed to get value for yawRatePIDControllerI\n\r");
joe4465 0:c6a85bb2a827 103
joe4465 0:c6a85bb2a827 104 if (_configFile.getValue("yawRatePIDControllerD", &value[0], sizeof(value))) _yawRateParameters.d = atof(value);
joe4465 0:c6a85bb2a827 105 else DEBUG("Failed to get value for yawRatePIDControllerD\n\r");
joe4465 0:c6a85bb2a827 106
joe4465 0:c6a85bb2a827 107 if (_configFile.getValue("pitchRatePIDControllerP", &value[0], sizeof(value))) _pitchRateParameters.p = atof(value);
joe4465 0:c6a85bb2a827 108 else DEBUG("Failed to get value for pitchRatePIDControllerP\n\r");
joe4465 0:c6a85bb2a827 109
joe4465 0:c6a85bb2a827 110 if (_configFile.getValue("pitchRatePIDControllerI", &value[0], sizeof(value))) _pitchRateParameters.i = atof(value);
joe4465 0:c6a85bb2a827 111 else DEBUG("Failed to get value for pitchRatePIDControllerI\n\r");
joe4465 0:c6a85bb2a827 112
joe4465 0:c6a85bb2a827 113 if (_configFile.getValue("pitchRatePIDControllerD", &value[0], sizeof(value))) _pitchRateParameters.d = atof(value);
joe4465 0:c6a85bb2a827 114 else DEBUG("Failed to get value for pitchRatePIDControllerD\n\r");
joe4465 0:c6a85bb2a827 115
joe4465 0:c6a85bb2a827 116 if (_configFile.getValue("rollRatePIDControllerP", &value[0], sizeof(value))) _rollRateParameters.p = atof(value);
joe4465 0:c6a85bb2a827 117 else DEBUG("Failed to get value for rollRatePIDControllerP\n\r");
joe4465 0:c6a85bb2a827 118
joe4465 0:c6a85bb2a827 119 if (_configFile.getValue("rollRatePIDControllerI", &value[0], sizeof(value))) _rollRateParameters.i = atof(value);
joe4465 0:c6a85bb2a827 120 else DEBUG("Failed to get value for rollRatePIDControllerI\n\r");
joe4465 0:c6a85bb2a827 121
joe4465 0:c6a85bb2a827 122 if (_configFile.getValue("rollRatePIDControllerD", &value[0], sizeof(value))) _rollRateParameters.d = atof(value);
joe4465 0:c6a85bb2a827 123 else DEBUG("Failed to get value for rollRatePIDControllerD\n\r");
joe4465 0:c6a85bb2a827 124
joe4465 0:c6a85bb2a827 125
joe4465 0:c6a85bb2a827 126 if (_configFile.getValue("yawStabPIDControllerP", &value[0], sizeof(value))) _yawStabParameters.p = atof(value);
joe4465 0:c6a85bb2a827 127 else DEBUG("Failed to get value for yawStabPIDControllerP\n\r");
joe4465 0:c6a85bb2a827 128
joe4465 0:c6a85bb2a827 129 if (_configFile.getValue("yawStabPIDControllerI", &value[0], sizeof(value))) _yawStabParameters.i = atof(value);
joe4465 0:c6a85bb2a827 130 else DEBUG("Failed to get value for yawStabPIDControllerI\n\r");
joe4465 0:c6a85bb2a827 131
joe4465 0:c6a85bb2a827 132 if (_configFile.getValue("yawStabPIDControllerD", &value[0], sizeof(value))) _yawStabParameters.d = atof(value);
joe4465 0:c6a85bb2a827 133 else DEBUG("Failed to get value for yawStabPIDControllerD\n\r");
joe4465 0:c6a85bb2a827 134
joe4465 0:c6a85bb2a827 135 if (_configFile.getValue("pitchStabPIDControllerP", &value[0], sizeof(value))) _pitchStabParameters.p = atof(value);
joe4465 0:c6a85bb2a827 136 else DEBUG("Failed to get value for pitchStabPIDControllerP\n\r");
joe4465 0:c6a85bb2a827 137
joe4465 0:c6a85bb2a827 138 if (_configFile.getValue("pitchStabPIDControllerI", &value[0], sizeof(value))) _pitchStabParameters.i = atof(value);
joe4465 0:c6a85bb2a827 139 else DEBUG("Failed to get value for pitchStabPIDControllerI\n\r");
joe4465 0:c6a85bb2a827 140
joe4465 0:c6a85bb2a827 141 if (_configFile.getValue("pitchStabPIDControllerD", &value[0], sizeof(value))) _pitchStabParameters.d = atof(value);
joe4465 0:c6a85bb2a827 142 else DEBUG("Failed to get value for pitchStabPIDControllerD\n\r");
joe4465 0:c6a85bb2a827 143
joe4465 0:c6a85bb2a827 144 if (_configFile.getValue("rollStabPIDControllerP", &value[0], sizeof(value))) _rollStabParameters.p = atof(value);
joe4465 0:c6a85bb2a827 145 else DEBUG("Failed to get value for rollStabPIDControllerP\n\r");
joe4465 0:c6a85bb2a827 146
joe4465 0:c6a85bb2a827 147 if (_configFile.getValue("rollStabPIDControllerI", &value[0], sizeof(value))) _rollStabParameters.i = atof(value);
joe4465 0:c6a85bb2a827 148 else DEBUG("Failed to get value for rollStabPIDControllerI\n\r");
joe4465 0:c6a85bb2a827 149
joe4465 0:c6a85bb2a827 150 if (_configFile.getValue("rollStabPIDControllerD", &value[0], sizeof(value))) _rollStabParameters.d = atof(value);
joe4465 0:c6a85bb2a827 151 else DEBUG("Failed to get value for rollStabPIDControllerD\n\r");
joe4465 0:c6a85bb2a827 152
joe4465 0:c6a85bb2a827 153 /*if (_configFile.getValue("zeroPitch", &value[0], sizeof(value))) _zeroValues[1] = atof(value);
joe4465 0:c6a85bb2a827 154 else DEBUG("Failed to get value for zero pitch\n\r");
joe4465 0:c6a85bb2a827 155
joe4465 0:c6a85bb2a827 156 if (_configFile.getValue("zeroRoll", &value[0], sizeof(value))) _zeroValues[2] = atof(value);
joe4465 0:c6a85bb2a827 157 else printf("Failed to get value for zero roll\n\r");*/
joe4465 0:c6a85bb2a827 158 }
joe4465 0:c6a85bb2a827 159
joe4465 0:c6a85bb2a827 160 DEBUG("Finished loading settings from config file\n\r");
joe4465 0:c6a85bb2a827 161 }