TinyRobotics
Loading...
Searching...
No Matches
Message.h
1#pragma once
2#include "TinyRobotics/utils/Common.h"
3
4namespace tinyrobotics {
5
6/**
7 * @enum MessageOrigin
8 * @ingroup communications
9 * @brief Source/origin of a message in the communication framework.
10 */
11enum class MessageOrigin {
12 Undefined = 0,
13 RemoteControl, ///< Message from a remote control interface (e.g., RC
14 ///< receiver)
15 Autonomy, ///< Message from an autonomous control module (e.g., path planner)
16 Sensor, ///< Message from a sensor module (e.g., IMU, GPS)
17 System, ///< Internal system message (e.g., status update)
18 Motor, ///< Message from a motor controller (e.g., ESC)
19 Servo, ///< Message from a servo controller
20 Rudder, ///< Message from a rudder controller (specific to boats/planes)
21 Aileron, ///< Message from an aileron controller (specific to planes)
22 Elevator, ///< Message from an elevator controller (specific to planes)
23 IMU, ///< Message from an IMU sensor
24 LIDAR, ///< Message from a LIDAR or IR distance sensor
25 Camera, ///< Message from a camera or vision sensor
26 GPS, ///< Message from a GPS module
27 Vehicle, ///< Message from the vehicle itself (e.g., for telemetry or state updates)
28 Odometry, ///< Message from the odometry system (e.g., position updates)
29 Navigation, ///< Message from the navigation system (e.g., waypoint updates)
30 User ///< Message from a user-defined source (e.g., custom module)
31};
32
33/**
34 * @enum MessageContent
35 * @ingroup communications
36 * @brief Types of message content for communication between modules or devices.
37 */
38enum class MessageContent {
39 Undefined = 0,
40 Angle, ///< Generic angle (e.g., for orientation or steering)
41 Pitch, ///< Pitch angle or command
42 Roll, ///< Roll angle or command
43 Yaw, ///< Yaw angle or command
44 Throttle, ///< Throttle or power command
45 Speed, ///< Linear speed
46 SteeringAngle, ///< Steering angle (e.g., for Ackerman vehicles)
47 Turn, ///< Turn command (e.g., for differential drive)
48 Heading, ///< Heading angle (e.g., compass direction)
49 MotorSpeed, ///< Motor speed (RPM or percent)
50 Position, ///< Position data (coordinates)
51 PositionGPS, ///< Position data from GPS (latitude, longitude)
52 Distance, ///< Distance measurement (e.g., from a range sensor)
53 Temperature, ///< Temperature reading (e.g., from a temperature sensor)
54 Error, ///< Error value (e.g., for PID control)
55 Density, ///< Density value (e.g., for obstacle detection)
56 MotionState, ///< Full motion state (e.g., for publishing a MotionState3D struct)
57 Obstacle, ///< Obstacle detected (e.g., for publishing obstacle coordinates or status)
58};
59
60/**
61 * @class Message
62 * @ingroup communication
63 * @brief Generic message structure for communication, parameterized by value
64 * type.
65 * @tparam T Type of the value (default: float)
66 *
67 * @note When using Message in function signatures (e.g., virtual functions),
68 * always use Message<float> explicitly. C++ requires the template argument in
69 * these contexts, even though the default is float.
70 */
71template <typename T = float>
72struct Message {
73 const char* prefix = "MSG"; ///< prefix for message identification
74 uint8_t size = sizeof(Message);
75 MessageOrigin origin =
76 MessageOrigin::RemoteControl; ///< Source of the message. @see
77 ///< MessageOrigin
78 uint8_t origin_id =
79 0; /// Optional identifier for the source (e.g., sensor ID, motor ID)
80 MessageContent content; ///< Type of message content. @see MessageContent
81 Unit unit; ///< Unit of the value
82 T value{}; ///< Value of the message
83
84 /**
85 * @brief Default constructor.
86 */
87 Message() = default;
88
89 /**
90 * @brief Construct a message with content, value, and unit.
91 * @param c Message content type
92 * @param v Value
93 * @param u Unit
94 */
95 Message(MessageContent c, T v, Unit u) : content(c), unit(u), value(v) {}
96 Message(MessageContent c, T v, Unit u, MessageOrigin orig)
97 : origin(orig), content(c), unit(u), value(v) {}
98};
99
100} // namespace tinyrobotics
Unit
Units for message values.
Definition: Common.h:45
Generic message structure for communication, parameterized by value type.
Definition: Message.h:72
T value
Value of the message.
Definition: Message.h:82
const char * prefix
prefix for message identification
Definition: Message.h:73
Message(MessageContent c, T v, Unit u)
Construct a message with content, value, and unit.
Definition: Message.h:95
MessageContent content
Optional identifier for the source (e.g., sensor ID, motor ID)
Definition: Message.h:80
Unit unit
Unit of the value.
Definition: Message.h:81
Message()=default
Default constructor.
MessageOrigin origin
Definition: Message.h:75