35 #define JOYSTICK_UPDATE_RATE 50
39 : IUAVGadget(classId, parent)
60 connect(pl->sdlGamepad, SIGNAL(
gamepads(quint8)),
this, SLOT(
gamepads(quint8)));
61 connect(pl->sdlGamepad, SIGNAL(
buttonState(ButtonNumber,
bool)),
this,
80 rollChannel = ql.at(0);
81 pitchChannel = ql.at(1);
82 yawChannel = ql.at(2);
83 throttleChannel = ql.at(3);
89 for (
unsigned int i = 0;
i < 8;
i++) {
105 enableSending = enable;
112 ManualControlCommand *GCSControlGadget::getManualControlCommand()
116 return dynamic_cast<ManualControlCommand *
>(
117 objManager->
getObject(QString(
"ManualControlCommand")));
124 Q_ASSERT(gcsControl);
140 switch (controlsMode) {
164 double rightY,
double arming)
167 setGcsReceiver(leftX, leftY, rightX, rightY, arming);
171 void GCSControlGadget::setGcsReceiver(
double leftX,
double leftY,
double rightX,
double rightY,
182 double newThrottle = 0;
185 switch (controlsMode) {
191 newThrottle = rightY;
205 newThrottle = rightY;
222 switch (controlsMode) {
253 double GCSControlGadget::constrain(
double value)
265 if ((buttonSettings[number].ActionID > 0) && (buttonSettings[number].FunctionID > 0)
271 bool currentCGSControl =
274 switch (buttonSettings[number].ActionID) {
276 if (currentCGSControl) {
277 switch (buttonSettings[number].FunctionID) {
280 bound(obj->getField(
"Roll")->getValue().toDouble()
281 + buttonSettings[number].
Amount));
284 obj->getField(
"Pitch")->setValue(
285 bound(obj->getField(
"Pitch")->getValue().toDouble()
286 + buttonSettings[number].
Amount));
289 obj->getField(
"Yaw")->setValue(wrap(obj->getField(
"Yaw")->getValue().toDouble()
290 + buttonSettings[number].
Amount));
293 obj->getField(
"Throttle")
294 ->setValue(bound(obj->getField(
"Throttle")->getValue().toDouble()
295 + buttonSettings[number].
Amount));
301 if (currentCGSControl) {
302 switch (buttonSettings[number].FunctionID) {
304 obj->getField(
"Roll")->setValue(
305 bound(obj->getField(
"Roll")->getValue().toDouble()
306 - buttonSettings[number].
Amount));
309 obj->getField(
"Pitch")->setValue(
310 bound(obj->getField(
"Pitch")->getValue().toDouble()
311 - buttonSettings[number].
Amount));
314 obj->getField(
"Yaw")->setValue(wrap(obj->getField(
"Yaw")->getValue().toDouble()
315 - buttonSettings[number].
Amount));
318 obj->getField(
"Throttle")
319 ->setValue(bound(obj->getField(
"Throttle")->getValue().toDouble()
320 - buttonSettings[number].
Amount));
326 switch (buttonSettings[number].FunctionID) {
328 if (currentCGSControl) {
332 objManager->
getObject(QString(
"FlightStatus")));
334 if (obj->getField(
"Armed")->getValue().toString().compare(
"Armed") == 0) {
337 obj->getField(
"Armed")->setValue(
"Armed");
345 ->setGCSControl(!currentCGSControl);
362 int chMax = values.length();
363 if (rollChannel >= chMax || pitchChannel >= chMax || yawChannel >= chMax
364 || throttleChannel >= chMax) {
366 <<
"GCSControl: configuration is inconsistent with current joystick! Aborting update.";
370 double rValue = (rollChannel > -1) ? values[rollChannel] : 0;
371 double pValue = (pitchChannel > -1) ? values[pitchChannel] : 0;
372 double yValue = (yawChannel > -1) ? values[yawChannel] : 0;
373 double tValue = (throttleChannel > -1) ? values[throttleChannel] : 0;
379 if (rollChannel > -1)
380 if (channelReverse[rollChannel] ==
true)
382 if (pitchChannel > -1)
383 if (channelReverse[pitchChannel] ==
true)
386 if (channelReverse[yawChannel] ==
true)
388 if (throttleChannel > -1)
389 if (channelReverse[throttleChannel] ==
true)
392 if (joystickTime.elapsed() > JOYSTICK_UPDATE_RATE) {
393 joystickTime.restart();
399 switch (controlsMode) {
417 double GCSControlGadget::bound(
double input)
426 double GCSControlGadget::wrap(
double input)
void loadConfiguration(IUAVGadgetConfiguration *config)
buttonSettingsStruct getbuttonSettings(int i)
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.
GCSControlGadget(QString classId, GCSControlGadgetWidget *widget, QWidget *parent=nullptr, QObject *plugin=nullptr)
void sticksChangedLocally(double leftX, double leftY, double rightX, double rightY, double arming)
double getDouble(int index=0) const
Core plugin system that manages the plugins, their life cycle and their registered objects...
bool setRoll(float value)
void manualControlCommandUpdated(UAVObject *)
bool setThrottle(float value)
bool setFlightMode(ManualControlSettings::FlightModePositionOptions flightMode)
void sticksChangedRemotely(double leftX, double leftY, double rightX, double rightY)
void objectUpdated(UAVObject *obj)
Signal sent whenever any field of the object is updated.
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.
bool beginGCSControl()
GCSControl::beginGCSControl Configure the FC to use the GCSReceiver control for manual control (cache...
void gamepads(quint8 count)
void setValue(const QVariant &data, int index=0)
bool setPitch(float value)
void axesValues(QListInt16 values)
UAVObjectField * getField(const QString &name)
void controlEnabled(bool)
void enableControl(bool enable)
Enable or disable sending data.
void flightModeChangedLocally(ManualControlSettings::FlightModePositionOptions)
bool endGCSControl()
GCSControl::endGCSControl restores the cached ManualControlSettings.
QList< bool > getChannelsReverse()
bool getGcsReceiverMode()
QList< int > getChannelsMapping()
void buttonState(ButtonNumber number, bool pressed)
UAVObject * getObject(const QString &name, quint32 instId=0)
bool setArming(float value)
void flightModeChanged(ManualControlSettings::FlightModePositionOptions mode)