Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Valentin Platzgummer
qgroundcontrol
Commits
51d20e25
Commit
51d20e25
authored
Apr 04, 2018
by
Gus Grubba
Browse files
Allow defining Joystick message frequency
parent
1d0a8d8e
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/Joystick/Joystick.cc
View file @
51d20e25
...
...
@@ -26,6 +26,7 @@ const char* Joystick::_exponentialSettingsKey = "Exponential";
const
char
*
Joystick
::
_accumulatorSettingsKey
=
"Accumulator"
;
const
char
*
Joystick
::
_deadbandSettingsKey
=
"Deadband"
;
const
char
*
Joystick
::
_circleCorrectionSettingsKey
=
"Circle_Correction"
;
const
char
*
Joystick
::
_frequencySettingsKey
=
"Frequency"
;
const
char
*
Joystick
::
_txModeSettingsKey
=
NULL
;
const
char
*
Joystick
::
_fixedWingTXModeSettingsKey
=
"TXMode_FixedWing"
;
const
char
*
Joystick
::
_multiRotorTXModeSettingsKey
=
"TXMode_MultiRotor"
;
...
...
@@ -66,6 +67,7 @@ Joystick::Joystick(const QString& name, int axisCount, int buttonCount, int hatC
,
_accumulator
(
false
)
,
_deadband
(
false
)
,
_circleCorrection
(
true
)
,
_frequency
(
25.0
f
)
,
_activeVehicle
(
NULL
)
,
_pollingStartedForCalibration
(
false
)
,
_multiVehicleManager
(
multiVehicleManager
)
...
...
@@ -127,6 +129,7 @@ void Joystick::_setDefaultCalibration(void) {
_accumulator
=
false
;
_deadband
=
false
;
_circleCorrection
=
false
;
_frequency
=
25.0
f
;
_throttleMode
=
ThrottleModeCenterZero
;
_calibrated
=
true
;
...
...
@@ -192,6 +195,7 @@ void Joystick::_loadSettings(void)
_accumulator
=
settings
.
value
(
_accumulatorSettingsKey
,
false
).
toBool
();
_deadband
=
settings
.
value
(
_deadbandSettingsKey
,
false
).
toBool
();
_circleCorrection
=
settings
.
value
(
_circleCorrectionSettingsKey
,
false
).
toBool
();
_frequency
=
settings
.
value
(
_frequencySettingsKey
,
25.0
f
).
toFloat
();
_throttleMode
=
(
ThrottleMode_t
)
settings
.
value
(
_throttleModeSettingsKey
,
ThrottleModeCenterZero
).
toInt
(
&
convertOk
);
badSettings
|=
!
convertOk
;
...
...
@@ -269,6 +273,7 @@ void Joystick::_saveSettings(void)
settings
.
setValue
(
_accumulatorSettingsKey
,
_accumulator
);
settings
.
setValue
(
_deadbandSettingsKey
,
_deadband
);
settings
.
setValue
(
_circleCorrectionSettingsKey
,
_circleCorrection
);
settings
.
setValue
(
_frequencySettingsKey
,
_frequency
);
settings
.
setValue
(
_throttleModeSettingsKey
,
_throttleMode
);
qCDebug
(
JoystickLog
)
<<
"_saveSettings calibrated:throttlemode:deadband:txmode"
<<
_calibrated
<<
_throttleMode
<<
_deadband
<<
_circleCorrection
<<
_transmitterMode
;
...
...
@@ -542,8 +547,9 @@ void Joystick::run(void)
emit
manualControl
(
roll
,
-
pitch
,
yaw
,
throttle
,
buttonPressedBits
,
_activeVehicle
->
joystickMode
());
}
// Sleep, update rate of joystick is approx. 25 Hz (1000 ms / 25 = 40 ms)
QGC
::
SLEEP
::
msleep
(
40
);
// Sleep. Update rate of joystick is by default 25 Hz
int
mswait
=
(
int
)(
1000.0
f
/
_frequency
);
QGC
::
SLEEP
::
msleep
(
mswait
);
}
_close
();
...
...
@@ -787,6 +793,21 @@ void Joystick::setCircleCorrection(bool circleCorrection)
emit
circleCorrectionChanged
(
_circleCorrection
);
}
float
Joystick
::
frequency
()
{
return
_frequency
;
}
void
Joystick
::
setFrequency
(
float
val
)
{
//-- Arbitrary limits
if
(
val
<
0.25
f
)
val
=
0.25
f
;
if
(
val
>
100.0
f
)
val
=
100.0
f
;
_frequency
=
val
;
_saveSettings
();
emit
frequencyChanged
();
}
void
Joystick
::
setCalibrationMode
(
bool
calibrating
)
{
_calibrationMode
=
calibrating
;
...
...
src/Joystick/Joystick.h
View file @
51d20e25
...
...
@@ -77,6 +77,7 @@ public:
Q_PROPERTY
(
bool
accumulator
READ
accumulator
WRITE
setAccumulator
NOTIFY
accumulatorChanged
)
Q_PROPERTY
(
bool
requiresCalibration
READ
requiresCalibration
CONSTANT
)
Q_PROPERTY
(
bool
circleCorrection
READ
circleCorrection
WRITE
setCircleCorrection
NOTIFY
circleCorrectionChanged
)
Q_PROPERTY
(
float
frequency
READ
frequency
WRITE
setFrequency
NOTIFY
frequencyChanged
)
// Property accessors
...
...
@@ -129,6 +130,9 @@ public:
/// Set the current calibration mode
void
setCalibrationMode
(
bool
calibrating
);
float
frequency
();
void
setFrequency
(
float
val
);
signals:
void
calibratedChanged
(
bool
calibrated
);
...
...
@@ -160,6 +164,8 @@ signals:
void
buttonActionTriggered
(
int
action
);
void
frequencyChanged
();
protected:
void
_setDefaultCalibration
(
void
);
void
_saveSettings
(
void
);
...
...
@@ -216,6 +222,7 @@ protected:
bool
_accumulator
;
bool
_deadband
;
bool
_circleCorrection
;
float
_frequency
;
Vehicle
*
_activeVehicle
;
bool
_pollingStartedForCalibration
;
...
...
@@ -233,6 +240,7 @@ private:
static
const
char
*
_accumulatorSettingsKey
;
static
const
char
*
_deadbandSettingsKey
;
static
const
char
*
_circleCorrectionSettingsKey
;
static
const
char
*
_frequencySettingsKey
;
static
const
char
*
_txModeSettingsKey
;
static
const
char
*
_fixedWingTXModeSettingsKey
;
static
const
char
*
_multiRotorTXModeSettingsKey
;
...
...
src/VehicleSetup/JoystickConfig.qml
View file @
51d20e25
...
...
@@ -531,6 +531,24 @@ SetupPage {
}
}
Row
{
width
:
parent
.
width
spacing
:
ScreenTools
.
defaultFontPixelWidth
visible
:
advancedSettings
.
checked
QGCLabel
{
text
:
qsTr
(
"
Message frequency (Hz):
"
)
anchors.verticalCenter
:
parent
.
verticalCenter
}
QGCTextField
{
text
:
_activeJoystick
.
frequency
validator
:
DoubleValidator
{
bottom
:
0.25
;
top
:
100.0
;
}
inputMethodHints
:
Qt
.
ImhFormattedNumbersOnly
onEditingFinished
:
{
_activeJoystick
.
frequency
=
parseFloat
(
text
)
}
}
}
Row
{
width
:
parent
.
width
spacing
:
ScreenTools
.
defaultFontPixelWidth
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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