Commit 275855b9 authored by Bryant's avatar Bryant

The default UAS.cc now lists available actions that it can be commanded. These...

The default UAS.cc now lists available actions that it can be commanded. These are polled by the Joystick Configuration window for each joystick button so that they can be assigned to trigger this action. Button presses don't yet trigger these actions, nor are they stored and reloaded on UAS switch.
parent 55efdf8d
......@@ -28,11 +28,11 @@ This file is part of the QGROUNDCONTROL project
#include "ArduPilotMegaMAV.h"
#ifndef mavlink_mount_configure_t
#ifndef MAVLINK_MSG_ID_MOUNT_CONFIGURE
#include "ardupilotmega/mavlink_msg_mount_configure.h"
#endif
#ifndef mavlink_mount_control_t
#ifndef MAVLINK_MSG_ID_MOUNT_CONTROL
#include "ardupilotmega/mavlink_msg_mount_control.h";
#endif
......
......@@ -145,7 +145,60 @@ UAS::UAS(MAVLinkProtocol* protocol, int id) : UASInterface(),
componentID[i] = -1;
componentMulti[i] = false;
}
// Store a list of available actions for this UAS.
// Basically everything exposted as a SLOT with no return value or arguments.
QAction* newAction = new QAction(tr("Arm"), this);
newAction->setToolTip(tr("Enable the UAS so that all actuators are online"));
connect(newAction, SIGNAL(triggered()), this, SLOT(armSystem()));
actions.append(newAction);
newAction = new QAction(tr("Disarm"), this);
newAction->setToolTip(tr("Disable the UAS so that all actuators are offline"));
connect(newAction, SIGNAL(triggered()), this, SLOT(disarmSystem()));
actions.append(newAction);
newAction = new QAction(tr("Go home"), this);
newAction->setToolTip(tr("Command the UAS to return to its home position"));
connect(newAction, SIGNAL(triggered()), this, SLOT(home()));
actions.append(newAction);
newAction = new QAction(tr("Land"), this);
newAction->setToolTip(tr("Command the UAS to land"));
connect(newAction, SIGNAL(triggered()), this, SLOT(land()));
actions.append(newAction);
newAction = new QAction(tr("Launch"), this);
newAction->setToolTip(tr("Command the UAS to launch itself and begin its mission"));
connect(newAction, SIGNAL(triggered()), this, SLOT(launch()));
actions.append(newAction);
newAction = new QAction(tr("Resume"), this);
newAction->setToolTip(tr("Command the UAS to continue its mission"));
connect(newAction, SIGNAL(triggered()), this, SLOT(go()));
actions.append(newAction);
newAction = new QAction(tr("Stop"), this);
newAction->setToolTip(tr("Command the UAS to halt and hold position"));
connect(newAction, SIGNAL(triggered()), this, SLOT(halt()));
actions.append(newAction);
newAction = new QAction(tr("Go autonomous"), this);
newAction->setToolTip(tr("Set the UAS into an autonomous control mode"));
connect(newAction, SIGNAL(triggered()), this, SLOT(goAutonomous()));
actions.append(newAction);
newAction = new QAction(tr("Go manual"), this);
newAction->setToolTip(tr("Set the UAS into a manual control mode"));
connect(newAction, SIGNAL(triggered()), this, SLOT(goManual()));
actions.append(newAction);
newAction = new QAction(tr("Toggle autonomy"), this);
newAction->setToolTip(tr("Toggle between manual and full-autonomy"));
connect(newAction, SIGNAL(triggered()), this, SLOT(toggleAutonomy()));
actions.append(newAction);
color = UASInterface::getNextColor();
setBatterySpecs(QString("9V,9.5V,12.6V"));
connect(statusTimeout, SIGNAL(timeout()), this, SLOT(updateState()));
......@@ -2633,6 +2686,27 @@ void UAS::disarmSystem()
sendMessage(msg);
}
void UAS::goAutonomous()
{
mavlink_message_t msg;
mavlink_msg_set_mode_pack(mavlink->getSystemId(), mavlink->getComponentId(), &msg, this->getUASID(), mode & MAV_MODE_FLAG_AUTO_ENABLED & ~MAV_MODE_FLAG_MANUAL_INPUT_ENABLED, navMode);
sendMessage(msg);
}
void UAS::goManual()
{
mavlink_message_t msg;
mavlink_msg_set_mode_pack(mavlink->getSystemId(), mavlink->getComponentId(), &msg, this->getUASID(), mode & ~MAV_MODE_FLAG_AUTO_ENABLED & MAV_MODE_FLAG_MANUAL_INPUT_ENABLED, navMode);
sendMessage(msg);
}
void UAS::toggleAutonomy()
{
mavlink_message_t msg;
mavlink_msg_set_mode_pack(mavlink->getSystemId(), mavlink->getComponentId(), &msg, this->getUASID(), mode ^ MAV_MODE_FLAG_AUTO_ENABLED ^ MAV_MODE_FLAG_MANUAL_INPUT_ENABLED, navMode);
sendMessage(msg);
}
/**
* Set the manual control commands.
* This can only be done if the system has manual inputs enabled and is armed.
......@@ -2694,41 +2768,6 @@ int UAS::getSystemType()
return this->type;
}
/**
* @brief Returns true for systems that can reverse. If the system has no control over position, it returns false as well.
* @return If the specified vehicle type can
*/
//bool UAS::systemCanReverse() const
//{
// switch(type)
// {
// case MAV_TYPE_GENERIC:
// case MAV_TYPE_FIXED_WING:
// case MAV_TYPE_ROCKET:
// case MAV_TYPE_FLAPPING_WING:
// // System types that don't have movement
// case MAV_TYPE_ANTENNA_TRACKER:
// case MAV_TYPE_GCS:
// case MAV_TYPE_FREE_BALLOON:
// default:
// return false;
// break;
// case MAV_TYPE_QUADROTOR:
// case MAV_TYPE_COAXIAL:
// case MAV_TYPE_HELICOPTER:
// case MAV_TYPE_AIRSHIP:
// case MAV_TYPE_GROUND_ROVER:
// case MAV_TYPE_SURFACE_BOAT:
// case MAV_TYPE_SUBMARINE:
// case MAV_TYPE_HEXAROTOR:
// case MAV_TYPE_OCTOROTOR:
// case MAV_TYPE_TRICOPTER:
// return true;
// break;
// }
//}
/**
* @param buttonIndex
*/
......
......@@ -676,6 +676,11 @@ public:
break;
}
}
/** From UASInterface */
QList<QAction*> getActions() const
{
return actions;
}
public slots:
/** @brief Set the autopilot type */
......@@ -777,6 +782,18 @@ public slots:
void armSystem();
/** @brief Disable the motors */
void disarmSystem();
/**
* @brief Tell the UAS to switch into a completely-autonomous mode, so disable manual input.
*/
void goAutonomous();
/**
* @brief Tell the UAS to switch to manual control. Stabilized attitude may simultaneously be engaged.
*/
void goManual();
/**
* @brief Tell the UAS to switch between manual and autonomous control.
*/
void toggleAutonomy();
/** @brief Set the values for the manual control of the vehicle */
void setManualControlCommands(double roll, double pitch, double yaw, double thrust, int xHat, int yHat, int buttons);
......@@ -922,6 +939,7 @@ protected:
bool sensorHil; ///< True if sensor HIL is enabled
quint64 lastSendTimeGPS; ///< Last HIL GPS message sent
quint64 lastSendTimeSensors;
QList<QAction*> actions; ///< A list of actions that this UAS can perform.
protected slots:
/** @brief Write settings to disk */
......
......@@ -260,6 +260,11 @@ public:
return color;
}
/** @brief Returns a list of actions/commands that this vehicle can perform.
* Used for creating UI elements for built-in functionality for this vehicle.
*/
virtual QList<QAction*> getActions() const = 0;
public slots:
/** @brief Set a new name for the system */
......
......@@ -8,9 +8,34 @@ JoystickButton::JoystickButton(int id, QWidget *parent) :
{
m_ui->setupUi(this);
m_ui->joystickButtonLabel->setText(QString::number(id));
connect(m_ui->joystickAction, SIGNAL(currentIndexChanged(int)), this, SLOT(actionComboBoxChanged(int)));
}
JoystickButton::~JoystickButton()
{
delete m_ui;
}
void JoystickButton::setActiveUAS(UASInterface* uas)
{
if (uas)
{
m_ui->joystickAction->setEnabled(true);
m_ui->joystickAction->clear();
m_ui->joystickAction->addItem("--");
QList<QAction*> actions = uas->getActions();
foreach (QAction* a, actions)
{
m_ui->joystickAction->addItem(a->text());
}
} else {
m_ui->joystickAction->setEnabled(false);
m_ui->joystickAction->clear();
m_ui->joystickAction->addItem("--");
}
}
void JoystickButton::actionComboBoxChanged(int index)
{
emit actionChanged(id, index);
}
......@@ -3,6 +3,8 @@
#include <QWidget>
#include "UASInterface.h"
namespace Ui
{
class JoystickButton;
......@@ -16,8 +18,19 @@ public:
explicit JoystickButton(int id, QWidget *parent = 0);
virtual ~JoystickButton();
public slots:
/** @brief Specify the UAS that this axis should track for displaying throttle properly. */
void setActiveUAS(UASInterface* uas);
signals:
/** @brief Signal a change in this buttons' action mapping */
void actionChanged(int id, int index);
private:
int id;
Ui::JoystickButton *m_ui;
private slots:
void actionComboBoxChanged(int index);
};
#endif // JOYSTICKBUTTON_H
......@@ -65,6 +65,9 @@
</item>
<item>
<widget class="QComboBox" name="joystickAction">
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
......@@ -73,15 +76,13 @@
</property>
<property name="minimumSize">
<size>
<width>30</width>
<width>60</width>
<height>0</height>
</size>
</property>
<item>
<property name="text">
<string>--</string>
</property>
</item>
<property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToContents</enum>
</property>
</widget>
</item>
</layout>
......
......@@ -125,6 +125,7 @@ void JoystickWidget::updateUIForJoystick(int id)
for (int i = 0; i < newButtons; i++)
{
JoystickButton* button = new JoystickButton(i, m_ui->buttonBox);
connect(UASManager::instance(), SIGNAL(activeUASSet(UASInterface*)), button, SLOT(setActiveUAS(UASInterface*)));
m_ui->buttonLayout->addWidget(button);
buttons.append(button);
}
......
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