11 : _statusLog (
nullptr)
12 , _progressBar (
nullptr)
13 , _showOrientationCalArea (false)
14 , _gyroCalInProgress (false)
15 , _magCalInProgress (false)
16 , _accelCalInProgress (false)
17 , _airspeedCalInProgress (false)
18 , _levelCalInProgress (false)
19 , _orientationCalDownSideDone (false)
20 , _orientationCalUpsideDownSideDone (false)
21 , _orientationCalLeftSideDone (false)
22 , _orientationCalRightSideDone (false)
23 , _orientationCalNoseDownSideDone (false)
24 , _orientationCalTailDownSideDone (false)
25 , _orientationCalDownSideVisible (false)
26 , _orientationCalUpsideDownSideVisible (false)
27 , _orientationCalLeftSideVisible (false)
28 , _orientationCalRightSideVisible (false)
29 , _orientationCalNoseDownSideVisible (false)
30 , _orientationCalTailDownSideVisible (false)
31 , _orientationCalDownSideInProgress (false)
32 , _orientationCalUpsideDownSideInProgress (false)
33 , _orientationCalLeftSideInProgress (false)
34 , _orientationCalRightSideInProgress (false)
35 , _orientationCalNoseDownSideInProgress (false)
36 , _orientationCalTailDownSideInProgress (false)
37 , _orientationCalDownSideRotate (false)
38 , _orientationCalUpsideDownSideRotate (false)
39 , _orientationCalLeftSideRotate (false)
40 , _orientationCalRightSideRotate (false)
41 , _orientationCalNoseDownSideRotate (false)
42 , _orientationCalTailDownSideRotate (false)
43 , _unknownFirmwareVersion (false)
44 , _waitingForCancel (false)
61void SensorsComponentController::_appendStatusLog(
const QString& text)
64 qWarning() <<
"Internal error";
68 QString varText = text;
69 QMetaObject::invokeMethod(_statusLog,
71 Q_ARG(QString, varText));
74void SensorsComponentController::_startLogCalibration(
void)
76 _unknownFirmwareVersion =
false;
82void SensorsComponentController::_startVisualCalibration(
void)
84 _resetInternalState();
86 _progressBar->setProperty(
"value", 0);
89void SensorsComponentController::_resetInternalState(
void)
91 _orientationCalDownSideDone =
true;
92 _orientationCalUpsideDownSideDone =
true;
93 _orientationCalLeftSideDone =
true;
94 _orientationCalRightSideDone =
true;
95 _orientationCalTailDownSideDone =
true;
96 _orientationCalNoseDownSideDone =
true;
97 _orientationCalDownSideInProgress =
false;
98 _orientationCalUpsideDownSideInProgress =
false;
99 _orientationCalLeftSideInProgress =
false;
100 _orientationCalRightSideInProgress =
false;
101 _orientationCalNoseDownSideInProgress =
false;
102 _orientationCalTailDownSideInProgress =
false;
103 _orientationCalDownSideRotate =
false;
104 _orientationCalUpsideDownSideRotate =
false;
105 _orientationCalLeftSideRotate =
false;
106 _orientationCalRightSideRotate =
false;
107 _orientationCalNoseDownSideRotate =
false;
108 _orientationCalTailDownSideRotate =
false;
115void SensorsComponentController::_stopCalibration(SensorsComponentController::StopCalibrationCode code)
119 if (code == StopCalibrationSuccess) {
120 _resetInternalState();
122 _progressBar->setProperty(
"value", 1);
124 _progressBar->setProperty(
"value", 0);
127 _waitingForCancel =
false;
133 case StopCalibrationSuccess:
134 _orientationCalAreaHelpText->setProperty(
"text", tr(
"Calibration complete"));
135 if (!_airspeedCalInProgress && !_levelCalInProgress) {
138 if (_magCalInProgress) {
143 case StopCalibrationCancelled:
155 _magCalInProgress =
false;
156 _accelCalInProgress =
false;
157 _gyroCalInProgress =
false;
158 _airspeedCalInProgress =
false;
159 _levelCalInProgress =
false;
166 _startLogCalibration();
172 _startLogCalibration();
178 _startLogCalibration();
184 _startLogCalibration();
190 _startLogCalibration();
194void SensorsComponentController::_handleUASTextMessage(
int uasId,
int compId,
int severity, QString text,
const QString &description)
198 Q_UNUSED(description);
205 text.replace(
"<",
"<");
206 text.replace(
">",
">");
208 if (text.contains(
"progress <")) {
209 QString percent = text.split(
"<").last().split(
">").first();
211 int p = percent.toInt(&ok);
214 _progressBar->setProperty(
"value", (
float)(p / 100.0));
216 qWarning() <<
"Internal error";
222 _appendStatusLog(text);
223 qCDebug(SensorsComponentControllerLog) << text;
225 if (_unknownFirmwareVersion) {
231 QString calPrefix(
"[cal] ");
232 if (!text.startsWith(calPrefix)) {
235 text = text.right(text.length() - calPrefix.length());
237 QString calStartPrefix(
"calibration started: ");
238 if (text.startsWith(calStartPrefix)) {
239 text = text.right(text.length() - calStartPrefix.length());
242 QStringList parts = text.split(
" ");
243 if (parts.count() != 2 && parts[0].toInt() != _supportedFirmwareCalVersion) {
244 _unknownFirmwareVersion =
true;
245 QString msg = tr(
"Unsupported calibration firmware version, using log");
246 _appendStatusLog(msg);
251 _startVisualCalibration();
254 if (text ==
"accel" || text ==
"mag" || text ==
"gyro") {
256 _orientationCalDownSideDone =
false;
257 _orientationCalUpsideDownSideDone =
false;
258 _orientationCalLeftSideDone =
false;
259 _orientationCalRightSideDone =
false;
260 _orientationCalTailDownSideDone =
false;
261 _orientationCalNoseDownSideDone =
false;
262 _orientationCalDownSideInProgress =
false;
263 _orientationCalUpsideDownSideInProgress =
false;
264 _orientationCalLeftSideInProgress =
false;
265 _orientationCalRightSideInProgress =
false;
266 _orientationCalNoseDownSideInProgress =
false;
267 _orientationCalTailDownSideInProgress =
false;
270 _orientationCalDownSideVisible =
false;
271 _orientationCalUpsideDownSideVisible =
false;
272 _orientationCalLeftSideVisible =
false;
273 _orientationCalRightSideVisible =
false;
274 _orientationCalTailDownSideVisible =
false;
275 _orientationCalNoseDownSideVisible =
false;
277 _orientationCalAreaHelpText->setProperty(
"text", tr(
"Place your vehicle into one of the Incomplete orientations shown below and hold it still"));
279 if (text ==
"accel") {
280 _accelCalInProgress =
true;
281 _orientationCalDownSideVisible =
true;
282 _orientationCalUpsideDownSideVisible =
true;
283 _orientationCalLeftSideVisible =
true;
284 _orientationCalRightSideVisible =
true;
285 _orientationCalTailDownSideVisible =
true;
286 _orientationCalNoseDownSideVisible =
true;
287 }
else if (text ==
"mag") {
297 sides = (1 << 5) | (1 << 4) | (1 << 3) | (1 << 2) | (1 << 1) | (1 << 0);
300 _magCalInProgress =
true;
301 _orientationCalTailDownSideVisible = ((sides & (1 << 0)) > 0);
302 _orientationCalNoseDownSideVisible = ((sides & (1 << 1)) > 0);
303 _orientationCalLeftSideVisible = ((sides & (1 << 2)) > 0);
304 _orientationCalRightSideVisible = ((sides & (1 << 3)) > 0);
305 _orientationCalUpsideDownSideVisible = ((sides & (1 << 4)) > 0);
306 _orientationCalDownSideVisible = ((sides & (1 << 5)) > 0);
307 }
else if (text ==
"gyro") {
308 _gyroCalInProgress =
true;
309 _orientationCalDownSideVisible =
true;
311 qWarning() <<
"Unknown calibration message type" << text;
316 _updateAndEmitShowOrientationCalArea(
true);
317 }
else if (text ==
"airspeed") {
318 _airspeedCalInProgress =
true;
319 }
else if (text ==
"level") {
320 _levelCalInProgress =
true;
326 if (text.endsWith(
"orientation detected")) {
327 QString side = text.section(
" ", 0, 0);
328 qCDebug(SensorsComponentControllerLog) <<
"Side started" << side;
330 if (side ==
"down") {
331 _orientationCalDownSideInProgress =
true;
332 if (_magCalInProgress) {
333 _orientationCalDownSideRotate =
true;
335 }
else if (side ==
"up") {
336 _orientationCalUpsideDownSideInProgress =
true;
337 if (_magCalInProgress) {
338 _orientationCalUpsideDownSideRotate =
true;
340 }
else if (side ==
"left") {
341 _orientationCalLeftSideInProgress =
true;
342 if (_magCalInProgress) {
343 _orientationCalLeftSideRotate =
true;
345 }
else if (side ==
"right") {
346 _orientationCalRightSideInProgress =
true;
347 if (_magCalInProgress) {
348 _orientationCalRightSideRotate =
true;
350 }
else if (side ==
"front") {
351 _orientationCalNoseDownSideInProgress =
true;
352 if (_magCalInProgress) {
353 _orientationCalNoseDownSideRotate =
true;
355 }
else if (side ==
"back") {
356 _orientationCalTailDownSideInProgress =
true;
357 if (_magCalInProgress) {
358 _orientationCalTailDownSideRotate =
true;
362 if (_magCalInProgress) {
363 _orientationCalAreaHelpText->setProperty(
"text", tr(
"Rotate the vehicle continuously as shown in the diagram until marked as Completed"));
365 _orientationCalAreaHelpText->setProperty(
"text", tr(
"Hold still in the current orientation"));
373 if (text.endsWith(
"side done, rotate to a different side")) {
374 QString side = text.section(
" ", 0, 0);
375 qCDebug(SensorsComponentControllerLog) <<
"Side finished" << side;
377 if (side ==
"down") {
378 _orientationCalDownSideInProgress =
false;
379 _orientationCalDownSideDone =
true;
380 _orientationCalDownSideRotate =
false;
381 }
else if (side ==
"up") {
382 _orientationCalUpsideDownSideInProgress =
false;
383 _orientationCalUpsideDownSideDone =
true;
384 _orientationCalUpsideDownSideRotate =
false;
385 }
else if (side ==
"left") {
386 _orientationCalLeftSideInProgress =
false;
387 _orientationCalLeftSideDone =
true;
388 _orientationCalLeftSideRotate =
false;
389 }
else if (side ==
"right") {
390 _orientationCalRightSideInProgress =
false;
391 _orientationCalRightSideDone =
true;
392 _orientationCalRightSideRotate =
false;
393 }
else if (side ==
"front") {
394 _orientationCalNoseDownSideInProgress =
false;
395 _orientationCalNoseDownSideDone =
true;
396 _orientationCalNoseDownSideRotate =
false;
397 }
else if (side ==
"back") {
398 _orientationCalTailDownSideInProgress =
false;
399 _orientationCalTailDownSideDone =
true;
400 _orientationCalTailDownSideRotate =
false;
403 _orientationCalAreaHelpText->setProperty(
"text", tr(
"Place you vehicle into one of the orientations shown below and hold it still"));
411 if (text.endsWith(
"side already completed")) {
412 _orientationCalAreaHelpText->setProperty(
"text", tr(
"Orientation already completed, place you vehicle into one of the incomplete orientations shown below and hold it still"));
416 QString calCompletePrefix(
"calibration done:");
417 if (text.startsWith(calCompletePrefix)) {
418 _stopCalibration(StopCalibrationSuccess);
422 if (text.startsWith(
"calibration cancelled")) {
423 _stopCalibration(_waitingForCancel ? StopCalibrationCancelled : StopCalibrationFailed);
427 if (text.startsWith(
"calibration failed")) {
428 _stopCalibration(StopCalibrationFailed);
433void SensorsComponentController::_refreshParams(
void)
435 QStringList fastRefreshList;
438 fastRefreshList <<
"CAL_MAG0_ID" <<
"CAL_MAG1_ID" <<
"CAL_MAG2_ID" <<
"CAL_MAG0_ROT" <<
"CAL_MAG1_ROT" <<
"CAL_MAG2_ROT";
439 for (
const QString ¶mName : std::as_const(fastRefreshList)) {
448void SensorsComponentController::_updateAndEmitShowOrientationCalArea(
bool show)
450 _showOrientationCalArea = show;
454void SensorsComponentController::_hideAllCalAreas(
void)
456 _updateAndEmitShowOrientationCalArea(
false);
463 _waitingForCancel =
true;
468void SensorsComponentController::_handleParametersReset(
bool success)
473 QTimer::singleShot(1000,
this, [
this]() {
487 MAV_CMD_PREFLIGHT_STORAGE,
std::shared_ptr< LinkInterface > SharedLinkInterfacePtr
#define QGC_LOGGING_CATEGORY(name, categoryStr)
QVariant rawValue() const
Value after translation.
bool parameterExists(int componentId, const QString ¶mName) const
Fact * getParameter(int componentId, const QString ¶mName)
void refreshParametersPrefix(int componentId, const QString &namePrefix)
Request a refresh on all parameters that begin with the specified prefix.
static constexpr int defaultComponentId
void refreshParameter(int componentId, const QString ¶mName)
Request a refresh on the specific parameter.
Sensors Component MVC Controller for SensorsComponent.qml.
Q_INVOKABLE void calibrateGyro(void)
Q_INVOKABLE void calibrateAccel(void)
void orientationCalSidesVisibleChanged(void)
void magCalComplete(void)
Q_INVOKABLE void calibrateLevel(void)
void waitingForCancelChanged(void)
void orientationCalSidesInProgressChanged(void)
void orientationCalSidesDoneChanged(void)
void resetStatusTextArea(void)
void orientationCalSidesRotateChanged(void)
Q_INVOKABLE void calibrateAirspeed(void)
Q_INVOKABLE void calibrateCompass(void)
Q_INVOKABLE void cancelCalibration(void)
void calibrationActiveChanged(void)
Q_INVOKABLE bool usingUDPLink(void)
Q_INVOKABLE void resetFactoryParameters()
void showOrientationCalAreaChanged(void)
WeakLinkInterfacePtr primaryLink() const
void sendMavCommand(int compId, MAV_CMD command, bool showError, float param1=0.0f, float param2=0.0f, float param3=0.0f, float param4=0.0f, float param5=0.0f, float param6=0.0f, float param7=0.0f)
void textMessageReceived(int sysid, int componentid, int severity, QString text, QString description)
VehicleLinkManager * vehicleLinkManager()
void sensorsParametersResetAck(bool success)
int defaultComponentId() const
ParameterManager * parameterManager()
void startCalibration(QGCMAVLink::CalibrationType calType)
void stopCalibration(bool showError)
void showAppMessage(const QString &message, const QString &title)
Modal application message. Queued if the UI isn't ready yet.