TinyRobotics
Loading...
Searching...
No Matches
Vehicle.h
1#pragma once
2
3#include <vector>
4
5#include "TinyRobotics/communication/Message.h"
6#include "TinyRobotics/communication/MessageHandler.h"
7#include "TinyRobotics/communication/MessageSource.h"
8#include "TinyRobotics/motors/IMotor.h"
9
10namespace tinyrobotics {
11
12/**
13 * @class Vehicle
14 * @ingroup vehicles
15 * @brief Abstract base class for all vehicle types.
16 *
17 * The Vehicle class defines a common interface for all robotic vehicles in the
18 * library. It enforces the implementation of a reset() method, which should
19 * reset the vehicle's actuators and internal state to a safe or neutral
20 * configuration.
21 *
22 * All vehicle classes (e.g., Car4WD, Quadrotor, AirPlane, MotorBoat) should
23 * inherit from Vehicle.
24 */
25template <typename MotorT = float>
26class Vehicle : public MessageHandler, public MessageSource {
27 public:
28
29 /**
30 * @brief Initialize the vehicle.
31 *
32 * @return true
33 * @return false
34 */
35
36 bool begin() {
37 end();
38 // start all motors
39 for (auto* motor : getMotors()) {
40 if (motor) motor->begin();
41 }
42 speedFactor_ = 1.0f;
43 return true;
44 }
45 /**
46 * @brief Reset the vehicle to a safe or neutral state (pure virtual).
47 */
48 virtual void end() = 0;
49
50 /**
51 * @brief Check if the necessary pins for the vehicle's actuators have been
52 * set (pure virtual).
53 */
54 virtual bool isPinsSet() const = 0;
55
56 virtual std::vector<MessageContent> getControls() const = 0;
57
58 /**
59 * @brief Get the speed factor (scaling for speed commands).
60 */
61 float getSpeedFactor() const { return speedFactor_; }
62
63 /**
64 * @brief Set the speed factor (scaling for speed commands).
65 */
66 void setSpeedFactor(float factor) { speedFactor_ = factor; }
67
68 virtual std::vector<IMotor<MotorT>*> getMotors() = 0;
69
70 protected:
71 float speedFactor_ = 1.0f;
72
73};
74
75} // namespace tinyrobotics
Interface for handling messages in the TinyRobotics framework.
Definition: MessageHandler.h:18
Base class for message sources in the TinyRobotics communication framework.
Definition: MessageSource.h:35
Abstract base class for all vehicle types.
Definition: Vehicle.h:26
bool begin()
Initialize the vehicle.
Definition: Vehicle.h:36
float getSpeedFactor() const
Get the speed factor (scaling for speed commands).
Definition: Vehicle.h:61
void setSpeedFactor(float factor)
Set the speed factor (scaling for speed commands).
Definition: Vehicle.h:66
virtual void end()=0
Reset the vehicle to a safe or neutral state (pure virtual).
virtual bool isPinsSet() const =0
Check if the necessary pins for the vehicle's actuators have been set (pure virtual).