Ian Hua / Quadcopter-mbedRTOS

RTOS-Threads/src/Task3.cpp

Committer:
pHysiX
Date:
2014-04-30
Revision:
4:01921a136f58
Parent:
3:605fbcb54e75
Child:
5:4879ef0e6d41

File content as of revision 4:01921a136f58:

/* RC Command (50Hz) */

#include "tasks.h"
#include "setup.h"
#include "PwmIn.h"

float ypr_offset[3];
bool box_demo = false;

PwmIn rxModule[] = {p14, p15, p16, p17, p18};

/* [YAW PITCH ROLL THROTTLE AUX] */
int RCCommand[5] = {0, 0, 0, 0, 0};

void Task3(void const *argument)
{
    if (BT.readable()) {
        char data = BT.getc();
        if (data == 'B') {
            box_demo = true;
        } else if (data == 'Z') {
            ypr_offset[0] = ypr[0];
            ypr_offset[1] = ypr[1];
            ypr_offset[2] = ypr[2];
        } else if (data == 'O') {
            box_demo = false;
        }
    }
    RCCommand[0] = rxModule[0].pulsewidth();
    RCCommand[1] = rxModule[1].pulsewidth();
    RCCommand[2] = rxModule[2].pulsewidth();
    RCCommand[3] = rxModule[3].pulsewidth();

    if (rxModule[1].stallTimer.read_us() > 18900) {
        for (int i = 0; i < 4; i++)
            RCCommand[i] = 0;
    }
    
    //BT.printf("%5d %5d %5d %5d\n", RCCommand[0], RCCommand[1], RCCommand[2], RCCommand[3]);

    //LED[3] = !LED[3];
}