2010-07-19 08:20:13 +02:00
|
|
|
/**
|
|
|
|
******************************************************************************
|
|
|
|
*
|
|
|
|
* @file GCSControlgadgetwidget.cpp
|
|
|
|
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
|
|
|
* @addtogroup GCSPlugins GCS Plugins
|
|
|
|
* @{
|
|
|
|
* @addtogroup GCSControlGadgetPlugin GCSControl Gadget Plugin
|
|
|
|
* @{
|
|
|
|
* @brief A gadget to control the UAV, either from the keyboard or a joystick
|
|
|
|
*****************************************************************************/
|
|
|
|
/*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
#include "gcscontrolgadgetwidget.h"
|
|
|
|
#include "ui_gcscontrol.h"
|
|
|
|
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QStringList>
|
|
|
|
#include <QtGui/QWidget>
|
|
|
|
#include <QtGui/QTextEdit>
|
|
|
|
#include <QtGui/QVBoxLayout>
|
|
|
|
#include <QtGui/QPushButton>
|
|
|
|
|
2011-01-22 18:38:22 +01:00
|
|
|
#include "uavobject.h"
|
|
|
|
#include "uavobjectmanager.h"
|
|
|
|
#include "manualcontrolcommand.h"
|
2010-07-19 08:20:13 +02:00
|
|
|
#include "extensionsystem/pluginmanager.h"
|
|
|
|
|
|
|
|
GCSControlGadgetWidget::GCSControlGadgetWidget(QWidget *parent) : QLabel(parent)
|
|
|
|
{
|
|
|
|
m_gcscontrol = new Ui_GCSControl();
|
|
|
|
m_gcscontrol->setupUi(this);
|
2010-07-20 00:03:03 +02:00
|
|
|
|
2010-09-27 21:35:25 +02:00
|
|
|
|
|
|
|
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
|
|
|
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
|
|
|
|
UAVDataObject* obj = dynamic_cast<UAVDataObject*>( objManager->getObject(QString("ManualControlCommand")) );
|
|
|
|
UAVObject::Metadata mdata = obj->getMetadata();
|
|
|
|
m_gcscontrol->checkBoxGcsControl->setChecked(mdata.flightAccess == UAVObject::ACCESS_READONLY);
|
|
|
|
|
2010-07-20 00:03:03 +02:00
|
|
|
// Set up the drop down box for the flightmode
|
2010-09-27 21:35:25 +02:00
|
|
|
m_gcscontrol->comboBoxFlightMode->addItems(obj->getField("FlightMode")->getOptions());
|
|
|
|
|
|
|
|
// Set up slots and signals for joysticks
|
|
|
|
connect(m_gcscontrol->widgetLeftStick,SIGNAL(positionClicked(double,double)),this,SLOT(leftStickClicked(double,double)));
|
|
|
|
connect(m_gcscontrol->widgetRightStick,SIGNAL(positionClicked(double,double)),this,SLOT(rightStickClicked(double,double)));
|
2010-07-20 00:03:03 +02:00
|
|
|
|
2010-09-27 21:35:25 +02:00
|
|
|
// Connect misc controls
|
|
|
|
connect(m_gcscontrol->checkBoxGcsControl, SIGNAL(stateChanged(int)), this, SLOT(toggleControl(int)));
|
|
|
|
connect(m_gcscontrol->checkBoxArmed, SIGNAL(stateChanged(int)), this, SLOT(toggleArmed(int)));
|
|
|
|
connect(m_gcscontrol->comboBoxFlightMode, SIGNAL(currentIndexChanged(int)), this, SLOT(selectFlightMode(int)));
|
2010-09-16 17:41:11 +02:00
|
|
|
|
2010-09-27 21:35:25 +02:00
|
|
|
// Connect object updated event from UAVObject to also update check boxes and dropdown
|
|
|
|
connect(obj, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(mccChanged(UAVObject*)));
|
2010-07-20 00:03:03 +02:00
|
|
|
|
2010-09-27 21:35:25 +02:00
|
|
|
|
|
|
|
leftX = 0;
|
|
|
|
leftY = 0;
|
|
|
|
rightX = 0;
|
|
|
|
rightY = 0;
|
2010-07-19 08:20:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
GCSControlGadgetWidget::~GCSControlGadgetWidget()
|
|
|
|
{
|
|
|
|
// Do nothing
|
|
|
|
}
|
|
|
|
|
2010-11-07 23:16:45 +01:00
|
|
|
void GCSControlGadgetWidget::updateSticks(double nleftX, double nleftY, double nrightX, double nrightY) {
|
|
|
|
leftX = nleftX;
|
|
|
|
leftY = nleftY;
|
|
|
|
rightX = nrightX;
|
|
|
|
rightY = nrightY;
|
2010-09-27 21:35:25 +02:00
|
|
|
m_gcscontrol->widgetLeftStick->changePosition(leftX,leftY);
|
|
|
|
m_gcscontrol->widgetRightStick->changePosition(rightX,rightY);
|
2010-07-20 00:03:03 +02:00
|
|
|
}
|
2010-07-19 08:20:13 +02:00
|
|
|
|
2010-09-27 21:35:25 +02:00
|
|
|
void GCSControlGadgetWidget::leftStickClicked(double X, double Y) {
|
|
|
|
leftX = X;
|
|
|
|
leftY = Y;
|
|
|
|
emit sticksChanged(leftX,leftY,rightX,rightY);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GCSControlGadgetWidget::rightStickClicked(double X, double Y) {
|
|
|
|
rightX = X;
|
|
|
|
rightY = Y;
|
|
|
|
emit sticksChanged(leftX,leftY,rightX,rightY);
|
2010-09-16 17:41:11 +02:00
|
|
|
}
|
|
|
|
|
2010-07-20 00:03:03 +02:00
|
|
|
/*!
|
|
|
|
\brief Called when the gcs control is toggled and enabled or disables flight write access to manual control command
|
|
|
|
*/
|
2010-09-27 21:35:25 +02:00
|
|
|
void GCSControlGadgetWidget::toggleControl(int state)
|
2010-07-20 00:03:03 +02:00
|
|
|
{
|
2010-09-27 21:35:25 +02:00
|
|
|
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
|
|
|
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
|
|
|
|
UAVDataObject* obj = dynamic_cast<UAVDataObject*>( objManager->getObject(QString("ManualControlCommand")) );
|
|
|
|
|
|
|
|
UAVObject::Metadata mdata = obj->getMetadata();
|
2010-07-20 00:03:03 +02:00
|
|
|
if (state)
|
|
|
|
{
|
2010-08-19 22:39:19 +02:00
|
|
|
mccInitialData = mdata;
|
2010-07-20 00:03:03 +02:00
|
|
|
mdata.flightAccess = UAVObject::ACCESS_READONLY;
|
2010-08-19 22:39:19 +02:00
|
|
|
mdata.flightTelemetryUpdateMode = UAVObject::UPDATEMODE_ONCHANGE;
|
|
|
|
mdata.gcsTelemetryAcked = false;
|
|
|
|
mdata.gcsTelemetryUpdateMode = UAVObject::UPDATEMODE_ONCHANGE;
|
|
|
|
mdata.gcsTelemetryUpdatePeriod = 100;
|
|
|
|
|
2010-07-20 00:03:03 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-08-19 22:39:19 +02:00
|
|
|
mdata = mccInitialData;
|
2010-07-20 00:03:03 +02:00
|
|
|
}
|
2010-09-27 21:35:25 +02:00
|
|
|
obj->setMetadata(mdata);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GCSControlGadgetWidget::toggleArmed(int state)
|
|
|
|
{
|
|
|
|
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
|
|
|
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
|
|
|
|
UAVDataObject* obj = dynamic_cast<UAVDataObject*>( objManager->getObject(QString("ManualControlCommand")) );
|
|
|
|
if(state)
|
|
|
|
obj->getField("Armed")->setValue("True");
|
|
|
|
else
|
|
|
|
obj->getField("Armed")->setValue("False");
|
|
|
|
obj->updated();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GCSControlGadgetWidget::mccChanged(UAVObject * obj)
|
|
|
|
{
|
|
|
|
m_gcscontrol->checkBoxArmed->setChecked(obj->getField("Armed")->getValue() == "True");
|
|
|
|
m_gcscontrol->comboBoxFlightMode->setCurrentIndex(m_gcscontrol->comboBoxFlightMode->findText(obj->getField("FlightMode")->getValue().toString()));
|
2010-07-20 00:03:03 +02:00
|
|
|
}
|
2010-07-19 08:20:13 +02:00
|
|
|
|
2010-07-20 00:03:03 +02:00
|
|
|
/*!
|
|
|
|
\brief Called when the flight mode drop down is changed and sets the ManualControlCommand->FlightMode accordingly
|
|
|
|
*/
|
2010-09-27 21:35:25 +02:00
|
|
|
void GCSControlGadgetWidget::selectFlightMode(int state)
|
2010-07-20 00:03:03 +02:00
|
|
|
{
|
2010-09-27 21:35:25 +02:00
|
|
|
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
|
|
|
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
|
|
|
|
UAVDataObject* obj = dynamic_cast<UAVDataObject*>( objManager->getObject(QString("ManualControlCommand")) );
|
|
|
|
UAVObjectField * field = obj->getField("FlightMode");
|
|
|
|
field->setValue(field->getOptions()[state]);
|
|
|
|
obj->updated();
|
2010-07-19 08:20:13 +02:00
|
|
|
}
|
|
|
|
|
2010-12-12 05:09:32 +01:00
|
|
|
void GCSControlGadgetWidget::setGCSControl(bool newState)
|
|
|
|
{
|
|
|
|
m_gcscontrol->checkBoxGcsControl->setChecked(newState);
|
|
|
|
};
|
|
|
|
bool GCSControlGadgetWidget::getGCSControl(void)
|
|
|
|
{
|
|
|
|
return m_gcscontrol->checkBoxGcsControl->isChecked();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2010-07-20 21:57:29 +02:00
|
|
|
/**
|
|
|
|
* @}
|
|
|
|
* @}
|
|
|
|
*/
|
2010-12-12 05:09:32 +01:00
|
|
|
|