Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Q
qgroundcontrol
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Valentin Platzgummer
qgroundcontrol
Commits
dd7e7fa0
Commit
dd7e7fa0
authored
Jul 26, 2020
by
DonLakeFlyer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
parent
2fb02111
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
61 additions
and
43 deletions
+61
-43
Joystick.cc
src/Joystick/Joystick.cc
+36
-29
Joystick.h
src/Joystick/Joystick.h
+19
-8
JoystickConfigAdvanced.qml
src/VehicleSetup/JoystickConfigAdvanced.qml
+6
-6
No files found.
src/Joystick/Joystick.cc
View file @
dd7e7fa0
...
@@ -77,6 +77,13 @@ const char* Joystick::_rgFunctionSettingsKey[Joystick::maxFunction] = {
...
@@ -77,6 +77,13 @@ const char* Joystick::_rgFunctionSettingsKey[Joystick::maxFunction] = {
int
Joystick
::
_transmitterMode
=
2
;
int
Joystick
::
_transmitterMode
=
2
;
const
float
Joystick
::
_defaultAxisFrequencyHz
=
25.0
f
;
const
float
Joystick
::
_defaultButtonFrequencyHz
=
5.0
f
;
const
float
Joystick
::
_minAxisFrequencyHz
=
0.25
f
;
const
float
Joystick
::
_maxAxisFrequencyHz
=
200.0
f
;
const
float
Joystick
::
_minButtonFrequencyHz
=
0.25
f
;
const
float
Joystick
::
_maxButtonFrequencyHz
=
50.0
f
;
AssignedButtonAction
::
AssignedButtonAction
(
QObject
*
parent
,
const
QString
name
)
AssignedButtonAction
::
AssignedButtonAction
(
QObject
*
parent
,
const
QString
name
)
:
QObject
(
parent
)
:
QObject
(
parent
)
,
action
(
name
)
,
action
(
name
)
...
@@ -156,14 +163,14 @@ void Joystick::_setDefaultCalibration(void) {
...
@@ -156,14 +163,14 @@ void Joystick::_setDefaultCalibration(void) {
_rgFunctionAxis
[
gimbalPitchFunction
]
=
4
;
_rgFunctionAxis
[
gimbalPitchFunction
]
=
4
;
_rgFunctionAxis
[
gimbalYawFunction
]
=
5
;
_rgFunctionAxis
[
gimbalYawFunction
]
=
5
;
_exponential
=
0
;
_exponential
=
0
;
_accumulator
=
false
;
_accumulator
=
false
;
_deadband
=
false
;
_deadband
=
false
;
_axisFrequency
=
25.0
f
;
_axisFrequency
Hz
=
_defaultAxisFrequencyHz
;
_buttonFrequency
=
5.0
f
;
_buttonFrequency
Hz
=
_defaultButtonFrequencyHz
;
_throttleMode
=
ThrottleModeDownZero
;
_throttleMode
=
ThrottleModeDownZero
;
_calibrated
=
true
;
_calibrated
=
true
;
_circleCorrection
=
false
;
_circleCorrection
=
false
;
_saveSettings
();
_saveSettings
();
}
}
...
@@ -218,14 +225,14 @@ void Joystick::_loadSettings()
...
@@ -218,14 +225,14 @@ void Joystick::_loadSettings()
qCDebug
(
JoystickLog
)
<<
"_loadSettings "
<<
_name
;
qCDebug
(
JoystickLog
)
<<
"_loadSettings "
<<
_name
;
_calibrated
=
settings
.
value
(
_calibratedSettingsKey
,
false
).
toBool
();
_calibrated
=
settings
.
value
(
_calibratedSettingsKey
,
false
).
toBool
();
_exponential
=
settings
.
value
(
_exponentialSettingsKey
,
0
).
toFloat
();
_exponential
=
settings
.
value
(
_exponentialSettingsKey
,
0
).
toFloat
();
_accumulator
=
settings
.
value
(
_accumulatorSettingsKey
,
false
).
toBool
();
_accumulator
=
settings
.
value
(
_accumulatorSettingsKey
,
false
).
toBool
();
_deadband
=
settings
.
value
(
_deadbandSettingsKey
,
false
).
toBool
();
_deadband
=
settings
.
value
(
_deadbandSettingsKey
,
false
).
toBool
();
_axisFrequency
=
settings
.
value
(
_axisFrequencySettingsKey
,
25.0
f
).
toFloat
();
_axisFrequency
Hz
=
settings
.
value
(
_axisFrequencySettingsKey
,
_defaultAxisFrequencyHz
).
toFloat
();
_buttonFrequency
=
settings
.
value
(
_buttonFrequencySettingsKey
,
5.0
f
).
toFloat
();
_buttonFrequency
Hz
=
settings
.
value
(
_buttonFrequencySettingsKey
,
_defaultButtonFrequencyHz
).
toFloat
();
_circleCorrection
=
settings
.
value
(
_circleCorrectionSettingsKey
,
false
).
toBool
();
_circleCorrection
=
settings
.
value
(
_circleCorrectionSettingsKey
,
false
).
toBool
();
_gimbalEnabled
=
settings
.
value
(
_gimbalSettingsKey
,
false
).
toBool
();
_gimbalEnabled
=
settings
.
value
(
_gimbalSettingsKey
,
false
).
toBool
();
_throttleMode
=
static_cast
<
ThrottleMode_t
>
(
settings
.
value
(
_throttleModeSettingsKey
,
ThrottleModeDownZero
).
toInt
(
&
convertOk
));
_throttleMode
=
static_cast
<
ThrottleMode_t
>
(
settings
.
value
(
_throttleModeSettingsKey
,
ThrottleModeDownZero
).
toInt
(
&
convertOk
));
badSettings
|=
!
convertOk
;
badSettings
|=
!
convertOk
;
...
@@ -326,8 +333,8 @@ void Joystick::_saveSettings()
...
@@ -326,8 +333,8 @@ void Joystick::_saveSettings()
settings
.
setValue
(
_exponentialSettingsKey
,
_exponential
);
settings
.
setValue
(
_exponentialSettingsKey
,
_exponential
);
settings
.
setValue
(
_accumulatorSettingsKey
,
_accumulator
);
settings
.
setValue
(
_accumulatorSettingsKey
,
_accumulator
);
settings
.
setValue
(
_deadbandSettingsKey
,
_deadband
);
settings
.
setValue
(
_deadbandSettingsKey
,
_deadband
);
settings
.
setValue
(
_axisFrequencySettingsKey
,
_axisFrequency
);
settings
.
setValue
(
_axisFrequencySettingsKey
,
_axisFrequency
Hz
);
settings
.
setValue
(
_buttonFrequencySettingsKey
,
_buttonFrequency
);
settings
.
setValue
(
_buttonFrequencySettingsKey
,
_buttonFrequency
Hz
);
settings
.
setValue
(
_throttleModeSettingsKey
,
_throttleMode
);
settings
.
setValue
(
_throttleModeSettingsKey
,
_throttleMode
);
settings
.
setValue
(
_gimbalSettingsKey
,
_gimbalEnabled
);
settings
.
setValue
(
_gimbalSettingsKey
,
_gimbalEnabled
);
settings
.
setValue
(
_circleCorrectionSettingsKey
,
_circleCorrection
);
settings
.
setValue
(
_circleCorrectionSettingsKey
,
_circleCorrection
);
...
@@ -470,7 +477,7 @@ void Joystick::run()
...
@@ -470,7 +477,7 @@ void Joystick::run()
_update
();
_update
();
_handleButtons
();
_handleButtons
();
_handleAxis
();
_handleAxis
();
QGC
::
SLEEP
::
msleep
(
20
);
QGC
::
SLEEP
::
msleep
(
qMin
(
static_cast
<
int
>
(
1000.0
f
/
_maxAxisFrequencyHz
),
static_cast
<
int
>
(
1000.0
f
/
_maxButtonFrequencyHz
))
/
2
);
}
}
_close
();
_close
();
}
}
...
@@ -544,7 +551,7 @@ void Joystick::_handleButtons()
...
@@ -544,7 +551,7 @@ void Joystick::_handleButtons()
}
}
}
else
{
}
else
{
//-- Process repeat buttons
//-- Process repeat buttons
int
buttonDelay
=
static_cast
<
int
>
(
1000.0
f
/
_buttonFrequency
);
int
buttonDelay
=
static_cast
<
int
>
(
1000.0
f
/
_buttonFrequency
Hz
);
if
(
_buttonActionArray
[
buttonIndex
]
->
buttonTime
.
elapsed
()
>
buttonDelay
)
{
if
(
_buttonActionArray
[
buttonIndex
]
->
buttonTime
.
elapsed
()
>
buttonDelay
)
{
_buttonActionArray
[
buttonIndex
]
->
buttonTime
.
start
();
_buttonActionArray
[
buttonIndex
]
->
buttonTime
.
start
();
qCDebug
(
JoystickLog
)
<<
"Repeat button triggered"
<<
buttonIndex
<<
buttonAction
;
qCDebug
(
JoystickLog
)
<<
"Repeat button triggered"
<<
buttonIndex
<<
buttonAction
;
...
@@ -574,7 +581,7 @@ void Joystick::_handleButtons()
...
@@ -574,7 +581,7 @@ void Joystick::_handleButtons()
void
Joystick
::
_handleAxis
()
void
Joystick
::
_handleAxis
()
{
{
//-- Get frequency
//-- Get frequency
int
axisDelay
=
static_cast
<
int
>
(
1000.0
f
/
_axisFrequency
);
int
axisDelay
=
static_cast
<
int
>
(
1000.0
f
/
_axisFrequency
Hz
);
//-- Check elapsed time since last run
//-- Check elapsed time since last run
if
(
_axisTime
.
elapsed
()
>
axisDelay
)
{
if
(
_axisTime
.
elapsed
()
>
axisDelay
)
{
_axisTime
.
start
();
_axisTime
.
start
();
...
@@ -938,21 +945,21 @@ void Joystick::setGimbalEnabled(bool set)
...
@@ -938,21 +945,21 @@ void Joystick::setGimbalEnabled(bool set)
void
Joystick
::
setAxisFrequency
(
float
val
)
void
Joystick
::
setAxisFrequency
(
float
val
)
{
{
//-- Arbitrary limits
//-- Arbitrary limits
if
(
val
<
0.25
f
)
val
=
0.25
f
;
val
=
qMin
(
_minAxisFrequencyHz
,
val
)
;
if
(
val
>
50.0
f
)
val
=
50.0
f
;
val
=
qMax
(
_maxAxisFrequencyHz
,
val
)
;
_axisFrequency
=
val
;
_axisFrequency
Hz
=
val
;
_saveSettings
();
_saveSettings
();
emit
axisFrequencyChanged
();
emit
axisFrequency
Hz
Changed
();
}
}
void
Joystick
::
setButtonFrequency
(
float
val
)
void
Joystick
::
setButtonFrequency
(
float
val
)
{
{
//-- Arbitrary limits
//-- Arbitrary limits
if
(
val
<
0.25
f
)
val
=
0.25
f
;
val
=
qMin
(
_minButtonFrequencyHz
,
val
)
;
if
(
val
>
50.0
f
)
val
=
50.0
f
;
val
=
qMax
(
_maxButtonFrequencyHz
,
val
)
;
_buttonFrequency
=
val
;
_buttonFrequency
Hz
=
val
;
_saveSettings
();
_saveSettings
();
emit
buttonFrequencyChanged
();
emit
buttonFrequency
Hz
Changed
();
}
}
void
Joystick
::
setCalibrationMode
(
bool
calibrating
)
void
Joystick
::
setCalibrationMode
(
bool
calibrating
)
...
...
src/Joystick/Joystick.h
View file @
dd7e7fa0
...
@@ -101,8 +101,12 @@ public:
...
@@ -101,8 +101,12 @@ public:
Q_PROPERTY
(
bool
gimbalEnabled
READ
gimbalEnabled
WRITE
setGimbalEnabled
NOTIFY
gimbalEnabledChanged
)
Q_PROPERTY
(
bool
gimbalEnabled
READ
gimbalEnabled
WRITE
setGimbalEnabled
NOTIFY
gimbalEnabledChanged
)
Q_PROPERTY
(
int
throttleMode
READ
throttleMode
WRITE
setThrottleMode
NOTIFY
throttleModeChanged
)
Q_PROPERTY
(
int
throttleMode
READ
throttleMode
WRITE
setThrottleMode
NOTIFY
throttleModeChanged
)
Q_PROPERTY
(
float
axisFrequency
READ
axisFrequency
WRITE
setAxisFrequency
NOTIFY
axisFrequencyChanged
)
Q_PROPERTY
(
float
axisFrequencyHz
READ
axisFrequencyHz
WRITE
setAxisFrequency
NOTIFY
axisFrequencyHzChanged
)
Q_PROPERTY
(
float
buttonFrequency
READ
buttonFrequency
WRITE
setButtonFrequency
NOTIFY
buttonFrequencyChanged
)
Q_PROPERTY
(
float
minAxisFrequencyHz
MEMBER
_minAxisFrequencyHz
CONSTANT
)
Q_PROPERTY
(
float
maxAxisFrequencyHz
MEMBER
_minAxisFrequencyHz
CONSTANT
)
Q_PROPERTY
(
float
buttonFrequencyHz
READ
buttonFrequencyHz
WRITE
setButtonFrequency
NOTIFY
buttonFrequencyHzChanged
)
Q_PROPERTY
(
float
minButtonFrequencyHz
MEMBER
_minButtonFrequencyHz
CONSTANT
)
Q_PROPERTY
(
float
maxButtonFrequencyHz
MEMBER
_maxButtonFrequencyHz
CONSTANT
)
Q_PROPERTY
(
bool
negativeThrust
READ
negativeThrust
WRITE
setNegativeThrust
NOTIFY
negativeThrustChanged
)
Q_PROPERTY
(
bool
negativeThrust
READ
negativeThrust
WRITE
setNegativeThrust
NOTIFY
negativeThrustChanged
)
Q_PROPERTY
(
float
exponential
READ
exponential
WRITE
setExponential
NOTIFY
exponentialChanged
)
Q_PROPERTY
(
float
exponential
READ
exponential
WRITE
setExponential
NOTIFY
exponentialChanged
)
Q_PROPERTY
(
bool
accumulator
READ
accumulator
WRITE
setAccumulator
NOTIFY
accumulatorChanged
)
Q_PROPERTY
(
bool
accumulator
READ
accumulator
WRITE
setAccumulator
NOTIFY
accumulatorChanged
)
...
@@ -171,12 +175,12 @@ public:
...
@@ -171,12 +175,12 @@ public:
void
setCalibrationMode
(
bool
calibrating
);
void
setCalibrationMode
(
bool
calibrating
);
/// Get joystick message rate (in Hz)
/// Get joystick message rate (in Hz)
float
axisFrequency
()
{
return
_axisFrequency
;
}
float
axisFrequency
Hz
()
{
return
_axisFrequencyHz
;
}
/// Set joystick message rate (in Hz)
/// Set joystick message rate (in Hz)
void
setAxisFrequency
(
float
val
);
void
setAxisFrequency
(
float
val
);
/// Get joystick button repeat rate (in Hz)
/// Get joystick button repeat rate (in Hz)
float
buttonFrequency
()
{
return
_buttonFrequency
;
}
float
buttonFrequency
Hz
()
{
return
_buttonFrequencyHz
;
}
/// Set joystick button repeat rate (in Hz)
/// Set joystick button repeat rate (in Hz)
void
setButtonFrequency
(
float
val
);
void
setButtonFrequency
(
float
val
);
...
@@ -197,8 +201,8 @@ signals:
...
@@ -197,8 +201,8 @@ signals:
void
manualControlGimbal
(
float
gimbalPitch
,
float
gimbalYaw
);
void
manualControlGimbal
(
float
gimbalPitch
,
float
gimbalYaw
);
void
gimbalEnabledChanged
();
void
gimbalEnabledChanged
();
void
axisFrequencyChanged
();
void
axisFrequency
Hz
Changed
();
void
buttonFrequencyChanged
();
void
buttonFrequency
Hz
Changed
();
void
startContinuousZoom
(
int
direction
);
void
startContinuousZoom
(
int
direction
);
void
stopContinuousZoom
();
void
stopContinuousZoom
();
void
stepZoom
(
int
direction
);
void
stepZoom
(
int
direction
);
...
@@ -260,6 +264,9 @@ protected:
...
@@ -260,6 +264,9 @@ protected:
BUTTON_REPEAT
BUTTON_REPEAT
};
};
static
const
float
_defaultAxisFrequencyHz
;
static
const
float
_defaultButtonFrequencyHz
;
uint8_t
*
_rgButtonValues
=
nullptr
;
uint8_t
*
_rgButtonValues
=
nullptr
;
bool
_exitThread
=
false
;
///< true: signal thread to exit
bool
_exitThread
=
false
;
///< true: signal thread to exit
...
@@ -272,8 +279,8 @@ protected:
...
@@ -272,8 +279,8 @@ protected:
bool
_accumulator
=
false
;
bool
_accumulator
=
false
;
bool
_deadband
=
false
;
bool
_deadband
=
false
;
bool
_circleCorrection
=
true
;
bool
_circleCorrection
=
true
;
float
_axisFrequency
=
25
.
0
f
;
float
_axisFrequency
Hz
=
_defaultAxisFrequencyHz
;
float
_buttonFrequency
=
5
.
0
f
;
float
_buttonFrequency
Hz
=
_defaultButtonFrequencyHz
;
Vehicle
*
_activeVehicle
=
nullptr
;
Vehicle
*
_activeVehicle
=
nullptr
;
bool
_gimbalEnabled
=
false
;
bool
_gimbalEnabled
=
false
;
...
@@ -296,6 +303,10 @@ protected:
...
@@ -296,6 +303,10 @@ protected:
QStringList
_availableActionTitles
;
QStringList
_availableActionTitles
;
MultiVehicleManager
*
_multiVehicleManager
=
nullptr
;
MultiVehicleManager
*
_multiVehicleManager
=
nullptr
;
static
const
float
_minAxisFrequencyHz
;
static
const
float
_maxAxisFrequencyHz
;
static
const
float
_minButtonFrequencyHz
;
static
const
float
_maxButtonFrequencyHz
;
private:
private:
static
const
char
*
_rgFunctionSettingsKey
[
maxFunction
];
static
const
char
*
_rgFunctionSettingsKey
[
maxFunction
];
...
...
src/VehicleSetup/JoystickConfigAdvanced.qml
View file @
dd7e7fa0
...
@@ -135,13 +135,13 @@ Item {
...
@@ -135,13 +135,13 @@ Item {
visible
:
advancedSettings
.
checked
visible
:
advancedSettings
.
checked
}
}
QGCTextField
{
QGCTextField
{
text
:
_activeJoystick
.
axisFrequency
text
:
_activeJoystick
.
axisFrequency
Hz
enabled
:
advancedSettings
.
checked
enabled
:
advancedSettings
.
checked
validator
:
DoubleValidator
{
bottom
:
0.25
;
top
:
50.0
;
}
validator
:
DoubleValidator
{
bottom
:
_activeJoystick
.
minAxisFrequencyHz
;
top
:
_activeJoystick
.
maxAxisFrequencyHz
;
}
inputMethodHints
:
Qt
.
ImhFormattedNumbersOnly
inputMethodHints
:
Qt
.
ImhFormattedNumbersOnly
Layout.alignment
:
Qt
.
AlignVCenter
Layout.alignment
:
Qt
.
AlignVCenter
onEditingFinished
:
{
onEditingFinished
:
{
_activeJoystick
.
axisFrequency
=
parseFloat
(
text
)
_activeJoystick
.
axisFrequency
Hz
=
parseFloat
(
text
)
}
}
visible
:
advancedSettings
.
checked
visible
:
advancedSettings
.
checked
}
}
...
@@ -153,13 +153,13 @@ Item {
...
@@ -153,13 +153,13 @@ Item {
visible
:
advancedSettings
.
checked
visible
:
advancedSettings
.
checked
}
}
QGCTextField
{
QGCTextField
{
text
:
_activeJoystick
.
buttonFrequency
text
:
_activeJoystick
.
buttonFrequency
Hz
enabled
:
advancedSettings
.
checked
enabled
:
advancedSettings
.
checked
validator
:
DoubleValidator
{
bottom
:
0.25
;
top
:
50.0
;
}
validator
:
DoubleValidator
{
bottom
:
_activeJoystick
.
minButtonFrequencyHz
;
top
:
_activeJoystick
.
maxButtonFrequencyHz
;
}
inputMethodHints
:
Qt
.
ImhFormattedNumbersOnly
inputMethodHints
:
Qt
.
ImhFormattedNumbersOnly
Layout.alignment
:
Qt
.
AlignVCenter
Layout.alignment
:
Qt
.
AlignVCenter
onEditingFinished
:
{
onEditingFinished
:
{
_activeJoystick
.
buttonFrequency
=
parseFloat
(
text
)
_activeJoystick
.
buttonFrequency
Hz
=
parseFloat
(
text
)
}
}
visible
:
advancedSettings
.
checked
visible
:
advancedSettings
.
checked
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment