First version of my PPM library.
Dependents: PPM_Test QuadCopter Quadcopter_mk2
Have a look at PPM_Test to see how this library is used.
Import programPPM_Test
Test program for my PPM library.
Ppm.h@3:d13b9e50312f, 2015-04-01 (annotated)
- Committer:
- joe4465
- Date:
- Wed Apr 01 11:18:23 2015 +0000
- Revision:
- 3:d13b9e50312f
- Parent:
- 2:b67f18c84c05
...
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
joe4465 | 2:b67f18c84c05 | 1 | #include "mbed.h" |
joe4465 | 2:b67f18c84c05 | 2 | |
joe4465 | 2:b67f18c84c05 | 3 | #ifndef Ppm_H |
joe4465 | 2:b67f18c84c05 | 4 | #define Ppm_H |
joe4465 | 2:b67f18c84c05 | 5 | |
joe4465 | 2:b67f18c84c05 | 6 | class Ppm |
joe4465 | 2:b67f18c84c05 | 7 | { |
joe4465 | 2:b67f18c84c05 | 8 | public: |
joe4465 | 2:b67f18c84c05 | 9 | //Constructor |
joe4465 | 3:d13b9e50312f | 10 | Ppm(PinName pin, int minimumOutput, int maximumOutput, int minimumPulseTime, int maximumPulseTime, int numberOfChannels, int throttleChannel); |
joe4465 | 2:b67f18c84c05 | 11 | |
joe4465 | 2:b67f18c84c05 | 12 | private: |
joe4465 | 2:b67f18c84c05 | 13 | //Interrupt |
joe4465 | 2:b67f18c84c05 | 14 | void SignalRise(); |
joe4465 | 2:b67f18c84c05 | 15 | |
joe4465 | 2:b67f18c84c05 | 16 | //Interrupt pin |
joe4465 | 2:b67f18c84c05 | 17 | InterruptIn *_ppmPin; |
joe4465 | 2:b67f18c84c05 | 18 | |
joe4465 | 2:b67f18c84c05 | 19 | //Timer, times length of pulses |
joe4465 | 2:b67f18c84c05 | 20 | Timer _timer; |
joe4465 | 2:b67f18c84c05 | 21 | //Number of channels in Ppm signal |
joe4465 | 2:b67f18c84c05 | 22 | int _numberOfChannels; |
joe4465 | 2:b67f18c84c05 | 23 | //Current channel |
joe4465 | 2:b67f18c84c05 | 24 | char _currentChannel; |
joe4465 | 2:b67f18c84c05 | 25 | //Stores channel times |
joe4465 | 2:b67f18c84c05 | 26 | int _times[100]; |
joe4465 | 2:b67f18c84c05 | 27 | //Stores most recent complete frame times |
joe4465 | 2:b67f18c84c05 | 28 | int _completeTimes[100]; |
joe4465 | 2:b67f18c84c05 | 29 | //Keeps track of time between Ppm interrupts |
joe4465 | 2:b67f18c84c05 | 30 | int _timeElapsed; |
joe4465 | 2:b67f18c84c05 | 31 | //Minimum time of frame |
joe4465 | 2:b67f18c84c05 | 32 | int _minFrameTime; |
joe4465 | 2:b67f18c84c05 | 33 | //If the pulse time for a channel is this short, something is wrong uS |
joe4465 | 2:b67f18c84c05 | 34 | int _shortTime; |
joe4465 | 2:b67f18c84c05 | 35 | //Minimum pulse time uS |
joe4465 | 2:b67f18c84c05 | 36 | int _minimumPulseTime; |
joe4465 | 2:b67f18c84c05 | 37 | //Maximum pulse time uS |
joe4465 | 3:d13b9e50312f | 38 | double _maximumPulseTime; |
joe4465 | 2:b67f18c84c05 | 39 | //Minimum output |
joe4465 | 3:d13b9e50312f | 40 | double _minimumOutput; |
joe4465 | 2:b67f18c84c05 | 41 | //Maximum output |
joe4465 | 3:d13b9e50312f | 42 | double _maximumOutput; |
joe4465 | 2:b67f18c84c05 | 43 | //Throttle channel - used for fail safe |
joe4465 | 2:b67f18c84c05 | 44 | int _throttleChannel; |
joe4465 | 2:b67f18c84c05 | 45 | |
joe4465 | 2:b67f18c84c05 | 46 | public: |
joe4465 | 2:b67f18c84c05 | 47 | //Get channel data |
joe4465 | 3:d13b9e50312f | 48 | void GetChannelData(double* channelData); |
joe4465 | 2:b67f18c84c05 | 49 | |
joe4465 | 2:b67f18c84c05 | 50 | private: |
joe4465 | 3:d13b9e50312f | 51 | double Map(double input, double inputMin, double inputMax, double outputMin, double outputMax); |
joe4465 | 2:b67f18c84c05 | 52 | }; |
joe4465 | 2:b67f18c84c05 | 53 | |
joe4465 | 2:b67f18c84c05 | 54 | #endif |
joe4465 | 2:b67f18c84c05 | 55 | |
joe4465 | 2:b67f18c84c05 | 56 |