upm  0.1.8
Sensor/Actuator repository for libmraa (v0.4.5)
 All Data Structures Files Functions Variables Macros 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 MAX_PERIOD 7968
34 
35 #define HIGH 1
36 #define LOW 0
37 
44 class Servo {
45  public:
51  Servo (int pin);
52 
56  ~Servo();
57 
73  mraa_result_t setAngle (int angle);
74 
78  std::string name()
79  {
80  return m_name;
81  }
82 
88  void setMinPulseWidth (int width);
89 
95  void setMaxPulseWidth (int width);
96 
102  void setMaxPeriod (int width);
103 
107  int getMinPulseWidth ();
108 
112  int getMaxPulseWidth ();
113 
117  int getMaxPeriod ();
118 
119  protected:
120  int calcPulseTraveling (int value);
121 
122  std::string m_name;
123  int m_servoPin;
124  float m_maxAngle;
125  mraa_pwm_context m_pwmServoContext;
126  int m_currAngle;
127 
128  int m_minPulseWidth;
129  int m_maxPulseWidth;
130  int m_maxPeriod;
131 };
132 
133 }
mraa_result_t setAngle(int angle)
Definition: servo.cxx:65
void setMaxPeriod(int width)
Definition: servo.cxx:122
void setMinPulseWidth(int width)
Definition: servo.cxx:112
int getMaxPeriod()
Definition: servo.cxx:137
Base class for other servo components.
Definition: servo.h:44
void setMaxPulseWidth(int width)
Definition: servo.cxx:117
std::string name()
Definition: servo.h:78
int getMaxPulseWidth()
Definition: servo.cxx:132
int getMinPulseWidth()
Definition: servo.cxx:127
~Servo()
Definition: servo.cxx:50
Servo(int pin)
Definition: servo.cxx:34