New version of quadcopter software written to OO principles
Dependencies: mbed MODSERIAL filter mbed-rtos ConfigFile PID PPM FreeIMU_external_magnetometer TinyGPS
FlightController/RateController/RateController.cpp@0:c6a85bb2a827, 2015-03-04 (annotated)
- Committer:
- joe4465
- Date:
- Wed Mar 04 18:50:37 2015 +0000
- Revision:
- 0:c6a85bb2a827
- Child:
- 2:969dfa4f2436
New version of quadcopter software, written following OO principles
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
joe4465 | 0:c6a85bb2a827 | 1 | #include "RateController.h" |
joe4465 | 0:c6a85bb2a827 | 2 | |
joe4465 | 0:c6a85bb2a827 | 3 | RateController::RateController(){} |
joe4465 | 0:c6a85bb2a827 | 4 | |
joe4465 | 0:c6a85bb2a827 | 5 | RateController::~RateController(){} |
joe4465 | 0:c6a85bb2a827 | 6 | |
joe4465 | 0:c6a85bb2a827 | 7 | bool RateController::initialise(Sensors& sensors, NavigationController& navigationController) |
joe4465 | 0:c6a85bb2a827 | 8 | { |
joe4465 | 0:c6a85bb2a827 | 9 | _sensors = sensors; |
joe4465 | 0:c6a85bb2a827 | 10 | _navigationController = navigationController; |
joe4465 | 0:c6a85bb2a827 | 11 | |
joe4465 | 0:c6a85bb2a827 | 12 | ConfigFileWrapper configFileWrapper = new ConfigFileWrapper(); |
joe4465 | 0:c6a85bb2a827 | 13 | configFileWrapper.initialise(); |
joe4465 | 0:c6a85bb2a827 | 14 | |
joe4465 | 0:c6a85bb2a827 | 15 | _yawRatePidController.initialise(configFileWrapper.getYawRateParameters, IMU_YAW_RATE_MIN, IMU_YAW_RATE_MAX, RATE_PID_CONTROLLER_OUTPUT_MIN, RATE_PID_CONTROLLER_OUTPUT_MAX); |
joe4465 | 0:c6a85bb2a827 | 16 | _pitchRatePidController.initialise(configFileWrapper.getPitchRateParameters, IMU_PITCH_RATE_MIN, IMU_PITCH_RATE_MAX, RATE_PID_CONTROLLER_OUTPUT_MIN, RATE_PID_CONTROLLER_OUTPUT_MAX); |
joe4465 | 0:c6a85bb2a827 | 17 | _rollRatePidController.initialise(configFileWrapper.getRollRateParameters, IMU_ROLL_RATE_MIN, IMU_ROLL_RATE_MAX, RATE_PID_CONTROLLER_OUTPUT_MIN, RATE_PID_CONTROLLER_OUTPUT_MAX); |
joe4465 | 0:c6a85bb2a827 | 18 | |
joe4465 | 0:c6a85bb2a827 | 19 | DEBUG("Rate controller initialised"); |
joe4465 | 0:c6a85bb2a827 | 20 | return true; |
joe4465 | 0:c6a85bb2a827 | 21 | } |
joe4465 | 0:c6a85bb2a827 | 22 | |
joe4465 | 0:c6a85bb2a827 | 23 | PidWrapper::PidOutputs RateController::compute() |
joe4465 | 0:c6a85bb2a827 | 24 | { |
joe4465 | 0:c6a85bb2a827 | 25 | //Update rate PID process value with gyro rate |
joe4465 | 0:c6a85bb2a827 | 26 | _yawRatePIDController->setProcessValue(_gyroRate[0]); |
joe4465 | 0:c6a85bb2a827 | 27 | _pitchRatePIDController->setProcessValue(_gyroRate[1]); |
joe4465 | 0:c6a85bb2a827 | 28 | _rollRatePIDController->setProcessValue(_gyroRate[2]); |
joe4465 | 0:c6a85bb2a827 | 29 | |
joe4465 | 0:c6a85bb2a827 | 30 | //Update rate PID set point with desired rate from RC |
joe4465 | 0:c6a85bb2a827 | 31 | _yawRatePIDController->setSetPoint(_rcMappedCommands[0]); |
joe4465 | 0:c6a85bb2a827 | 32 | _pitchRatePIDController->setSetPoint(_rcMappedCommands[1]); |
joe4465 | 0:c6a85bb2a827 | 33 | _rollRatePIDController->setSetPoint(_rcMappedCommands[2]); |
joe4465 | 0:c6a85bb2a827 | 34 | |
joe4465 | 0:c6a85bb2a827 | 35 | //Compute rate PID outputs |
joe4465 | 0:c6a85bb2a827 | 36 | _ratePIDControllerOutputs[0] = _yawRatePIDController->compute(); |
joe4465 | 0:c6a85bb2a827 | 37 | _ratePIDControllerOutputs[1] = _pitchRatePIDController->compute(); |
joe4465 | 0:c6a85bb2a827 | 38 | _ratePIDControllerOutputs[2] = _rollRatePIDController->compute(); |
joe4465 | 0:c6a85bb2a827 | 39 | } |