Skip to content

Commit

Permalink
Vehicle: Move Generic Code to MAVLink Module
Browse files Browse the repository at this point in the history
  • Loading branch information
HTRamsey committed May 10, 2024
1 parent c1bbb84 commit 0fa19b5
Show file tree
Hide file tree
Showing 14 changed files with 290 additions and 306 deletions.
5 changes: 3 additions & 2 deletions src/AutoPilotPlugins/APM/APMSensorsComponent.qml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import QGroundControl.ScreenTools
import QGroundControl.Controllers
import QGroundControl.ArduPilot
import QGroundControl.QGCPositionManager
import MAVLink

SetupPage {
id: sensorsPage
Expand Down Expand Up @@ -166,8 +167,8 @@ SetupPage {

onCalibrationComplete: {
switch (calType) {
case APMSensorsComponentController.CalTypeAccel:
case APMSensorsComponentController.CalTypeOnboardCompass:
case MAVLink.CalibrationAccel:
case MAVLink.CalibrationMag:
_singleCompassSettingsComponentShowPriority = true
postOnboardCompassCalibrationComponent.createObject(mainWindow).open()
break
Expand Down
48 changes: 24 additions & 24 deletions src/AutoPilotPlugins/APM/APMSensorsComponentController.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ APMSensorsComponentController::APMSensorsComponentController(void)
, _nextButton(nullptr)
, _cancelButton(nullptr)
, _showOrientationCalArea(false)
, _calTypeInProgress(CalTypeNone)
, _calTypeInProgress(QGCMAVLink::CalibrationNone)
, _orientationCalDownSideDone(false)
, _orientationCalUpsideDownSideDone(false)
, _orientationCalLeftSideDone(false)
Expand Down Expand Up @@ -101,10 +101,10 @@ void APMSensorsComponentController::_startLogCalibration(void)
connect(_vehicle, &Vehicle::textMessageReceived, this, &APMSensorsComponentController::_handleUASTextMessage);

emit setAllCalButtonsEnabled(false);
if (_calTypeInProgress == CalTypeAccel || _calTypeInProgress == CalTypeCompassMot) {
if (_calTypeInProgress == QGCMAVLink::CalibrationAccel || _calTypeInProgress == QGCMAVLink::CalibrationAPMCompassMot) {
_nextButton->setEnabled(true);
}
_cancelButton->setEnabled(_calTypeInProgress == CalTypeOnboardCompass);
_cancelButton->setEnabled(_calTypeInProgress == QGCMAVLink::CalibrationMag);

connect(qgcApp()->toolbox()->mavlinkProtocol(), &MAVLinkProtocol::messageReceived, this, &APMSensorsComponentController::_mavlinkMessageReceived);
}
Expand Down Expand Up @@ -159,7 +159,7 @@ void APMSensorsComponentController::_stopCalibration(APMSensorsComponentControll
_nextButton->setEnabled(false);
_cancelButton->setEnabled(false);

if (_calTypeInProgress == CalTypeOnboardCompass) {
if (_calTypeInProgress == QGCMAVLink::CalibrationMag) {
_restorePreviousCompassCalFitness();
}

Expand Down Expand Up @@ -201,7 +201,7 @@ void APMSensorsComponentController::_stopCalibration(APMSensorsComponentControll
break;
}

_calTypeInProgress = CalTypeNone;
_calTypeInProgress = QGCMAVLink::CalibrationNone;
}

void APMSensorsComponentController::_mavCommandResult(int vehicleId, int component, int command, int result, bool noReponseFromVehicle)
Expand All @@ -217,7 +217,7 @@ void APMSensorsComponentController::_mavCommandResult(int vehicleId, int compone
disconnect(_vehicle, &Vehicle::mavCommandResult, this, &APMSensorsComponentController::_mavCommandResult);
if (result == MAV_RESULT_ACCEPTED) {
// Onboard mag cal is supported
_calTypeInProgress = CalTypeOnboardCompass;
_calTypeInProgress = QGCMAVLink::CalibrationMag;
_rgCompassCalProgress[0] = 0;
_rgCompassCalProgress[1] = 0;
_rgCompassCalProgress[2] = 0;
Expand Down Expand Up @@ -305,11 +305,11 @@ void APMSensorsComponentController::calibrateCompassNorth(float lat, float lon,
void APMSensorsComponentController::calibrateAccel(bool doSimpleAccelCal)
{

_calTypeInProgress = CalTypeAccel;
_calTypeInProgress = QGCMAVLink::CalibrationAccel;
if (doSimpleAccelCal) {
_startLogCalibration();
_calTypeInProgress = CalTypeAccelFast;
_vehicle->startCalibration(Vehicle::CalibrationAPMAccelSimple);
_calTypeInProgress = QGCMAVLink::CalibrationAPMAccelSimple;
_vehicle->startCalibration(_calTypeInProgress);
return;
}
_vehicle->vehicleLinkManager()->setCommunicationLostEnabled(false);
Expand Down Expand Up @@ -339,7 +339,7 @@ void APMSensorsComponentController::calibrateAccel(bool doSimpleAccelCal)
_orientationCalTailDownSideVisible = false;
_orientationCalNoseDownSideVisible = false;

_calTypeInProgress = CalTypeAccel;
_calTypeInProgress = QGCMAVLink::CalibrationAccel;
_orientationCalDownSideVisible = true;
_orientationCalUpsideDownSideVisible = true;
_orientationCalLeftSideVisible = true;
Expand All @@ -352,45 +352,45 @@ void APMSensorsComponentController::calibrateAccel(bool doSimpleAccelCal)
emit orientationCalSidesInProgressChanged();
_updateAndEmitShowOrientationCalArea(true);

_vehicle->startCalibration(Vehicle::CalibrationAccel);
_vehicle->startCalibration(_calTypeInProgress);
}

void APMSensorsComponentController::calibrateMotorInterference(void)
{
_calTypeInProgress = CalTypeCompassMot;
_calTypeInProgress = QGCMAVLink::CalibrationAPMCompassMot;
_vehicle->vehicleLinkManager()->setCommunicationLostEnabled(false);
_startLogCalibration();
_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("Press the Next button to complete the calibration"));
_vehicle->startCalibration(Vehicle::CalibrationAPMCompassMot);
_vehicle->startCalibration(_calTypeInProgress);
}

void APMSensorsComponentController::levelHorizon(void)
{
_calTypeInProgress = CalTypeLevelHorizon;
_calTypeInProgress = QGCMAVLink::CalibrationLevel;
_vehicle->vehicleLinkManager()->setCommunicationLostEnabled(false);
_startLogCalibration();
_appendStatusLog(tr("Hold the vehicle in its level flight position."));
_vehicle->startCalibration(Vehicle::CalibrationLevel);
_vehicle->startCalibration(_calTypeInProgress);
}

void APMSensorsComponentController::calibratePressure(void)
{
_calTypeInProgress = CalTypePressure;
_calTypeInProgress = QGCMAVLink::CalibrationAPMPressureAirspeed;
_vehicle->vehicleLinkManager()->setCommunicationLostEnabled(false);
_startLogCalibration();
_appendStatusLog(tr("Requesting pressure calibration..."));
_vehicle->startCalibration(Vehicle::CalibrationAPMPressureAirspeed);
_vehicle->startCalibration(_calTypeInProgress);
}

void APMSensorsComponentController::calibrateGyro(void)
{
_calTypeInProgress = CalTypeGyro;
_calTypeInProgress = QGCMAVLink::CalibrationGyro;
_vehicle->vehicleLinkManager()->setCommunicationLostEnabled(false);
_startLogCalibration();
_appendStatusLog(tr("Requesting gyro calibration..."));
_vehicle->startCalibration(Vehicle::CalibrationGyro);
_vehicle->startCalibration(_calTypeInProgress);
}

void APMSensorsComponentController::_handleUASTextMessage(int uasId, int compId, int severity, QString text)
Expand Down Expand Up @@ -446,7 +446,7 @@ void APMSensorsComponentController::cancelCalibration(void)
{
_cancelButton->setEnabled(false);

if (_calTypeInProgress == CalTypeOnboardCompass) {
if (_calTypeInProgress == QGCMAVLink::CalibrationMag) {
_vehicle->sendMavCommand(_vehicle->defaultComponentId(), MAV_CMD_DO_CANCEL_MAG_CAL, true /* showError */);
_stopCalibration(StopCalibrationCancelled);
} else {
Expand Down Expand Up @@ -479,7 +479,7 @@ void APMSensorsComponentController::nextClicked(void)

_vehicle->sendMessageOnLinkThreadSafe(sharedLink.get(), msg);

if (_calTypeInProgress == CalTypeCompassMot) {
if (_calTypeInProgress == QGCMAVLink::CalibrationAPMCompassMot) {
_stopCalibration(StopCalibrationSuccess);
}
}
Expand Down Expand Up @@ -508,7 +508,7 @@ bool APMSensorsComponentController::usingUDPLink(void)

void APMSensorsComponentController::_handleCommandAck(mavlink_message_t& message)
{
if (_calTypeInProgress == CalTypeLevelHorizon || _calTypeInProgress == CalTypeGyro || _calTypeInProgress == CalTypePressure || _calTypeInProgress == CalTypeAccelFast) {
if (_calTypeInProgress == QGCMAVLink::CalibrationLevel || _calTypeInProgress == QGCMAVLink::CalibrationGyro || _calTypeInProgress == QGCMAVLink::CalibrationAPMPressureAirspeed || _calTypeInProgress == QGCMAVLink::CalibrationAPMAccelSimple) {
mavlink_command_ack_t commandAck;
mavlink_msg_command_ack_decode(&message, &commandAck);

Expand All @@ -532,7 +532,7 @@ void APMSensorsComponentController::_handleCommandAck(mavlink_message_t& message

void APMSensorsComponentController::_handleMagCalProgress(mavlink_message_t& message)
{
if (_calTypeInProgress == CalTypeOnboardCompass) {
if (_calTypeInProgress == QGCMAVLink::CalibrationMag) {
mavlink_mag_cal_progress_t magCalProgress;
mavlink_msg_mag_cal_progress_decode(&message, &magCalProgress);

Expand Down Expand Up @@ -560,7 +560,7 @@ void APMSensorsComponentController::_handleMagCalProgress(mavlink_message_t& mes

void APMSensorsComponentController::_handleMagCalReport(mavlink_message_t& message)
{
if (_calTypeInProgress == CalTypeOnboardCompass) {
if (_calTypeInProgress == QGCMAVLink::CalibrationMag) {
mavlink_mag_cal_report_t magCalReport;
mavlink_msg_mag_cal_report_decode(&message, &magCalReport);

Expand Down
18 changes: 3 additions & 15 deletions src/AutoPilotPlugins/APM/APMSensorsComponentController.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#pragma once

#include "FactPanelController.h"
#include "MAVLinkLib.h"
#include "QGCMAVLink.h"

#include <QtQuick/QQuickItem>
#include <QtCore/QObject>
Expand Down Expand Up @@ -95,18 +95,6 @@ class APMSensorsComponentController : public FactPanelController
bool compassSetupNeeded (void) const;
bool accelSetupNeeded (void) const;

typedef enum {
CalTypeAccel,
CalTypeGyro,
CalTypeOnboardCompass,
CalTypeLevelHorizon,
CalTypeCompassMot,
CalTypePressure,
CalTypeAccelFast,
CalTypeNone
} CalType_t;
Q_ENUM(CalType_t)

bool compass1CalSucceeded(void) const { return _rgCompassCalSucceeded[0]; }
bool compass2CalSucceeded(void) const { return _rgCompassCalSucceeded[1]; }
bool compass3CalSucceeded(void) const { return _rgCompassCalSucceeded[2]; }
Expand All @@ -125,7 +113,7 @@ class APMSensorsComponentController : public FactPanelController
void resetStatusTextArea (void);
void waitingForCancelChanged (void);
void setupNeededChanged (void);
void calibrationComplete (CalType_t calType);
void calibrationComplete (QGCMAVLink::CalibrationType calType);
void compass1CalSucceededChanged (bool compass1CalSucceeded);
void compass2CalSucceededChanged (bool compass2CalSucceeded);
void compass3CalSucceededChanged (bool compass3CalSucceeded);
Expand Down Expand Up @@ -172,7 +160,7 @@ private slots:

bool _showOrientationCalArea;

CalType_t _calTypeInProgress;
QGCMAVLink::CalibrationType _calTypeInProgress;

uint8_t _rgCompassCalProgress[3];
bool _rgCompassCalComplete[3];
Expand Down
4 changes: 2 additions & 2 deletions src/AutoPilotPlugins/Common/RadioComponentController.cc
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@ void RadioComponentController::_startCalibration(void)
_resetInternalCalibrationValues();

// Let the mav known we are starting calibration. This should turn off motors and so forth.
_vehicle->startCalibration(Vehicle::CalibrationRadio);
_vehicle->startCalibration(QGCMAVLink::CalibrationRadio);

_nextButton->setProperty("text", tr("Next"));
_cancelButton->setEnabled(true);
Expand Down Expand Up @@ -1025,7 +1025,7 @@ void RadioComponentController::_signalAllAttitudeValueChanges(void)

void RadioComponentController::copyTrims(void)
{
_vehicle->startCalibration(Vehicle::CalibrationCopyTrims);
_vehicle->startCalibration(QGCMAVLink::CalibrationCopyTrims);
}

bool RadioComponentController::_px4Vehicle(void) const
Expand Down
2 changes: 1 addition & 1 deletion src/AutoPilotPlugins/PX4/PowerComponentController.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ void PowerComponentController::calibrateEsc(void)
{
_warningMessages.clear();
connect(_vehicle, &Vehicle::textMessageReceived, this, &PowerComponentController::_handleVehicleTextMessage);
_vehicle->startCalibration(Vehicle::CalibrationEsc);
_vehicle->startCalibration(QGCMAVLink::CalibrationEsc);
}

void PowerComponentController::startBusConfigureActuators(void)
Expand Down
10 changes: 5 additions & 5 deletions src/AutoPilotPlugins/PX4/SensorsComponentController.cc
Original file line number Diff line number Diff line change
Expand Up @@ -196,31 +196,31 @@ void SensorsComponentController::_stopCalibration(SensorsComponentController::St
void SensorsComponentController::calibrateGyro(void)
{
_startLogCalibration();
_vehicle->startCalibration(Vehicle::CalibrationGyro);
_vehicle->startCalibration(QGCMAVLink::CalibrationGyro);
}

void SensorsComponentController::calibrateCompass(void)
{
_startLogCalibration();
_vehicle->startCalibration(Vehicle::CalibrationMag);
_vehicle->startCalibration(QGCMAVLink::CalibrationMag);
}

void SensorsComponentController::calibrateAccel(void)
{
_startLogCalibration();
_vehicle->startCalibration(Vehicle::CalibrationAccel);
_vehicle->startCalibration(QGCMAVLink::CalibrationAccel);
}

void SensorsComponentController::calibrateLevel(void)
{
_startLogCalibration();
_vehicle->startCalibration(Vehicle::CalibrationLevel);
_vehicle->startCalibration(QGCMAVLink::CalibrationLevel);
}

void SensorsComponentController::calibrateAirspeed(void)
{
_startLogCalibration();
_vehicle->startCalibration(Vehicle::CalibrationPX4Airspeed);
_vehicle->startCalibration(QGCMAVLink::CalibrationPX4Airspeed);
}

void SensorsComponentController::_handleUASTextMessage(int uasId, int compId, int severity, QString text)
Expand Down
2 changes: 1 addition & 1 deletion src/MAVLink/ImageProtocolManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

#include <QtCore/QObject>
#include <QtCore/QByteArray>
#include <QtGui/QImage>
#include <QtCore/QLoggingCategory>
#include <QtGui/QImage>

Q_DECLARE_LOGGING_CATEGORY(ImageProtocolManagerLog)

Expand Down
3 changes: 3 additions & 0 deletions src/MAVLink/MAVLinkFTP.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@
#pragma once

#include <QtCore/QString>
#include <QtCore/QLoggingCategory>

#include "MAVLinkLib.h"

Q_DECLARE_LOGGING_CATEGORY(MavlinkFTPLog)

class MavlinkFTP {
public:
/// This is the fixed length portion of the protocol data.
Expand Down
3 changes: 3 additions & 0 deletions src/MAVLink/MAVLinkStreamConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
#pragma once

#include <QtCore/QVector>
#include <QtCore/QLoggingCategory>

Q_DECLARE_LOGGING_CATEGORY(MAVLinkStreamConfigLog)

/**
* @class MAVLinkStreamConfig
Expand Down
Loading

0 comments on commit 0fa19b5

Please sign in to comment.