Commit 860e47b6 authored by Bryant's avatar Bryant

Restored range limiting to the throttle channel. Now if the UAS can't reverse,...

Restored range limiting to the throttle channel. Now if the UAS can't reverse, the throttle can be set to only use the positive range of the axis (useful with auto-centering control sticks) or to use the full range (for sticks that hold position).
parent 24af948f
...@@ -37,7 +37,8 @@ JoystickInput::JoystickInput() : ...@@ -37,7 +37,8 @@ JoystickInput::JoystickInput() :
throttleAxis(-1), throttleAxis(-1),
joystickName(""), joystickName(""),
joystickID(-1), joystickID(-1),
joystickNumButtons(0) joystickNumButtons(0),
throttleAxisLimited(false)
{ {
loadSettings(); loadSettings();
...@@ -191,6 +192,7 @@ void JoystickInput::run() ...@@ -191,6 +192,7 @@ void JoystickInput::run()
{ {
// First emit the uncalibrated values for each axis based on their ID. // First emit the uncalibrated values for each axis based on their ID.
// This is generally not used for controlling a vehicle, but a UI representation, so it being slightly off is fine. // This is generally not used for controlling a vehicle, but a UI representation, so it being slightly off is fine.
// Here we map the joystick axis value into the initial range of [0:1].
float axisValue = SDL_JoystickGetAxis(joystick, i); float axisValue = SDL_JoystickGetAxis(joystick, i);
if (joystickAxesInverted[i]) if (joystickAxesInverted[i])
{ {
...@@ -202,12 +204,20 @@ void JoystickInput::run() ...@@ -202,12 +204,20 @@ void JoystickInput::run()
} }
axisValue = 1.0f - axisValue; axisValue = 1.0f - axisValue;
// Only map the throttle into [0:1] if the UAS can reverse. // For non-throttle axes or if the UAS can reverse, go ahead and convert this into the range [-1:1].
if (uasCanReverse || throttleAxis != i) if (uasCanReverse || throttleAxis != i)
{ {
axisValue = axisValue * 2.0f - 1.0f; axisValue = axisValue * 2.0f - 1.0f;
} else { }
int a = 8; // Otherwise if this vehicle can only go forward, but the axis is limited to only the positive range,
// scale this so the negative values are ignored for this axis and it's clamped to [0:1].
else if (throttleAxis == i && joystickAxesLimited[i])
{
axisValue = axisValue * 2.0f - 1.0f;
if (axisValue < 0.0f)
{
axisValue = 0.0f;
}
} }
// Bound rounding errors // Bound rounding errors
...@@ -217,6 +227,7 @@ void JoystickInput::run() ...@@ -217,6 +227,7 @@ void JoystickInput::run()
{ {
joystickAxes[i] = axisValue; joystickAxes[i] = axisValue;
emit axisValueChanged(i, axisValue); emit axisValueChanged(i, axisValue);
qDebug() << "Axis " << i << ": " << axisValue;
} }
} }
...@@ -272,8 +283,8 @@ void JoystickInput::setActiveJoystick(int id) ...@@ -272,8 +283,8 @@ void JoystickInput::setActiveJoystick(int id)
joystick = NULL; joystick = NULL;
joystickID = -1; joystickID = -1;
} }
}
joystickID = id;
joystick = SDL_JoystickOpen(joystickID); joystick = SDL_JoystickOpen(joystickID);
if (joystick && SDL_JoystickOpened(joystickID)) if (joystick && SDL_JoystickOpened(joystickID))
{ {
...@@ -286,6 +297,7 @@ void JoystickInput::setActiveJoystick(int id) ...@@ -286,6 +297,7 @@ void JoystickInput::setActiveJoystick(int id)
// Update cached joystick values // Update cached joystick values
joystickAxes.clear(); joystickAxes.clear();
joystickAxesInverted.clear(); joystickAxesInverted.clear();
joystickAxesLimited.clear();
for (int i = 0; i < joystickNumAxes; i++) for (int i = 0; i < joystickNumAxes; i++)
{ {
int axisValue = SDL_JoystickGetAxis(joystick, i); int axisValue = SDL_JoystickGetAxis(joystick, i);
...@@ -293,6 +305,7 @@ void JoystickInput::setActiveJoystick(int id) ...@@ -293,6 +305,7 @@ void JoystickInput::setActiveJoystick(int id)
emit axisValueChanged(i, axisValue); emit axisValueChanged(i, axisValue);
joystickAxesInverted.append(false); joystickAxesInverted.append(false);
joystickAxesLimited.append(false);
} }
joystickButtons = 0; joystickButtons = 0;
for (int i = 0; i < joystickNumButtons; i++) for (int i = 0; i < joystickNumButtons; i++)
...@@ -345,6 +358,7 @@ void JoystickInput::setAxisMapping(int axis, JOYSTICK_INPUT_MAPPING newMapping) ...@@ -345,6 +358,7 @@ void JoystickInput::setAxisMapping(int axis, JOYSTICK_INPUT_MAPPING newMapping)
if (throttleAxis == axis) if (throttleAxis == axis)
{ {
throttleAxis = -1; throttleAxis = -1;
joystickAxesLimited[axis] = false;
} }
break; break;
} }
...@@ -358,6 +372,14 @@ void JoystickInput::setAxisInversion(int axis, bool inverted) ...@@ -358,6 +372,14 @@ void JoystickInput::setAxisInversion(int axis, bool inverted)
} }
} }
void JoystickInput::setAxisRangeLimit(int axis, bool limitRange)
{
if (axis < joystickAxesLimited.size())
{
joystickAxesLimited[axis] = limitRange;
}
}
float JoystickInput::getCurrentValueForAxis(int axis) float JoystickInput::getCurrentValueForAxis(int axis)
{ {
if (axis < joystickAxes.size()) if (axis < joystickAxes.size())
......
...@@ -159,6 +159,8 @@ protected: ...@@ -159,6 +159,8 @@ protected:
QList<float> joystickAxes; ///< The values of every axes during the last sample. QList<float> joystickAxes; ///< The values of every axes during the last sample.
QList<bool> joystickAxesInverted; ///< Whether each axis should be used inverted from what was reported. QList<bool> joystickAxesInverted; ///< Whether each axis should be used inverted from what was reported.
QList<bool> joystickAxesLimited; ///< Whether each axis should be limited to only the positive range.
bool throttleAxisLimited; ///< Indicates if the throttle channel should be limited to mapping from a 0:1 range instead of -1:1. Useful for controlling throttle with an axis that autocenters.
quint16 joystickButtons; ///< The state of every button. Bitfield supporting 16 buttons with 1s indicating that the button is down. quint16 joystickButtons; ///< The state of every button. Bitfield supporting 16 buttons with 1s indicating that the button is down.
int xHat, yHat; ///< The horizontal/vertical hat directions. Values are -1, 0, 1, with (-1,-1) indicating bottom-left. int xHat, yHat; ///< The horizontal/vertical hat directions. Values are -1, 0, 1, with (-1,-1) indicating bottom-left.
...@@ -233,6 +235,12 @@ public slots: ...@@ -233,6 +235,12 @@ public slots:
* @param inverted True indicates inverted from normal. Varies by controller. * @param inverted True indicates inverted from normal. Varies by controller.
*/ */
void setAxisInversion(int axis, bool inverted); void setAxisInversion(int axis, bool inverted);
/**
* @brief Specify that an axis should only transmit the positive values. Useful for controlling throttle from auto-centering axes.
* @param axis Which axis has its range limited.
* @param limitRange If true only the positive half of this axis will be read.
*/
void setAxisRangeLimit(int axis, bool limitRange);
}; };
#endif // _JOYSTICKINPUT_H_ #endif // _JOYSTICKINPUT_H_
#include "JoystickAxis.h" #include "JoystickAxis.h"
#include "JoystickInput.h" #include "JoystickInput.h"
#include "ui_JoystickAxis.h" #include "ui_JoystickAxis.h"
<<<<<<< HEAD
#include "UASManager.h" #include "UASManager.h"
=======
>>>>>>> 64d0741ee82db3d5dac2108f3f6d03c6fa66e5c6
#include <QString> #include <QString>
JoystickAxis::JoystickAxis(int id, QWidget *parent) : JoystickAxis::JoystickAxis(int id, QWidget *parent) :
...@@ -13,9 +10,11 @@ JoystickAxis::JoystickAxis(int id, QWidget *parent) : ...@@ -13,9 +10,11 @@ JoystickAxis::JoystickAxis(int id, QWidget *parent) :
ui(new Ui::JoystickAxis) ui(new Ui::JoystickAxis)
{ {
ui->setupUi(this); ui->setupUi(this);
mappingComboBoxChanged(JoystickInput::JOYSTICK_INPUT_MAPPING_NONE);
ui->label->setText(QString::number(id)); ui->label->setText(QString::number(id));
connect(ui->comboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(mappingComboBoxChanged(int))); connect(ui->comboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(mappingComboBoxChanged(int)));
connect(ui->invertedCheckBox, SIGNAL(clicked(bool)), this, SLOT(inversionCheckBoxChanged(bool))); connect(ui->invertedCheckBox, SIGNAL(clicked(bool)), this, SLOT(inversionCheckBoxChanged(bool)));
connect(ui->rangeCheckBox, SIGNAL(clicked(bool)), this, SLOT(rangeCheckBoxChanged(bool)));
} }
JoystickAxis::~JoystickAxis() JoystickAxis::~JoystickAxis()
...@@ -30,6 +29,14 @@ void JoystickAxis::setValue(float value) ...@@ -30,6 +29,14 @@ void JoystickAxis::setValue(float value)
void JoystickAxis::mappingComboBoxChanged(int newMapping) void JoystickAxis::mappingComboBoxChanged(int newMapping)
{ {
if (newMapping == JoystickInput::JOYSTICK_INPUT_MAPPING_THROTTLE)
{
ui->rangeCheckBox->show();
}
else
{
ui->rangeCheckBox->hide();
}
emit mappingChanged(id, (JoystickInput::JOYSTICK_INPUT_MAPPING)newMapping); emit mappingChanged(id, (JoystickInput::JOYSTICK_INPUT_MAPPING)newMapping);
this->setActiveUAS(UASManager::instance()->getActiveUAS()); this->setActiveUAS(UASManager::instance()->getActiveUAS());
} }
...@@ -39,14 +46,24 @@ void JoystickAxis::inversionCheckBoxChanged(bool inverted) ...@@ -39,14 +46,24 @@ void JoystickAxis::inversionCheckBoxChanged(bool inverted)
emit inversionChanged(id, inverted); emit inversionChanged(id, inverted);
} }
void JoystickAxis::rangeCheckBoxChanged(bool limited)
{
emit rangeChanged(id, limited);
}
void JoystickAxis::setActiveUAS(UASInterface* uas) void JoystickAxis::setActiveUAS(UASInterface* uas)
{ {
if (uas && !uas->systemCanReverse() && ui->comboBox->currentIndex() == JoystickInput::JOYSTICK_INPUT_MAPPING_THROTTLE) // Set the throttle display to only positive if:
// * This is the throttle axis AND
// * The current UAS can't reverse OR there is no current UAS
if (((uas && !uas->systemCanReverse()) || !uas) && ui->comboBox->currentIndex() == JoystickInput::JOYSTICK_INPUT_MAPPING_THROTTLE)
{ {
ui->progressBar->setRange(0, 100); ui->progressBar->setRange(0, 100);
ui->rangeCheckBox->show();
} }
else else
{ {
ui->progressBar->setRange(-100, 100); ui->progressBar->setRange(-100, 100);
ui->rangeCheckBox->hide();
} }
} }
...@@ -20,7 +20,9 @@ signals: ...@@ -20,7 +20,9 @@ signals:
/** @brief Signal a change in this axis' yaw/pitch/roll mapping */ /** @brief Signal a change in this axis' yaw/pitch/roll mapping */
void mappingChanged(int id, JoystickInput::JOYSTICK_INPUT_MAPPING newMapping); void mappingChanged(int id, JoystickInput::JOYSTICK_INPUT_MAPPING newMapping);
/** @brief Signal a change in this axis' inversion status */ /** @brief Signal a change in this axis' inversion status */
void inversionChanged(int id, bool); void inversionChanged(int id, bool inversion);
/** @brief Signal a change in this axis' range setting. If limited is true then only the positive values should be read from this axis. */
void rangeChanged(int id, bool limited);
public slots: public slots:
/** @brief Update the displayed value of the included progressbar. /** @brief Update the displayed value of the included progressbar.
...@@ -39,6 +41,8 @@ private slots: ...@@ -39,6 +41,8 @@ private slots:
void mappingComboBoxChanged(int newMapping); void mappingComboBoxChanged(int newMapping);
/** @brief Emit signal when the inversion checkbox is changed. */ /** @brief Emit signal when the inversion checkbox is changed. */
void inversionCheckBoxChanged(bool inverted); void inversionCheckBoxChanged(bool inverted);
/** @brief Emit signal when the range checkbox is changed. */
void rangeCheckBoxChanged(bool inverted);
}; };
#endif // JOYSTICKAXIS_H #endif // JOYSTICKAXIS_H
...@@ -59,6 +59,9 @@ ...@@ -59,6 +59,9 @@
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<property name="toolTip">
<string>Specify what property of the UAS this axis should command</string>
</property>
<item> <item>
<property name="text"> <property name="text">
<string>--</string> <string>--</string>
...@@ -86,6 +89,13 @@ ...@@ -86,6 +89,13 @@
</item> </item>
</widget> </widget>
</item> </item>
<item>
<widget class="QCheckBox" name="rangeCheckBox">
<property name="text">
<string>Half range</string>
</property>
</widget>
</item>
<item> <item>
<widget class="QProgressBar" name="progressBar"> <widget class="QProgressBar" name="progressBar">
<property name="enabled"> <property name="enabled">
...@@ -103,6 +113,9 @@ ...@@ -103,6 +113,9 @@
<height>100</height> <height>100</height>
</size> </size>
</property> </property>
<property name="toolTip">
<string>Only use the positive values from this axis for control</string>
</property>
<property name="minimum"> <property name="minimum">
<number>-100</number> <number>-100</number>
</property> </property>
...@@ -140,6 +153,9 @@ ...@@ -140,6 +153,9 @@
<height>25</height> <height>25</height>
</size> </size>
</property> </property>
<property name="toolTip">
<string>Reverse the values for this axis</string>
</property>
<property name="text"> <property name="text">
<string>Inverted</string> <string>Inverted</string>
</property> </property>
......
...@@ -144,6 +144,7 @@ void JoystickWidget::updateUIForJoystick(int id) ...@@ -144,6 +144,7 @@ void JoystickWidget::updateUIForJoystick(int id)
axis->setValue(joystick->getCurrentValueForAxis(i)); axis->setValue(joystick->getCurrentValueForAxis(i));
connect(axis, SIGNAL(mappingChanged(int,JoystickInput::JOYSTICK_INPUT_MAPPING)), this->joystick, SLOT(setAxisMapping(int,JoystickInput::JOYSTICK_INPUT_MAPPING))); connect(axis, SIGNAL(mappingChanged(int,JoystickInput::JOYSTICK_INPUT_MAPPING)), this->joystick, SLOT(setAxisMapping(int,JoystickInput::JOYSTICK_INPUT_MAPPING)));
connect(axis, SIGNAL(inversionChanged(int,bool)), this->joystick, SLOT(setAxisInversion(int,bool))); connect(axis, SIGNAL(inversionChanged(int,bool)), this->joystick, SLOT(setAxisInversion(int,bool)));
connect(axis, SIGNAL(rangeChanged(int,bool)), this->joystick, SLOT(setAxisRangeLimit(int,bool)));
connect(UASManager::instance(), SIGNAL(activeUASSet(UASInterface*)), axis, SLOT(setActiveUAS(UASInterface*))); connect(UASManager::instance(), SIGNAL(activeUASSet(UASInterface*)), axis, SLOT(setActiveUAS(UASInterface*)));
m_ui->axesLayout->addWidget(axis); m_ui->axesLayout->addWidget(axis);
axes.append(axis); axes.append(axis);
......
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