QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
VehicleDistanceSensorFactGroup.cc
Go to the documentation of this file.
2
3#include "MAVLinkLib.h"
4#include "Vehicle.h"
5
7 : FactGroup(1000, QStringLiteral(":/json/Vehicle/DistanceSensorFact.json"), parent)
8{
9 _addFact(&_rotationNoneFact);
10 _addFact(&_rotationYaw45Fact);
11 _addFact(&_rotationYaw90Fact);
12 _addFact(&_rotationYaw135Fact);
13 _addFact(&_rotationYaw180Fact);
14 _addFact(&_rotationYaw225Fact);
15 _addFact(&_rotationYaw270Fact);
16 _addFact(&_rotationYaw315Fact);
17 _addFact(&_rotationPitch90Fact);
18 _addFact(&_rotationPitch270Fact);
19 _addFact(&_minDistanceFact);
20 _addFact(&_maxDistanceFact);
21}
22
24{
25 Q_UNUSED(vehicle);
26
27 if (message.msgid != MAVLINK_MSG_ID_DISTANCE_SENSOR) {
28 return;
29 }
30
31 mavlink_distance_sensor_t distanceSensor{};
32 mavlink_msg_distance_sensor_decode(&message, &distanceSensor);
33
34 struct orientation2Fact_s {
35 const MAV_SENSOR_ORIENTATION orientation;
36 Fact *fact;
37 };
38
39 const orientation2Fact_s rgOrientation2Fact[] = {
40 { MAV_SENSOR_ROTATION_NONE, rotationNone() },
41 { MAV_SENSOR_ROTATION_YAW_45, rotationYaw45() },
42 { MAV_SENSOR_ROTATION_YAW_90, rotationYaw90() },
43 { MAV_SENSOR_ROTATION_YAW_135, rotationYaw135() },
44 { MAV_SENSOR_ROTATION_YAW_180, rotationYaw180() },
45 { MAV_SENSOR_ROTATION_YAW_225, rotationYaw225() },
46 { MAV_SENSOR_ROTATION_YAW_270, rotationYaw270() },
47 { MAV_SENSOR_ROTATION_YAW_315, rotationYaw315() },
48 { MAV_SENSOR_ROTATION_PITCH_90, rotationPitch90() },
49 { MAV_SENSOR_ROTATION_PITCH_270, rotationPitch270() },
50 };
51
52 for (const orientation2Fact_s &orientation2Fact : rgOrientation2Fact) {
53 if (orientation2Fact.orientation == distanceSensor.orientation) {
54 orientation2Fact.fact->setRawValue(distanceSensor.current_distance / 100.0); // cm to meters
55 break;
56 }
57 }
58
59 minDistance()->setRawValue(distanceSensor.min_distance / 100.0);
60 maxDistance()->setRawValue(distanceSensor.max_distance / 100.0);
61
63}
struct __mavlink_message mavlink_message_t
Used to group Facts together into an object hierarachy.
Definition FactGroup.h:16
void _setTelemetryAvailable(bool telemetryAvailable)
Definition FactGroup.cc:175
void _addFact(Fact *fact, const QString &name)
Definition FactGroup.cc:116
A Fact is used to hold a single value within the system.
Definition Fact.h:15
void setRawValue(const QVariant &value)
Definition Fact.cc:135
VehicleDistanceSensorFactGroup(QObject *parent=nullptr)
void handleMessage(Vehicle *vehicle, const mavlink_message_t &message) final
Allows a FactGroup to parse incoming messages and fill in values.