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 , _orientationCalDownSideVisible (false)
20 , _orientationCalUpsideDownSideVisible (false)
21 , _orientationCalLeftSideVisible (false)
22 , _orientationCalRightSideVisible (false)
23 , _orientationCalNoseDownSideVisible (false)
24 , _orientationCalTailDownSideVisible (false)
25 , _orientationCalDownSideState (SideCalStateIdle)
26 , _orientationCalUpsideDownSideState (SideCalStateIdle)
27 , _orientationCalLeftSideState (SideCalStateIdle)
28 , _orientationCalRightSideState (SideCalStateIdle)
29 , _orientationCalNoseDownSideState (SideCalStateIdle)
30 , _orientationCalTailDownSideState (SideCalStateIdle)
31 , _unknownFirmwareVersion (false)
32 , _waitingForCancel (false)
49void SensorsComponentController::_appendStatusLog(
const QString& text)
52 qWarning() <<
"Internal error";
56 QString varText = text;
57 QMetaObject::invokeMethod(_statusLog,
59 Q_ARG(QString, varText));
62void SensorsComponentController::_startLogCalibration(
void)
64 _unknownFirmwareVersion =
false;
70void SensorsComponentController::_startVisualCalibration(
void)
74 _progressBar->setProperty(
"value", 0);
88void SensorsComponentController::_setAllSidesState(SideCalState state)
90 _orientationCalDownSideState = state;
91 _orientationCalUpsideDownSideState = state;
92 _orientationCalLeftSideState = state;
93 _orientationCalRightSideState = state;
94 _orientationCalTailDownSideState = state;
95 _orientationCalNoseDownSideState = state;
100void SensorsComponentController::_stopCalibration(SensorsComponentController::StopCalibrationCode code)
104 if (code == StopCalibrationSuccess) {
107 _progressBar->setProperty(
"value", 1);
113 _progressBar->setProperty(
"value", 0);
116 _waitingForCancel =
false;
122 case StopCalibrationSuccess:
123 _orientationCalAreaHelpText->setProperty(
"text", tr(
"Calibration complete"));
124 if (!_airspeedCalInProgress && !_levelCalInProgress) {
127 if (_magCalInProgress) {
133 case StopCalibrationCancelled:
145 _magCalInProgress =
false;
146 _accelCalInProgress =
false;
147 _gyroCalInProgress =
false;
148 _airspeedCalInProgress =
false;
149 _levelCalInProgress =
false;
156 _startLogCalibration();
162 _startLogCalibration();
168 _startLogCalibration();
174 _startLogCalibration();
180 _startLogCalibration();
184void SensorsComponentController::_handleUASTextMessage(
int uasId,
int compId,
int severity, QString text,
const QString &description)
188 Q_UNUSED(description);
195 text.replace(
"<",
"<");
196 text.replace(
">",
">");
198 if (text.contains(
"progress <")) {
199 QString percent = text.split(
"<").last().split(
">").first();
201 int p = percent.toInt(&ok);
204 _progressBar->setProperty(
"value", (
float)(p / 100.0));
206 qWarning() <<
"Internal error";
212 _appendStatusLog(text);
213 qCDebug(SensorsComponentControllerLog) << text;
215 if (_unknownFirmwareVersion) {
221 QString calPrefix(
"[cal] ");
222 if (!text.startsWith(calPrefix)) {
225 text = text.right(text.length() - calPrefix.length());
227 QString calStartPrefix(
"calibration started: ");
228 if (text.startsWith(calStartPrefix)) {
229 text = text.right(text.length() - calStartPrefix.length());
232 QStringList parts = text.split(
" ");
233 if (parts.count() != 2 && parts[0].toInt() != _supportedFirmwareCalVersion) {
234 _unknownFirmwareVersion =
true;
235 QString msg = tr(
"Unsupported calibration firmware version, using log");
236 _appendStatusLog(msg);
241 _startVisualCalibration();
244 if (text ==
"accel" || text ==
"mag" || text ==
"gyro") {
248 _orientationCalDownSideVisible =
false;
249 _orientationCalUpsideDownSideVisible =
false;
250 _orientationCalLeftSideVisible =
false;
251 _orientationCalRightSideVisible =
false;
252 _orientationCalTailDownSideVisible =
false;
253 _orientationCalNoseDownSideVisible =
false;
255 _orientationCalAreaHelpText->setProperty(
"text", tr(
"Place your vehicle into one of the Incomplete orientations shown below and hold it still"));
257 if (text ==
"accel") {
258 _accelCalInProgress =
true;
259 _orientationCalDownSideVisible =
true;
260 _orientationCalUpsideDownSideVisible =
true;
261 _orientationCalLeftSideVisible =
true;
262 _orientationCalRightSideVisible =
true;
263 _orientationCalTailDownSideVisible =
true;
264 _orientationCalNoseDownSideVisible =
true;
265 }
else if (text ==
"mag") {
275 sides = (1 << 5) | (1 << 4) | (1 << 3) | (1 << 2) | (1 << 1) | (1 << 0);
278 _magCalInProgress =
true;
279 _orientationCalTailDownSideVisible = ((sides & (1 << 0)) > 0);
280 _orientationCalNoseDownSideVisible = ((sides & (1 << 1)) > 0);
281 _orientationCalLeftSideVisible = ((sides & (1 << 2)) > 0);
282 _orientationCalRightSideVisible = ((sides & (1 << 3)) > 0);
283 _orientationCalUpsideDownSideVisible = ((sides & (1 << 4)) > 0);
284 _orientationCalDownSideVisible = ((sides & (1 << 5)) > 0);
285 }
else if (text ==
"gyro") {
286 _gyroCalInProgress =
true;
287 _orientationCalDownSideVisible =
true;
289 qWarning() <<
"Unknown calibration message type" << text;
292 _updateAndEmitShowOrientationCalArea(
true);
293 }
else if (text ==
"airspeed") {
294 _airspeedCalInProgress =
true;
295 }
else if (text ==
"level") {
296 _levelCalInProgress =
true;
302 if (text.endsWith(
"orientation detected")) {
303 QString side = text.section(
" ", 0, 0);
304 qCDebug(SensorsComponentControllerLog) <<
"Side started" << side;
306 if (side ==
"down") {
308 }
else if (side ==
"up") {
310 }
else if (side ==
"left") {
312 }
else if (side ==
"right") {
314 }
else if (side ==
"front") {
316 }
else if (side ==
"back") {
320 if (_magCalInProgress) {
321 _orientationCalAreaHelpText->setProperty(
"text", tr(
"Rotate the vehicle continuously as shown in the diagram until marked as Completed"));
323 _orientationCalAreaHelpText->setProperty(
"text", tr(
"Hold still in the current orientation"));
330 if (text.endsWith(
"side done, rotate to a different side")) {
331 QString side = text.section(
" ", 0, 0);
332 qCDebug(SensorsComponentControllerLog) <<
"Side finished" << side;
334 if (side ==
"down") {
336 }
else if (side ==
"up") {
338 }
else if (side ==
"left") {
340 }
else if (side ==
"right") {
342 }
else if (side ==
"front") {
344 }
else if (side ==
"back") {
348 _orientationCalAreaHelpText->setProperty(
"text", tr(
"Place you vehicle into one of the orientations shown below and hold it still"));
354 if (text.endsWith(
"side already completed")) {
355 _orientationCalAreaHelpText->setProperty(
"text", tr(
"Orientation already completed, place you vehicle into one of the incomplete orientations shown below and hold it still"));
359 QString calCompletePrefix(
"calibration done:");
360 if (text.startsWith(calCompletePrefix)) {
361 _stopCalibration(StopCalibrationSuccess);
365 if (text.startsWith(
"calibration cancelled")) {
366 _stopCalibration(_waitingForCancel ? StopCalibrationCancelled : StopCalibrationFailed);
370 if (text.startsWith(
"calibration failed")) {
371 _stopCalibration(StopCalibrationFailed);
376void SensorsComponentController::_refreshParams(
void)
379 QStringLiteral(
"CAL_MAG0_ID"), QStringLiteral(
"CAL_MAG1_ID"), QStringLiteral(
"CAL_MAG2_ID"),
380 QStringLiteral(
"CAL_MAG0_ROT"), QStringLiteral(
"CAL_MAG1_ROT"), QStringLiteral(
"CAL_MAG2_ROT"),
381 QStringLiteral(
"CAL_*"),
382 QStringLiteral(
"SENS_*"),
386void SensorsComponentController::_updateAndEmitShowOrientationCalArea(
bool show)
388 _showOrientationCalArea = show;
392void SensorsComponentController::_hideAllCalAreas(
void)
394 _updateAndEmitShowOrientationCalArea(
false);
401 _waitingForCancel =
true;
406void SensorsComponentController::_handleParametersReset(
bool success)
411 QTimer::singleShot(1000,
this, [
this]() {
425 MAV_CMD_PREFLIGHT_STORAGE,
std::shared_ptr< LinkInterface > SharedLinkInterfacePtr
#define QGC_LOGGING_CATEGORY(name, categoryStr)
QVariant rawValue() const
bool parameterExists(int componentId, const QString ¶mName) const
Fact * getParameter(int componentId, const QString ¶mName)
void bulkRefresh(int componentId, const QStringList &names, bool notifyFailure=true)
static constexpr int defaultComponentId
Sensors Component MVC Controller for SensorsComponent.qml.
bool calibrationActive() const
Q_INVOKABLE void calibrateGyro(void)
Q_INVOKABLE void calibrateAccel(void)
void orientationCalSidesVisibleChanged(void)
void magCalComplete(void)
Q_INVOKABLE void calibrateLevel(void)
void waitingForCancelChanged(void)
Q_INVOKABLE void resetSidesToIdle(void)
@ SideCalStateIncomplete
Calibration running, side not yet calibrated.
@ SideCalStateInProgress
Side actively being calibrated.
@ SideCalStateIdle
No calibration data to show (neutral preview)
@ SideCalStateCompleted
Side calibration complete.
void orientationCalSidesStateChanged(void)
void resetStatusTextArea(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)
void setRebootRequired()
Latches rebootRequired until the vehicle reboots.
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.