Commit 3f707f95 authored by Don Gagne's avatar Don Gagne

Simpler RC Calibration

parent 9c48d0e9
......@@ -489,6 +489,7 @@ HEADERS += \
src/ui/px4_configuration/QGCPX4MulticopterConfig.h \
src/ui/px4_configuration/QGCPX4SensorCalibration.h \
src/ui/px4_configuration/PX4RCCalibration.h \
src/ui/px4_configuration/RCValueWidget.h \
src/ui/px4_configuration/PX4Bootloader.h \
src/ui/px4_configuration/PX4FirmwareUpgradeThread.h \
src/ui/px4_configuration/PX4FirmwareUpgrade.h \
......@@ -646,6 +647,7 @@ SOURCES += \
src/ui/px4_configuration/QGCPX4MulticopterConfig.cc \
src/ui/px4_configuration/QGCPX4SensorCalibration.cc \
src/ui/px4_configuration/PX4RCCalibration.cc \
src/ui/px4_configuration/RCValueWidget.cc \
src/ui/px4_configuration/PX4Bootloader.cc \
src/ui/px4_configuration/PX4FirmwareUpgradeThread.cc \
src/ui/px4_configuration/PX4FirmwareUpgrade.cc \
......
......@@ -175,6 +175,17 @@
<file>files/images/px4/calibration/accel_z-.png</file>
<file>files/images/px4/calibration/accel_y+.png</file>
<file>files/images/px4/calibration/mag_calibration_figure8.png</file>
<file>files/images/px4/calibration/radioCenter.png</file>
<file>files/images/px4/calibration/radioHome.png</file>
<file>files/images/px4/calibration/radioRollLeft.png</file>
<file>files/images/px4/calibration/radioRollRight.png</file>
<file>files/images/px4/calibration/radioPitchUp.png</file>
<file>files/images/px4/calibration/radioPitchDown.png</file>
<file>files/images/px4/calibration/radioYawLeft.png</file>
<file>files/images/px4/calibration/radioYawRight.png</file>
<file>files/images/px4/calibration/radioThrottleUp.png</file>
<file>files/images/px4/calibration/radioThrottleDown.png</file>
<file>files/images/px4/calibration/radioSwitchMinMax.png</file>
<file>files/images/px4/menu/sensors.png</file>
<file>files/images/px4/menu/firmware_upgrade.png</file>
<file>files/images/px4/menu/plane.png</file>
......
This diff is collapsed.
......@@ -27,6 +27,7 @@
#include "AutoTest.h"
#include "MockUASManager.h"
#include "MockUAS.h"
#include "MultiSignalSpy.h"
#include "px4_configuration/PX4RCCalibration.h"
/// @file
......@@ -49,13 +50,6 @@ private slots:
void _setUAS_test(void);
void _minRCChannels_test(void);
//void _liveRC_test(void);
void _beginState_test(void);
void _identifyState_test(void);
void _minMaxState_test(void);
void _centerThrottleState_test(void);
void _detectInversionState_test(void);
void _trimsState_test(void);
void _fullCalibration_test(void);
private:
......@@ -66,13 +60,20 @@ private:
testModeFullSequence, ///< Run as full calibration sequence
};
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 MoveToDirection {
moveToMax,
moveToMin,
moveToCenter,
};
void _channelHomePosition(void);
void _minRCChannels(void);
void _beginCalibration(void);
void _stickMoveWaitForSettle(int channel, int value);
void _stickMoveAutoStep(const char* functionStr, enum PX4RCCalibration::rcCalFunctions function, enum MoveToDirection direction, bool identifyStep);
void _switchMinMaxStep(void);
void _flapsDetectStep(void);
void _switchSelectAutoStep(const char* functionStr, PX4RCCalibration::rcCalFunctions function);
enum {
validateMinMaxMask = 1 << 0,
......@@ -88,13 +89,9 @@ private:
int rcMax;
int rcTrim;
int reversed;
bool isMinMaxShown;
bool isMinValid;
bool isMaxValid;
};
void _validateParameters(int validateMask);
void _validateWidgets(int validateMask, const struct ChannelSettings* rgChannelSettings);
void _validateParameters(void);
MockUASManager* _mockUASManager;
MockUAS* _mockUAS;
......@@ -104,29 +101,30 @@ private:
enum {
nextButtonMask = 1 << 0,
cancelButtonMask = 1 << 1,
skipButtonMask = 1 << 2,
tryAgainButtonMask = 1 << 3
skipButtonMask = 1 << 2
};
QPushButton* _nextButton;
QPushButton* _cancelButton;
QPushButton* _skipButton;
QPushButton* _tryAgainButton;
QLabel* _statusLabel;
RCChannelWidget* _rgRadioWidget[PX4RCCalibration::_chanMax];
RCValueWidget* _rgValueWidget[PX4RCCalibration::_chanMax];
const char* _rgSignals[1];
MultiSignalSpy* _multiSpyNextButtonMessageBox;
// 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 _testCenterValue;
static const int _availableChannels = 18; ///< Simulate 18 channel RC Transmitter
static const int _stickSettleWait;
static const struct ChannelSettings _rgChannelSettingsPreValidate[_availableChannels];
static const struct ChannelSettings _rgChannelSettingsPostValidate[PX4RCCalibration::_chanMax];
static const struct ChannelSettings _rgChannelSettings[_availableChannels];
static const struct ChannelSettings _rgChannelSettingsValidate[PX4RCCalibration::_chanMax];
static const int _rgFunctionChannelMap[PX4RCCalibration::rcCalFunctionMax];
};
......
This diff is collapsed.
......@@ -32,8 +32,8 @@
#include <QWidget>
#include <QTimer>
#include "QGCToolWidget.h"
#include "UASInterface.h"
#include "RCValueWidget.h"
#include "ui_PX4RCCalibration.h"
......@@ -52,18 +52,23 @@ class PX4RCCalibration : public QWidget
public:
explicit PX4RCCalibration(QWidget *parent = 0);
~ PX4RCCalibration();
signals:
// @brief Signalled when in unit test mode and a message box should be displayed by the next button
void nextButtonMessageBoxDisplayed(void);
private slots:
void _rcCalNext(void);
void _rcCalTryAgain(void);
void _rcCalSkip(void);
void _rcCalCancel(void);
void _nextButton(void);
void _skipButton(void);
void _spektrumBind(void);
void _trimNYI(void);
void _updateView(void);
void _remoteControlChannelRawChanged(int chan, float val);
void _setActiveUAS(UASInterface* uas);
void _toggleSpektrumPairing(bool enabled);
void _parameterListUpToDate(void);
......@@ -105,52 +110,104 @@ private:
rcCalStateSave
};
typedef void (PX4RCCalibration::*inputFn)(enum rcCalFunctions function, int chan, int value);
typedef void (PX4RCCalibration::*buttonFn)(void);
struct stateMachineEntry {
enum rcCalFunctions function;
const char* instructions;
const char* image;
inputFn rcInputFn;
buttonFn nextFn;
buttonFn skipFn;
};
/// @brief A set of information associated with a function.
struct FunctionInfo {
const char* functionName; ///< User visible function name
const char* inversionMsg; ///< Message to display to user to detect inversion
const char* parameterName; ///< Parameter name for function mapping
bool required; ///< true: function must be mapped
};
/// @brief A set of information associated with a radio channel.
struct ChannelInfo {
enum rcCalFunctions function; ///< Function mapped to this channel, rcCalFunctionMax for none
bool reversed; ///< true: channel is reverse, false: not reversed
float rcMin; ///< Minimum RC value
float rcMax; ///< Maximum RC value
float rcTrim; ///< Trim position
int rcMin; ///< Minimum RC value
int rcMax; ///< Maximum RC value
int rcTrim; ///< Trim position
};
/// @brief Information to relate a function to it's value widget.
struct AttitudeInfo {
enum rcCalFunctions function;
RCValueWidget* valueWidget;
};
// Methods - see source code for documentation
int _currentStep; ///< Current step of state machine
const struct stateMachineEntry* _getStateMachineEntry(int step);
void _nextStep(void);
void _setupCurrentState(void);
void _inputCenterWaitBegin(enum rcCalFunctions function, int channel, int value);
void _inputStickDetect(enum rcCalFunctions function, int channel, int value);
void _inputStickMin(enum rcCalFunctions function, int channel, int value);
void _inputCenterWait(enum rcCalFunctions function, int channel, int value);
void _inputSwitchMinMax(enum rcCalFunctions function, int channel, int value);
void _inputFlapsDown(enum rcCalFunctions function, int channel, int value);
void _inputFlapsUp(enum rcCalFunctions function, int channel, int value);
void _inputSwitchDetect(enum rcCalFunctions function, int channel, int value);
void _inputFlapsDetect(enum rcCalFunctions function, int channel, int value);
void _switchDetect(enum rcCalFunctions function, int channel, int value, bool moveToNextStep);
void _saveFlapsDown(void);
void _skipFlaps(void);
void _saveAllTrims(void);
bool _stickSettleComplete(int value);
void _validateCalibration(void);
void _writeCalibration(bool trimsOnly);
void _writeCalibration(void);
void _resetInternalCalibrationValues(void);
void _setInternalCalibrationValuesFromParameters(void);
void _rcCalChannelWait(bool firstTime);
void _rcCalBegin(void);
void _rcCalNextIdentifyChannelMapping(void);
void _rcCalReadChannelsMinMax(void);
void _rcCalCenterThrottle(void);
void _rcCalNextDetectChannelInversion(void);
void _rcCalTrims(void);
void _startCalibration(void);
void _stopCalibration(void);
void _rcCalSave(void);
void _writeParameters(void);
void _rcCalSaveCurrentValues(void);
void _showMinMaxOnRadioWidgets(bool show);
void _showTrimOnRadioWidgets(bool show);
void _unitTestForceCalState(enum rcCalStates state);
// @brief Called by unit test code to set the mode to unit testing
void _setUnitTestMode(void){ _unitTestMode = true; }
// Member variables
static const char* _imageFilePrefix;
static const char* _imageHome;
static const char* _imageThrottleUp;
static const char* _imageThrottleDown;
static const char* _imageYawLeft;
static const char* _imageYawRight;
static const char* _imageRollLeft;
static const char* _imageRollRight;
static const char* _imagePitchUp;
static const char* _imagePitchDown;
static const char* _imageSwitchMinMax;
static const int _updateInterval; ///< Interval for ui update timer
static const struct FunctionInfo _rgFunctionInfo[rcCalFunctionMax]; ///< Information associated with each function.
int _rgFunctionChannelMapping[rcCalFunctionMax]; ///< Maps from rcCalFunctions to channel index. _chanMax indicates channel not set for this function.
static const int _attitudeControls = 5;
struct AttitudeInfo _rgAttitudeControl[_attitudeControls];
int _chanCount; ///< Number of actual rc channels available
static const int _chanMax = 18; ///< Maximum number of supported rc channels
......@@ -169,16 +226,17 @@ private:
static const int _rcCalPWMValidMaxValue;
static const int _rcCalPWMDefaultMinValue;
static const int _rcCalPWMDefaultMaxValue;
static const int _rcCalPWMDefaultTrimValue;
static const int _rcCalRoughCenterDelta;
static const float _rcCalMoveDelta;
static const float _rcCalMinDelta;
static const int _rcCalMoveDelta;
static const int _rcCalSettleDelta;
static const int _rcCalMinDelta;
float _rcValueSave[_chanMax]; ///< Saved values prior to detecting channel movement
int _rcValueSave[_chanMax]; ///< Saved values prior to detecting channel movement
float _rcRawValue[_chanMax]; ///< Current set of raw channel values
int _rcRawValue[_chanMax]; ///< Current set of raw channel values
RCChannelWidget* _rgRadioWidget[_chanMax]; ///< Array of radio channel widgets
RCValueWidget* _rgRCValueMonitorWidget[_chanMax]; ///< Array of radio channel value widgets
QLabel* _rgRCValueMonitorLabel[_chanMax]; ///< Array of radio channel value labels
UASInterface* _mav; ///< The current MAV
QGCUASParamManagerInterface* _paramMgr;
......@@ -188,6 +246,15 @@ private:
Ui::PX4RCCalibration* _ui;
QTimer _updateTimer; ///< Timer used to update widgete ui
int _stickDetectChannel;
int _stickDetectInitialValue;
int _stickDetectValue;
bool _stickDetectSettleStarted;
QTime _stickDetectSettleElapsed;
static const int _stickDetectSettleMSecs;
bool _unitTestMode;
};
#endif // PX4RCCalibration_H
This diff is collapsed.
/*=====================================================================
QGroundControl Open Source Ground Control Station
(c) 2009, 2014 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
This file is part of the QGROUNDCONTROL project
QGROUNDCONTROL is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
QGROUNDCONTROL is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.
======================================================================*/
/// @file
/// @brief Widget which shows current RC value on a bar with tick marks.
/// @author Don Gagne <don@thegagnes.com>
#ifndef RCValueWidget_H
#define RCValueWidget_H
#include <QWidget>
#include <QColor>
/// @brief Widget which shows current RC value on a bar with tick marks.
class RCValueWidget : public QWidget
{
Q_OBJECT
public:
explicit RCValueWidget(QWidget *parent = 0);
/// @brief Set the widget to display small value bar.
void setSmallMode(void) { _smallMode = true; }
/// @brief Set the current RC value to display
void setValue(int value);
/// @brief Set the current RC Value, Minimum RC Value and Maximum RC Value
void setValueAndMinMax(int val, int min, int max);
void setMinMax(int min, int max);
void setMin(int min);
void setMax(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
void setTrim(int value);
/// @brief Sets the reversed state of channel
/// @param reversed true: channel is reversed
void setReversed(bool reversed) { _reversed = reversed; }
int value(void) { return _value; } ///< Returns the current RC Value set in the control
int min(void) { return _min; } ///< Returns the min value set in the control
int max(void) { return _max; } ///< Returns the max values set in the control
int trim(void) { return _trim; } ///< Returns the trim value set in the control
void showMinMax(bool show);
bool isMinMaxShown() { return _showMinMax; }
bool isMinValid(void) { return _minValid; }
bool isMaxValid(void) { return _maxValid; }
void showTrim(bool show);
bool isTrimShown() { return _showTrim; }
protected:
virtual void paintEvent(QPaintEvent *event);
private:
void _drawValuePointer(QPainter* painter, int xTip, int yTip, int height, bool rightSideUp);
bool _smallMode; ///< true: draw small value bar, false: draw normal value bar
int _value; ///< Current RC value
int _min; ///< Min RC value
int _max; ///< Max RC value
int _trim; ///< RC Value for Trim position
bool _reversed; ///< true: channel is reversed
bool _minValid; ///< true: minimum value is valid
bool _maxValid; ///< true: maximum value is valid
bool _showMinMax; ///< true: show min max values on display
bool _showTrim; ///< true: show trim value on display
static const int _centerValue = 1500; ///< RC Value which is at center
static const int _maxDeltaRange = 650; ///< Delta around center value which is the max range for widget
static const int _minRange = _centerValue - _maxDeltaRange; ///< Smallest value widget can display
static const int _maxRange = _centerValue + _maxDeltaRange; ///< Largest value widget can display
static const int _barHeight = 7;
QColor _fgColor;
};
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment