Skip to content

Commit 29e3254

Browse files
committed
Joystick: Overhaul ManualControl Handling
1 parent 87fd499 commit 29e3254

File tree

10 files changed

+565
-266
lines changed

10 files changed

+565
-266
lines changed

src/Joystick/Joystick.cc

Lines changed: 135 additions & 76 deletions
Large diffs are not rendered by default.

src/Joystick/Joystick.h

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class Joystick : public QThread
8282
Q_PROPERTY(QString name READ name CONSTANT)
8383
Q_PROPERTY(QStringList assignableActionTitles READ assignableActionTitles NOTIFY assignableActionsChanged)
8484
Q_PROPERTY(QStringList buttonActions READ buttonActions NOTIFY buttonActionsChanged)
85-
85+
Q_PROPERTY(bool )
8686
enum ButtonEvent_t {
8787
BUTTON_UP,
8888
BUTTON_DOWN,
@@ -183,6 +183,9 @@ class Joystick : public QThread
183183
/// Set joystick button repeat rate (in Hz)
184184
void setButtonFrequency(float val);
185185

186+
QBitArray getButtonStates() const;
187+
QList<float> getAxisValues() const;
188+
186189
signals:
187190
// The raw signals are only meant for use by calibration
188191
void rawAxisValueChanged(int index, int value);
@@ -196,7 +199,8 @@ class Joystick : public QThread
196199
void accumulatorChanged(bool accumulator);
197200
void enabledChanged(bool enabled);
198201
void circleCorrectionChanged(bool circleCorrection);
199-
void axisValues(float roll, float pitch, float yaw, float throttle);
202+
void axisValuesUpdated(QList<float> axisValues);
203+
void dataUpdated(QList<float> axisValues, QBitArray buttons);
200204
void axisFrequencyHzChanged();
201205
void buttonFrequencyHzChanged();
202206
void startContinuousZoom(int direction);
@@ -279,6 +283,7 @@ private slots:
279283
QmlObjectListModel *_assignableButtonActions = nullptr;
280284

281285
bool _accumulator = false;
286+
float _throttleAccumulator = 0.f;
282287
bool _calibrated = false;
283288
bool _calibrationMode = false;
284289
bool _circleCorrection = true;
@@ -299,13 +304,20 @@ private slots:
299304

300305
static int _transmitterMode;
301306

302-
static constexpr float _defaultAxisFrequencyHz = 25.0f;
303-
static constexpr float _defaultButtonFrequencyHz = 5.0f;
307+
static constexpr float kMinAxisValue = -1.0f;
308+
static constexpr float kMaxAxisValue = 1.0f;
309+
310+
static constexpr float kDefaultAxisFrequencyHz = 25.0f;
311+
static constexpr float kDefaultButtonFrequencyHz = 5.0f;
312+
304313
// Arbitrary Limits
305-
static constexpr float _minAxisFrequencyHz = 0.25f;
306-
static constexpr float _maxAxisFrequencyHz = 200.0f;
307-
static constexpr float _minButtonFrequencyHz = 0.25f;
308-
static constexpr float _maxButtonFrequencyHz = 50.0f;
314+
static constexpr float kMinAxisFrequencyHz = 0.25f;
315+
static constexpr float kMaxAxisFrequencyHz = 200.0f;
316+
static constexpr float kMinButtonFrequencyHz = 0.25f;
317+
static constexpr float kMaxButtonFrequencyHz = 50.0f;
318+
319+
// for throttle to change from min to max it will take 1000ms
320+
static constexpr float kAccumulatorMaxSlewRate = 1000.0f;
309321

310322
static constexpr const char *_rgFunctionSettingsKey[maxFunction] = {
311323
"RollAxis",

src/Joystick/JoystickAndroid.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#include <QtCore/QJniEnvironment>
1616
#include <QtCore/QJniObject>
1717

18-
QGC_LOGGING_CATEGORY(JoystickAndroidLog, "Joystick.joystickandroid")
18+
QGC_LOGGING_CATEGORY(JoystickAndroidLog, "Joystick.JoystickAndroid")
1919

2020
QList<int> JoystickAndroid::_androidBtnList(_androidBtnListCount);
2121
int JoystickAndroid::ACTION_DOWN = 0;

src/Joystick/JoystickManager.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#include <QtCore/QApplicationStatic>
2121
#include <QtCore/QSettings>
2222

23-
QGC_LOGGING_CATEGORY(JoystickManagerLog, "Joystick.joystickmanager")
23+
QGC_LOGGING_CATEGORY(JoystickManagerLog, "Joystick.JoystickManager")
2424

2525
Q_APPLICATION_STATIC(JoystickManager, _joystickManager);
2626

src/Joystick/JoystickSDL.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
#include <SDL3/SDL.h>
1818

19-
QGC_LOGGING_CATEGORY(JoystickSDLLog, "Joystick.joysticksdl")
19+
QGC_LOGGING_CATEGORY(JoystickSDLLog, "Joystick.JoystickSDL")
2020

2121
JoystickSDL::JoystickSDL(const QString &name, QList<int> gamepadAxes, QList<int> nonGamepadAxes, int buttonCount, int hatCount, int instanceId, bool isGamepad, QObject *parent)
2222
: Joystick(name, gamepadAxes.length() + nonGamepadAxes.length(), buttonCount, hatCount, parent)

src/MAVLink/MAVLinkMessages.cc

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/****************************************************************************
2+
*
3+
* (c) 2009-2024 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
4+
*
5+
* QGroundControl is licensed according to the terms in the file
6+
* COPYING.md in the root of the source code directory.
7+
*
8+
****************************************************************************/
9+
10+
#include "MAVLinkMessages.h"
11+
#include "QGCLoggingCategory.h"
12+
13+
QGC_LOGGING_CATEGORY(MAVLinkMessagesLog, "MAVLink.MAVLinkMessages")
14+
15+
namespace MAVLinkMessages
16+
{
17+
18+
void ManualControl::sendManualControlMsg(int16_t x, int16_t y, int16_t z, int16_t r,
19+
int16_t s, int16_t t,
20+
int16_t aux1, int16_t aux2, int16_t aux3, int16_t aux4, int16_t aux5, int16_t aux6,
21+
QBitArray buttons)
22+
{
23+
mavlink_manual_control_t manual_control{};
24+
manual_control.x = x;
25+
manual_control.y = y;
26+
manual_control.z = z;
27+
manual_control.r = r;
28+
29+
manual_control.s = s;
30+
manual_control.t = t;
31+
manual_control.aux1 = aux1;
32+
manual_control.aux2 = aux2;
33+
manual_control.aux3 = aux3;
34+
manual_control.aux4 = aux4;
35+
manual_control.aux5 = aux5;
36+
manual_control.aux6 = aux6;
37+
38+
bool ok;
39+
const quint32 buttonPressed = buttons.toUInt32(QSysInfo::Endian::LittleEndian, &ok);
40+
if (ok) {
41+
manual_control.buttons = static_cast<uint16_t>(buttonPressed);
42+
manual_control.buttons2 = static_cast<uint16_t>((buttonPressed >> 16) & 0xFFFF);
43+
}
44+
45+
SharedLinkInterfacePtr sharedLink = vehicleLinkManager()->primaryLink().lock();
46+
if (!sharedLink) {
47+
qCWarning(VehicleLog) << "primary link gone!";
48+
return;
49+
}
50+
51+
if (sharedLink->linkConfiguration()->isHighLatency()) {
52+
return;
53+
}
54+
55+
sendMessageOnLinkThreadSafe(sharedLink.get(), message);
56+
}
57+
58+
} // namespace MAVLinkMessages

src/MAVLink/MAVLinkMessages.h

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/****************************************************************************
2+
*
3+
* (c) 2009-2024 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
4+
*
5+
* QGroundControl is licensed according to the terms in the file
6+
* COPYING.md in the root of the source code directory.
7+
*
8+
****************************************************************************/
9+
10+
#pragma once
11+
12+
#include "MAVLinkLib.h"
13+
14+
#include <QtCore/QLoggingCategory>
15+
16+
Q_DECLARE_LOGGING_CATEGORY(QGCMAVLinkMessagesLog)
17+
18+
namespace MAVLinkMessages
19+
{
20+
21+
class MAVLinkMessage
22+
{
23+
public:
24+
MAVLinkMessage() = default;
25+
~MAVLinkMessage() = default;
26+
27+
protected:
28+
mavlink_message_t message;
29+
}
30+
31+
class ManualControl : public MAVLinkMessage
32+
{
33+
public:
34+
ManualControl() = default;
35+
36+
private:
37+
int16_t x = INT16_MAX;
38+
int16_t y = INT16_MAX;
39+
int16_t z = INT16_MAX;
40+
int16_t r = INT16_MAX;
41+
42+
QBitArray buttons{32};
43+
44+
QBitArray extensions{8};
45+
46+
int16_t s = 0;
47+
int16_t t = 0;
48+
49+
int16_t aux1 = 0;
50+
int16_t aux2 = 0;
51+
int16_t aux3 = 0;
52+
int16_t aux4 = 0;
53+
int16_t aux5 = 0;
54+
int16_t aux6 = 0;
55+
56+
mavlink_manual_control_t manual_control{};
57+
};
58+
59+
}; // namespace MAVLinkMessages

0 commit comments

Comments
 (0)