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.
RTOS-Threads/src/Task2.cpp@22:ef8aa9728013, 2014-05-08 (annotated)
- Committer:
- pHysiX
- Date:
- Thu May 08 10:33:43 2014 +0000
- Revision:
- 22:ef8aa9728013
- Parent:
- 21:b642c18eccd1
- Child:
- 24:54a8cdf17378
Commented and tidied entire code for release
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
pHysiX | 22:ef8aa9728013 | 1 | /* File: Task2.cpp |
pHysiX | 22:ef8aa9728013 | 2 | * Author: Trung Tin Ian HUA |
pHysiX | 22:ef8aa9728013 | 3 | * Date: May 2014 |
pHysiX | 22:ef8aa9728013 | 4 | * Purpose: Thread2: Gyro sample and PID Control loop |
pHysiX | 22:ef8aa9728013 | 5 | * Settings: 200Hz |
pHysiX | 22:ef8aa9728013 | 6 | */ |
pHysiX | 2:ab967d7b4346 | 7 | |
pHysiX | 1:43f8ac7ca6d7 | 8 | #include "Task2.h" |
pHysiX | 1:43f8ac7ca6d7 | 9 | #include "setup.h" |
pHysiX | 3:605fbcb54e75 | 10 | #include "PID.h" |
pHysiX | 3:605fbcb54e75 | 11 | |
pHysiX | 21:b642c18eccd1 | 12 | /* YPR Adjust */ |
pHysiX | 21:b642c18eccd1 | 13 | volatile float adjust[3] = {0.0, 0.0, 0.0}; |
pHysiX | 21:b642c18eccd1 | 14 | volatile float adjust_stable[3] = {0.0, 0.0, 0.0}; |
pHysiX | 21:b642c18eccd1 | 15 | |
pHysiX | 3:605fbcb54e75 | 16 | int16_t gx, gy, gz; |
pHysiX | 10:ef5fe86f67fe | 17 | volatile int gyro[3] = {0, 0, 0}; |
pHysiX | 10:ef5fe86f67fe | 18 | |
pHysiX | 10:ef5fe86f67fe | 19 | bool counterESC = false; |
pHysiX | 1:43f8ac7ca6d7 | 20 | |
pHysiX | 1:43f8ac7ca6d7 | 21 | void Task2(void const *argument) |
pHysiX | 1:43f8ac7ca6d7 | 22 | { |
pHysiX | 21:b642c18eccd1 | 23 | imu.getRotation(&gx, &gy, &gz); |
pHysiX | 21:b642c18eccd1 | 24 | gyro[0] = gx + 60; |
pHysiX | 21:b642c18eccd1 | 25 | gyro[1] = gy - 15; |
pHysiX | 21:b642c18eccd1 | 26 | gyro[2] = gz + 25; |
pHysiX | 17:18c3bd016e49 | 27 | |
pHysiX | 21:b642c18eccd1 | 28 | for (int i = 0; i < 3; i++) |
pHysiX | 21:b642c18eccd1 | 29 | gyro[i] /= (float) 32.8; |
pHysiX | 17:18c3bd016e49 | 30 | |
pHysiX | 21:b642c18eccd1 | 31 | //if (counterTask1) { |
pHysiX | 21:b642c18eccd1 | 32 | pitchPIDstable.setSetPoint(inputYPR[1]); |
pHysiX | 21:b642c18eccd1 | 33 | rollPIDstable.setSetPoint(inputYPR[2]); |
pHysiX | 17:18c3bd016e49 | 34 | |
pHysiX | 21:b642c18eccd1 | 35 | pitchPIDstable.setProcessValue(ypr[1] - ypr_offset[1]); |
pHysiX | 21:b642c18eccd1 | 36 | rollPIDstable.setProcessValue(ypr[2] - ypr_offset[2]); |
pHysiX | 17:18c3bd016e49 | 37 | |
pHysiX | 21:b642c18eccd1 | 38 | adjust_stable[1] = pitchPIDstable.compute(); |
pHysiX | 21:b642c18eccd1 | 39 | adjust_stable[2] = rollPIDstable.compute(); |
pHysiX | 17:18c3bd016e49 | 40 | |
pHysiX | 21:b642c18eccd1 | 41 | yawPIDrate.setSetPoint(inputYPR[0]); |
pHysiX | 21:b642c18eccd1 | 42 | pitchPIDrate.setSetPoint(inputYPR[1]); |
pHysiX | 21:b642c18eccd1 | 43 | rollPIDrate.setSetPoint(inputYPR[2]); |
pHysiX | 21:b642c18eccd1 | 44 | //pitchPIDrate.setSetPoint(adjust_stable[1]); |
pHysiX | 21:b642c18eccd1 | 45 | //rollPIDrate.setSetPoint(adjust_stable[2]); |
pHysiX | 5:4879ef0e6d41 | 46 | |
pHysiX | 10:ef5fe86f67fe | 47 | yawPIDrate.setProcessValue(gyro[2]); |
pHysiX | 10:ef5fe86f67fe | 48 | pitchPIDrate.setProcessValue(gyro[1]); |
pHysiX | 10:ef5fe86f67fe | 49 | rollPIDrate.setProcessValue(gyro[0]); |
pHysiX | 5:4879ef0e6d41 | 50 | |
pHysiX | 21:b642c18eccd1 | 51 | adjust[0] = yawPIDrate.compute(); |
pHysiX | 21:b642c18eccd1 | 52 | adjust[1] = pitchPIDrate.compute(); |
pHysiX | 21:b642c18eccd1 | 53 | adjust[2] = rollPIDrate.compute(); |
pHysiX | 21:b642c18eccd1 | 54 | |
pHysiX | 21:b642c18eccd1 | 55 | counterTask1 = false; |
pHysiX | 5:4879ef0e6d41 | 56 | |
pHysiX | 10:ef5fe86f67fe | 57 | counterESC = true; |
pHysiX | 11:f9fd410c48c2 | 58 | |
pHysiX | 21:b642c18eccd1 | 59 | if (adjust_check) |
pHysiX | 21:b642c18eccd1 | 60 | BT.printf("%3.4f %3.4f %3.4f\n", adjust[0], adjust[1], adjust[2]); |
pHysiX | 21:b642c18eccd1 | 61 | |
pHysiX | 10:ef5fe86f67fe | 62 | if (gyro_out) |
pHysiX | 21:b642c18eccd1 | 63 | BT.printf("%3d %3d %3d\n", (int) gyro[0], (int) gyro[1], (int) gyro[2]); |
pHysiX | 21:b642c18eccd1 | 64 | } |