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
d4b826c3
Commit
d4b826c3
authored
Aug 25, 2014
by
Lorenz Meier
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #840 from DonLakeFlyer/RCCalFixes
Updated RC Cal validation rules
parents
1898be3f
e39b779a
Changes
6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
469 additions
and
180 deletions
+469
-180
PX4RCCalibrationTest.cc
src/qgcunittest/PX4RCCalibrationTest.cc
+291
-122
PX4RCCalibrationTest.h
src/qgcunittest/PX4RCCalibrationTest.h
+45
-10
RCChannelWidget.cc
src/ui/designer/RCChannelWidget.cc
+39
-6
RCChannelWidget.h
src/ui/designer/RCChannelWidget.h
+11
-0
PX4RCCalibration.cc
src/ui/px4_configuration/PX4RCCalibration.cc
+73
-35
PX4RCCalibration.h
src/ui/px4_configuration/PX4RCCalibration.h
+10
-7
No files found.
src/qgcunittest/PX4RCCalibrationTest.cc
View file @
d4b826c3
This diff is collapsed.
Click to expand it.
src/qgcunittest/PX4RCCalibrationTest.h
View file @
d4b826c3
...
@@ -30,10 +30,11 @@
...
@@ -30,10 +30,11 @@
#include "px4_configuration/PX4RCCalibration.h"
#include "px4_configuration/PX4RCCalibration.h"
/// @file
/// @file
/// @brief
QGCPX4RCCA
libration Widget unit test
/// @brief
PX4RCCa
libration Widget unit test
///
///
/// @author Don Gagne <don@thegagnes.com>
/// @author Don Gagne <don@thegagnes.com>
/// @brief PX4RCCalibration Widget unit test
class
PX4RCCalibrationTest
:
public
QObject
class
PX4RCCalibrationTest
:
public
QObject
{
{
Q_OBJECT
Q_OBJECT
...
@@ -42,6 +43,7 @@ public:
...
@@ -42,6 +43,7 @@ public:
PX4RCCalibrationTest
(
void
);
PX4RCCalibrationTest
(
void
);
private
slots
:
private
slots
:
void
initTestCase
(
void
);
void
init
(
void
);
void
init
(
void
);
void
cleanup
(
void
);
void
cleanup
(
void
);
...
@@ -50,7 +52,6 @@ private slots:
...
@@ -50,7 +52,6 @@ private slots:
//void _liveRC_test(void);
//void _liveRC_test(void);
void
_beginState_test
(
void
);
void
_beginState_test
(
void
);
void
_identifyState_test
(
void
);
void
_identifyState_test
(
void
);
void
_identifyStateSkipOptional_test
(
void
);
void
_minMaxState_test
(
void
);
void
_minMaxState_test
(
void
);
void
_centerThrottleState_test
(
void
);
void
_centerThrottleState_test
(
void
);
void
_detectInversionState_test
(
void
);
void
_detectInversionState_test
(
void
);
...
@@ -58,13 +59,20 @@ private slots:
...
@@ -58,13 +59,20 @@ private slots:
void
_fullCalibration_test
(
void
);
void
_fullCalibration_test
(
void
);
private:
private:
void
_centerAllChannels
(
void
);
/// @brief Modes to run worker functions
void
_beginState_worker
(
bool
standaloneTest
);
enum
TestMode
{
void
_identifyState_worker
(
bool
standaloneTest
,
bool
skipOptional
);
testModeStandalone
,
///< Perform standalone test of calibration state
void
_minMaxState_worker
(
bool
standaloneTest
);
testModePrerequisite
,
///< Setup prequisites for subsequent calibration state
void
_centerThrottleState_worker
(
bool
standaloneTest
);
testModeFullSequence
,
///< Run as full calibration sequence
void
_detectInversionState_worker
(
bool
standaloneTest
);
};
void
_trimsState_worker
(
bool
standaloneTest
);
void
_centerChannels
(
void
);
void
_beginState_worker
(
enum
TestMode
mode
);
void
_identifyState_worker
(
enum
TestMode
mode
);
void
_minMaxState_worker
(
enum
TestMode
mode
);
void
_centerThrottleState_worker
(
enum
TestMode
mode
);
void
_detectInversionState_worker
(
enum
TestMode
mode
);
void
_trimsState_worker
(
enum
TestMode
mode
);
enum
{
enum
{
validateMinMaxMask
=
1
<<
0
,
validateMinMaxMask
=
1
<<
0
,
...
@@ -73,7 +81,19 @@ private:
...
@@ -73,7 +81,19 @@ private:
validateMappingMask
=
1
<<
3
,
validateMappingMask
=
1
<<
3
,
validateAllMask
=
0xFFFF
validateAllMask
=
0xFFFF
};
};
void
_validateParameters
(
int
validateMask
,
bool
skipOptional
=
false
);
struct
ChannelSettings
{
int
rcMin
;
int
rcMax
;
int
rcTrim
;
int
reversed
;
bool
isMinMaxShown
;
bool
isMinValid
;
bool
isMaxValid
;
};
void
_validateParameters
(
int
validateMask
);
void
_validateWidgets
(
int
validateMask
,
const
struct
ChannelSettings
*
rgChannelSettings
);
MockUASManager
*
_mockUASManager
;
MockUASManager
*
_mockUASManager
;
MockUAS
*
_mockUAS
;
MockUAS
*
_mockUAS
;
...
@@ -94,6 +114,21 @@ private:
...
@@ -94,6 +114,21 @@ private:
QLabel
*
_statusLabel
;
QLabel
*
_statusLabel
;
RCChannelWidget
*
_rgRadioWidget
[
PX4RCCalibration
::
_chanMax
];
RCChannelWidget
*
_rgRadioWidget
[
PX4RCCalibration
::
_chanMax
];
// When settings values into min/max/trim we set them slightly different than the defaults so that
// we can distinguish between the two values.
static
const
int
_testMinValue
;
static
const
int
_testMaxValue
;
static
const
int
_testTrimValue
;
static
const
int
_testThrottleTrimValue
;
static
const
int
_availableChannels
=
8
;
///< 8 channel RC Trasmitter
static
const
int
_requiredChannels
=
5
;
///< Required channels are 0-4
static
const
int
_minMaxChannels
=
_requiredChannels
+
1
;
///< Send min/max to channels 0-5
static
const
int
_attitudeChannels
=
4
;
///< Attitude channels are 0-3
static
const
struct
ChannelSettings
_rgChannelSettingsPreValidate
[
_availableChannels
];
static
const
struct
ChannelSettings
_rgChannelSettingsPostValidate
[
PX4RCCalibration
::
_chanMax
];
};
};
DECLARE_TEST
(
PX4RCCalibrationTest
)
DECLARE_TEST
(
PX4RCCalibrationTest
)
...
...
src/ui/designer/RCChannelWidget.cc
View file @
d4b826c3
...
@@ -37,6 +37,8 @@ RCChannelWidget::RCChannelWidget(QWidget *parent) :
...
@@ -37,6 +37,8 @@ RCChannelWidget::RCChannelWidget(QWidget *parent) :
_min
(
_centerValue
),
_min
(
_centerValue
),
_max
(
_centerValue
),
_max
(
_centerValue
),
_trim
(
_centerValue
),
_trim
(
_centerValue
),
_minValid
(
false
),
_maxValid
(
false
),
_showMinMax
(
false
),
_showMinMax
(
false
),
_showTrim
(
false
)
_showTrim
(
false
)
{
{
...
@@ -90,19 +92,36 @@ void RCChannelWidget::paintEvent(QPaintEvent *event)
...
@@ -90,19 +92,36 @@ void RCChannelWidget::paintEvent(QPaintEvent *event)
painter
.
setBrush
(
hGradientBrush
);
painter
.
setBrush
(
hGradientBrush
);
if
(
_showMinMax
)
{
if
(
_showMinMax
)
{
QString
text
;
// Draw the Min numeric value display to the left
// Draw the Min numeric value display to the left
painter
.
drawText
(
0
,
rowHeigth
,
minMaxDisplayWidth
,
fontHeight
,
Qt
::
AlignHCenter
|
Qt
::
AlignBottom
,
"Min"
);
painter
.
drawText
(
0
,
rowHeigth
,
minMaxDisplayWidth
,
fontHeight
,
Qt
::
AlignHCenter
|
Qt
::
AlignBottom
,
"Min"
);
painter
.
drawText
(
0
,
rowHeigth
*
2
,
minMaxDisplayWidth
,
fontHeight
,
Qt
::
AlignHCenter
|
Qt
::
AlignBottom
,
QString
::
number
(
_min
));
if
(
_minValid
)
{
text
=
QString
::
number
(
_min
);
}
else
{
text
=
"----"
;
}
painter
.
drawText
(
0
,
rowHeigth
*
2
,
minMaxDisplayWidth
,
fontHeight
,
Qt
::
AlignHCenter
|
Qt
::
AlignBottom
,
text
);
// Draw the Max numeric value display to the right
// Draw the Max numeric value display to the right
painter
.
drawText
(
width
()
-
minMaxDisplayWidth
,
rowHeigth
,
minMaxDisplayWidth
,
fontHeight
,
Qt
::
AlignHCenter
|
Qt
::
AlignBottom
,
"Max"
);
painter
.
drawText
(
width
()
-
minMaxDisplayWidth
,
rowHeigth
,
minMaxDisplayWidth
,
fontHeight
,
Qt
::
AlignHCenter
|
Qt
::
AlignBottom
,
"Max"
);
painter
.
drawText
(
width
()
-
minMaxDisplayWidth
,
rowHeigth
*
2
,
minMaxDisplayWidth
,
fontHeight
,
Qt
::
AlignHCenter
|
Qt
::
AlignBottom
,
QString
::
number
(
_max
));
if
(
_maxValid
)
{
text
=
QString
::
number
(
_max
);
}
else
{
text
=
QString
::
number
(
_max
);
}
painter
.
drawText
(
width
()
-
minMaxDisplayWidth
,
rowHeigth
*
2
,
minMaxDisplayWidth
,
fontHeight
,
Qt
::
AlignHCenter
|
Qt
::
AlignBottom
,
text
);
// Draw the Min/Max tick marks on the axis
// Draw the Min/Max tick marks on the axis
int
xTick
=
rcValueAxis
.
left
()
+
(
rcValueAxis
.
width
()
*
((
float
)(
_min
-
_minRange
)
/
(
_maxRange
-
_minRange
)));
int
xTick
;
painter
.
drawLine
(
xTick
,
rcValueAxis
.
top
(),
xTick
,
rcValueAxis
.
bottom
());
if
(
_minValid
)
{
xTick
=
rcValueAxis
.
left
()
+
(
rcValueAxis
.
width
()
*
((
float
)(
_max
-
_minRange
)
/
(
_maxRange
-
_minRange
)));
int
xTick
=
rcValueAxis
.
left
()
+
(
rcValueAxis
.
width
()
*
((
float
)(
_min
-
_minRange
)
/
(
_maxRange
-
_minRange
)));
painter
.
drawLine
(
xTick
,
rcValueAxis
.
top
(),
xTick
,
rcValueAxis
.
bottom
());
painter
.
drawLine
(
xTick
,
rcValueAxis
.
top
(),
xTick
,
rcValueAxis
.
bottom
());
}
if
(
_maxValid
)
{
xTick
=
rcValueAxis
.
left
()
+
(
rcValueAxis
.
width
()
*
((
float
)(
_max
-
_minRange
)
/
(
_maxRange
-
_minRange
)));
painter
.
drawLine
(
xTick
,
rcValueAxis
.
top
(),
xTick
,
rcValueAxis
.
bottom
());
}
}
}
if
(
_showTrim
)
{
if
(
_showTrim
)
{
...
@@ -221,3 +240,17 @@ void RCChannelWidget::_drawValuePointer(QPainter* painter, int xTip, int yTip, i
...
@@ -221,3 +240,17 @@ void RCChannelWidget::_drawValuePointer(QPainter* painter, int xTip, int yTip, i
painter
->
drawPolygon
(
trianglePoints
,
3
);
painter
->
drawPolygon
(
trianglePoints
,
3
);
}
}
/// @brief Set whether the Min range value is valid or not.
void
RCChannelWidget
::
setMinValid
(
bool
valid
)
{
_minValid
=
valid
;
update
();
}
/// @brief Set whether the Max range value is valid or not.
void
RCChannelWidget
::
setMaxValid
(
bool
valid
)
{
_maxValid
=
valid
;
update
();
}
src/ui/designer/RCChannelWidget.h
View file @
d4b826c3
...
@@ -46,6 +46,12 @@ public:
...
@@ -46,6 +46,12 @@ public:
void
setMinMax
(
int
min
,
int
max
);
void
setMinMax
(
int
min
,
int
max
);
/// @brief Set whether the Min range value is valid or not.
void
setMinValid
(
bool
valid
);
/// @brief Set whether the Max range value is valid or not.
void
setMaxValid
(
bool
valid
);
/// @brief Sets the Trim value for the channel
/// @brief Sets the Trim value for the channel
void
setTrim
(
int
value
);
void
setTrim
(
int
value
);
...
@@ -56,6 +62,8 @@ public:
...
@@ -56,6 +62,8 @@ public:
void
showMinMax
(
bool
show
);
void
showMinMax
(
bool
show
);
bool
isMinMaxShown
()
{
return
_showMinMax
;
}
bool
isMinMaxShown
()
{
return
_showMinMax
;
}
bool
isMinValid
(
void
)
{
return
_minValid
;
}
bool
isMaxValid
(
void
)
{
return
_maxValid
;
}
void
showTrim
(
bool
show
);
void
showTrim
(
bool
show
);
bool
isTrimShown
()
{
return
_showTrim
;
}
bool
isTrimShown
()
{
return
_showTrim
;
}
...
@@ -71,6 +79,9 @@ private:
...
@@ -71,6 +79,9 @@ private:
int
_max
;
///< Max RC value
int
_max
;
///< Max RC value
int
_trim
;
///< RC Value for Trim position
int
_trim
;
///< RC Value for Trim position
bool
_minValid
;
///< true: minimum value is valid
bool
_maxValid
;
///< true: maximum value is valid
bool
_showMinMax
;
///< true: show min max values on display
bool
_showMinMax
;
///< true: show min max values on display
bool
_showTrim
;
///< true: show trim value on display
bool
_showTrim
;
///< true: show trim value on display
...
...
src/ui/px4_configuration/PX4RCCalibration.cc
View file @
d4b826c3
...
@@ -31,13 +31,16 @@
...
@@ -31,13 +31,16 @@
#include "PX4RCCalibration.h"
#include "PX4RCCalibration.h"
#include "UASManager.h"
#include "UASManager.h"
const
int
PX4RCCalibration
::
_updateInterval
=
150
;
///< Interval for timer which updates radio channel widgets
const
int
PX4RCCalibration
::
_updateInterval
=
150
;
///< Interval for timer which updates radio channel widgets
const
int
PX4RCCalibration
::
_rcCalPWMValidMinValue
=
1000
;
const
int
PX4RCCalibration
::
_rcCalPWMValidMaxValue
=
2000
;
const
int
PX4RCCalibration
::
_rcCalPWMCenterPoint
=
((
PX4RCCalibration
::
_rcCalPWMValidMaxValue
-
PX4RCCalibration
::
_rcCalPWMValidMinValue
)
/
2.0
f
)
+
PX4RCCalibration
::
_rcCalPWMValidMinValue
;
const
int
PX4RCCalibration
::
_rcCalPWMCenterPoint
=
((
PX4RCCalibration
::
_rcCalPWMValidMaxValue
-
PX4RCCalibration
::
_rcCalPWMValidMinValue
)
/
2.0
f
)
+
PX4RCCalibration
::
_rcCalPWMValidMinValue
;
const
int
PX4RCCalibration
::
_rcCalRoughCenterDelta
=
200
;
///< Delta around center point which is considered to be roughly centered
const
int
PX4RCCalibration
::
_rcCalPWMValidMinValue
=
1300
;
///< Largest valid minimum PWM Min range value
const
float
PX4RCCalibration
::
_rcCalMoveDelta
=
300.0
f
;
///< Amount of delta which is considered stick movement
const
int
PX4RCCalibration
::
_rcCalPWMValidMaxValue
=
1700
;
///< Smallest valid maximum PWM Max range value
const
float
PX4RCCalibration
::
_rcCalMinDelta
=
100.0
f
;
///< Amount of delta allowed around min value to consider channel at min
const
int
PX4RCCalibration
::
_rcCalPWMDefaultMinValue
=
1000
;
///< Default value for Min if not set
const
int
PX4RCCalibration
::
_rcCalPWMDefaultMaxValue
=
2000
;
///< Default value for Max if not set
const
int
PX4RCCalibration
::
_rcCalPWMDefaultTrimValue
=
PX4RCCalibration
::
_rcCalPWMCenterPoint
;
///< Default value for Trim if not set
const
int
PX4RCCalibration
::
_rcCalRoughCenterDelta
=
200
;
///< Delta around center point which is considered to be roughly centered
const
float
PX4RCCalibration
::
_rcCalMoveDelta
=
300.0
f
;
///< Amount of delta which is considered stick movement
const
float
PX4RCCalibration
::
_rcCalMinDelta
=
100.0
f
;
///< Amount of delta allowed around min value to consider channel at min
const
struct
PX4RCCalibration
::
FunctionInfo
PX4RCCalibration
::
_rgFunctionInfo
[
PX4RCCalibration
::
rcCalFunctionMax
]
=
{
const
struct
PX4RCCalibration
::
FunctionInfo
PX4RCCalibration
::
_rgFunctionInfo
[
PX4RCCalibration
::
rcCalFunctionMax
]
=
{
// Name Inversion Message Parameter required
// Name Inversion Message Parameter required
...
@@ -274,6 +277,31 @@ void PX4RCCalibration::_setActiveUAS(UASInterface* active)
...
@@ -274,6 +277,31 @@ void PX4RCCalibration::_setActiveUAS(UASInterface* active)
setEnabled
(
_mav
?
true
:
false
);
setEnabled
(
_mav
?
true
:
false
);
}
}
/// @brief Validates the current settings against the calibration rules resetting values as necessary.
void
PX4RCCalibration
::
_validateCalibration
(
void
)
{
for
(
int
chan
=
0
;
chan
<
_chanMax
;
chan
++
)
{
struct
ChannelInfo
*
info
=
&
_rgChannelInfo
[
chan
];
if
(
chan
<
_chanCount
)
{
// Validate Min/Max values. Although the channel appears as available we still may
// not have good min/max/trim values for it. Set to defaults if needed.
if
(
info
->
rcMin
>
_rcCalPWMValidMinValue
||
info
->
rcMax
<
_rcCalPWMValidMaxValue
)
{
info
->
rcMin
=
_rcCalPWMDefaultMinValue
;
info
->
rcMax
=
_rcCalPWMDefaultMaxValue
;
info
->
rcTrim
=
_rcCalPWMDefaultTrimValue
;
}
}
else
{
// Unavailable channels are set to defaults
info
->
rcMin
=
_rcCalPWMDefaultMinValue
;
info
->
rcMax
=
_rcCalPWMDefaultMaxValue
;
info
->
rcTrim
=
_rcCalPWMDefaultTrimValue
;
info
->
reversed
=
false
;
}
}
}
/// @brief Saves the rc calibration values to the board parameters.
/// @brief Saves the rc calibration values to the board parameters.
/// @param trimsOnly true: write only trim values, false: write all calibration values
/// @param trimsOnly true: write only trim values, false: write all calibration values
void
PX4RCCalibration
::
_writeCalibration
(
bool
trimsOnly
)
void
PX4RCCalibration
::
_writeCalibration
(
bool
trimsOnly
)
...
@@ -282,6 +310,8 @@ void PX4RCCalibration::_writeCalibration(bool trimsOnly)
...
@@ -282,6 +310,8 @@ void PX4RCCalibration::_writeCalibration(bool trimsOnly)
_mav
->
endRadioControlCalibration
();
_mav
->
endRadioControlCalibration
();
_validateCalibration
();
QGCUASParamManagerInterface
*
paramMgr
=
_mav
->
getParamManager
();
QGCUASParamManagerInterface
*
paramMgr
=
_mav
->
getParamManager
();
Q_ASSERT
(
paramMgr
);
Q_ASSERT
(
paramMgr
);
...
@@ -290,17 +320,14 @@ void PX4RCCalibration::_writeCalibration(bool trimsOnly)
...
@@ -290,17 +320,14 @@ void PX4RCCalibration::_writeCalibration(bool trimsOnly)
QString
trimTpl
(
"RC%1_TRIM"
);
QString
trimTpl
(
"RC%1_TRIM"
);
QString
revTpl
(
"RC%1_REV"
);
QString
revTpl
(
"RC%1_REV"
);
// Do not write the RC type, as these values depend on this
for
(
int
chan
=
0
;
chan
<
_chanMax
;
chan
++
)
{
// active onboard parameter
struct
ChannelInfo
*
info
=
&
_rgChannelInfo
[
chan
];
int
oneBasedChannel
=
chan
+
1
;
for
(
int
i
=
0
;
i
<
_chanCount
;
++
i
)
{
paramMgr
->
setPendingParam
(
0
,
trimTpl
.
arg
(
oneBasedChannel
),
info
->
rcTrim
);
struct
ChannelInfo
*
info
=
&
_rgChannelInfo
[
i
];
paramMgr
->
setPendingParam
(
0
,
trimTpl
.
arg
(
i
+
1
),
info
->
rcTrim
);
if
(
!
trimsOnly
)
{
if
(
!
trimsOnly
)
{
paramMgr
->
setPendingParam
(
0
,
minTpl
.
arg
(
i
+
1
),
info
->
rcMin
);
paramMgr
->
setPendingParam
(
0
,
minTpl
.
arg
(
oneBasedChannel
),
info
->
rcMin
);
paramMgr
->
setPendingParam
(
0
,
maxTpl
.
arg
(
i
+
1
),
info
->
rcMax
);
paramMgr
->
setPendingParam
(
0
,
maxTpl
.
arg
(
oneBasedChannel
),
info
->
rcMax
);
paramMgr
->
setPendingParam
(
0
,
revTpl
.
arg
(
i
+
1
),
info
->
reversed
?
-
1.0
f
:
1.0
f
);
paramMgr
->
setPendingParam
(
0
,
revTpl
.
arg
(
oneBasedChannel
),
info
->
reversed
?
-
1.0
f
:
1.0
f
);
}
}
}
}
...
@@ -355,13 +382,7 @@ void PX4RCCalibration::_remoteControlChannelRawChanged(int chan, float fval)
...
@@ -355,13 +382,7 @@ void PX4RCCalibration::_remoteControlChannelRawChanged(int chan, float fval)
case
rcCalStateIdentify
:
case
rcCalStateIdentify
:
if
(
!
_rcCalStateChannelComplete
)
{
if
(
!
_rcCalStateChannelComplete
)
{
// If this channel is already used in a mapping we can't used it again
// If this channel is already used in a mapping we can't used it again
bool
channelAlreadyMapped
=
false
;
bool
channelAlreadyMapped
=
!
(
_rgChannelInfo
[
chan
].
function
==
rcCalFunctionMax
);
for
(
int
chanFunction
=
0
;
chanFunction
<
rcCalFunctionMax
;
chanFunction
++
)
{
if
(
_rgFunctionChannelMapping
[
chanFunction
]
==
chan
)
{
channelAlreadyMapped
=
true
;
break
;
}
}
// If the channel moved considerably, pick it
// If the channel moved considerably, pick it
if
(
!
channelAlreadyMapped
&&
fabsf
(
_rcValueSave
[
chan
]
-
fval
)
>
_rcCalMoveDelta
)
{
if
(
!
channelAlreadyMapped
&&
fabsf
(
_rcValueSave
[
chan
]
-
fval
)
>
_rcCalMoveDelta
)
{
...
@@ -383,10 +404,12 @@ void PX4RCCalibration::_remoteControlChannelRawChanged(int chan, float fval)
...
@@ -383,10 +404,12 @@ void PX4RCCalibration::_remoteControlChannelRawChanged(int chan, float fval)
break
;
break
;
case
rcCalStateMinMax
:
case
rcCalStateMinMax
:
if
(
fval
<
_rgChannelInfo
[
chan
].
rcMin
)
{
if
(
fval
<
_rgChannelInfo
[
chan
].
rcMin
&&
fval
<=
_rcCalPWMValidMinValue
)
{
_rgRadioWidget
[
chan
]
->
setMinValid
(
true
);
_rgChannelInfo
[
chan
].
rcMin
=
fval
;
_rgChannelInfo
[
chan
].
rcMin
=
fval
;
}
}
if
(
fval
>
_rgChannelInfo
[
chan
].
rcMax
)
{
if
(
fval
>
_rgChannelInfo
[
chan
].
rcMax
&&
fval
>=
_rcCalPWMValidMaxValue
)
{
_rgRadioWidget
[
chan
]
->
setMaxValid
(
true
);
_rgChannelInfo
[
chan
].
rcMax
=
fval
;
_rgChannelInfo
[
chan
].
rcMax
=
fval
;
}
}
break
;
break
;
...
@@ -572,7 +595,11 @@ void PX4RCCalibration::_rcCalChannelWait(bool firstTime)
...
@@ -572,7 +595,11 @@ void PX4RCCalibration::_rcCalChannelWait(bool firstTime)
{
{
_rcCalState
=
rcCalStateChannelWait
;
_rcCalState
=
rcCalStateChannelWait
;
_resetInternalCalibrationValues
();
if
(
firstTime
)
{
_resetInternalCalibrationValues
();
}
else
{
_setInternalCalibrationValuesFromParameters
();
}
if
(
_chanCount
==
0
)
{
if
(
_chanCount
==
0
)
{
_ui
->
rcCalFound
->
setText
(
tr
(
"Please turn on Radio"
));
_ui
->
rcCalFound
->
setText
(
tr
(
"Please turn on Radio"
));
...
@@ -741,18 +768,9 @@ void PX4RCCalibration::_rcCalTrims(void)
...
@@ -741,18 +768,9 @@ void PX4RCCalibration::_rcCalTrims(void)
_ui
->
rcCalSkip
->
setEnabled
(
false
);
_ui
->
rcCalSkip
->
setEnabled
(
false
);
_ui
->
rcCalCancel
->
setEnabled
(
true
);
_ui
->
rcCalCancel
->
setEnabled
(
true
);
_initializeTrims
();
_showTrimOnRadioWidgets
(
true
);
_showTrimOnRadioWidgets
(
true
);
}
}
/// @brief Initializes the trim values based on current min/max.
void
PX4RCCalibration
::
_initializeTrims
(
void
)
{
for
(
int
chan
=
0
;
chan
<=
_chanMax
;
chan
++
)
{
_rgChannelInfo
[
chan
].
rcTrim
=
((
_rgChannelInfo
[
chan
].
rcMax
-
_rgChannelInfo
[
chan
].
rcMin
)
/
2.0
f
)
+
_rgChannelInfo
[
chan
].
rcMin
;
}
}
/// @brief Set up the Save state of calibration.
/// @brief Set up the Save state of calibration.
void
PX4RCCalibration
::
_rcCalSave
(
void
)
void
PX4RCCalibration
::
_rcCalSave
(
void
)
{
{
...
@@ -766,6 +784,12 @@ void PX4RCCalibration::_rcCalSave(void)
...
@@ -766,6 +784,12 @@ void PX4RCCalibration::_rcCalSave(void)
_ui
->
rcCalTryAgain
->
setEnabled
(
false
);
_ui
->
rcCalTryAgain
->
setEnabled
(
false
);
_ui
->
rcCalSkip
->
setEnabled
(
false
);
_ui
->
rcCalSkip
->
setEnabled
(
false
);
_ui
->
rcCalCancel
->
setEnabled
(
true
);
_ui
->
rcCalCancel
->
setEnabled
(
true
);
// This updates the internal values according to the validation rules. Then _updateView will tick and update ui
// such that the settings that will be written our are displayed.
_validateCalibration
();
_showMinMaxOnRadioWidgets
(
true
);
}
}
/// @brief This is used by unit test code to force the calibration state machine to the specified state.
/// @brief This is used by unit test code to force the calibration state machine to the specified state.
...
@@ -811,12 +835,26 @@ void PX4RCCalibration::_unitTestForceCalState(enum rcCalStates state) {
...
@@ -811,12 +835,26 @@ void PX4RCCalibration::_unitTestForceCalState(enum rcCalStates state) {
/// @param show true: show the min/max values, false: hide the min/max values
/// @param show true: show the min/max values, false: hide the min/max values
void
PX4RCCalibration
::
_showMinMaxOnRadioWidgets
(
bool
show
)
void
PX4RCCalibration
::
_showMinMaxOnRadioWidgets
(
bool
show
)
{
{
// Force a view update to widget have current values
_updateView
();
// Turn on min/max display for all radio widgets
// Turn on min/max display for all radio widgets
for
(
int
i
=
0
;
i
<
_chanMax
;
i
++
)
{
for
(
int
i
=
0
;
i
<
_chanMax
;
i
++
)
{
RCChannelWidget
*
radioWidget
=
_rgRadioWidget
[
i
];
RCChannelWidget
*
radioWidget
=
_rgRadioWidget
[
i
];
Q_ASSERT
(
radioWidget
);
Q_ASSERT
(
radioWidget
);
radioWidget
->
showMinMax
(
show
);
radioWidget
->
showMinMax
(
show
);
if
(
show
)
{
if
(
radioWidget
->
min
()
<=
_rcCalPWMValidMinValue
)
{
radioWidget
->
setMinValid
(
true
);
}
if
(
radioWidget
->
max
()
>=
_rcCalPWMValidMaxValue
)
{
radioWidget
->
setMaxValid
(
true
);
}
}
else
{
radioWidget
->
setMinValid
(
false
);
radioWidget
->
setMaxValid
(
false
);
}
}
}
}
}
...
...
src/ui/px4_configuration/PX4RCCalibration.h
View file @
d4b826c3
...
@@ -124,10 +124,10 @@ private:
...
@@ -124,10 +124,10 @@ private:
// Methods - see source code for documentation
// Methods - see source code for documentation
void
_validateCalibration
(
void
);
void
_writeCalibration
(
bool
trimsOnly
);
void
_writeCalibration
(
bool
trimsOnly
);
void
_resetInternalCalibrationValues
(
void
);
void
_resetInternalCalibrationValues
(
void
);
void
_setInternalCalibrationValuesFromParameters
(
void
);
void
_setInternalCalibrationValuesFromParameters
(
void
);
void
_initializeTrims
(
void
);
void
_rcCalChannelWait
(
bool
firstTime
);
void
_rcCalChannelWait
(
bool
firstTime
);
void
_rcCalBegin
(
void
);
void
_rcCalBegin
(
void
);
...
@@ -164,12 +164,15 @@ private:
...
@@ -164,12 +164,15 @@ private:
int
_rcCalStateIdentifyOldMapping
;
///< Previous mapping for channel being currently identified
int
_rcCalStateIdentifyOldMapping
;
///< Previous mapping for channel being currently identified
int
_rcCalStateReverseOldMapping
;
///< Previous mapping for channel being currently used to detect inversion
int
_rcCalStateReverseOldMapping
;
///< Previous mapping for channel being currently used to detect inversion
static
const
int
_rcCalPWMCenterPoint
;
///< PWM center value;
static
const
int
_rcCalPWMCenterPoint
;
static
const
int
_rcCalPWMValidMinValue
;
///< Valid minimum PWM value
static
const
int
_rcCalPWMValidMinValue
;
static
const
int
_rcCalPWMValidMaxValue
;
///< Valid maximum PWM value
static
const
int
_rcCalPWMValidMaxValue
;
static
const
int
_rcCalRoughCenterDelta
;
///< Delta around center point which is considered to be roughly centered
static
const
int
_rcCalPWMDefaultMinValue
;
static
const
float
_rcCalMoveDelta
;
///< Amount of delta which is considered stick movement
static
const
int
_rcCalPWMDefaultMaxValue
;
static
const
float
_rcCalMinDelta
;
///< Amount of delta allowed around min value to consider channel at min
static
const
int
_rcCalPWMDefaultTrimValue
;
static
const
int
_rcCalRoughCenterDelta
;
static
const
float
_rcCalMoveDelta
;
static
const
float
_rcCalMinDelta
;
float
_rcValueSave
[
_chanMax
];
///< Saved values prior to detecting channel movement
float
_rcValueSave
[
_chanMax
];
///< Saved values prior to detecting channel movement
...
...
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