Browse Source

Add separate Gyro cal support

QGC4.4
DonLakeFlyer 5 years ago
parent
commit
d46cdc9355
  1. 29
      src/AutoPilotPlugins/APM/APMSensorsComponent.qml
  2. 240
      src/AutoPilotPlugins/APM/APMSensorsComponentController.cc
  3. 8
      src/AutoPilotPlugins/APM/APMSensorsComponentController.h

29
src/AutoPilotPlugins/APM/APMSensorsComponent.qml

@ -569,6 +569,26 @@ SetupPage {
} // QGCViewDialog } // QGCViewDialog
} // Component - calibratePressureDialogComponent } // Component - calibratePressureDialogComponent
Component {
id: calibrateGyroDialogComponent
QGCViewDialog {
id: calibrateGyroDialog
function accept() {
controller.calibrateGyro()
calibrateGyroDialog.hideDialog()
}
QGCLabel {
anchors.left: parent.left
anchors.right: parent.right
wrapMode: Text.WordWrap
text: qsTr("For Gyroscope calibration you will need to place your vehicle on a surface and leave it still.\n\nClick Ok to start calibration.")
}
}
}
QGCFlickable { QGCFlickable {
id: buttonFlickable id: buttonFlickable
anchors.left: parent.left anchors.left: parent.left
@ -623,10 +643,17 @@ SetupPage {
QGCButton { QGCButton {
width: _buttonWidth width: _buttonWidth
text: qsTr("Gyro")
visible: activeVehicle && (activeVehicle.multiRotor | activeVehicle.rover)
onClicked: mainWindow.showComponentDialog(calibrateGyroDialogComponent, qsTr("Calibrate Gyro"), mainWindow.showDialogDefaultWidth, StandardButton.Cancel | StandardButton.Ok)
}
QGCButton {
width: _buttonWidth
text: _calibratePressureText text: _calibratePressureText
onClicked: mainWindow.showComponentDialog(calibratePressureDialogComponent, _calibratePressureText, mainWindow.showDialogDefaultWidth, StandardButton.Cancel | StandardButton.Ok) onClicked: mainWindow.showComponentDialog(calibratePressureDialogComponent, _calibratePressureText, mainWindow.showDialogDefaultWidth, StandardButton.Cancel | StandardButton.Ok)
readonly property string _calibratePressureText: activeVehicle.fixedWing ? qsTr("Cal Baro/Airspeed") : qsTr("Calibrate Pressure") readonly property string _calibratePressureText: activeVehicle.fixedWing ? qsTr("Baro/Airspeed") : qsTr("Pressure")
} }
QGCButton { QGCButton {

240
src/AutoPilotPlugins/APM/APMSensorsComponentController.cc

@ -294,7 +294,7 @@ void APMSensorsComponentController::calibrateAccel(void)
_calTypeInProgress = CalTypeAccel; _calTypeInProgress = CalTypeAccel;
_vehicle->setConnectionLostEnabled(false); _vehicle->setConnectionLostEnabled(false);
_startLogCalibration(); _startLogCalibration();
_uas->startCalibration(UASInterface::StartCalibrationAccel); _vehicle->startCalibration(Vehicle::CalibrationAccel);
} }
void APMSensorsComponentController::calibrateMotorInterference(void) void APMSensorsComponentController::calibrateMotorInterference(void)
@ -305,7 +305,7 @@ void APMSensorsComponentController::calibrateMotorInterference(void)
_appendStatusLog(tr("Raise the throttle slowly to between 50% ~ 75% (the props will spin!) for 5 ~ 10 seconds.")); _appendStatusLog(tr("Raise the throttle slowly to between 50% ~ 75% (the props will spin!) for 5 ~ 10 seconds."));
_appendStatusLog(tr("Quickly bring the throttle back down to zero")); _appendStatusLog(tr("Quickly bring the throttle back down to zero"));
_appendStatusLog(tr("Press the Next button to complete the calibration")); _appendStatusLog(tr("Press the Next button to complete the calibration"));
_uas->startCalibration(UASInterface::StartCalibrationCompassMot); _vehicle->startCalibration(Vehicle::CalibrationAPMCompassMot);
} }
void APMSensorsComponentController::levelHorizon(void) void APMSensorsComponentController::levelHorizon(void)
@ -314,7 +314,7 @@ void APMSensorsComponentController::levelHorizon(void)
_vehicle->setConnectionLostEnabled(false); _vehicle->setConnectionLostEnabled(false);
_startLogCalibration(); _startLogCalibration();
_appendStatusLog(tr("Hold the vehicle in its level flight position.")); _appendStatusLog(tr("Hold the vehicle in its level flight position."));
_uas->startCalibration(UASInterface::StartCalibrationLevel); _vehicle->startCalibration(Vehicle::CalibrationLevel);
} }
void APMSensorsComponentController::calibratePressure(void) void APMSensorsComponentController::calibratePressure(void)
@ -323,7 +323,16 @@ void APMSensorsComponentController::calibratePressure(void)
_vehicle->setConnectionLostEnabled(false); _vehicle->setConnectionLostEnabled(false);
_startLogCalibration(); _startLogCalibration();
_appendStatusLog(tr("Requesting pressure calibration...")); _appendStatusLog(tr("Requesting pressure calibration..."));
_uas->startCalibration(UASInterface::StartCalibrationPressure); _vehicle->startCalibration(Vehicle::CalibrationAPMPressureAirspeed);
}
void APMSensorsComponentController::calibrateGyro(void)
{
_calTypeInProgress = CalTypeGyro;
_vehicle->setConnectionLostEnabled(false);
_startLogCalibration();
_appendStatusLog(tr("Requesting gyro calibration..."));
_vehicle->startCalibration(Vehicle::CalibrationGyro);
} }
void APMSensorsComponentController::_handleUASTextMessage(int uasId, int compId, int severity, QString text) void APMSensorsComponentController::_handleUASTextMessage(int uasId, int compId, int severity, QString text)
@ -444,203 +453,6 @@ void APMSensorsComponentController::_handleUASTextMessage(int uasId, int compId,
_stopCalibration(StopCalibrationFailed); _stopCalibration(StopCalibrationFailed);
return; return;
} }
#if 0
if (text.contains(QLatin1Literal("progress <"))) {
QString percent = text.split("<").last().split(">").first();
bool ok;
int p = percent.toInt(&ok);
if (ok && _progressBar) {
_progressBar->setProperty("value", (float)(p / 100.0));
}
return;
}
QString anyKey(QStringLiteral("and press any"));
if (text.contains(anyKey)) {
text = text.left(text.indexOf(anyKey)) + QStringLiteral("and click Next to continue.");
_nextButton->setEnabled(true);
}
_appendStatusLog(text);
qCDebug(APMSensorsComponentControllerLog) << text << severity;
if (text.contains(QLatin1String("Calibration successful"))) {
_stopCalibration(StopCalibrationSuccess);
return;
}
if (text.contains(QLatin1String("FAILED"))) {
_stopCalibration(StopCalibrationFailed);
return;
}
// All calibration messages start with [cal]
QString calPrefix(QStringLiteral("[cal] "));
if (!text.startsWith(calPrefix)) {
return;
}
text = text.right(text.length() - calPrefix.length());
QString calStartPrefix(QStringLiteral("calibration started: "));
if (text.startsWith(calStartPrefix)) {
text = text.right(text.length() - calStartPrefix.length());
_startVisualCalibration();
if (text == QLatin1Literal("accel") || text == QLatin1Literal("mag") || text == QLatin1Literal("gyro")) {
// Reset all progress indication
_orientationCalDownSideDone = false;
_orientationCalUpsideDownSideDone = false;
_orientationCalLeftSideDone = false;
_orientationCalRightSideDone = false;
_orientationCalTailDownSideDone = false;
_orientationCalNoseDownSideDone = false;
_orientationCalDownSideInProgress = false;
_orientationCalUpsideDownSideInProgress = false;
_orientationCalLeftSideInProgress = false;
_orientationCalRightSideInProgress = false;
_orientationCalNoseDownSideInProgress = false;
_orientationCalTailDownSideInProgress = false;
// Reset all visibility
_orientationCalDownSideVisible = false;
_orientationCalUpsideDownSideVisible = false;
_orientationCalLeftSideVisible = false;
_orientationCalRightSideVisible = false;
_orientationCalTailDownSideVisible = false;
_orientationCalNoseDownSideVisible = false;
_orientationCalAreaHelpText->setProperty("text", "Place your vehicle into one of the Incomplete orientations shown below and hold it still");
if (text == "accel") {
_calTypeInProgress = CalTypeAccel;
_orientationCalDownSideVisible = true;
_orientationCalUpsideDownSideVisible = true;
_orientationCalLeftSideVisible = true;
_orientationCalRightSideVisible = true;
_orientationCalTailDownSideVisible = true;
_orientationCalNoseDownSideVisible = true;
} else if (text == "mag") {
_calTypeInProgress = CalTypeOffboardCompass;
_orientationCalDownSideVisible = true;
_orientationCalUpsideDownSideVisible = true;
_orientationCalLeftSideVisible = true;
_orientationCalRightSideVisible = true;
_orientationCalTailDownSideVisible = true;
_orientationCalNoseDownSideVisible = true;
} else {
Q_ASSERT(false);
}
emit orientationCalSidesDoneChanged();
emit orientationCalSidesVisibleChanged();
emit orientationCalSidesInProgressChanged();
_updateAndEmitShowOrientationCalArea(true);
}
return;
}
if (text.endsWith(QLatin1Literal("orientation detected"))) {
QString side = text.section(" ", 0, 0);
qDebug() << "Side started" << side;
if (side == QLatin1Literal("down")) {
_orientationCalDownSideInProgress = true;
if (_calTypeInProgress == CalTypeOffboardCompass) {
_orientationCalDownSideRotate = true;
}
} else if (side == QLatin1Literal("up")) {
_orientationCalUpsideDownSideInProgress = true;
if (_calTypeInProgress == CalTypeOffboardCompass) {
_orientationCalUpsideDownSideRotate = true;
}
} else if (side == QLatin1Literal("left")) {
_orientationCalLeftSideInProgress = true;
if (_calTypeInProgress == CalTypeOffboardCompass) {
_orientationCalLeftSideRotate = true;
}
} else if (side == QLatin1Literal("right")) {
_orientationCalRightSideInProgress = true;
if (_calTypeInProgress == CalTypeOffboardCompass) {
_orientationCalRightSideRotate = true;
}
} else if (side == QLatin1Literal("front")) {
_orientationCalNoseDownSideInProgress = true;
if (_calTypeInProgress == CalTypeOffboardCompass) {
_orientationCalNoseDownSideRotate = true;
}
} else if (side == QLatin1Literal("back")) {
_orientationCalTailDownSideInProgress = true;
if (_calTypeInProgress == CalTypeOffboardCompass) {
_orientationCalTailDownSideRotate = true;
}
}
if (_calTypeInProgress == CalTypeOffboardCompass) {
_orientationCalAreaHelpText->setProperty("text", tr("Rotate the vehicle continuously as shown in the diagram until marked as Completed"));
} else {
_orientationCalAreaHelpText->setProperty("text", tr("Hold still in the current orientation"));
}
emit orientationCalSidesInProgressChanged();
emit orientationCalSidesRotateChanged();
return;
}
if (text.endsWith(QLatin1Literal("side done, rotate to a different side"))) {
QString side = text.section(" ", 0, 0);
qDebug() << "Side finished" << side;
if (side == QLatin1Literal("down")) {
_orientationCalDownSideInProgress = false;
_orientationCalDownSideDone = true;
_orientationCalDownSideRotate = false;
} else if (side == QLatin1Literal("up")) {
_orientationCalUpsideDownSideInProgress = false;
_orientationCalUpsideDownSideDone = true;
_orientationCalUpsideDownSideRotate = false;
} else if (side == QLatin1Literal("left")) {
_orientationCalLeftSideInProgress = false;
_orientationCalLeftSideDone = true;
_orientationCalLeftSideRotate = false;
} else if (side == QLatin1Literal("right")) {
_orientationCalRightSideInProgress = false;
_orientationCalRightSideDone = true;
_orientationCalRightSideRotate = false;
} else if (side == QLatin1Literal("front")) {
_orientationCalNoseDownSideInProgress = false;
_orientationCalNoseDownSideDone = true;
_orientationCalNoseDownSideRotate = false;
} else if (side == QLatin1Literal("back")) {
_orientationCalTailDownSideInProgress = false;
_orientationCalTailDownSideDone = true;
_orientationCalTailDownSideRotate = false;
}
_orientationCalAreaHelpText->setProperty("text", tr("Place you vehicle into one of the orientations shown below and hold it still"));
emit orientationCalSidesInProgressChanged();
emit orientationCalSidesDoneChanged();
emit orientationCalSidesRotateChanged();
return;
}
if (text.startsWith(QLatin1Literal("calibration done:"))) {
_stopCalibration(StopCalibrationSuccess);
return;
}
if (text.startsWith(QLatin1Literal("calibration cancelled"))) {
_stopCalibration(_waitingForCancel ? StopCalibrationCancelled : StopCalibrationFailed);
return;
}
if (text.startsWith(QLatin1Literal("calibration failed"))) {
_stopCalibration(StopCalibrationFailed);
return;
}
#endif
} }
void APMSensorsComponentController::_refreshParams(void) void APMSensorsComponentController::_refreshParams(void)
@ -685,7 +497,7 @@ void APMSensorsComponentController::cancelCalibration(void)
emit waitingForCancelChanged(); emit waitingForCancelChanged();
// The firmware doesn't always allow us to cancel calibration. The best we can do is wait // The firmware doesn't always allow us to cancel calibration. The best we can do is wait
// for it to timeout. // for it to timeout.
_uas->stopCalibration(); _vehicle->stopCalibration();
} }
} }
@ -728,36 +540,18 @@ bool APMSensorsComponentController::usingUDPLink(void)
void APMSensorsComponentController::_handleCommandAck(mavlink_message_t& message) void APMSensorsComponentController::_handleCommandAck(mavlink_message_t& message)
{ {
if (_calTypeInProgress == CalTypeLevelHorizon) { if (_calTypeInProgress == CalTypeLevelHorizon || _calTypeInProgress == CalTypeGyro || _calTypeInProgress == CalTypePressure) {
mavlink_command_ack_t commandAck;
mavlink_msg_command_ack_decode(&message, &commandAck);
if (commandAck.command == MAV_CMD_PREFLIGHT_CALIBRATION) {
switch (commandAck.result) {
case MAV_RESULT_ACCEPTED:
_appendStatusLog(tr("Level horizon complete"));
_stopCalibration(StopCalibrationSuccessShowLog);
break;
default:
_appendStatusLog(tr("Level horizon failed"));
_stopCalibration(StopCalibrationFailed);
break;
}
}
}
if (_calTypeInProgress == CalTypePressure) {
mavlink_command_ack_t commandAck; mavlink_command_ack_t commandAck;
mavlink_msg_command_ack_decode(&message, &commandAck); mavlink_msg_command_ack_decode(&message, &commandAck);
if (commandAck.command == MAV_CMD_PREFLIGHT_CALIBRATION) { if (commandAck.command == MAV_CMD_PREFLIGHT_CALIBRATION) {
switch (commandAck.result) { switch (commandAck.result) {
case MAV_RESULT_ACCEPTED: case MAV_RESULT_ACCEPTED:
_appendStatusLog(tr("Pressure calibration success")); _appendStatusLog(tr("Successfully completed"));
_stopCalibration(StopCalibrationSuccessShowLog); _stopCalibration(StopCalibrationSuccessShowLog);
break; break;
default: default:
_appendStatusLog(tr("Pressure calibration fail")); _appendStatusLog(tr("Failed"));
_stopCalibration(StopCalibrationFailed); _stopCalibration(StopCalibrationFailed);
break; break;
} }

8
src/AutoPilotPlugins/APM/APMSensorsComponentController.h

@ -7,9 +7,7 @@
* *
****************************************************************************/ ****************************************************************************/
#pragma once
#ifndef APMSensorsComponentController_H
#define APMSensorsComponentController_H
#include <QObject> #include <QObject>
@ -83,6 +81,7 @@ public:
Q_INVOKABLE void calibrateCompass (void); Q_INVOKABLE void calibrateCompass (void);
Q_INVOKABLE void calibrateAccel (void); Q_INVOKABLE void calibrateAccel (void);
Q_INVOKABLE void calibrateGyro (void);
Q_INVOKABLE void calibrateMotorInterference (void); Q_INVOKABLE void calibrateMotorInterference (void);
Q_INVOKABLE void levelHorizon (void); Q_INVOKABLE void levelHorizon (void);
Q_INVOKABLE void calibratePressure (void); Q_INVOKABLE void calibratePressure (void);
@ -95,6 +94,7 @@ public:
typedef enum { typedef enum {
CalTypeAccel, CalTypeAccel,
CalTypeGyro,
CalTypeOnboardCompass, CalTypeOnboardCompass,
CalTypeOffboardCompass, CalTypeOffboardCompass,
CalTypeLevelHorizon, CalTypeLevelHorizon,
@ -212,5 +212,3 @@ private:
static const int _supportedFirmwareCalVersion = 2; static const int _supportedFirmwareCalVersion = 2;
}; };
#endif

Loading…
Cancel
Save