Skip to content

Commit

Permalink
Add joystick landing gear button support
Browse files Browse the repository at this point in the history
  • Loading branch information
DonLakeFlyer authored and julianoes committed Apr 11, 2024
1 parent edcfa7b commit 3cbf805
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 6 deletions.
14 changes: 14 additions & 0 deletions src/Joystick/Joystick.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ const char* Joystick::_buttonActionGimbalCenter = QT_TR_NOOP("Gimbal Cente
const char* Joystick::_buttonActionEmergencyStop = QT_TR_NOOP("Emergency Stop");
const char* Joystick::_buttonActionGripperGrab = QT_TR_NOOP("Gripper Close");
const char* Joystick::_buttonActionGripperRelease = QT_TR_NOOP("Gripper Open");
const char* Joystick::_buttonActionLandingGearDeploy= QT_TR_NOOP("Landing gear deploy");
const char* Joystick::_buttonActionLandingGearRetract= QT_TR_NOOP("Landing gear retract");

const char* Joystick::_rgFunctionSettingsKey[Joystick::maxFunction] = {
"RollAxis",
Expand Down Expand Up @@ -721,6 +723,8 @@ void Joystick::startPolling(Vehicle* vehicle)
disconnect(this, &Joystick::gimbalControlValue, _activeVehicle, &Vehicle::gimbalControlValue);
disconnect(this, &Joystick::emergencyStop, _activeVehicle, &Vehicle::emergencyStop);
disconnect(this, &Joystick::gripperAction, _activeVehicle, &Vehicle::setGripperAction);
disconnect(this, &Joystick::landingGearDeploy, _activeVehicle, &Vehicle::landingGearDeploy);
disconnect(this, &Joystick::landingGearRetract, _activeVehicle, &Vehicle::landingGearRetract);
disconnect(_activeVehicle, &Vehicle::flightModesChanged, this, &Joystick::_flightModesChanged);
}
// Always set up the new vehicle
Expand All @@ -745,6 +749,8 @@ void Joystick::startPolling(Vehicle* vehicle)
connect(this, &Joystick::gimbalControlValue, _activeVehicle, &Vehicle::gimbalControlValue);
connect(this, &Joystick::emergencyStop, _activeVehicle, &Vehicle::emergencyStop);
connect(this, &Joystick::gripperAction, _activeVehicle, &Vehicle::setGripperAction);
connect(this, &Joystick::landingGearDeploy, _activeVehicle, &Vehicle::landingGearDeploy);
connect(this, &Joystick::landingGearRetract, _activeVehicle, &Vehicle::landingGearRetract);
connect(_activeVehicle, &Vehicle::flightModesChanged, this, &Joystick::_flightModesChanged);
}
}
Expand All @@ -766,6 +772,8 @@ void Joystick::stopPolling(void)
disconnect(this, &Joystick::centerGimbal, _activeVehicle, &Vehicle::centerGimbal);
disconnect(this, &Joystick::gimbalControlValue, _activeVehicle, &Vehicle::gimbalControlValue);
disconnect(this, &Joystick::gripperAction, _activeVehicle, &Vehicle::setGripperAction);
disconnect(this, &Joystick::landingGearDeploy, _activeVehicle, &Vehicle::landingGearDeploy);
disconnect(this, &Joystick::landingGearRetract, _activeVehicle, &Vehicle::landingGearRetract);
disconnect(_activeVehicle, &Vehicle::flightModesChanged, this, &Joystick::_flightModesChanged);
}
_exitThread = true;
Expand Down Expand Up @@ -1064,6 +1072,10 @@ void Joystick::_executeButtonAction(const QString& action, bool buttonDown)
if(buttonDown) {
emit gripperAction(GRIPPER_ACTION_RELEASE);
}
} else if(action == _buttonActionLandingGearDeploy) {
if (buttonDown) emit landingGearDeploy();
} else if(action == _buttonActionLandingGearRetract) {
if (buttonDown) emit landingGearRetract();
} else {
if (buttonDown && _activeVehicle) {
for (auto& item : _customMavCommands) {
Expand Down Expand Up @@ -1158,6 +1170,8 @@ void Joystick::_buildActionList(Vehicle* activeVehicle)
_assignableButtonActions.append(new AssignableButtonAction(this, _buttonActionEmergencyStop));
_assignableButtonActions.append(new AssignableButtonAction(this, _buttonActionGripperGrab));
_assignableButtonActions.append(new AssignableButtonAction(this, _buttonActionGripperRelease));
_assignableButtonActions.append(new AssignableButtonAction(this, _buttonActionLandingGearDeploy));
_assignableButtonActions.append(new AssignableButtonAction(this, _buttonActionLandingGearRetract));

for (auto& item : _customMavCommands) {
_assignableButtonActions.append(new AssignableButtonAction(this, item.name()));
Expand Down
10 changes: 4 additions & 6 deletions src/Joystick/Joystick.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,12 +218,9 @@ class Joystick : public QThread
void setVtolInFwdFlight (bool set);
void setFlightMode (const QString& flightMode);
void emergencyStop ();
/**
* @brief Send MAV_CMD_DO_GRIPPER command to the vehicle
*
* @param gripperAction (Open / Close) Gripper action to command
*/
void gripperAction (GRIPPER_ACTIONS gripperAction);
void landingGearDeploy ();
void landingGearRetract ();

protected:
void _setDefaultCalibration ();
Expand Down Expand Up @@ -361,7 +358,8 @@ class Joystick : public QThread
static const char* _buttonActionEmergencyStop;
static const char* _buttonActionGripperGrab;
static const char* _buttonActionGripperRelease;

static const char* _buttonActionLandingGearDeploy;
static const char* _buttonActionLandingGearRetract;

private slots:
void _activeVehicleChanged(Vehicle* activeVehicle);
Expand Down
20 changes: 20 additions & 0 deletions src/Vehicle/Vehicle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2953,6 +2953,26 @@ void Vehicle::emergencyStop()
21196.0f); // Magic number for emergency stop
}

void Vehicle::landingGearDeploy()
{
sendMavCommand(
defaultComponentId(),
MAV_CMD_AIRFRAME_CONFIGURATION,
true, // show error if fails
-1.0f, // all gears
0.0f); // down
}

void Vehicle::landingGearRetract()
{
sendMavCommand(
defaultComponentId(),
MAV_CMD_AIRFRAME_CONFIGURATION,
true, // show error if fails
-1.0f, // all gears
1.0f); // up
}

void Vehicle::setCurrentMissionSequence(int seq)
{
SharedLinkInterfacePtr sharedLink = vehicleLinkManager()->primaryLink().lock();
Expand Down
6 changes: 6 additions & 0 deletions src/Vehicle/Vehicle.h
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,12 @@ class Vehicle : public FactGroup
/// Command vehicle to abort landing
Q_INVOKABLE void abortLanding(double climbOutAltitude);

/// Command vichecle to deploy landing gear
Q_INVOKABLE void landingGearDeploy();

/// Command vichecle to retract landing gear
Q_INVOKABLE void landingGearRetract();

Q_INVOKABLE void startMission();

/// Alter the current mission item on the vehicle
Expand Down

0 comments on commit 3cbf805

Please sign in to comment.