RumPi 1.0
A self-assembling C++ sensor & actuator library for the Raspberry Pi 5
Vehicle.h
Go to the documentation of this file.
1#pragma once
2#include <vector>
3#include "BaseComponent.h"
4#include "Motor.h"
5
6namespace RumPi
7{
14 class Vehicle : public BaseComponent
15 {
16 public:
17 //Owns and deletes its Motor* elements, so a copy would double-free them. Non-copyable.
18 Vehicle(const Vehicle&) = delete;
19 Vehicle& operator=(const Vehicle&) = delete;
20
21 private:
22 std::vector<Motor*> myMotors;
23
24 public:
40 Vehicle(const unsigned int numberOfMotors, const unsigned int* motorPinNumbers = nullptr, MotorAlignment* motorAlignments = nullptr);
41
53 virtual ~Vehicle();
54
65 virtual void TurnOn() override;
66
77 virtual void TurnOff() override;
78
89 virtual void ProcessRawValues() override;
90
103 virtual std::string ToString() const override;
104
115 void TurnOnMotors();
116
127 void TurnOffMotors();
128
139 void MoveForward();
140
151 void MoveBackward();
152
163 void TurnLeft();
164
175 void TurnRight();
176
191 Motor* GetMotor(int index) const;
192 };
193} // 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
A vehicle composed of several Motors, providing drive and steering by coordinating the motors it owns...
Definition: Vehicle.h:15
virtual void ProcessRawValues() override
No-op: a vehicle is an output device with no raw values to process.
Definition: Vehicle.cpp:144
void TurnLeft()
Steers the vehicle left: left-aligned motors reverse and right-aligned motors drive forward.
Definition: Vehicle.cpp:198
Motor * GetMotor(int index) const
Gets the motor at the given index, or nullptr if the index is out of range.
Definition: Vehicle.cpp:264
void TurnOnMotors()
Turns on every motor the vehicle owns.
Definition: Vehicle.cpp:108
void MoveBackward()
Drives every motor backward, enabling them first.
Definition: Vehicle.cpp:178
void MoveForward()
Drives every motor forward, enabling them first.
Definition: Vehicle.cpp:158
virtual void TurnOn() override
Turns the vehicle on by turning on all its motors.
Definition: Vehicle.cpp:78
Vehicle & operator=(const Vehicle &)=delete
void TurnRight()
Steers the vehicle right: left-aligned motors drive forward and right-aligned motors reverse.
Definition: Vehicle.cpp:229
virtual std::string ToString() const override
Serializes every motor's description into one string.
Definition: Vehicle.cpp:288
Vehicle(const Vehicle &)=delete
void TurnOffMotors()
Turns off every motor the vehicle owns.
Definition: Vehicle.cpp:126
virtual void TurnOff() override
Turns the vehicle off by turning off all its motors.
Definition: Vehicle.cpp:93
std::vector< Motor * > myMotors
The motors this vehicle owns and drives.
Definition: Vehicle.h:22
virtual ~Vehicle()
Destroys the vehicle, turning it off and deleting the motors it owns.
Definition: Vehicle.cpp:57
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