Test program for my PPM library.
Connect the PPM input to pin 5 of your mbed, the result of each channel will be printed over serial at 115200.
My channel mapping, yours will be different
- Channel 1 is roll. min 1000. max 1900
- Channel 2 is pitch. min 1000. max 1900
- Channel 3 is throttle < 900 when not connected. min 1000. max 1900
- Channel 4 is yaw. min 1000. max 1900
- Channel 5 is arm. armed > 1800 else unarmed
- Channel 6 is mode. rate > 1800. stab < 1100. else error
- Channel 7 is spare
- Channel 8 is spare
main.cpp@0:20458b362896, 2014-08-26 (annotated)
- Committer:
- joe4465
- Date:
- Tue Aug 26 15:58:19 2014 +0000
- Revision:
- 0:20458b362896
Test program for my PPM library.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
joe4465 | 0:20458b362896 | 1 | #include "mbed.h" |
joe4465 | 0:20458b362896 | 2 | #include "PPM.h" |
joe4465 | 0:20458b362896 | 3 | |
joe4465 | 0:20458b362896 | 4 | //My channel mapping, yours will be different |
joe4465 | 0:20458b362896 | 5 | //Channel 1 is roll. min 1000. max 1900 |
joe4465 | 0:20458b362896 | 6 | //Channel 2 is pitch. min 1000. max 1900 |
joe4465 | 0:20458b362896 | 7 | //Channel 3 is throttle < 900 when not connected. min 1000. max 1900 |
joe4465 | 0:20458b362896 | 8 | //Channel 4 is yaw. min 1000. max 1900 |
joe4465 | 0:20458b362896 | 9 | //Channel 5 is arm. armed > 1800 else unarmed |
joe4465 | 0:20458b362896 | 10 | //Channel 6 is mode. rate > 1800. stab < 1100. else error |
joe4465 | 0:20458b362896 | 11 | //Channel 7 is spare |
joe4465 | 0:20458b362896 | 12 | //Channel 8 is spare |
joe4465 | 0:20458b362896 | 13 | |
joe4465 | 0:20458b362896 | 14 | //PPM object |
joe4465 | 0:20458b362896 | 15 | PPM *_ppm; |
joe4465 | 0:20458b362896 | 16 | //InterruptIn pin (p5) |
joe4465 | 0:20458b362896 | 17 | InterruptIn *_interruptPin = new InterruptIn(p5); |
joe4465 | 0:20458b362896 | 18 | //Connection to the PC |
joe4465 | 0:20458b362896 | 19 | Serial pc(USBTX, USBRX); |
joe4465 | 0:20458b362896 | 20 | |
joe4465 | 0:20458b362896 | 21 | int main() |
joe4465 | 0:20458b362896 | 22 | { |
joe4465 | 0:20458b362896 | 23 | //Create instance of PPM class |
joe4465 | 0:20458b362896 | 24 | //Pass in interrupt pin, minimum output value, maximum output value, minimum pulse time from transmitter, maximum pulse time from transmitter, number of channels, throttle channel (used for failsafe) |
joe4465 | 0:20458b362896 | 25 | _ppm = new PPM(_interruptPin, 0, 1, 1000, 1900, 8, 3); |
joe4465 | 0:20458b362896 | 26 | |
joe4465 | 0:20458b362896 | 27 | //Setup serial connection |
joe4465 | 0:20458b362896 | 28 | pc.baud(115200); |
joe4465 | 0:20458b362896 | 29 | |
joe4465 | 0:20458b362896 | 30 | //Loop, printing data |
joe4465 | 0:20458b362896 | 31 | while(true) |
joe4465 | 0:20458b362896 | 32 | { |
joe4465 | 0:20458b362896 | 33 | //Array to hold RC commands |
joe4465 | 0:20458b362896 | 34 | float rcCommands[8] = {0,0,0,0,0,0,0,0}; |
joe4465 | 0:20458b362896 | 35 | |
joe4465 | 0:20458b362896 | 36 | //Get channel data (mapped to between 0 and 1 as I passed these in as my max and min in the PPM constructor) |
joe4465 | 0:20458b362896 | 37 | //The throttle channel will return -1 if the signal from the transmitter is lost (the throttle pulse time goes below the minimum pulse time passed into the PPM constructor) |
joe4465 | 0:20458b362896 | 38 | _ppm->GetChannelData(rcCommands); |
joe4465 | 0:20458b362896 | 39 | |
joe4465 | 0:20458b362896 | 40 | |
joe4465 | 0:20458b362896 | 41 | printf("%f, %f, %f, %f, %f, %f, %f, %f\r\n", rcCommands[0], rcCommands[1], rcCommands[2], rcCommands[3], rcCommands[4], rcCommands[5], rcCommands[6], rcCommands[7]); |
joe4465 | 0:20458b362896 | 42 | |
joe4465 | 0:20458b362896 | 43 | //Wait 1 so the data can be read |
joe4465 | 0:20458b362896 | 44 | wait(1); |
joe4465 | 0:20458b362896 | 45 | } |
joe4465 | 0:20458b362896 | 46 | } |