Read IMU data at Serial port (p28, p27), data rate <100Hz @115200bps Read 5 channels PPM signal at p11 using InterruptIn Send data via RF Modem at serial port (p13, p14) in 36Hz @115200 Drive i2C motor speed controller at I2C port (p9, p10) in every 10mS (control loop delay time)

Dependencies:   mbed

rc.h

Committer:
agiembed
Date:
2010-08-12
Revision:
0:bd282c11d296

File content as of revision 0:bd282c11d296:

Timer tick;
InterruptIn rc(p11);
short buf_ppm[6];
char i = 0, idx, cnt = 0;


void get_PPM(){
    switch (idx){
        case 1:
            RC.roll = buf_ppm[2];
            RC.throttle = buf_ppm[3];
            RC.pitch = buf_ppm[4];
            RC.yaw = buf_ppm[5];
            RC.sw = buf_ppm[0];
            break;
            
        case 2:
            RC.roll = buf_ppm[3];
            RC.throttle = buf_ppm[4];
            RC.pitch = buf_ppm[5];
            RC.yaw = buf_ppm[0];
            RC.sw = buf_ppm[1];
            break;
            
        case 3:
            RC.roll = buf_ppm[4];
            RC.throttle = buf_ppm[5];
            RC.pitch = buf_ppm[0];
            RC.yaw = buf_ppm[1];
            RC.sw = buf_ppm[2];
            break;
            
        case 4:           
            RC.roll = buf_ppm[5];
            RC.throttle = buf_ppm[0];
            RC.pitch = buf_ppm[1];
            RC.yaw = buf_ppm[2];
            RC.sw = buf_ppm[3];
            break;
            
        case 5:            
            RC.roll = buf_ppm[0];
            RC.throttle = buf_ppm[1];
            RC.pitch = buf_ppm[2];
            RC.yaw = buf_ppm[3];
            RC.sw = buf_ppm[4];
            break;
            
        case 0:            
            RC.roll = buf_ppm[1];
            RC.throttle = buf_ppm[2];
            RC.pitch = buf_ppm[3];
            RC.yaw = buf_ppm[4];
            RC.sw = buf_ppm[5];
            break;
            
        default: break;  
    }           
    test = buf_ppm[2];
    if(cnt<100)test1 = test;
    return;
}                                                                 



void gets_PPM(){
    test = buf_ppm[2];
    if(cnt<100)test1 = test;
    //eyetosee(); 
}    

void PPM_rise() {
    tick.stop();                        // Stop timer
    buf_ppm[i]=tick.read_us();          // Read timer to buffer[i] i=turns
    tick.reset();                       // Reset timer
    i++;                                // increment i.
    if(buf_ppm[i]>5000) idx = i;    
    if(i==6) i = 0; 
    get_PPM();
    cnt++;
    if(cnt>200) cnt = 200;
    tick.start();  
}


/*
Channel 1 = Roll  
Channel 2 = Throttle
Channel 3 = Pitch
Channel 4 = Yaw   
Channel 5 = Switch 
*/