![](/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@10:8981152753a6, 2016-05-01 (annotated)
- Committer:
- ivo_david_michelle
- Date:
- Sun May 01 21:58:57 2016 +0000
- Revision:
- 10:8981152753a6
- Parent:
- 9:2a3b3e067847
calibrate remote control
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 | 9:2a3b3e067847 | 23 | int main (void) |
ivo_david_michelle | 9:2a3b3e067847 | 24 | { |
ivo_david_michelle | 9:2a3b3e067847 | 25 | long long id = 0; |
ivo_david_michelle | 5:3ad830e95ffd | 26 | uint8_t channel = 3; |
ivo_david_michelle | 5:3ad830e95ffd | 27 | |
ivo_david_michelle | 5:3ad830e95ffd | 28 | //Set the Channel. 0 is default, 15 is max |
ivo_david_michelle | 5:3ad830e95ffd | 29 | mrf.SetChannel(channel); |
ivo_david_michelle | 5:3ad830e95ffd | 30 | |
ivo_david_michelle | 5:3ad830e95ffd | 31 | //Start the timer |
ivo_david_michelle | 5:3ad830e95ffd | 32 | timer.start(); |
ivo_david_michelle | 7:8714628b62e5 | 33 | |
ivo_david_michelle | 5:3ad830e95ffd | 34 | pc.printf("START\r\n"); |
ivo_david_michelle | 7:8714628b62e5 | 35 | |
ivo_david_michelle | 9:2a3b3e067847 | 36 | char txBuffer[250]; |
ivo_david_michelle | 6:db985df4354b | 37 | |
ivo_david_michelle | 10:8981152753a6 | 38 | |
ivo_david_michelle | 10:8981152753a6 | 39 | float thrustOffset =0; |
ivo_david_michelle | 10:8981152753a6 | 40 | float rollOffset =0; |
ivo_david_michelle | 10:8981152753a6 | 41 | float pitchOffset =0; |
ivo_david_michelle | 10:8981152753a6 | 42 | float yawOffset =0; |
ivo_david_michelle | 10:8981152753a6 | 43 | |
ivo_david_michelle | 10:8981152753a6 | 44 | int nSamples = 100; |
ivo_david_michelle | 10:8981152753a6 | 45 | |
ivo_david_michelle | 10:8981152753a6 | 46 | for (int n = 0; n < nSamples; n++) { |
ivo_david_michelle | 10:8981152753a6 | 47 | thrustOffset += read_thrust(); |
ivo_david_michelle | 10:8981152753a6 | 48 | yawOffset += read_yaw(); |
ivo_david_michelle | 10:8981152753a6 | 49 | pitchOffset += read_pitch(); |
ivo_david_michelle | 10:8981152753a6 | 50 | rollOffset += read_roll(); |
ivo_david_michelle | 10:8981152753a6 | 51 | |
ivo_david_michelle | 10:8981152753a6 | 52 | } |
ivo_david_michelle | 10:8981152753a6 | 53 | thrustOffset /= nSamples; |
ivo_david_michelle | 10:8981152753a6 | 54 | yawOffset /= nSamples; |
ivo_david_michelle | 10:8981152753a6 | 55 | pitchOffset /= nSamples; |
ivo_david_michelle | 10:8981152753a6 | 56 | rollOffset /= nSamples; |
ivo_david_michelle | 10:8981152753a6 | 57 | |
ivo_david_michelle | 10:8981152753a6 | 58 | |
ivo_david_michelle | 9:2a3b3e067847 | 59 | while(1) { |
ivo_david_michelle | 10:8981152753a6 | 60 | sprintf(txBuffer, "%lld,%f,%f,%f,%f", id, read_thrust()-thrustOffset, read_yaw()-yawOffset, read_pitch()-pitchOffset, read_roll()-rollOffset); |
ivo_david_michelle | 5:3ad830e95ffd | 61 | rf_send(mrf, txBuffer, strlen(txBuffer) + 1); |
ivo_david_michelle | 5:3ad830e95ffd | 62 | pc.printf("RC Sent: %s \r\n", txBuffer); |
ivo_david_michelle | 7:8714628b62e5 | 63 | |
ivo_david_michelle | 9:2a3b3e067847 | 64 | id++; |
ivo_david_michelle | 5:3ad830e95ffd | 65 | } |
ivo_david_michelle | 5:3ad830e95ffd | 66 | } |