QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
SensorsComponent.cc
Go to the documentation of this file.
1#include "SensorsComponent.h"
2#include "ParameterManager.h"
3#include "Vehicle.h"
4
5SensorsComponent::SensorsComponent(Vehicle* vehicle, AutoPilotPlugin* autopilot, QObject* parent)
6 : VehicleComponent(vehicle, autopilot, AutoPilotPlugin::KnownSensorsVehicleComponent, parent)
7 , _name(tr("Sensors"))
8{
9 _deviceIds = QStringList({QStringLiteral("CAL_GYRO0_ID"), QStringLiteral("CAL_ACC0_ID") });
10
11 if (_vehicle->fixedWing() || _vehicle->vtol() || _vehicle->airship()) {
12 _airspeedCalTriggerParams << "SENS_DPRES_OFF";
14 _airspeedCalTriggerParams << "SYS_HAS_NUM_ASPD";
15 } else {
16 _airspeedCalTriggerParams << "FW_ARSP_MODE" << "CBRK_AIRSPD_CHK";
17 }
18 }
19}
20
21QString SensorsComponent::name(void) const
22{
23 return _name;
24}
25
27{
28 return tr("Configure and calibrate gyroscope, accelerometer, magnetometer, and airspeed sensors.");
29}
30
32{
33 return "/qmlimages/SensorsComponentIcon.png";
34}
35
37{
38 return true;
39}
40
42{
43 for (const QString &triggerParam : std::as_const(_deviceIds)) {
44 if (_vehicle->parameterManager()->getParameter(ParameterManager::defaultComponentId, triggerParam)->rawValue().toFloat() == 0.0f) {
45 return false;
46 }
47 }
48 bool magEnabled = true;
50 magEnabled = _vehicle->parameterManager()->getParameter(ParameterManager::defaultComponentId, _magEnabledParam)->rawValue().toBool();
51 }
52
53 if (magEnabled && _vehicle->parameterManager()->getParameter(ParameterManager::defaultComponentId, _magCalParam)->rawValue().toFloat() == 0.0f) {
54 return false;
55 }
56
57 if (_vehicle->fixedWing() || _vehicle->vtol() || _vehicle->airship()) {
60 _vehicle->parameterManager()->getParameter(ParameterManager::defaultComponentId, "SENS_DPRES_OFF")->rawValue().toFloat() == 0.0f) {
61 return false;
62 }
63 } else {
65 _vehicle->parameterManager()->getParameter(ParameterManager::defaultComponentId, "CBRK_AIRSPD_CHK")->rawValue().toInt() != 162128 &&
66 _vehicle->parameterManager()->getParameter(ParameterManager::defaultComponentId, "SENS_DPRES_OFF")->rawValue().toFloat() == 0.0f) {
67 return false;
68 }
69 }
70 }
71
72 return true;
73}
74
76{
77 QStringList triggers;
78
79 triggers << _deviceIds << _magCalParam << _magEnabledParam;
80 if (_vehicle->fixedWing() || _vehicle->vtol() || _vehicle->airship()) {
81 triggers << _airspeedCalTriggerParams;
82 }
83
84 return triggers;
85}
86
88{
89 return QUrl::fromUserInput("qrc:/qml/QGroundControl/AutoPilotPlugins/PX4/SensorsComponent.qml");
90}
91
93{
94 QStringList sectionList;
95
96 // Compass (hidden when all mags disabled)
97 bool allMagsDisabled = false;
99 allMagsDisabled = !_vehicle->parameterManager()->getParameter(ParameterManager::defaultComponentId, _magEnabledParam)->rawValue().toBool();
100 }
101 if (!allMagsDisabled) {
102 sectionList << QStringLiteral("Compass");
103 }
104
105 sectionList << QStringLiteral("Gyroscope");
106 sectionList << QStringLiteral("Accelerometer");
107 sectionList << QStringLiteral("Level Horizon");
108
109 if (_airspeedCalSupported()) {
110 sectionList << QStringLiteral("Airspeed");
111 }
112
113 sectionList << QStringLiteral("Orientations");
114
115 return sectionList;
116}
117
118QString SensorsComponent::sectionDisplayName(const QString& sectionId) const
119{
120 if (sectionId == QStringLiteral("Compass")) {
121 return tr("Compass");
122 }
123 if (sectionId == QStringLiteral("Gyroscope")) {
124 return tr("Gyroscope");
125 }
126 if (sectionId == QStringLiteral("Accelerometer")) {
127 return tr("Accelerometer");
128 }
129 if (sectionId == QStringLiteral("Level Horizon")) {
130 return tr("Level Horizon");
131 }
132 if (sectionId == QStringLiteral("Airspeed")) {
133 return tr("Airspeed");
134 }
135 if (sectionId == QStringLiteral("Orientations")) {
136 return tr("Orientations");
137 }
138 return sectionId;
139}
140
142{
143 QString summaryQml;
144
145 if (_vehicle->fixedWing() || _vehicle->vtol() || _vehicle->airship()) {
146 summaryQml = "qrc:/qml/QGroundControl/AutoPilotPlugins/PX4/SensorsComponentSummaryFixedWing.qml";
147 } else {
148 summaryQml = "qrc:/qml/QGroundControl/AutoPilotPlugins/PX4/SensorsComponentSummary.qml";
149 }
150
151 return QUrl::fromUserInput(summaryQml);
152}
153
154 bool SensorsComponent::_airspeedCalSupported(void) const
155 {
156 if (_vehicle->fixedWing() || _vehicle->vtol() || _vehicle->airship()) {
159 return true;
160 }
161 } else {
163 _vehicle->parameterManager()->getParameter(ParameterManager::defaultComponentId, "CBRK_AIRSPD_CHK")->rawValue().toInt() != 162128) {
164 return true;
165 }
166 }
167 }
168
169 return false;
170 }
171
172 bool SensorsComponent::_airspeedCalRequired(void) const
173 {
174 return _airspeedCalSupported() && _vehicle->parameterManager()->getParameter(ParameterManager::defaultComponentId, "SENS_DPRES_OFF")->rawValue().toFloat() == 0.0f;
175 }
176
177bool SensorsComponent::sectionSetupComplete(const QString &sectionId) const
178{
179 auto *pm = _vehicle->parameterManager();
180
181 if (sectionId == QStringLiteral("Compass")) {
182 bool magEnabled = true;
183 if (pm->parameterExists(ParameterManager::defaultComponentId, _magEnabledParam)) {
184 magEnabled = pm->getParameter(ParameterManager::defaultComponentId, _magEnabledParam)->rawValue().toBool();
185 }
186 if (!magEnabled) return true;
187 return pm->getParameter(ParameterManager::defaultComponentId, _magCalParam)->rawValue().toFloat() != 0.0f;
188 }
189 if (sectionId == QStringLiteral("Gyroscope")) {
190 return pm->getParameter(ParameterManager::defaultComponentId, "CAL_GYRO0_ID")->rawValue().toFloat() != 0.0f;
191 }
192 if (sectionId == QStringLiteral("Accelerometer")) {
193 return pm->getParameter(ParameterManager::defaultComponentId, "CAL_ACC0_ID")->rawValue().toFloat() != 0.0f;
194 }
195 if (sectionId == QStringLiteral("Level Horizon")) {
196 // Level cal doesn't have a distinct completion indicator — consider complete if accel+gyro are done
197 return pm->getParameter(ParameterManager::defaultComponentId, "CAL_ACC0_ID")->rawValue().toFloat() != 0.0f
198 && pm->getParameter(ParameterManager::defaultComponentId, "CAL_GYRO0_ID")->rawValue().toFloat() != 0.0f;
199 }
200 if (sectionId == QStringLiteral("Airspeed")) {
201 return !_airspeedCalRequired();
202 }
203
204 return true;
205}
The AutoPilotPlugin class is an abstract base class which represents the methods and objects which ar...
QVariant rawValue() const
Definition Fact.h:87
bool parameterExists(int componentId, const QString &paramName) const
Fact * getParameter(int componentId, const QString &paramName)
static constexpr int defaultComponentId
virtual bool requiresSetup(void) const override
bool sectionSetupComplete(const QString &sectionId) const override
Returns setup-complete status for a section ID. Default returns true (no per-section tracking).
virtual QUrl setupSource(void) const override
virtual QString iconResource(void) const override
QStringList sectionIds() const override
QStringList setupCompleteChangedTriggerList(void) const override
virtual bool setupComplete(void) const override
virtual QString name(void) const override
virtual QUrl summaryQmlSource(void) const override
QString sectionDisplayName(const QString &sectionId) const override
SensorsComponent(Vehicle *vehicle, AutoPilotPlugin *autopilot, QObject *parent=nullptr)
virtual QString description(void) const override
A vehicle component is an object which abstracts the physical portion of a vehicle into a set of conf...
bool vtol() const
Definition Vehicle.cc:1780
int firmwareMinorVersion() const
Definition Vehicle.h:680
ParameterManager * parameterManager()
Definition Vehicle.h:595
bool fixedWing() const
Definition Vehicle.cc:1755
int firmwareMajorVersion() const
Definition Vehicle.h:679
bool airship() const
Definition Vehicle.cc:1750