dRonin  adbada4
dRonin GCS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
gcscontrolgadgetwidget.cpp
Go to the documentation of this file.
1 
12 /*
13  * This program is free software; you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License as published by
15  * the Free Software Foundation; either version 3 of the License, or
16  * (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful, but
19  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  * for more details.
22  *
23  * You should have received a copy of the GNU General Public License along
24  * with this program; if not, see <http://www.gnu.org/licenses/>
25  */
26 #include "gcscontrolgadgetwidget.h"
27 #include "ui_gcscontrol.h"
28 
29 #include <QDebug>
30 #include <QStringList>
31 #include <QWidget>
32 #include <QTextEdit>
33 #include <QVBoxLayout>
34 #include <QPushButton>
35 
36 #include "uavobjects/uavobject.h"
38 #include "manualcontrolcommand.h"
40 #include "flightstatus.h"
41 
43  : QLabel(parent)
44 {
45  m_gcscontrol = new Ui_GCSControl();
46  m_gcscontrol->setupUi(this);
47 
48  ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
49  UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
50 
51  // Set up the drop down box for the flightmode
52  FlightStatus *flightStatus = FlightStatus::GetInstance(objManager);
53  ;
54  m_gcscontrol->comboBoxFlightMode->addItems(flightStatus->getField("FlightMode")->getOptions());
55 
56  // Set up slots and signals for joysticks
57  connect(m_gcscontrol->widgetLeftStick, &JoystickControl::positionClicked, this,
59  connect(m_gcscontrol->widgetRightStick, &JoystickControl::positionClicked, this,
61 
62  // Connect misc controls
63  connect(m_gcscontrol->checkBoxGcsControl, &QAbstractButton::clicked, this,
65  connect(m_gcscontrol->checkBoxArmed, &QAbstractButton::clicked, this,
67  connect(m_gcscontrol->comboBoxFlightMode, QOverload<int>::of(&QComboBox::currentIndexChanged),
69 
70  // Connect object updated event from UAVObject to also update check boxes and dropdown
71  connect(flightStatus, &FlightStatus::FlightModeChanged, this,
73  connect(flightStatus, &FlightStatus::ArmedChanged, this, &GCSControlGadgetWidget::armedChanged);
74 
75  leftX = 0;
76  leftY = 0;
77  rightX = 0;
78  rightY = 0;
79  arming = -1;
80 }
81 
82 void GCSControlGadgetWidget::updateSticks(double nleftX, double nleftY, double nrightX,
83  double nrightY)
84 {
85  leftX = nleftX;
86  leftY = nleftY;
87  rightX = nrightX;
88  rightY = nrightY;
89  m_gcscontrol->widgetLeftStick->changePosition(leftX, leftY);
90  m_gcscontrol->widgetRightStick->changePosition(rightX, rightY);
91 }
92 
94 {
95  leftX = X;
96  leftY = Y;
97  emit sticksChanged(leftX, leftY, rightX, rightY, arming);
98 }
99 
101 {
102  rightX = X;
103  rightY = Y;
104  emit sticksChanged(leftX, leftY, rightX, rightY, arming);
105 }
106 
111 {
112  if (checked) {
113  arming = 1;
114  } else {
115  arming = -1;
116  }
117 
118  emit sticksChanged(leftX, leftY, rightX, rightY, arming);
119 }
120 
125 {
126  emit controlEnabled(checked);
127 }
128 
130 {
131  m_gcscontrol->comboBoxFlightMode->setCurrentIndex(mode);
132 }
133 
135 {
136  m_gcscontrol->checkBoxArmed->setChecked(armed != 0);
137 }
138 
143 {
144  emit flightModeChangedLocally((ManualControlSettings::FlightModePositionOptions)state);
145 }
146 
149 {
150  m_gcscontrol->checkBoxGcsControl->setEnabled(allow);
151  if (allow)
152  m_gcscontrol->checkBoxGcsControl->setToolTip(tr("Take control of the board from GCS"));
153  else
154  m_gcscontrol->checkBoxGcsControl->setToolTip(
155  tr("Disabled for safety. Enable this in the options page."));
156 }
157 
159 {
160  m_gcscontrol->checkBoxGcsControl->setChecked(newState);
161 }
162 
164 {
165  return m_gcscontrol->checkBoxGcsControl->isChecked();
166 }
167 
void setGCSControl(bool newState)
void updateSticks(double leftX, double leftY, double rightX, double rightY)
Signals from parent gadget indicating change from the remote system.
void allowGcsControl(bool allow)
Allow the GCS to take over control of UAV.
Core plugin system that manages the plugins, their life cycle and their registered objects...
Definition: pluginmanager.h:53
GCSControlGadgetWidget(QWidget *parent=nullptr)
void leftStickClicked(double X, double Y)
void sticksChanged(double leftX, double leftY, double rightX, double rightY, double arming)
Emitted whenever the UI is clicked on to indicate the new stick positions.
void rightStickClicked(double X, double Y)
void toggleControl(bool checked)
Called when the gcs control is toggled.
void positionClicked(double x, double y)
void flightModeChangedLocally(ManualControlSettings::FlightModePositionOptions)
void toggleArming(bool checked)
Called when the gcs control is toggled.
void selectFlightMode(int state)
Called when the flight mode drop down is changed and sets the ManualControlCommand->FlightMode accord...