upm  0.5.1
Sensor/Actuator repository for libmraa (v0.9.1)
 All Data Structures Files Functions Variables Enumerations Enumerator Macros Groups Pages
servo.h
1 /*
2  * Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
3  * Copyright (c) 2014 Intel Corporation.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining
6  * a copy of this software and associated documentation files (the
7  * "Software"), to deal in the Software without restriction, including
8  * without limitation the rights to use, copy, modify, merge, publish,
9  * distribute, sublicense, and/or sell copies of the Software, and to
10  * permit persons to whom the Software is furnished to do so, subject to
11  * the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 #pragma once
25 
26 #include <string>
27 #include <mraa/pwm.h>
28 
29 namespace upm {
30 
31 #define MIN_PULSE_WIDTH 600
32 #define MAX_PULSE_WIDTH 2500
33 #define PERIOD 20000
34 
35 #define HIGH 1
36 #define LOW 0
37 
38 #define DEFAULT_WAIT_DISABLE_PWM 0
39 
50 class Servo {
51  public:
57  Servo (int pin);
58 
66  Servo (int pin, int minPulseWidth, int maxPulseWidth);
67 
77  Servo (int pin, int minPulseWidth, int maxPulseWidth, int waitAndDisablePwm);
78 
82  ~Servo();
83 
90  mraa_result_t setAngle (int angle);
91 
95  mraa_result_t haltPwm ();
96 
102  std::string name()
103  {
104  return m_name;
105  }
106 
112  void setMinPulseWidth (int width);
113 
119  void setMaxPulseWidth (int width);
120 
126  void setPeriod (int period);
127 
133  int getMinPulseWidth ();
134 
140  int getMaxPulseWidth ();
141 
147  int getPeriod ();
148 
149  protected:
150  int calcPulseTraveling (int value);
151 
152  std::string m_name;
153  int m_servoPin;
154  float m_maxAngle;
155  mraa_pwm_context m_pwmServoContext;
156  int m_currAngle;
157 
158  int m_minPulseWidth;
159  int m_maxPulseWidth;
160  int m_period;
161 
162  int m_waitAndDisablePwm;
163 
164  private:
165  void init (int pin, int minPulseWidth, int maxPulseWidth, int waitAndDisablePwm);
166 };
167 
168 }
mraa_result_t setAngle(int angle)
Definition: servo.cxx:63
void setMinPulseWidth(int width)
Definition: servo.cxx:111
Definition: servo.h:50
void setMaxPulseWidth(int width)
Definition: servo.cxx:116
int getPeriod()
Definition: servo.cxx:136
std::string name()
Definition: servo.h:102
void setPeriod(int period)
Definition: servo.cxx:121
int getMaxPulseWidth()
Definition: servo.cxx:131
int getMinPulseWidth()
Definition: servo.cxx:126
~Servo()
Definition: servo.cxx:49
Servo(int pin)
Definition: servo.cxx:37
mraa_result_t haltPwm()
Definition: servo.cxx:88