upm  0.2.0
Sensor/Actuator repository for libmraa (v0.6.1)
stepmotor.h
1 /*
2  * Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
3  * Copyright (c) 2014 Intel Corporation.
4  *
5  * Credits to Adafruit.
6  * Based on Adafruit BMP085 library.
7  *
8  * Permission is hereby granted, free of charge, to any person obtaining
9  * a copy of this software and associated documentation files (the
10  * "Software"), to deal in the Software without restriction, including
11  * without limitation the rights to use, copy, modify, merge, publish,
12  * distribute, sublicense, and/or sell copies of the Software, and to
13  * permit persons to whom the Software is furnished to do so, subject to
14  * the following conditions:
15  *
16  * The above copyright notice and this permission notice shall be
17  * included in all copies or substantial portions of the Software.
18  *
19  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
23  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
24  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
25  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26  */
27 #pragma once
28 
29 #include <string>
30 #include <math.h>
31 #include <mraa/pwm.h>
32 #include <mraa/aio.h>
33 #include <mraa/gpio.h>
34 
35 #define MIN_PERIOD 500
36 #define MAX_PERIOD 1000
37 #define PULSEWIDTH 480
38 
39 #define HIGH 1
40 #define LOW 0
41 
42 namespace upm {
66 class StepMotor {
67  public:
74  StepMotor (int dirPin, int stePin);
75 
79  ~StepMotor ();
80 
86  void setSpeed (int speed);
87 
93  mraa_result_t stepForward (int ticks);
94 
100  mraa_result_t stepBackwards (int ticks);
101 
102  private:
103  std::string m_name;
104 
105  int m_dirPin;
106  int m_stePin;
107  int m_speed;
108 
109  mraa_gpio_context m_dirPinCtx;
110  mraa_pwm_context m_pwmStepContext;
111 
112  mraa_result_t move (int ticks);
113  mraa_result_t dirForward ();
114  mraa_result_t dirBackwards ();
115  };
116 }
StepMotor(int dirPin, int stePin)
Definition: stepmotor.cxx:33
Definition: a110x.h:29
mraa_result_t stepBackwards(int ticks)
Definition: stepmotor.cxx:86
mraa_result_t stepForward(int ticks)
Definition: stepmotor.cxx:80
~StepMotor()
Definition: stepmotor.cxx:55
void setSpeed(int speed)
Definition: stepmotor.cxx:67
C++ API for the Stepper motor library.
Definition: stepmotor.h:66