Exploring BeagleBone  V1.0
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
DCMotor.h
Go to the documentation of this file.
1 /*
2  * DCMotor.h Created on: 12 Jun 2014
3  * Copyright (c) 2014 Derek Molloy (www.derekmolloy.ie)
4  * Made available for the book "Exploring BeagleBone"
5  * See: www.exploringbeaglebone.com
6  * Licensed under the EUPL V.1.1
7  *
8  * This Software is provided to You under the terms of the European
9  * Union Public License (the "EUPL") version 1.1 as published by the
10  * European Union. Any use of this Software, other than as authorized
11  * under this License is strictly prohibited (to the extent such use
12  * is covered by a right of the copyright holder of this Software).
13  *
14  * This Software is provided under the License on an "AS IS" basis and
15  * without warranties of any kind concerning the Software, including
16  * without limitation merchantability, fitness for a particular purpose,
17  * absence of defects or errors, accuracy, and non-infringement of
18  * intellectual property rights other than copyright. This disclaimer
19  * of warranty is an essential part of the License and a condition for
20  * the grant of any rights to this Software.
21  *
22  * For more details, see http://www.derekmolloy.ie/
23  */
24 
25 #ifndef DCMOTOR_H_
26 #define DCMOTOR_H_
27 #include "../gpio/GPIO.h"
28 #include "../gpio/PWM.h"
29 
30 #define DEFAULT_DCMOTOR_PWM_PERIOD 4000
31 #define DEFAULT_DCMOTOR_SPEED 50.0f
32 
33 namespace exploringBB {
34 
40 class DCMotor {
41 public:
43 private:
44  GPIO *gpio;
45  PWM *pwm;
46  float speedPercent;
47  DIRECTION direction;
48  void init(PWM *pwm, GPIO *gpio, DCMotor::DIRECTION direction, float speedPercent);
49 public:
50  DCMotor(PWM *pwm, GPIO *gpio);
51  DCMotor(PWM *pwm, int gpioNumber);
52  DCMotor(PWM *pwm, GPIO *gpio, DCMotor::DIRECTION direction);
53  DCMotor(PWM *pwm, int gpioNumber, DCMotor::DIRECTION direction);
54  DCMotor(PWM *pwm, GPIO *gpio, DCMotor::DIRECTION direction, float speedPercent);
55  DCMotor(PWM *pwm, int gpioNumber, DCMotor::DIRECTION direction, float speedPercent);
56  virtual void go();
57  virtual void setSpeedPercent(float speedPercent);
58  virtual float getSpeedPercent() { return this->speedPercent; }
59  virtual void setDirection(DIRECTION direction);
60  virtual DIRECTION getDirection() { return this->direction; }
61  virtual void reverseDirection();
62  virtual void stop();
63  virtual void setDutyCyclePeriod(unsigned int period_ns);
64  virtual ~DCMotor();
65 };
66 
67 } /* namespace exploringBB */
68 
69 #endif /* DCMOTOR_H_ */
virtual void stop()
Definition: DCMotor.cpp:96
virtual void setDirection(DIRECTION direction)
Definition: DCMotor.cpp:77
virtual void setDutyCyclePeriod(unsigned int period_ns)
Definition: DCMotor.cpp:104
A class to control a basic PWM output – you must know the exact sysfs filename for the PWM output...
Definition: PWM.h:43
GPIO class for input and output functionality on a single GPIO pin.
Definition: GPIO.h:46
virtual ~DCMotor()
Definition: DCMotor.cpp:108
DIRECTION
Definition: DCMotor.h:42
A generic DC motor class that controls a motor driver board using a PWM signal,and a GPIO state to co...
Definition: DCMotor.h:40
Definition: DCMotor.h:42
virtual DIRECTION getDirection()
Definition: DCMotor.h:60
Definition: BusDevice.cpp:27
Definition: DCMotor.h:42
virtual void reverseDirection()
Definition: DCMotor.cpp:87
virtual void setSpeedPercent(float speedPercent)
Definition: DCMotor.cpp:72
virtual float getSpeedPercent()
Definition: DCMotor.h:58
virtual void go()
Definition: DCMotor.cpp:100
DCMotor(PWM *pwm, GPIO *gpio)
Definition: DCMotor.cpp:29