2#include <SimpleMavlinkDrone.h>
4#include "TinyRobotics/utils/Common.h"
6namespace tinyrobotics {
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
29 MavlinkMessageSource(SimpleMavlinkDrone& drone,
31 : drone(drone), scenario(scenario) {}
36 this->scenario = scenario;
42 void end() { is_active_ =
false; }
46 if (!is_active_)
return;
48 if (drone.isArmed()) {
56 max_steering_deg = angleDeg;
60 SimpleMavlinkDrone& drone;
62 bool is_active_ =
false;
63 float max_steering_deg = 45.0f;
65 void publishScenario() {
84 float steeringAngle = -drone.getValue(YAW) * max_steering_deg / 100.0f;
85 steeringAngle = normalizeAngleDeg(steeringAngle);
86 float throttle = drone.getValue(THROTTLE) * 100.0f;
87 publish(Message(MessageContent::SteeringAngle, steeringAngle,
Unit::AngleDegree));
88 publish(Message(MessageContent::Throttle, throttle,
Unit::Percent));
93 float steeringAngle = -drone.getValue(YAW) * max_steering_deg / 100.0f;
94 steeringAngle = normalizeAngleDeg(steeringAngle);
95 float throttle = drone.getValue(THROTTLE) * 100.0f;
96 publish(Message(MessageContent::SteeringAngle, steeringAngle,
Unit::AngleDegree));
97 publish(Message(MessageContent::Throttle, throttle,
Unit::Percent));
100 void publishDrone() {
102 float roll = drone.getValue(ROLL);
103 float pitch = drone.getValue(PITCH);
104 float throttle = drone.getValue(THROTTLE) * 100.0f;
105 float yaw = -drone.getValue(YAW);
107 publish(Message(MessageContent::Pitch, pitch,
Unit::Percent));
108 publish(Message(MessageContent::Throttle, throttle,
Unit::Percent));
112 void publishPlane() {
114 float aileron = drone.getValue(ROLL);
115 float elevator = drone.getValue(PITCH);
116 float throttle = drone.getValue(THROTTLE) * 100.0f;
117 float rudder = -drone.getValue(YAW);
118 publish(Message(MessageContent::Roll, aileron,
Unit::Percent));
119 publish(Message(MessageContent::Pitch, elevator,
Unit::Percent));
120 publish(Message(MessageContent::Throttle, throttle,
Unit::Percent));
121 publish(Message(MessageContent::Yaw, rudder,
Unit::Percent));
125 void publish(
const Message<
float>& msg) {
131 static float mapFloat(
float x,
float in_min,
float in_max,
float out_min,
133 return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
Message source for MAVLink integration using ArduinoMavlinkDrone.
Definition: MavlinkMessageSource.h:27
void setMaxSteeringAngle(float angleDeg)
Defines the max steering ange in degrees: default 45.
Definition: MavlinkMessageSource.h:55
bool begin(ControlScenario scenario=ControlScenario::Car)
Start the message source.
Definition: MavlinkMessageSource.h:35
void end()
Stop the message source.
Definition: MavlinkMessageSource.h:42
void update()
Call this in your main loop to handle MAVLink messages.
Definition: MavlinkMessageSource.h:45
Base class for message sources in the TinyRobotics communication framework.
Definition: MessageSource.h:35
ControlScenario
Control scenario types for remote control vehicles.
Definition: Common.h:68
Unit
Units for message values.
Definition: Common.h:45
@ AngleDegree
Angle in degrees.
@ Percent
Percentage (0-100)
Generic message structure for communication, parameterized by value type.
Definition: Message.h:72