upm  0.5.1
Sensor/Actuator repository for libmraa (v0.9.1)
 All Data Structures Files Functions Variables Enumerations Enumerator Macros Groups Pages
adafruitms1438.h
1 /*
2  * Author: Jon Trulson <jtrulson@ics.com>
3  * Copyright (c) 2015 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 <stdint.h>
27 #include <sys/time.h>
28 
29 #include <string>
30 #include <mraa/i2c.h>
31 #include <mraa/gpio.h>
32 
33 #include "pca9685.h"
34 
35 #define ADAFRUITMS1438_I2C_BUS 0
36 #define ADAFRUITMS1438_DEFAULT_I2C_ADDR 0x60
37 
38 namespace upm {
39 
70  public:
71 
75  typedef enum {
76  DIR_NONE = 0x00,
77  DIR_CW = 0x01,
78  DIR_CCW = 0x02
79  } DIRECTION_T;
80 
84  typedef enum {
85  MOTOR_M1 = 0,
86  MOTOR_M2 = 1,
87  MOTOR_M3 = 2,
88  MOTOR_M4 = 3
89  } DCMOTORS_T;
90 
94  typedef enum {
95  STEPMOTOR_M12 = 0,
96  STEPMOTOR_M34 = 1
97  } STEPMOTORS_T;
98 
105  AdafruitMS1438(int bus, uint8_t address = ADAFRUITMS1438_DEFAULT_I2C_ADDR);
106 
110  ~AdafruitMS1438();
111 
118  uint32_t getMillis(STEPMOTORS_T motor);
119 
124  void initClock(STEPMOTORS_T motor);
125 
131  void setPWMPeriod(float hz);
132 
138  void enableMotor(DCMOTORS_T motor);
139 
145  void disableMotor(DCMOTORS_T motor);
146 
152  void enableStepper(STEPMOTORS_T motor);
153 
159  void disableStepper(STEPMOTORS_T motor);
160 
168  void setMotorSpeed(DCMOTORS_T motor, int speed);
169 
176  void setStepperSpeed(STEPMOTORS_T motor, int speed);
177 
184  void setMotorDirection(DCMOTORS_T motor, DIRECTION_T dir);
185 
193 
200  void stepConfig(STEPMOTORS_T motor, unsigned int stepsPerRev);
201 
208  void stepperSteps(STEPMOTORS_T motor, unsigned int steps);
209 
210  private:
211  // SWIG will generate a warning for these 'nested structs'; however,
212  // it can be ignored as these structs are never exposed.
213 
214  // struct to hold mappings of DC motors
215  typedef struct {
216  int pwm;
217  int in1;
218  int in2;
219  } DC_PINMAP_T;
220 
221  // struct to hold mappings of stepper motors
222  typedef struct {
223  int pwmA;
224  int in1A;
225  int in2A;
226  int pwmB;
227  int in1B;
228  int in2B;
229  } STEPPER_PINMAP_T;
230 
231  // struct to hold information about each stepper
232  typedef struct {
233  int stepsPerRev; // steps per revolution
234  int currentStep; // current step number
235  uint32_t stepDelay; // delay between steps
236  int stepDirection; // direction to step
237  struct timeval startTime; // starting time
238  } STEPPER_CONFIG_T;
239 
240  void setupPinMaps();
241  void stepperStep(STEPMOTORS_T motor);
242 
243  DC_PINMAP_T m_dcMotors[4];
244  STEPPER_PINMAP_T m_stepMotors[2];
245  STEPPER_CONFIG_T m_stepConfig[2];
246 
247  PCA9685 *m_pca9685;
248  };
249 }
250 
251 
void setStepperDirection(STEPMOTORS_T motor, DIRECTION_T dir)
Definition: adafruitms1438.cxx:194
void disableMotor(DCMOTORS_T motor)
Definition: adafruitms1438.cxx:128
uint32_t getMillis(STEPMOTORS_T motor)
Definition: adafruitms1438.cxx:69
void setStepperSpeed(STEPMOTORS_T motor, int speed)
Definition: adafruitms1438.cxx:163
void enableMotor(DCMOTORS_T motor)
Definition: adafruitms1438.cxx:123
void disableStepper(STEPMOTORS_T motor)
Definition: adafruitms1438.cxx:139
API for the AdafruitMS1438 Motor Shield.
Definition: adafruitms1438.h:69
void stepperSteps(STEPMOTORS_T motor, unsigned int steps)
Definition: adafruitms1438.cxx:281
AdafruitMS1438(int bus, uint8_t address=ADAFRUITMS1438_DEFAULT_I2C_ADDR)
Definition: adafruitms1438.cxx:36
STEPMOTORS_T
Definition: adafruitms1438.h:94
void setMotorDirection(DCMOTORS_T motor, DIRECTION_T dir)
Definition: adafruitms1438.cxx:169
~AdafruitMS1438()
Definition: adafruitms1438.cxx:59
DCMOTORS_T
Definition: adafruitms1438.h:84
void setMotorSpeed(DCMOTORS_T motor, int speed)
Definition: adafruitms1438.cxx:145
void stepConfig(STEPMOTORS_T motor, unsigned int stepsPerRev)
Definition: adafruitms1438.cxx:210
void enableStepper(STEPMOTORS_T motor)
Definition: adafruitms1438.cxx:133
void setPWMPeriod(float hz)
Definition: adafruitms1438.cxx:115
void initClock(STEPMOTORS_T motor)
Definition: adafruitms1438.cxx:64
DIRECTION_T
Definition: adafruitms1438.h:75