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_Slave.cpp
- Committer:
- pHysiX
- Date:
- 2014-05-12
- Revision:
- 33:f88a6ee18103
- Parent:
- 32:7a9be7761c46
- Child:
- 34:228d87c45151
File content as of revision 33:f88a6ee18103:
/* File: Task2_Slave.cpp * Author: Trung Tin Ian HUA * Date: May 2014 * Purpose: Thread2S: Gyro sample and Slave PID control loop (rate) * Settings: 200Hz * Timing: 290us */ #include "Task2_Slave.h" #include "setup.h" #include "PID.h" /* YPR Adjust */ volatile float adjust[3] = {0.0, 0.0, 0.0}; int16_t gx, gy, gz; volatile int gyro[3] = {0, 0, 0}; bool counterESC = false; //Timer void Task2_Slave(void const *argument) { //Timer imu.getRotation(&gx, &gy, &gz); gyro[0] = gx + 60; gyro[1] = gy - 15; gyro[2] = gz + 25; for (int i = 0; i < 3; i++) gyro[i] /= (float) 32.8; //Timer if (armed) { yawPIDrate.setSetPoint(inputYPR[0]); switch (mode) { case RATE: pitchPIDrate.setSetPoint(inputYPR[1]); rollPIDrate.setSetPoint(inputYPR[2]); yawPIDrate.setProcessValue(gyro[2]); pitchPIDrate.setProcessValue(gyro[1]); rollPIDrate.setProcessValue(gyro[0]); adjust[0] = yawPIDrate.compute(); adjust[1] = pitchPIDrate.compute(); adjust[2] = rollPIDrate.compute(); counterESC = true; break; case ATTITUDE: default: pitchPIDrate.setSetPoint(adjust_attitude[1]); rollPIDrate.setSetPoint(adjust_attitude[2]); yawPIDrate.setProcessValue(gyro[2]); pitchPIDrate.setProcessValue(gyro[1]); rollPIDrate.setProcessValue(gyro[0]); adjust[0] = yawPIDrate.compute(); adjust[1] = pitchPIDrate.compute(); adjust[2] = rollPIDrate.compute(); counterESC = true; break; } //Timer /* Telemetry output: */ if (adjust_check) BT.printf("%3.2f %3.2f %3.2f\n", adjust[0], adjust[1], adjust[2]); } if (gyro_out) BT.printf("%3d %3d %3d\n", (int) gyro[0], (int) gyro[1], (int) gyro[2]); //Timer } // ======================== // === Helper functions === // ========================