RC_reciever
Dependencies: mbed RC_reciever
main.cpp@1:16b2e229b739, 2012-12-08 (annotated)
- Committer:
- higedura
- Date:
- Sat Dec 08 23:52:11 2012 +0000
- Revision:
- 1:16b2e229b739
- Parent:
- 0:18d415e9d13b
- Child:
- 2:8c428bae83a8
RC_reciever
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
higedura | 1:16b2e229b739 | 1 | #include "mbed.h" |
higedura | 1:16b2e229b739 | 2 | #include "TextLCD.h" |
higedura | 1:16b2e229b739 | 3 | |
higedura | 1:16b2e229b739 | 4 | #define chan 6 // the numbers of channels |
higedura | 1:16b2e229b739 | 5 | |
higedura | 1:16b2e229b739 | 6 | Serial pc(USBTX, USBRX); |
higedura | 1:16b2e229b739 | 7 | DigitalOut led1(LED1); |
higedura | 1:16b2e229b739 | 8 | DigitalOut led2(LED2); |
higedura | 1:16b2e229b739 | 9 | DigitalOut led3(LED3); |
higedura | 1:16b2e229b739 | 10 | DigitalOut led4(LED4); |
higedura | 1:16b2e229b739 | 11 | |
higedura | 1:16b2e229b739 | 12 | Serial xbee(p9,p10); // tx, rx |
higedura | 1:16b2e229b739 | 13 | |
higedura | 1:16b2e229b739 | 14 | InterruptIn ch1(p13); // yaw |
higedura | 1:16b2e229b739 | 15 | InterruptIn ch2(p14); // pitch |
higedura | 1:16b2e229b739 | 16 | InterruptIn ch3(p15); // throttle |
higedura | 1:16b2e229b739 | 17 | InterruptIn ch4(p16); // roll |
higedura | 1:16b2e229b739 | 18 | //InterruptIn ch5(p17); // aux1 |
higedura | 1:16b2e229b739 | 19 | //InterruptIn ch6(p18); // aux2 |
higedura | 1:16b2e229b739 | 20 | /* |
higedura | 1:16b2e229b739 | 21 | InterruptIn ch1(p5); // yaw |
higedura | 1:16b2e229b739 | 22 | InterruptIn ch2(p6); // pitch |
higedura | 1:16b2e229b739 | 23 | InterruptIn ch3(p7); // throttle |
higedura | 1:16b2e229b739 | 24 | InterruptIn ch4(p8); // roll |
higedura | 1:16b2e229b739 | 25 | InterruptIn ch5(p9); // aux1 |
higedura | 1:16b2e229b739 | 26 | InterruptIn ch6(p10); // aux2 |
higedura | 1:16b2e229b739 | 27 | TextLCD lcd(p24, p26, p27, p28, p29, p30); |
higedura | 1:16b2e229b739 | 28 | */ |
higedura | 1:16b2e229b739 | 29 | void thro_up(); void roll_up(); void pitch_up(); void yaw_up(); void aux1_up(); void aux2_up(); |
higedura | 1:16b2e229b739 | 30 | void thro_down(); void roll_down(); void pitch_down(); void yaw_down(); void aux1_down(); void aux2_down(); |
higedura | 1:16b2e229b739 | 31 | |
higedura | 1:16b2e229b739 | 32 | Timer t_thro; Timer t_roll; Timer t_pitch; Timer t_yaw; Timer t_aux1; Timer t_aux2; |
higedura | 1:16b2e229b739 | 33 | |
higedura | 1:16b2e229b739 | 34 | // thro roll pitch yaw aux1 aux2 |
higedura | 1:16b2e229b739 | 35 | int pwm_pulse[chan] = {0, 0, 0, 0, 0, 0}; |
higedura | 1:16b2e229b739 | 36 | |
higedura | 1:16b2e229b739 | 37 | int main() { |
higedura | 1:16b2e229b739 | 38 | |
higedura | 1:16b2e229b739 | 39 | pc.baud(921600); |
higedura | 1:16b2e229b739 | 40 | xbee.baud(115200); |
higedura | 1:16b2e229b739 | 41 | |
higedura | 1:16b2e229b739 | 42 | //lcd.locate(0, 0); lcd.printf("StarBoard Orange"); |
higedura | 1:16b2e229b739 | 43 | //lcd.locate(0, 1); lcd.printf("mbed NXP LPC1768"); |
higedura | 1:16b2e229b739 | 44 | //wait(1); lcd.cls(); |
higedura | 1:16b2e229b739 | 45 | |
higedura | 1:16b2e229b739 | 46 | //xbee.printf("\n\r\n\rRC reciever\n\r"); |
higedura | 1:16b2e229b739 | 47 | |
higedura | 1:16b2e229b739 | 48 | // Reciever function |
higedura | 1:16b2e229b739 | 49 | ch1.rise(&yaw_up); ch1.fall(&yaw_down); |
higedura | 1:16b2e229b739 | 50 | ch2.rise(&pitch_up); ch2.fall(&pitch_down); |
higedura | 1:16b2e229b739 | 51 | ch3.rise(&thro_up); ch3.fall(&thro_down); |
higedura | 1:16b2e229b739 | 52 | ch4.rise(&roll_up); ch4.fall(&roll_down); |
higedura | 1:16b2e229b739 | 53 | //ch5.rise(&aux1_up); ch5.fall(&aux1_down); |
higedura | 1:16b2e229b739 | 54 | //ch6.rise(&aux2_up); ch6.fall(&aux2_down); |
higedura | 1:16b2e229b739 | 55 | |
higedura | 1:16b2e229b739 | 56 | while(1) { |
higedura | 1:16b2e229b739 | 57 | |
higedura | 1:16b2e229b739 | 58 | for( int i=0;i<4;i++ ){ xbee.printf("%d ", pwm_pulse[i]); } |
higedura | 1:16b2e229b739 | 59 | xbee.printf("\r\n\r\n"); |
higedura | 1:16b2e229b739 | 60 | |
higedura | 1:16b2e229b739 | 61 | //for( int i=0;i<4;i++ ){ pc.printf("%d ", pwm_pulse[i]); } |
higedura | 1:16b2e229b739 | 62 | //pc.printf("\r\n\r\n"); |
higedura | 1:16b2e229b739 | 63 | |
higedura | 1:16b2e229b739 | 64 | //lcd.locate(0, 0); |
higedura | 1:16b2e229b739 | 65 | //lcd.printf("%4d %4d %4d",pwm_pulse[0], pwm_pulse[1], pwm_pulse[2]); |
higedura | 1:16b2e229b739 | 66 | //lcd.locate(0, 1); |
higedura | 1:16b2e229b739 | 67 | //lcd.printf("%4d %4d %4d",pwm_pulse[3], pwm_pulse[4], pwm_pulse[5]); |
higedura | 1:16b2e229b739 | 68 | //lcd.cls(); |
higedura | 1:16b2e229b739 | 69 | |
higedura | 1:16b2e229b739 | 70 | wait(.1); |
higedura | 1:16b2e229b739 | 71 | |
higedura | 1:16b2e229b739 | 72 | } |
higedura | 1:16b2e229b739 | 73 | } |
higedura | 1:16b2e229b739 | 74 | |
higedura | 1:16b2e229b739 | 75 | void thro_up(){ t_thro.start(); } |
higedura | 1:16b2e229b739 | 76 | void roll_up(){ t_roll.start(); } |
higedura | 1:16b2e229b739 | 77 | void pitch_up(){ t_pitch.start(); } |
higedura | 1:16b2e229b739 | 78 | void yaw_up(){ t_yaw.start(); } |
higedura | 1:16b2e229b739 | 79 | //void aux1_up(){ t_aux1.start(); } |
higedura | 1:16b2e229b739 | 80 | //void aux2_up(){ t_aux2.start(); } |
higedura | 1:16b2e229b739 | 81 | |
higedura | 1:16b2e229b739 | 82 | void thro_down(){ |
higedura | 1:16b2e229b739 | 83 | t_thro.stop(); |
higedura | 1:16b2e229b739 | 84 | pwm_pulse[0] = (int)(t_thro.read()*1000000-1000); |
higedura | 1:16b2e229b739 | 85 | t_thro.reset(); |
higedura | 1:16b2e229b739 | 86 | } |
higedura | 1:16b2e229b739 | 87 | |
higedura | 1:16b2e229b739 | 88 | void roll_down(){ |
higedura | 1:16b2e229b739 | 89 | t_roll.stop(); |
higedura | 1:16b2e229b739 | 90 | pwm_pulse[1] = (int)(t_roll.read()*1000000-1000); |
higedura | 1:16b2e229b739 | 91 | t_roll.reset(); |
higedura | 1:16b2e229b739 | 92 | } |
higedura | 1:16b2e229b739 | 93 | |
higedura | 1:16b2e229b739 | 94 | void pitch_down(){ |
higedura | 1:16b2e229b739 | 95 | t_pitch.stop(); |
higedura | 1:16b2e229b739 | 96 | pwm_pulse[2] = (int)(t_pitch.read()*1000000-1000); |
higedura | 1:16b2e229b739 | 97 | t_pitch.reset(); |
higedura | 1:16b2e229b739 | 98 | } |
higedura | 1:16b2e229b739 | 99 | |
higedura | 1:16b2e229b739 | 100 | void yaw_down(){ |
higedura | 1:16b2e229b739 | 101 | t_yaw.stop(); |
higedura | 1:16b2e229b739 | 102 | pwm_pulse[3] = (int)(t_yaw.read()*1000000-1000); |
higedura | 1:16b2e229b739 | 103 | t_yaw.reset(); |
higedura | 1:16b2e229b739 | 104 | } |
higedura | 1:16b2e229b739 | 105 | /* |
higedura | 1:16b2e229b739 | 106 | void aux1_down(){ |
higedura | 1:16b2e229b739 | 107 | t_aux1.stop(); |
higedura | 1:16b2e229b739 | 108 | pwm_pulse[4] = (int)(t_aux1.read()*1000000-1000); |
higedura | 1:16b2e229b739 | 109 | t_aux1.reset(); |
higedura | 1:16b2e229b739 | 110 | } |
higedura | 1:16b2e229b739 | 111 | |
higedura | 1:16b2e229b739 | 112 | void aux2_down(){ |
higedura | 1:16b2e229b739 | 113 | t_aux2.stop(); |
higedura | 1:16b2e229b739 | 114 | pwm_pulse[5] = (int)(t_aux2.read()*1000000-1000); |
higedura | 1:16b2e229b739 | 115 | t_aux2.reset(); |
higedura | 1:16b2e229b739 | 116 | } |
higedura | 1:16b2e229b739 | 117 | */ |