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) {
132 case StopCalibrationCancelled:
144 _magCalInProgress =
false;
145 _accelCalInProgress =
false;
146 _gyroCalInProgress =
false;
147 _airspeedCalInProgress =
false;
148 _levelCalInProgress =
false;
155 _startLogCalibration();
161 _startLogCalibration();
167 _startLogCalibration();
173 _startLogCalibration();
179 _startLogCalibration();
183void SensorsComponentController::_handleUASTextMessage(
int uasId,
int compId,
int severity, QString text,
const QString &description)
187 Q_UNUSED(description);
194 text.replace(
"<",
"<");
195 text.replace(
">",
">");
197 if (text.contains(
"progress <")) {
198 QString percent = text.split(
"<").last().split(
">").first();
200 int p = percent.toInt(&ok);
203 _progressBar->setProperty(
"value", (
float)(p / 100.0));
205 qWarning() <<
"Internal error";
211 _appendStatusLog(text);
212 qCDebug(SensorsComponentControllerLog) << text;
214 if (_unknownFirmwareVersion) {
220 QString calPrefix(
"[cal] ");
221 if (!text.startsWith(calPrefix)) {
224 text = text.right(text.length() - calPrefix.length());
226 QString calStartPrefix(
"calibration started: ");
227 if (text.startsWith(calStartPrefix)) {
228 text = text.right(text.length() - calStartPrefix.length());
231 QStringList parts = text.split(
" ");
232 if (parts.count() != 2 && parts[0].toInt() != _supportedFirmwareCalVersion) {
233 _unknownFirmwareVersion =
true;
234 QString msg = tr(
"Unsupported calibration firmware version, using log");
235 _appendStatusLog(msg);
240 _startVisualCalibration();
243 if (text ==
"accel" || text ==
"mag" || text ==
"gyro") {
247 _orientationCalDownSideVisible =
false;
248 _orientationCalUpsideDownSideVisible =
false;
249 _orientationCalLeftSideVisible =
false;
250 _orientationCalRightSideVisible =
false;
251 _orientationCalTailDownSideVisible =
false;
252 _orientationCalNoseDownSideVisible =
false;
254 _orientationCalAreaHelpText->setProperty(
"text", tr(
"Place your vehicle into one of the Incomplete orientations shown below and hold it still"));
256 if (text ==
"accel") {
257 _accelCalInProgress =
true;
258 _orientationCalDownSideVisible =
true;
259 _orientationCalUpsideDownSideVisible =
true;
260 _orientationCalLeftSideVisible =
true;
261 _orientationCalRightSideVisible =
true;
262 _orientationCalTailDownSideVisible =
true;
263 _orientationCalNoseDownSideVisible =
true;
264 }
else if (text ==
"mag") {
274 sides = (1 << 5) | (1 << 4) | (1 << 3) | (1 << 2) | (1 << 1) | (1 << 0);
277 _magCalInProgress =
true;
278 _orientationCalTailDownSideVisible = ((sides & (1 << 0)) > 0);
279 _orientationCalNoseDownSideVisible = ((sides & (1 << 1)) > 0);
280 _orientationCalLeftSideVisible = ((sides & (1 << 2)) > 0);
281 _orientationCalRightSideVisible = ((sides & (1 << 3)) > 0);
282 _orientationCalUpsideDownSideVisible = ((sides & (1 << 4)) > 0);
283 _orientationCalDownSideVisible = ((sides & (1 << 5)) > 0);
284 }
else if (text ==
"gyro") {
285 _gyroCalInProgress =
true;
286 _orientationCalDownSideVisible =
true;
288 qWarning() <<
"Unknown calibration message type" << text;
291 _updateAndEmitShowOrientationCalArea(
true);
292 }
else if (text ==
"airspeed") {
293 _airspeedCalInProgress =
true;
294 }
else if (text ==
"level") {
295 _levelCalInProgress =
true;
301 if (text.endsWith(
"orientation detected")) {
302 QString side = text.section(
" ", 0, 0);
303 qCDebug(SensorsComponentControllerLog) <<
"Side started" << side;
305 if (side ==
"down") {
307 }
else if (side ==
"up") {
309 }
else if (side ==
"left") {
311 }
else if (side ==
"right") {
313 }
else if (side ==
"front") {
315 }
else if (side ==
"back") {
319 if (_magCalInProgress) {
320 _orientationCalAreaHelpText->setProperty(
"text", tr(
"Rotate the vehicle continuously as shown in the diagram until marked as Completed"));
322 _orientationCalAreaHelpText->setProperty(
"text", tr(
"Hold still in the current orientation"));
329 if (text.endsWith(
"side done, rotate to a different side")) {
330 QString side = text.section(
" ", 0, 0);
331 qCDebug(SensorsComponentControllerLog) <<
"Side finished" << side;
333 if (side ==
"down") {
335 }
else if (side ==
"up") {
337 }
else if (side ==
"left") {
339 }
else if (side ==
"right") {
341 }
else if (side ==
"front") {
343 }
else if (side ==
"back") {
347 _orientationCalAreaHelpText->setProperty(
"text", tr(
"Place you vehicle into one of the orientations shown below and hold it still"));
353 if (text.endsWith(
"side already completed")) {
354 _orientationCalAreaHelpText->setProperty(
"text", tr(
"Orientation already completed, place you vehicle into one of the incomplete orientations shown below and hold it still"));
358 QString calCompletePrefix(
"calibration done:");
359 if (text.startsWith(calCompletePrefix)) {
360 _stopCalibration(StopCalibrationSuccess);
364 if (text.startsWith(
"calibration cancelled")) {
365 _stopCalibration(_waitingForCancel ? StopCalibrationCancelled : StopCalibrationFailed);
369 if (text.startsWith(
"calibration failed")) {
370 _stopCalibration(StopCalibrationFailed);
375void SensorsComponentController::_refreshParams(
void)
378 QStringLiteral(
"CAL_MAG0_ID"), QStringLiteral(
"CAL_MAG1_ID"), QStringLiteral(
"CAL_MAG2_ID"),
379 QStringLiteral(
"CAL_MAG0_ROT"), QStringLiteral(
"CAL_MAG1_ROT"), QStringLiteral(
"CAL_MAG2_ROT"),
380 QStringLiteral(
"CAL_*"),
381 QStringLiteral(
"SENS_*"),
385void SensorsComponentController::_updateAndEmitShowOrientationCalArea(
bool show)
387 _showOrientationCalArea = show;
391void SensorsComponentController::_hideAllCalAreas(
void)
393 _updateAndEmitShowOrientationCalArea(
false);
400 _waitingForCancel =
true;
405void SensorsComponentController::_handleParametersReset(
bool success)
410 QTimer::singleShot(1000,
this, [
this]() {
424 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 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)
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.