TinyRobotics
Loading...
Searching...
No Matches
Common.h
1
2#pragma once
3
4#include <cstdint>
5#include "Config.h"
6#include <cmath>
7
8namespace tinyrobotics {
9
10/**
11 * @enum FrameType
12 * @ingroup utils
13 * @brief Frame type for coordinate systems and reference frames.
14 */
15enum class FrameType : uint8_t {
16 WORLD, ///< World/global reference frame (fixed, absolute)
17 ODOMETRY, ///< Odometry frame (incremental, mobile robot pose)
18 BASE, ///< Robot or vehicle base frame (body frame)
19 CAMERA, ///< Camera sensor frame
20 LIDAR, ///< LIDAR sensor frame
21 WHEEL, ///< Wheel or actuator frame
22 CUSTOM, ///< Custom user-defined frame
23 OBSTACLE, ///< Obstacle or object frame
24 TEMP ///< Temporary or auxiliary frame
25};
26
27/**
28 * @enum CellState
29 * @ingroup utils
30 * @brief Cell state for occupancy grid mapping (e.g., UNKNOWN, FREE, OCCUPIED).
31 */
32enum class CellState : int8_t { UNKNOWN = -1, FREE = 0, OCCUPIED = 100 };
33
34/// Default numeric type for distances: This can be changed
35using DistanceM = DEFAULT_TYPE;
36
37/// Default numeric type for angles in messages (degrees): This can be changed
38using AngleDeg = DEFAULT_TYPE;
39
40/**
41 * @enum Unit
42 * @ingroup utils
43 * @brief Units for message values.
44 */
45enum class Unit {
46 Undefined,
47 Percent, ///< Percentage (0-100)
48 MetersPerSecond, ///< Speed in meters per second
49 RadiansPerSecond, ///< Angular speed in radians per second
50 Meters, ///< Distance in meters
51 Centimeters, ///< Distance in centimeters
52 Millimeters, ///< Distance in millimeters
53 AngleDegree, ///< Angle in degrees
54 AngleRadian, ///< Angle in radians
55 TemperatureC, ///< Temperature in Celsius
56 TemperatureF, ///< Temperature in Fahrenheit
57 Pixel, ///< Pixel units (e.g., for image processing)
58};
59
60/**
61 * @enum ControlScenario
62 * @ingroup utils
63 * @brief Control scenario types for remote control vehicles.
64 *
65 * Used to select the control mapping for different vehicle types.
66 */
67
68enum class ControlScenario { Car, Boat, Drone, Plane };
69
70
71
72/// Convert a value from the given unit to degrees.
73inline bool toAngleDegree(DEFAULT_TYPE in, Unit unit, AngleDeg& out) {
74 switch (unit) {
76 out = in;
77 return true;
79 out = in * 180.0f / static_cast<float>(M_PI);
80 return true;
81 default:
82 return false; // Unsupported unit for angle
83 }
84}
85
86/// Normalize angle in radians to [-pi, pi)
87inline float normalizeAngleRad(float angle) {
88 float twoPi = 2.0f * static_cast<float>(M_PI);
89 angle = std::fmod(angle + static_cast<float>(M_PI), twoPi);
90 if (angle < 0.0f)
91 angle += twoPi;
92 return angle - static_cast<float>(M_PI);
93}
94
95/// Normalize angle in degrees to [-180, 180)
96inline float normalizeAngleDeg(float angle) {
97 angle = std::fmod(angle + 180.0f, 360.0f);
98 if (angle < 0.0f)
99 angle += 360.0f;
100 return angle - 180.0f;
101}
102
103} // namespace tinyrobotics
#define DEFAULT_TYPE
Definition: Config.h:5
ControlScenario
Control scenario types for remote control vehicles.
Definition: Common.h:68
CellState
Cell state for occupancy grid mapping (e.g., UNKNOWN, FREE, OCCUPIED).
Definition: Common.h:32
Unit
Units for message values.
Definition: Common.h:45
FrameType
Frame type for coordinate systems and reference frames.
Definition: Common.h:15
@ Pixel
Pixel units (e.g., for image processing)
@ RadiansPerSecond
Angular speed in radians per second.
@ AngleRadian
Angle in radians.
@ Centimeters
Distance in centimeters.
@ TemperatureF
Temperature in Fahrenheit.
@ Millimeters
Distance in millimeters.
@ AngleDegree
Angle in degrees.
@ Meters
Distance in meters.
@ Percent
Percentage (0-100)
@ TemperatureC
Temperature in Celsius.
@ MetersPerSecond
Speed in meters per second.
@ ODOMETRY
Odometry frame (incremental, mobile robot pose)
@ WHEEL
Wheel or actuator frame.
@ OBSTACLE
Obstacle or object frame.
@ WORLD
World/global reference frame (fixed, absolute)
@ CUSTOM
Custom user-defined frame.
@ TEMP
Temporary or auxiliary frame.
@ LIDAR
LIDAR sensor frame.
@ CAMERA
Camera sensor frame.
@ BASE
Robot or vehicle base frame (body frame)