1#include "TinyRobotics/communication/Message.h"
3#include "TinyRobotics/communication/MessageHandler.h"
4#include "TinyRobotics/odometry/IOdometryModel3D.h"
5#include "TinyRobotics/units/Units.h"
7namespace tinyrobotics {
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
61
62
64 this->callback = callback;
65 this->userData = userData;
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
88 float maxPitchRate = 40.0f,
float maxYawRate = 29.0f)
94 maxRollRate(maxRollRate * 0.01745329252f),
95 maxPitchRate(maxPitchRate * 0.01745329252f),
96 maxYawRate(maxYawRate * 0.01745329252f) {}
99
100
101
102
103
105 switch (msg.content) {
106 case MessageContent::Throttle:
107 setThrottle(msg.value);
109 case MessageContent::Roll:
110 setAileron(msg.value);
112 case MessageContent::Pitch:
113 setElevator(msg.value);
115 case MessageContent::Yaw:
116 setRudder(msg.value);
125 void setThrottle(
float percent) {
126 throttlePercent = clamp(percent, 0.0f, 100.0f);
127 if (callback) callback(userData);
130 void setAileron(
float deg) {
131 aileronDeg = clamp(deg, -45.0f, 45.0f);
132 if (callback) callback(userData);
134 void setElevator(
float deg) {
135 elevatorDeg = clamp(deg, -45.0f, 45.0f);
136 if (callback) callback(userData);
138 void setRudder(
float deg) {
139 rudderDeg = clamp(deg, -45.0f, 45.0f);
140 if (callback) callback(userData);
145 vx = (throttlePercent / 100.0f) * maxSpeed;
152 constexpr float deg2rad = 0.01745329252f;
153 wx = (aileronDeg / 45.0f) * maxRollRate;
154 wy = (elevatorDeg / 45.0f) * maxPitchRate;
155 wz = (rudderDeg / 45.0f) * maxYawRate;
162 void (*callback)(
void*) =
nullptr;
163 void* userData =
nullptr;
164 float throttlePercent;
173 static float clamp(
float v,
float min,
float max) {
174 return (v < min) ? min : (v > max) ? max : v;
IOdometryModel3D implementation for fixed-wing airplanes using control surface and throttle inputs.
Definition: AirplaneOdometryModel3D.h:57
void registerCallback(void(*callback)(void *), void *userData) override
Register a callback to be invoked on relevant events (e.g., input change).
Definition: AirplaneOdometryModel3D.h:63
bool onMessage(const Message< float > &msg)
Handle incoming control messages to set airplane control surfaces and throttle. Supports MessageConte...
Definition: AirplaneOdometryModel3D.h:104
void getAngularVelocity(float &wx, float &wy, float &wz) const override
Get the current angular velocity (wx, wy, wz) in rad/s (robot frame).
Definition: AirplaneOdometryModel3D.h:150
AirplaneOdometryModel3D(float maxSpeed=30.0f, float maxRollRate=57.0f, float maxPitchRate=40.0f, float maxYawRate=29.0f)
Construct an AirplaneOdometryModel3D with configurable max rates.
Definition: AirplaneOdometryModel3D.h:87
void getLinearVelocity(float &vx, float &vy, float &vz) const override
Get the current linear velocity (vx, vy, vz) in m/s (robot frame).
Definition: AirplaneOdometryModel3D.h:143
Abstract interface for 3D odometry models. Provides access to current linear and angular velocities f...
Definition: IOdometryModel3D.h:14
Generic message structure for communication, parameterized by value type.
Definition: Message.h:72