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

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers ServoIn.h Source File

ServoIn.h

00001 // J. Bradshaw 20150409
00002 /** ServoIn Class for Reading servo pulses on single input pin
00003  * Copyright (c) 2014, jbradshaw (http://mbed.org)
00004  *
00005  * Permission is hereby granted, free of charge, to any person obtaining a copy
00006  * of this software and associated documentation files (the "Software"), to deal
00007  * in the Software without restriction, including without limitation the rights
00008  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00009  * copies of the Software, and to permit persons to whom the Software is
00010  * furnished to do so, subject to the following conditions:
00011  *
00012  * The above copyright notice and this permission notice shall be included in
00013  * all copies or substantial portions of the Software.
00014  *
00015  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00016  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00017  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00018  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00019  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00020  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00021  * THE SOFTWARE.
00022  *
00023 */
00024 
00025 #ifndef MBED_SERVOIN_H
00026 #define MBED_SERVOIN_H
00027 
00028 /**
00029  * ServoIn Class.
00030  */
00031  
00032  class ServoIn {
00033 public:
00034     /**
00035     * Constructor.
00036     *
00037     * @param pin - servo pulse input pin, assigned as interrupt in
00038     */         
00039     
00040     ServoIn(PinName pin);
00041             
00042     int servoPulse;
00043     int servoPulseMax;
00044     int servoPulseMin;
00045     float servoPulseOffset;
00046     float servoPulseScale;
00047     
00048     float readCalPulse(void);
00049     int read(void);
00050     void PulseRead(void);
00051     void timeoutTest(void);
00052     
00053     ServoIn& operator= (ServoIn& rhs);
00054     operator int();
00055     
00056 private:
00057     InterruptIn _interrupt;
00058     DigitalIn _pin;
00059     Timeout _validPulseTimeout;
00060     bool _pulseFlag;
00061     Timer   pulseMeasure;
00062     bool _t_state;
00063 };
00064 
00065 #endif