Ian Hua / Quadcopter-mbedRTOS
Committer:
pHysiX
Date:
Wed Apr 30 07:13:11 2014 +0000
Revision:
5:4879ef0e6d41
Parent:
3:605fbcb54e75
Child:
7:3d28cfc4901b
Fixed bug with gyro and plane axis, added in corrected PID SP and PV

Who changed what in which revision?

UserRevisionLine numberNew contents of line
pHysiX 2:ab967d7b4346 1 /* PID */
pHysiX 2:ab967d7b4346 2
pHysiX 1:43f8ac7ca6d7 3 #include "Task2.h"
pHysiX 1:43f8ac7ca6d7 4 #include "setup.h"
pHysiX 3:605fbcb54e75 5 #include "PID.h"
pHysiX 3:605fbcb54e75 6
pHysiX 3:605fbcb54e75 7 int yaw_adjust = 0;
pHysiX 3:605fbcb54e75 8 int pitch_adjust = 0;
pHysiX 3:605fbcb54e75 9 int roll_adjust = 0;
pHysiX 3:605fbcb54e75 10
pHysiX 3:605fbcb54e75 11 int16_t gx, gy, gz;
pHysiX 1:43f8ac7ca6d7 12
pHysiX 1:43f8ac7ca6d7 13 void Task2(void const *argument)
pHysiX 1:43f8ac7ca6d7 14 {
pHysiX 5:4879ef0e6d41 15 yawPIDrate.setSetPoint((RCCommand[0]-1500)*9/10);
pHysiX 5:4879ef0e6d41 16 pitchPIDrate.setSetPoint((RCCommand[1]-1500)*-1*9/10);
pHysiX 5:4879ef0e6d41 17 rollPIDrate.setSetPoint((RCCommand[2]-1500)*9/10);
pHysiX 5:4879ef0e6d41 18
pHysiX 3:605fbcb54e75 19 imu.getRotation(&gx, &gy, &gz);
pHysiX 3:605fbcb54e75 20 gx /= 32.8;
pHysiX 5:4879ef0e6d41 21 gx += 2;
pHysiX 3:605fbcb54e75 22 gy /= 32.8;
pHysiX 3:605fbcb54e75 23 gz /= 32.8;
pHysiX 5:4879ef0e6d41 24
pHysiX 5:4879ef0e6d41 25 if (gyro_out)
pHysiX 5:4879ef0e6d41 26 BT.printf("%4d %4d %4d\n", gx, gy, gz);
pHysiX 5:4879ef0e6d41 27
pHysiX 3:605fbcb54e75 28 yawPIDrate.setProcessValue(gz);
pHysiX 3:605fbcb54e75 29 pitchPIDrate.setProcessValue(gy);
pHysiX 5:4879ef0e6d41 30 rollPIDrate.setProcessValue(gx);
pHysiX 5:4879ef0e6d41 31
pHysiX 3:605fbcb54e75 32 yaw_adjust = yawPIDrate.compute();
pHysiX 3:605fbcb54e75 33 pitch_adjust = pitchPIDrate.compute();
pHysiX 3:605fbcb54e75 34 roll_adjust = rollPIDrate.compute();
pHysiX 5:4879ef0e6d41 35
pHysiX 2:ab967d7b4346 36 //LED[2] = !LED[2];
pHysiX 1:43f8ac7ca6d7 37 }