RumPi 1.0
A self-assembling C++ sensor & actuator library for the Raspberry Pi 5
RumPi::Motor Class Reference

A DC motor driven through an H-bridge, with an optional enable pin and a wheel alignment used when steering. More...

#include <Motor.h>

Inheritance diagram for RumPi::Motor:
[legend]
Collaboration diagram for RumPi::Motor:
[legend]

Public Member Functions

 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. More...
 
 Motor (const unsigned int enablePinNumber, const unsigned int driveOnePinNumber, const unsigned int driveTwoPinNumber, const MotorAlignment alignment=MotorAlignment::None)
 Builds a motor driven by two drive pins and gated by an explicit enable pin. More...
 
virtual ~Motor () override
 Destroys the motor, turning it off first. More...
 
virtual void TurnOn () override
 Turns the motor on by enabling the H-bridge chip (no motion until a Move call). More...
 
virtual void TurnOff () override
 Turns the motor off by disabling the enable pin and driving both drive pins low. More...
 
virtual void ProcessRawValues () override
 No-op: a motor is an output device with no raw values to process. More...
 
virtual std::string ToString () const override
 Serializes the motor's enable/drive pins and alignment to a string. More...
 
virtual void MoveForward ()
 Drives the motor forward, enabling the H-bridge first. More...
 
virtual void MoveBackward ()
 Drives the motor backward, enabling the H-bridge first. More...
 
unsigned int GetEnablePinNumber () const
 Gets the H-bridge enable pin (UINT_MAX if the enable pin is always powered). More...
 
unsigned int GetDriveOnePinNumber () const
 Gets the first H-bridge drive pin. More...
 
unsigned int GetDriveTwoPinNumber () const
 Gets the second H-bridge drive pin. More...
 
MotorAlignment GetAlignment () const
 Gets this motor's alignment on the vehicle. More...
 
- Public Member Functions inherited from RumPi::BaseComponent
 BaseComponent ()
 Builds a base component with an unknown type and an empty name. More...
 
virtual ~BaseComponent ()
 Virtual destructor so deleting a component through a BaseComponent* also cleans up the concrete subclass. More...
 
virtual void TurnOn ()=0
 Turns the component on (e.g. More...
 
virtual void TurnOff ()=0
 Turns the component off. More...
 
virtual std::string ToString () const =0
 Serializes the component's current readings to a string (usually JSON). More...
 
virtual void ProcessRawValues ()=0
 Reads and processes the component's latest raw values (called once per poll). More...
 
virtual EComponentType GetComponentType () const
 Gets the component's type. More...
 
const std::string & GetName () const
 Gets the component's unique per-instance name. More...
 
void SetName (const std::string &name)
 Sets the component's unique per-instance name. More...
 

Private Attributes

unsigned int myEnablePinNumber
 The H-bridge enable pin (UINT_MAX if the enable pin is always powered). More...
 
unsigned int myDriveOnePinNumber
 The first H-bridge drive pin. More...
 
unsigned int myDriveTwoPinNumber
 The second H-bridge drive pin. More...
 
MotorAlignment myAlignment
 This motor's alignment on the vehicle (used when steering). More...
 

Additional Inherited Members

- Static Public Member Functions inherited from RumPi::BaseComponent
static std::string ComponentTypeToString (const EComponentType theComponentTypeToConvert)
 Maps an EComponentType to its string name. More...
 
static EComponentType StringToComponentType (const std::string &theComponentTypeName)
 Maps a type name back to its EComponentType (the inverse of ComponentTypeToString), so the client can turn the type carried on the wire back into a value it can look an icon up with. More...
 
- Protected Attributes inherited from RumPi::BaseComponent
EComponentType myComponentType
 The kind of component this is (set by each concrete subclass). More...
 
std::string myName
 A unique per-instance name, assigned when the component is added to the manager. More...
 

Detailed Description

A DC motor driven through an H-bridge, with an optional enable pin and a wheel alignment used when steering.

Author
Eddie O'Hagan
Date
8/13/2026

Constructor & Destructor Documentation

◆ Motor() [1/2]

RumPi::Motor::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.

Author
Eddie O'Hagan
Date
8/13/2026
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
constexpr unsigned int PIN_GPIO_23
BCM GPIO pin 23.
Definition: Common.h:49
constexpr unsigned int PIN_GPIO_24
BCM GPIO pin 24.
Definition: Common.h:50
@ Left
Definition: Motor.h:14
Parameters
[in]driveOnePinNumberThe first H-bridge drive pin.
[in]driveTwoPinNumberThe second H-bridge drive pin.
[in]alignmentThis motor's alignment on the vehicle.

◆ Motor() [2/2]

RumPi::Motor::Motor ( const unsigned int  enablePinNumber,
const unsigned int  driveOnePinNumber,
const unsigned int  driveTwoPinNumber,
const MotorAlignment  alignment = MotorAlignment::None 
)

Builds a motor driven by two drive pins and gated by an explicit enable pin.

Author
Eddie O'Hagan
Date
8/13/2026
constexpr unsigned int PIN_GPIO_25
BCM GPIO pin 25.
Definition: Common.h:51
@ Right
Definition: Motor.h:15
Parameters
[in]enablePinNumberThe H-bridge enable pin.
[in]driveOnePinNumberThe first H-bridge drive pin.
[in]driveTwoPinNumberThe second H-bridge drive pin.
[in]alignmentThis motor's alignment on the vehicle.

◆ ~Motor()

RumPi::Motor::~Motor ( )
overridevirtual

Destroys the motor, turning it off first.

Author
Eddie O'Hagan
Date
8/13/2026
delete motor;

Member Function Documentation

◆ GetAlignment()

MotorAlignment RumPi::Motor::GetAlignment ( ) const

Gets this motor's alignment on the vehicle.

Author
Eddie O'Hagan
Date
8/13/2026
MotorAlignment alignment = motor.GetAlignment();
MotorAlignment
Helps determine direction to rotate a motor if/when turning a Vehicle.
Definition: Motor.h:13
Returns
The motor's alignment.

◆ GetDriveOnePinNumber()

unsigned int RumPi::Motor::GetDriveOnePinNumber ( ) const

Gets the first H-bridge drive pin.

Author
Eddie O'Hagan
Date
8/13/2026
unsigned int pin = motor.GetDriveOnePinNumber();
Returns
The first drive pin number.

◆ GetDriveTwoPinNumber()

unsigned int RumPi::Motor::GetDriveTwoPinNumber ( ) const

Gets the second H-bridge drive pin.

Author
Eddie O'Hagan
Date
8/13/2026
unsigned int pin = motor.GetDriveTwoPinNumber();
Returns
The second drive pin number.

◆ GetEnablePinNumber()

unsigned int RumPi::Motor::GetEnablePinNumber ( ) const

Gets the H-bridge enable pin (UINT_MAX if the enable pin is always powered).

Author
Eddie O'Hagan
Date
8/13/2026
unsigned int pin = motor.GetEnablePinNumber();
Returns
The enable pin number.

◆ MoveBackward()

void RumPi::Motor::MoveBackward ( )
virtual

Drives the motor backward, enabling the H-bridge first.

Author
Eddie O'Hagan
Date
8/13/2026
motor.MoveBackward();

◆ MoveForward()

void RumPi::Motor::MoveForward ( )
virtual

Drives the motor forward, enabling the H-bridge first.

Author
Eddie O'Hagan
Date
8/13/2026
motor.MoveForward();

◆ ProcessRawValues()

void RumPi::Motor::ProcessRawValues ( )
overridevirtual

No-op: a motor is an output device with no raw values to process.

Author
Eddie O'Hagan
Date
8/13/2026
motor.ProcessRawValues();

Implements RumPi::BaseComponent.

◆ ToString()

std::string RumPi::Motor::ToString ( ) const
overridevirtual

Serializes the motor's enable/drive pins and alignment to a string.

Author
Eddie O'Hagan
Date
8/13/2026
std::string data = motor.ToString();
Returns
A string describing the motor.

Implements RumPi::BaseComponent.

◆ TurnOff()

void RumPi::Motor::TurnOff ( )
overridevirtual

Turns the motor off by disabling the enable pin and driving both drive pins low.

Author
Eddie O'Hagan
Date
8/13/2026
motor.TurnOff();

Implements RumPi::BaseComponent.

◆ TurnOn()

void RumPi::Motor::TurnOn ( )
overridevirtual

Turns the motor on by enabling the H-bridge chip (no motion until a Move call).

Author
Eddie O'Hagan
Date
8/13/2026
motor.TurnOn();

Implements RumPi::BaseComponent.

Member Data Documentation

◆ myAlignment

MotorAlignment RumPi::Motor::myAlignment
private

This motor's alignment on the vehicle (used when steering).

◆ myDriveOnePinNumber

unsigned int RumPi::Motor::myDriveOnePinNumber
private

The first H-bridge drive pin.

◆ myDriveTwoPinNumber

unsigned int RumPi::Motor::myDriveTwoPinNumber
private

The second H-bridge drive pin.

◆ myEnablePinNumber

unsigned int RumPi::Motor::myEnablePinNumber
private

The H-bridge enable pin (UINT_MAX if the enable pin is always powered).


The documentation for this class was generated from the following files: