Class Library for reading hobby servos and detecting invalid or disconnected channels
Dependents: MadPulseCntrl Emaxx_Navigation Emaxx_Navigation_Dynamic_HIL Madpulse_Speed_Control_temp ... more
ServoIn Class Library
This class library uses external interrupts with timer functions to read servos pulses on mbed input pins.
ServoIn Library usage example
#include "mbed.h" #include "ServoIn.h" DigitalOut led1(LED1); ServoIn servoIn1(p15); ServoIn servoIn2(p14); Serial pc(USBTX, USBRX); // tx, rx int main() { pc.baud(921600); //Fast baud rate while(1) { led1 = 1; wait(0.05); led1 = 0; wait(0.05); pc.printf("servo pulse: CH1=%5dus CH2=%5dus\r\n", servoIn1.read(), servoIn2.read()); } }
Revision 5:598ccee73ed3, committed 2017-08-14
- Comitter:
- jebradshaw
- Date:
- Mon Aug 14 14:51:20 2017 +0000
- Parent:
- 4:379f9ab5cb4b
- Commit message:
- added check for valid servo pulse when greater then servo max to prevent flag check after pulse interrupt (inverted pulse measure phase)
Changed in this revision
ServoIn.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 379f9ab5cb4b -r 598ccee73ed3 ServoIn.cpp --- a/ServoIn.cpp Thu Aug 04 15:46:31 2016 +0000 +++ b/ServoIn.cpp Mon Aug 14 14:51:20 2017 +0000 @@ -48,8 +48,13 @@ } else{ servoPulse = pulseMeasure.read_us(); - _interrupt.rise(this, &ServoIn::PulseRead); - _pulseFlag = 0; + if(servoPulse < this->servoPulseMax){ + _interrupt.rise(this, &ServoIn::PulseRead); + _pulseFlag = 0; + } + else{ + _pulseFlag = 1; //set the pulse input flag + } } _validPulseTimeout.attach(this, &ServoIn::timeoutTest, 0.015); //setup interrupt for 15ms _t_state=0; //re-zero t-state