RumPi 1.0
A self-assembling C++ sensor & actuator library for the Raspberry Pi 5
Motor.h
Go to the documentation of this file.
1#pragma once
2#include "BaseComponent.h"
3
4namespace RumPi
5{
13 {
17 None
18 };
19
26 class Motor : public BaseComponent
27 {
28 private:
29 unsigned int myEnablePinNumber;
30 unsigned int myDriveOnePinNumber;
31 unsigned int myDriveTwoPinNumber;
33
34 public:
49 Motor(const unsigned int driveOnePinNumber, const unsigned int driveTwoPinNumber, const MotorAlignment alignment = MotorAlignment::None);
50
66 Motor(const unsigned int enablePinNumber, const unsigned int driveOnePinNumber, const unsigned int driveTwoPinNumber, const MotorAlignment alignment = MotorAlignment::None);
67
79 virtual ~Motor() override;
80
91 virtual void TurnOn() override;
92
103 virtual void TurnOff() override;
104
115 virtual void ProcessRawValues() override;
116
129 virtual std::string ToString() const override;
130
141 virtual void MoveForward();
142
153 virtual void MoveBackward();
154
167 unsigned int GetEnablePinNumber() const;
168
181 unsigned int GetDriveOnePinNumber() const;
182
195 unsigned int GetDriveTwoPinNumber() const;
196
210 };
211} // namespace RumPi
Abstract base class for every component (sensor, actuator, etc.) the library manages.
Definition: BaseComponent.h:60
A DC motor driven through an H-bridge, with an optional enable pin and a wheel alignment used when st...
Definition: Motor.h:27
virtual void TurnOn() override
Turns the motor on by enabling the H-bridge chip (no motion until a Move call).
Definition: Motor.cpp:89
virtual void MoveBackward()
Drives the motor backward, enabling the H-bridge first.
Definition: Motor.cpp:163
unsigned int GetDriveTwoPinNumber() const
Gets the second H-bridge drive pin.
Definition: Motor.cpp:218
Motor(const unsigned int driveOnePinNumber, const unsigned int driveTwoPinNumber, const MotorAlignment alignment=MotorAlignment::None)
Builds a motor driven by two drive pins, assuming the enable pin is always powered.
Definition: Motor.cpp:20
virtual void ProcessRawValues() override
No-op: a motor is an output device with no raw values to process.
Definition: Motor.cpp:129
unsigned int myDriveTwoPinNumber
The second H-bridge drive pin.
Definition: Motor.h:31
virtual void TurnOff() override
Turns the motor off by disabling the enable pin and driving both drive pins low.
Definition: Motor.cpp:108
MotorAlignment myAlignment
This motor's alignment on the vehicle (used when steering).
Definition: Motor.h:32
unsigned int GetDriveOnePinNumber() const
Gets the first H-bridge drive pin.
Definition: Motor.cpp:201
MotorAlignment GetAlignment() const
Gets this motor's alignment on the vehicle.
Definition: Motor.cpp:235
virtual void MoveForward()
Drives the motor forward, enabling the H-bridge first.
Definition: Motor.cpp:144
virtual std::string ToString() const override
Serializes the motor's enable/drive pins and alignment to a string.
Definition: Motor.cpp:252
unsigned int myDriveOnePinNumber
The first H-bridge drive pin.
Definition: Motor.h:30
unsigned int GetEnablePinNumber() const
Gets the H-bridge enable pin (UINT_MAX if the enable pin is always powered).
Definition: Motor.cpp:184
virtual ~Motor() override
Destroys the motor, turning it off first.
Definition: Motor.cpp:74
unsigned int myEnablePinNumber
The H-bridge enable pin (UINT_MAX if the enable pin is always powered).
Definition: Motor.h:29
RumPi is the library's top-level facade.
Definition: AlertManager.h:6
MotorAlignment
Helps determine direction to rotate a motor if/when turning a Vehicle.
Definition: Motor.h:13
@ Left
Definition: Motor.h:14
@ Right
Definition: Motor.h:15
@ Center
Definition: Motor.h:16
@ None
Definition: Motor.h:17