upm  0.5.1
Sensor/Actuator repository for libmraa (v0.9.1)
 All Data Structures Files Functions Variables Enumerations Enumerator Macros Groups Pages
stepmotor.h
1 /*
2  * Authors: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
3  * Mihai Tudor Panu <mihai.tudor.panu@intel.com>
4  * Copyright (c) 2014 Intel Corporation.
5  *
6  * Credits to Adafruit.
7  * Based on Adafruit BMP085 library.
8  *
9  * Permission is hereby granted, free of charge, to any person obtaining
10  * a copy of this software and associated documentation files (the
11  * "Software"), to deal in the Software without restriction, including
12  * without limitation the rights to use, copy, modify, merge, publish,
13  * distribute, sublicense, and/or sell copies of the Software, and to
14  * permit persons to whom the Software is furnished to do so, subject to
15  * the following conditions:
16  *
17  * The above copyright notice and this permission notice shall be
18  * included in all copies or substantial portions of the Software.
19  *
20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27  */
28 #pragma once
29 
30 #include <string>
31 #include <mraa/pwm.hpp>
32 #include <mraa/common.hpp>
33 #include <mraa/gpio.hpp>
34 
35 #define OVERHEAD_US 6
36 #define MINPULSE_US 5
37 
38 #define HIGH 1
39 #define LOW 0
40 
41 namespace upm {
78 class StepMotor {
79  public:
88  StepMotor (int dirPin, int stePin, int steps = 200, int enPin = -1);
89 
93  ~StepMotor ();
94 
102  void enable (bool flag);
103 
109  void setSpeed (int speed);
110 
117  mraa::Result step (int ticks);
118 
124  mraa::Result stepForward (int ticks);
125 
131  mraa::Result stepBackward (int ticks);
132 
139  void setPosition (int pos);
140 
147  int getPosition ();
148 
154  int getStep ();
155 
156  private:
157  std::string m_name;
158 
159  mraa::Gpio m_dirPinCtx;
160  mraa::Gpio m_stePinCtx;
161  mraa::Gpio *m_enPinCtx;
162 
163  int m_delay;
164  int m_steps;
165  int m_position;
166 
167  mraa::Result dirForward ();
168  mraa::Result dirBackward ();
169  void move ();
170  void delayus (int us);
171  };
172 }
mraa::Result stepBackward(int ticks)
Definition: stepmotor.cxx:119
int getStep()
Definition: stepmotor.cxx:140
mraa::Result stepForward(int ticks)
Definition: stepmotor.cxx:108
StepMotor(int dirPin, int stePin, int steps=200, int enPin=-1)
Definition: stepmotor.cxx:36
void enable(bool flag)
Definition: stepmotor.cxx:79
mraa::Result step(int ticks)
Definition: stepmotor.cxx:99
~StepMotor()
Definition: stepmotor.cxx:73
void setSpeed(int speed)
Definition: stepmotor.cxx:89
API for the Stepper Motor.
Definition: stepmotor.h:78
int getPosition()
Definition: stepmotor.cxx:135
void setPosition(int pos)
Definition: stepmotor.cxx:130