Commit 160e0014 authored by Lorenz Meier's avatar Lorenz Meier

HIL and Joystick input

parent b3f6fe78
...@@ -503,6 +503,11 @@ QString QGCFlightGearLink::getName() ...@@ -503,6 +503,11 @@ QString QGCFlightGearLink::getName()
return name; return name;
} }
QString QGCFlightGearLink::getRemoteHost()
{
return QString("%1:%2").arg(currentHost.toString(), currentPort);
}
void QGCFlightGearLink::setName(QString name) void QGCFlightGearLink::setName(QString name)
{ {
this->name = name; this->name = name;
......
...@@ -63,6 +63,12 @@ public: ...@@ -63,6 +63,12 @@ public:
*/ */
QString getName(); QString getName();
/**
* @brief Get remote host and port
* @return string in format <host>:<port>
*/
QString getRemoteHost();
void run(); void run();
public slots: public slots:
......
...@@ -19,6 +19,12 @@ public: ...@@ -19,6 +19,12 @@ public:
*/ */
virtual QString getName() = 0; virtual QString getName() = 0;
/**
* @brief Get remote host and port
* @return string in format <host>:<port>
*/
virtual QString getRemoteHost() = 0;
public slots: public slots:
virtual void setPort(int port) = 0; virtual void setPort(int port) = 0;
/** @brief Add a new host to broadcast messages to */ /** @brief Add a new host to broadcast messages to */
......
...@@ -51,15 +51,38 @@ QGCXPlaneLink::QGCXPlaneLink(UASInterface* mav, QString remoteHost, QHostAddress ...@@ -51,15 +51,38 @@ QGCXPlaneLink::QGCXPlaneLink(UASInterface* mav, QString remoteHost, QHostAddress
this->connectState = false; this->connectState = false;
this->name = tr("X-Plane Link (localPort:%1)").arg(localPort); this->name = tr("X-Plane Link (localPort:%1)").arg(localPort);
setRemoteHost(remoteHost); setRemoteHost(remoteHost);
loadSettings();
} }
QGCXPlaneLink::~QGCXPlaneLink() QGCXPlaneLink::~QGCXPlaneLink()
{ {
storeSettings();
// if(connectState) { // if(connectState) {
// disconnectSimulation(); // disconnectSimulation();
// } // }
} }
void QGCXPlaneLink::loadSettings()
{
// Load defaults from settings
QSettings settings;
settings.sync();
settings.beginGroup("QGC_XPLANE_LINK");
setRemoteHost(settings.value("REMOTE_HOST", QString("%1:%2").arg(remoteHost.toString(), remotePort)).toString());
settings.endGroup();
}
void QGCXPlaneLink::storeSettings()
{
// Store settings
QSettings settings;
settings.beginGroup("QGC_XPLANE_LINK");
settings.setValue("REMOTE_HOST", QString("%1:%2").arg(remoteHost.toString(), remotePort));
settings.endGroup();
settings.sync();
}
/** /**
* @brief Runs the thread * @brief Runs the thread
* *
...@@ -102,62 +125,54 @@ void QGCXPlaneLink::processError(QProcess::ProcessError err) ...@@ -102,62 +125,54 @@ void QGCXPlaneLink::processError(QProcess::ProcessError err)
} }
} }
QString QGCXPlaneLink::getRemoteHost()
{
return QString("%1:%2").arg(remoteHost.toString(), remotePort);
}
/** /**
* @param localHost Hostname in standard formatting, e.g. locallocalHost:14551 or 192.168.1.1:14551 * @param newHost Hostname in standard formatting, e.g. localhost:14551 or 192.168.1.1:14551
*/ */
void QGCXPlaneLink::setRemoteHost(const QString& localHost) void QGCXPlaneLink::setRemoteHost(const QString& newHost)
{ {
if (localHost.contains(":")) if (newHost.contains(":"))
{ {
//qDebug() << "HOST: " << localHost.split(":").first(); //qDebug() << "HOST: " << newHost.split(":").first();
QHostInfo info = QHostInfo::fromName(localHost.split(":").first()); QHostInfo info = QHostInfo::fromName(newHost.split(":").first());
if (info.error() == QHostInfo::NoError) if (info.error() == QHostInfo::NoError)
{ {
// Add localHost // Add newHost
QList<QHostAddress> localHostAddresses = info.addresses(); QList<QHostAddress> newHostAddresses = info.addresses();
QHostAddress address; QHostAddress address;
for (int i = 0; i < localHostAddresses.size(); i++) for (int i = 0; i < newHostAddresses.size(); i++)
{ {
// Exclude loopback IPv4 and all IPv6 addresses // Exclude loopback IPv4 and all IPv6 addresses
if (!localHostAddresses.at(i).toString().contains(":")) if (!newHostAddresses.at(i).toString().contains(":"))
{ {
address = localHostAddresses.at(i); address = newHostAddresses.at(i);
} }
} }
remoteHost = address; remoteHost = address;
//qDebug() << "Address:" << address.toString(); //qDebug() << "Address:" << address.toString();
// Set localPort according to user input // Set localPort according to user input
remotePort = localHost.split(":").last().toInt(); remotePort = newHost.split(":").last().toInt();
} }
} }
else else
{ {
QHostInfo info = QHostInfo::fromName(localHost); QHostInfo info = QHostInfo::fromName(newHost);
if (info.error() == QHostInfo::NoError) if (info.error() == QHostInfo::NoError)
{ {
// Add localHost // Add newHost
remoteHost = info.addresses().first(); remoteHost = info.addresses().first();
} }
} }
// // Send request to send correct data if (isConnected())
//#pragma pack(push, 1) {
// struct payload { disconnectSimulation();
// char b[5]; connectSimulation();
// int index; }
// float f[8];
// } p;
//#pragma pack(pop)
// p.b[0] = 'D';
// p.b[1] = 'A';
// p.b[2] = 'T';
// p.b[3] = 'A';
// p.b[4] = '\0';
// p.f[0]
// writeBytes((const char*)&p, sizeof(p));
} }
void QGCXPlaneLink::updateControls(uint64_t time, float rollAilerons, float pitchElevator, float yawRudder, float throttle, uint8_t systemMode, uint8_t navMode) void QGCXPlaneLink::updateControls(uint64_t time, float rollAilerons, float pitchElevator, float yawRudder, float throttle, uint8_t systemMode, uint8_t navMode)
......
...@@ -52,6 +52,16 @@ public: ...@@ -52,6 +52,16 @@ public:
QGCXPlaneLink(UASInterface* mav, QString remoteHost=QString("127.0.0.1:49000"), QHostAddress localHost = QHostAddress::Any, quint16 localPort = 49005); QGCXPlaneLink(UASInterface* mav, QString remoteHost=QString("127.0.0.1:49000"), QHostAddress localHost = QHostAddress::Any, quint16 localPort = 49005);
~QGCXPlaneLink(); ~QGCXPlaneLink();
/**
* @brief Load X-Plane HIL settings
*/
void loadSettings();
/**
* @brief Store X-Plane HIL settings
*/
void storeSettings();
bool isConnected(); bool isConnected();
qint64 bytesAvailable(); qint64 bytesAvailable();
int getPort() const { int getPort() const {
...@@ -65,6 +75,12 @@ public: ...@@ -65,6 +75,12 @@ public:
void run(); void run();
/**
* @brief Get remote host and port
* @return string in format <host>:<port>
*/
QString getRemoteHost();
public slots: public slots:
// void setAddress(QString address); // void setAddress(QString address);
void setPort(int port); void setPort(int port);
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "UASManager.h" #include "UASManager.h"
#include "QGC.h" #include "QGC.h"
#include <QMutexLocker> #include <QMutexLocker>
#include <QSettings>
/** /**
* The coordinate frame of the joystick axis is the aeronautical frame like shown on this image: * The coordinate frame of the joystick axis is the aeronautical frame like shown on this image:
...@@ -34,8 +35,13 @@ JoystickInput::JoystickInput() : ...@@ -34,8 +35,13 @@ JoystickInput::JoystickInput() :
xAxis(0), xAxis(0),
yAxis(1), yAxis(1),
yawAxis(3), yawAxis(3),
autoButtonMapping(-1),
manualButtonMapping(-1),
stabilizeButtonMapping(-1),
joystickName(tr("Unitinialized")) joystickName(tr("Unitinialized"))
{ {
loadSettings();
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
calibrationPositive[i] = sdlJoystickMax; calibrationPositive[i] = sdlJoystickMax;
calibrationNegative[i] = sdlJoystickMin; calibrationNegative[i] = sdlJoystickMin;
...@@ -49,9 +55,40 @@ JoystickInput::JoystickInput() : ...@@ -49,9 +55,40 @@ JoystickInput::JoystickInput() :
JoystickInput::~JoystickInput() JoystickInput::~JoystickInput()
{ {
storeSettings();
done = true; done = true;
QGC::SLEEP::usleep(50000); }
this->deleteLater();
void JoystickInput::loadSettings()
{
// Load defaults from settings
QSettings settings;
settings.sync();
settings.beginGroup("QGC_JOYSTICK_INPUT");
xAxis = (settings.value("X_AXIS_MAPPING", xAxis).toInt());
yAxis = (settings.value("Y_AXIS_MAPPING", yAxis).toInt());
thrustAxis = (settings.value("THRUST_AXIS_MAPPING", thrustAxis).toInt());
yawAxis = (settings.value("YAW_AXIS_MAPPING", yawAxis).toInt());
autoButtonMapping = (settings.value("AUTO_BUTTON_MAPPING", autoButtonMapping).toInt());
stabilizeButtonMapping = (settings.value("STABILIZE_BUTTON_MAPPING", stabilizeButtonMapping).toInt());
manualButtonMapping = (settings.value("MANUAL_BUTTON_MAPPING", manualButtonMapping).toInt());
settings.endGroup();
}
void JoystickInput::storeSettings()
{
// Store settings
QSettings settings;
settings.beginGroup("QGC_JOYSTICK_INPUT");
settings.setValue("X_AXIS_MAPPING", xAxis);
settings.setValue("Y_AXIS_MAPPING", yAxis);
settings.setValue("THRUST_AXIS_MAPPING", thrustAxis);
settings.setValue("YAW_AXIS_MAPPING", yawAxis);
settings.setValue("AUTO_BUTTON_MAPPING", autoButtonMapping);
settings.setValue("STABILIZE_BUTTON_MAPPING", stabilizeButtonMapping);
settings.setValue("MANUAL_BUTTON_MAPPING", manualButtonMapping);
settings.endGroup();
settings.sync();
} }
...@@ -95,7 +132,7 @@ void JoystickInput::init() ...@@ -95,7 +132,7 @@ void JoystickInput::init()
// Wait for joysticks if none is connected // Wait for joysticks if none is connected
while (numJoysticks == 0) while (numJoysticks == 0)
{ {
QGC::SLEEP::msleep(800); QGC::SLEEP::msleep(400);
// INITIALIZE SDL Joystick support // INITIALIZE SDL Joystick support
if (SDL_InitSubSystem(SDL_INIT_JOYSTICK | SDL_INIT_NOPARACHUTE) < 0) if (SDL_InitSubSystem(SDL_INIT_JOYSTICK | SDL_INIT_NOPARACHUTE) < 0)
{ {
......
...@@ -58,6 +58,51 @@ public: ...@@ -58,6 +58,51 @@ public:
const QString& getName(); const QString& getName();
/**
* @brief Load joystick settings
*/
void loadSettings();
/**
* @brief Store joystick settings
*/
void storeSettings();
int getMappingThrustAxis()
{
return thrustAxis;
}
int getMappingXAxis()
{
return xAxis;
}
int getMappingYAxis()
{
return yAxis;
}
int getMappingYawAxis()
{
return yawAxis;
}
int getMappingAutoButton()
{
return autoButtonMapping;
}
int getMappingManualButton()
{
return manualButtonMapping;
}
int getMappingStabilizeButton()
{
return stabilizeButtonMapping;
}
const double sdlJoystickMin; const double sdlJoystickMin;
const double sdlJoystickMax; const double sdlJoystickMax;
...@@ -76,6 +121,9 @@ protected: ...@@ -76,6 +121,9 @@ protected:
int xAxis; int xAxis;
int yAxis; int yAxis;
int yawAxis; int yawAxis;
int autoButtonMapping;
int manualButtonMapping;
int stabilizeButtonMapping;
SDL_Event event; SDL_Event event;
QString joystickName; QString joystickName;
...@@ -149,6 +197,40 @@ signals: ...@@ -149,6 +197,40 @@ signals:
public slots: public slots:
void setActiveUAS(UASInterface* uas); void setActiveUAS(UASInterface* uas);
void setMappingThrustAxis(int mapping)
{
thrustAxis = mapping;
}
void setMappingXAxis(int mapping)
{
xAxis = mapping;
}
void setMappingYAxis(int mapping)
{
yAxis = mapping;
}
void setMappingYawAxis(int mapping)
{
yawAxis = mapping;
}
void setMappingAutoButton(int mapping)
{
autoButtonMapping = mapping;
}
void setMappingManualButton(int mapping)
{
manualButtonMapping = mapping;
}
void setMappingStabilizeButton(int mapping)
{
stabilizeButtonMapping = mapping;
}
}; };
#endif // _JOYSTICKINPUT_H_ #endif // _JOYSTICKINPUT_H_
...@@ -2393,9 +2393,9 @@ void UAS::disarmSystem() ...@@ -2393,9 +2393,9 @@ void UAS::disarmSystem()
void UAS::setManualControlCommands(double roll, double pitch, double yaw, double thrust) void UAS::setManualControlCommands(double roll, double pitch, double yaw, double thrust)
{ {
// Scale values // Scale values
double rollPitchScaling = 0.2f; double rollPitchScaling = 0.2f * 1000.0f;
double yawScaling = 0.5f; double yawScaling = 0.5f * 1000.0f;
double thrustScaling = 1.0f; double thrustScaling = 1.0f * 1000.0f;
manualRollAngle = roll * rollPitchScaling; manualRollAngle = roll * rollPitchScaling;
manualPitchAngle = pitch * rollPitchScaling; manualPitchAngle = pitch * rollPitchScaling;
......
...@@ -9,8 +9,19 @@ JoystickWidget::JoystickWidget(JoystickInput* joystick, QWidget *parent) : ...@@ -9,8 +9,19 @@ JoystickWidget::JoystickWidget(JoystickInput* joystick, QWidget *parent) :
m_ui->setupUi(this); m_ui->setupUi(this);
this->joystick = joystick; this->joystick = joystick;
m_ui->rollMapSpinBox->setValue(joystick->getMappingXAxis());
m_ui->pitchMapSpinBox->setValue(joystick->getMappingYAxis());
m_ui->yawMapSpinBox->setValue(joystick->getMappingYawAxis());
m_ui->throttleMapSpinBox->setValue(joystick->getMappingThrustAxis());
m_ui->autoMapSpinBox->setValue(joystick->getMappingAutoButton());
connect(this->joystick, SIGNAL(joystickChanged(double,double,double,double,int,int)), this, SLOT(updateJoystick(double,double,double,double,int,int))); connect(this->joystick, SIGNAL(joystickChanged(double,double,double,double,int,int)), this, SLOT(updateJoystick(double,double,double,double,int,int)));
connect(this->joystick, SIGNAL(buttonPressed(int)), this, SLOT(pressKey(int))); connect(this->joystick, SIGNAL(buttonPressed(int)), this, SLOT(pressKey(int)));
connect(m_ui->rollMapSpinBox, SIGNAL(valueChanged(int)), this->joystick, SLOT(setMappingXAxis(int)));
connect(m_ui->pitchMapSpinBox, SIGNAL(valueChanged(int)), this->joystick, SLOT(setMappingYAxis(int)));
connect(m_ui->yawMapSpinBox, SIGNAL(valueChanged(int)), this->joystick, SLOT(setMappingYawAxis(int)));
connect(m_ui->throttleMapSpinBox, SIGNAL(valueChanged(int)), this->joystick, SLOT(setMappingThrustAxis(int)));
connect(m_ui->autoMapSpinBox, SIGNAL(valueChanged(int)), this->joystick, SLOT(setMappingAutoButton(int)));
// Display the widget // Display the widget
this->window()->setWindowTitle(tr("Joystick Settings")); this->window()->setWindowTitle(tr("Joystick Settings"));
......
...@@ -6,8 +6,8 @@ ...@@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>396</width> <width>654</width>
<height>323</height> <height>376</height>
</rect> </rect>
</property> </property>
<property name="minimumSize"> <property name="minimumSize">
...@@ -19,13 +19,57 @@ ...@@ -19,13 +19,57 @@
<property name="windowTitle"> <property name="windowTitle">
<string>Dialog</string> <string>Dialog</string>
</property> </property>
<layout class="QGridLayout" name="gridLayout_2"> <layout class="QGridLayout" name="gridLayout_2" columnstretch="10,10,1,5">
<property name="margin"> <property name="margin">
<number>8</number> <number>8</number>
</property> </property>
<property name="spacing"> <property name="spacing">
<number>8</number> <number>8</number>
</property> </property>
<item row="1" column="1" colspan="2">
<widget class="QLabel" name="statusLabel">
<property name="text">
<string>No joystick detecte yet.. waiting</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QGroupBox" name="groupBox_3">
<property name="maximumSize">
<size>
<width>60</width>
<height>16777215</height>
</size>
</property>
<property name="title">
<string>Throttle</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="spacing">
<number>0</number>
</property>
<property name="margin">
<number>2</number>
</property>
<item>
<widget class="QProgressBar" name="thrust">
<property name="minimumSize">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
<property name="value">
<number>0</number>
</property>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="0" column="1"> <item row="0" column="1">
<widget class="QGroupBox" name="groupBox_2"> <widget class="QGroupBox" name="groupBox_2">
<property name="title"> <property name="title">
...@@ -85,6 +129,9 @@ ...@@ -85,6 +129,9 @@
<property name="text"> <property name="text">
<string>Y</string> <string>Y</string>
</property> </property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget> </widget>
</item> </item>
<item row="4" column="0"> <item row="4" column="0">
...@@ -138,47 +185,6 @@ ...@@ -138,47 +185,6 @@
</layout> </layout>
</widget> </widget>
</item> </item>
<item row="0" column="2">
<widget class="QGroupBox" name="groupBox_3">
<property name="maximumSize">
<size>
<width>60</width>
<height>16777215</height>
</size>
</property>
<property name="title">
<string>Throttle</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="margin">
<number>2</number>
</property>
<item>
<widget class="QProgressBar" name="thrust">
<property name="minimumSize">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
<property name="value">
<number>0</number>
</property>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="1" column="1" colspan="2">
<widget class="QLabel" name="statusLabel">
<property name="text">
<string>No joystick - connect and restart QGroundControl</string>
</property>
</widget>
</item>
<item row="0" column="0" rowspan="3"> <item row="0" column="0" rowspan="3">
<widget class="QGroupBox" name="groupBox"> <widget class="QGroupBox" name="groupBox">
<property name="maximumSize"> <property name="maximumSize">
...@@ -357,7 +363,7 @@ ...@@ -357,7 +363,7 @@
</layout> </layout>
</widget> </widget>
</item> </item>
<item row="2" column="1" colspan="2"> <item row="1" column="3">
<widget class="QDialogButtonBox" name="buttonBox"> <widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
...@@ -367,6 +373,98 @@ ...@@ -367,6 +373,98 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="3">
<widget class="QGroupBox" name="groupBox_4">
<property name="title">
<string>Mappings</string>
</property>
<layout class="QGridLayout" name="gridLayout_3" columnstretch="30,10">
<item row="3" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
<string>Throttle</string>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="label_8">
<property name="text">
<string>Stabilized Button</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_7">
<property name="text">
<string>Auto Button</string>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QLabel" name="label_9">
<property name="text">
<string>Manual Button</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Pitch Axis</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Yaw Axis</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Roll Axis</string>
</property>
</widget>
</item>
<item row="7" column="0" colspan="2">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="1">
<widget class="QSpinBox" name="rollMapSpinBox"/>
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="pitchMapSpinBox"/>
</item>
<item row="2" column="1">
<widget class="QSpinBox" name="yawMapSpinBox"/>
</item>
<item row="3" column="1">
<widget class="QSpinBox" name="throttleMapSpinBox"/>
</item>
<item row="4" column="1">
<widget class="QSpinBox" name="autoMapSpinBox"/>
</item>
<item row="5" column="1">
<widget class="QSpinBox" name="stabilizedMapSpinBox"/>
</item>
<item row="6" column="1">
<widget class="QSpinBox" name="manualMapSpinBox"/>
</item>
</layout>
</widget>
</item>
</layout> </layout>
</widget> </widget>
<resources/> <resources/>
......
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