![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Remote control code for https://developer.mbed.org/users/ivo_david_michelle/code/QuadTrio/
Dependencies: Analog_Joystick Sender mbed
Fork of ESE350-Whack-a-Mole by
rc.cpp@7:8714628b62e5, 2016-03-31 (annotated)
- Committer:
- ivo_david_michelle
- Date:
- Thu Mar 31 22:41:19 2016 +0000
- Revision:
- 7:8714628b62e5
- Parent:
- 6:db985df4354b
- Child:
- 8:ff7cd3525c32
milestone - remote control sends four degrees of freedom
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ivo_david_michelle | 7:8714628b62e5 | 1 | #include "mbed.h" |
ivo_david_michelle | 5:3ad830e95ffd | 2 | #include "MRF24J40.h" |
ivo_david_michelle | 5:3ad830e95ffd | 3 | #include "sender.h" |
ivo_david_michelle | 5:3ad830e95ffd | 4 | #include "analog_joystick.h" |
ivo_david_michelle | 5:3ad830e95ffd | 5 | |
ivo_david_michelle | 7:8714628b62e5 | 6 | #include <string.h> |
ivo_david_michelle | 5:3ad830e95ffd | 7 | |
ivo_david_michelle | 5:3ad830e95ffd | 8 | // RF tranceiver to link with handheld. |
ivo_david_michelle | 5:3ad830e95ffd | 9 | MRF24J40 mrf(p11, p12, p13, p14, p21); |
ivo_david_michelle | 5:3ad830e95ffd | 10 | |
ivo_david_michelle | 5:3ad830e95ffd | 11 | // LEDs you can treat these as variables (led2 = 1 will turn led2 on!) |
ivo_david_michelle | 5:3ad830e95ffd | 12 | DigitalOut led1(LED1); |
ivo_david_michelle | 5:3ad830e95ffd | 13 | DigitalOut led2(LED2); |
ivo_david_michelle | 5:3ad830e95ffd | 14 | DigitalOut led3(LED3); |
ivo_david_michelle | 5:3ad830e95ffd | 15 | DigitalOut led4(LED4); |
ivo_david_michelle | 5:3ad830e95ffd | 16 | |
ivo_david_michelle | 5:3ad830e95ffd | 17 | // Timer |
ivo_david_michelle | 5:3ad830e95ffd | 18 | Timer timer; |
ivo_david_michelle | 5:3ad830e95ffd | 19 | |
ivo_david_michelle | 5:3ad830e95ffd | 20 | // Serial port for showing RX data. |
ivo_david_michelle | 5:3ad830e95ffd | 21 | Serial pc(USBTX, USBRX); |
ivo_david_michelle | 5:3ad830e95ffd | 22 | |
ivo_david_michelle | 7:8714628b62e5 | 23 | int iterations = 100; |
ivo_david_michelle | 5:3ad830e95ffd | 24 | |
ivo_david_michelle | 5:3ad830e95ffd | 25 | //***************** send and receive methods *****************// |
ivo_david_michelle | 5:3ad830e95ffd | 26 | /* |
ivo_david_michelle | 5:3ad830e95ffd | 27 | void wait_for_ping(uint8_t length) { |
ivo_david_michelle | 5:3ad830e95ffd | 28 | int receive = 0; |
ivo_david_michelle | 5:3ad830e95ffd | 29 | uint8_t *rssi = 0; |
ivo_david_michelle | 7:8714628b62e5 | 30 | |
ivo_david_michelle | 5:3ad830e95ffd | 31 | while (receive == 0) { |
ivo_david_michelle | 5:3ad830e95ffd | 32 | receive = rf_receive_rssi(rxBuffer, rssi, length); |
ivo_david_michelle | 5:3ad830e95ffd | 33 | } |
ivo_david_michelle | 5:3ad830e95ffd | 34 | } |
ivo_david_michelle | 5:3ad830e95ffd | 35 | */ |
ivo_david_michelle | 5:3ad830e95ffd | 36 | |
ivo_david_michelle | 5:3ad830e95ffd | 37 | |
ivo_david_michelle | 5:3ad830e95ffd | 38 | //***************** main loop *****************// |
ivo_david_michelle | 5:3ad830e95ffd | 39 | |
ivo_david_michelle | 7:8714628b62e5 | 40 | int main (void) { |
ivo_david_michelle | 5:3ad830e95ffd | 41 | uint8_t channel = 3; |
ivo_david_michelle | 5:3ad830e95ffd | 42 | |
ivo_david_michelle | 5:3ad830e95ffd | 43 | //Set the Channel. 0 is default, 15 is max |
ivo_david_michelle | 5:3ad830e95ffd | 44 | mrf.SetChannel(channel); |
ivo_david_michelle | 5:3ad830e95ffd | 45 | |
ivo_david_michelle | 5:3ad830e95ffd | 46 | //Start the timer |
ivo_david_michelle | 5:3ad830e95ffd | 47 | timer.start(); |
ivo_david_michelle | 7:8714628b62e5 | 48 | |
ivo_david_michelle | 5:3ad830e95ffd | 49 | pc.printf("START\r\n"); |
ivo_david_michelle | 7:8714628b62e5 | 50 | |
ivo_david_michelle | 7:8714628b62e5 | 51 | // send_three_way_handshake(); |
ivo_david_michelle | 6:db985df4354b | 52 | |
ivo_david_michelle | 7:8714628b62e5 | 53 | int i; |
ivo_david_michelle | 7:8714628b62e5 | 54 | char txBuffer[50]; |
ivo_david_michelle | 5:3ad830e95ffd | 55 | |
ivo_david_michelle | 7:8714628b62e5 | 56 | for (i = 0; i < iterations; i++) { |
ivo_david_michelle | 7:8714628b62e5 | 57 | sprintf(txBuffer, "%f,%f,%f,%f", read_thrust(), read_yaw(), read_pitch(), read_roll()); |
ivo_david_michelle | 5:3ad830e95ffd | 58 | rf_send(mrf, txBuffer, strlen(txBuffer) + 1); |
ivo_david_michelle | 5:3ad830e95ffd | 59 | pc.printf("RC Sent: %s \r\n", txBuffer); |
ivo_david_michelle | 7:8714628b62e5 | 60 | |
ivo_david_michelle | 7:8714628b62e5 | 61 | wait(0.2); // TODO: change this value? |
ivo_david_michelle | 5:3ad830e95ffd | 62 | } |
ivo_david_michelle | 7:8714628b62e5 | 63 | |
ivo_david_michelle | 5:3ad830e95ffd | 64 | pc.printf("END\r\n"); |
ivo_david_michelle | 5:3ad830e95ffd | 65 | } |