Commit 5e043189 authored by Don Gagne's avatar Don Gagne Committed by GitHub

Merge pull request #3896 from bluerobotics/pluginSemantics

Fix plugin semantics for ArduSub additions
parents 2ed50262 2664e9a5
......@@ -66,7 +66,7 @@ const QVariantList& APMAutoPilotPlugin::vehicleComponents(void)
_airframeComponent->setupTriggerSignals();
_components.append(QVariant::fromValue((VehicleComponent*)_airframeComponent));
if ( !_vehicle->sub() ) {
if ( _vehicle->supportsRadio() ) {
_radioComponent = new APMRadioComponent(_vehicle, this);
_radioComponent->setupTriggerSignals();
_components.append(QVariant::fromValue((VehicleComponent*)_radioComponent));
......
......@@ -52,3 +52,23 @@ int ArduSubFirmwarePlugin::manualControlReservedButtonCount(void)
{
return 0;
}
bool ArduSubFirmwarePlugin::supportsThrottleModeCenterZero(void)
{
return false;
}
bool ArduSubFirmwarePlugin::supportsManualControl(void)
{
return true;
}
bool ArduSubFirmwarePlugin::supportsRadio(void)
{
return false;
}
bool ArduSubFirmwarePlugin::supportsJSButton(void)
{
return true;
}
......@@ -69,6 +69,13 @@ public:
// Overrides from FirmwarePlugin
int manualControlReservedButtonCount(void);
bool supportsThrottleModeCenterZero(void);
bool supportsManualControl(void);
bool supportsRadio(void);
bool supportsJSButton(void);
};
#endif
......@@ -83,6 +83,27 @@ int FirmwarePlugin::manualControlReservedButtonCount(void)
return -1;
}
bool FirmwarePlugin::supportsThrottleModeCenterZero(void)
{
// By default, this is supported
return true;
}
bool FirmwarePlugin::supportsManualControl(void)
{
return false;
}
bool FirmwarePlugin::supportsRadio(void)
{
return true;
}
bool FirmwarePlugin::supportsJSButton(void)
{
return false;
}
bool FirmwarePlugin::adjustIncomingMavlinkMessage(Vehicle* vehicle, mavlink_message_t* message)
{
Q_UNUSED(vehicle);
......
......@@ -128,6 +128,23 @@ public:
/// @return -1: reserver all buttons, >0 number of buttons to reserve
virtual int manualControlReservedButtonCount(void);
/// Returns true if the vehicle and firmware supports the use of a throttle joystick that
/// is zero when centered. Typically not supported on vehicles that have bidirectional
/// throttle.
virtual bool supportsThrottleModeCenterZero(void);
/// Returns true if the firmware supports the use of the MAVlink "MANUAL_CONTROL" message.
/// By default, this returns false unless overridden in the firmware plugin.
virtual bool supportsManualControl(void);
/// Returns true if the firmware supports the use of the RC radio and requires the RC radio
/// setup page. Returns true by default.
virtual bool supportsRadio(void);
/// Returns true if the firmware supports the AP_JSButton library, which allows joystick buttons
/// to be assigned via parameters in firmware. Default is false.
virtual bool supportsJSButton(void);
/// Called before any mavlink message is processed by Vehicle such that the firmwre plugin
/// can adjust any message characteristics. This is handy to adjust or differences in mavlink
/// spec implementations such that the base code can remain mavlink generic.
......
......@@ -170,6 +170,11 @@ int PX4FirmwarePlugin::manualControlReservedButtonCount(void)
return 0; // 0 buttons reserved for rc switch simulation
}
bool PX4FirmwarePlugin::supportsManualControl(void)
{
return true;
}
bool PX4FirmwarePlugin::isCapable(const Vehicle *vehicle, FirmwareCapabilities capabilities)
{
if(vehicle->multiRotor()) {
......
......@@ -44,6 +44,7 @@ public:
void guidedModeChangeAltitude (Vehicle* vehicle, double altitudeRel) final;
bool isGuidedMode (const Vehicle* vehicle) const;
int manualControlReservedButtonCount(void) final;
bool supportsManualControl (void) final;
void initializeVehicle (Vehicle* vehicle) final;
bool sendHomePositionToVehicle (void) final;
void addMetaDataToFact (QObject* parameterMetaData, Fact* fact, MAV_TYPE vehicleType) final;
......
......@@ -284,7 +284,7 @@ void Joystick::run(void)
throttle = std::max(-1.0f, std::min(tanf(asinf(throttle_limited)), 1.0f));
// Adjust throttle to 0:1 range
if (_throttleMode == ThrottleModeCenterZero && !_activeVehicle->sub()) {
if (_throttleMode == ThrottleModeCenterZero && _activeVehicle->supportsThrottleModeCenterZero()) {
throttle = std::max(0.0f, throttle);
} else {
throttle = (throttle + 1.0f) / 2.0f;
......
......@@ -1517,15 +1517,22 @@ bool Vehicle::vtol(void) const
bool Vehicle::supportsManualControl(void) const
{
// PX4 Firmware supports manual control message
if ( px4Firmware() ) {
return true;
}
// ArduSub supports manual control message (identified by APM + Submarine type)
if ( apmFirmware() && vehicleType() == MAV_TYPE_SUBMARINE ) {
return true;
}
return false;
return _firmwarePlugin->supportsManualControl();
}
bool Vehicle::supportsThrottleModeCenterZero(void) const
{
return _firmwarePlugin->supportsThrottleModeCenterZero();
}
bool Vehicle::supportsRadio(void) const
{
return _firmwarePlugin->supportsRadio();
}
bool Vehicle::supportsJSButton(void) const
{
return _firmwarePlugin->supportsJSButton();
}
void Vehicle::_setCoordinateValid(bool coordinateValid)
......
......@@ -276,6 +276,8 @@ public:
Q_PROPERTY(bool vtol READ vtol CONSTANT)
Q_PROPERTY(bool rover READ rover CONSTANT)
Q_PROPERTY(bool supportsManualControl READ supportsManualControl CONSTANT)
Q_PROPERTY(bool supportsThrottleModeCenterZero READ supportsThrottleModeCenterZero CONSTANT)
Q_PROPERTY(bool supportsJSButton READ supportsJSButton CONSTANT)
Q_PROPERTY(bool sub READ sub CONSTANT)
Q_PROPERTY(bool autoDisconnect MEMBER _autoDisconnect NOTIFY autoDisconnectChanged)
Q_PROPERTY(QString prearmError READ prearmError WRITE setPrearmError NOTIFY prearmErrorChanged)
......@@ -473,6 +475,9 @@ public:
bool sub(void) const;
bool supportsManualControl(void) const;
bool supportsThrottleModeCenterZero(void) const;
bool supportsRadio(void) const;
bool supportsJSButton(void) const;
void setFlying(bool flying);
void setGuidedMode(bool guidedMode);
......
......@@ -381,7 +381,7 @@ QGCView {
Column {
spacing: ScreenTools.defaultFontPixelHeight / 3
visible: !_activeVehicle.sub
visible: _activeVehicle.supportsThrottleModeCenterZero
ExclusiveGroup { id: throttleModeExclusiveGroup }
......@@ -449,8 +449,8 @@ QGCView {
if (buttonActionRepeater.itemAt(index)) {
buttonActionRepeater.itemAt(index).pressed = pressed
}
if (subButtonActionRepeater.itemAt(index)) {
subButtonActionRepeater.itemAt(index).pressed = pressed
if (jsButtonActionRepeater.itemAt(index)) {
jsButtonActionRepeater.itemAt(index).pressed = pressed
}
}
}
......@@ -474,7 +474,7 @@ QGCView {
Row {
spacing: ScreenTools.defaultFontPixelWidth
visible: (_activeVehicle.manualControlReservedButtonCount == -1 ? false : modelData >= _activeVehicle.manualControlReservedButtonCount) && !_activeVehicle.sub
visible: (_activeVehicle.manualControlReservedButtonCount == -1 ? false : modelData >= _activeVehicle.manualControlReservedButtonCount) && !_activeVehicle.supportsJSButton
property bool pressed
......@@ -516,7 +516,7 @@ QGCView {
Row {
spacing: ScreenTools.defaultFontPixelWidth
visible: _activeVehicle.sub
visible: _activeVehicle.supportsJSButton
QGCLabel {
horizontalAlignment: Text.AlignHCenter
......@@ -536,12 +536,12 @@ QGCView {
} // Row
Repeater {
id: subButtonActionRepeater
id: jsButtonActionRepeater
model: _activeJoystick.totalButtonCount
Row {
spacing: ScreenTools.defaultFontPixelWidth
visible: _activeVehicle.sub
visible: _activeVehicle.supportsJSButton
property bool pressed
......@@ -564,14 +564,14 @@ QGCView {
}
FactComboBox {
id: mainSubButtonActionCombo
id: mainJSButtonActionCombo
width: ScreenTools.defaultFontPixelWidth * 15
fact: controller.parameterExists(-1, "BTN"+index+"_FUNCTION") ? controller.getParameterFact(-1, "BTN" + index + "_FUNCTION") : null;
indexModel: false
}
FactComboBox {
id: shiftSubButtonActionCombo
id: shiftJSButtonActionCombo
width: ScreenTools.defaultFontPixelWidth * 15
fact: controller.parameterExists(-1, "BTN"+index+"_SFUNCTION") ? controller.getParameterFact(-1, "BTN" + index + "_SFUNCTION") : null;
indexModel: false
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment