upm  1.6.0
Sensor/Actuator repository for libmraa (v1.9.0)
stepmotor.hpp
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  /* Disable implicit copy and assignment operators */
158  StepMotor(const StepMotor&) = delete;
159  StepMotor &operator=(const StepMotor&) = delete;
160 
161  std::string m_name;
162 
163  mraa::Gpio m_dirPinCtx;
164  mraa::Gpio m_stePinCtx;
165  mraa::Gpio *m_enPinCtx;
166 
167  int m_delay;
168  int m_steps;
169  int m_position;
170 
171  mraa::Result dirForward ();
172  mraa::Result dirBackward ();
173  void move ();
174  void delayus (int us);
175  };
176 }
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
C++ API for the kxtj3 driver.
Definition: a110x.hpp:29
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.hpp:78
int getPosition()
Definition: stepmotor.cxx:135
void setPosition(int pos)
Definition: stepmotor.cxx:130