Commit a821d121 authored by lm's avatar lm

Working HIL!

parent b51baab7
This diff is collapsed.
...@@ -36,6 +36,9 @@ protected: ...@@ -36,6 +36,9 @@ protected:
double roll; double roll;
double pitch; double pitch;
double yaw; double yaw;
double rollspeed;
double pitchspeed;
double yawspeed;
bool globalNavigation; bool globalNavigation;
bool firstWP; bool firstWP;
......
...@@ -24,6 +24,7 @@ This file is part of the QGROUNDCONTROL project ...@@ -24,6 +24,7 @@ This file is part of the QGROUNDCONTROL project
/** /**
* @file * @file
* @brief Definition of UDP connection (server) for unmanned vehicles * @brief Definition of UDP connection (server) for unmanned vehicles
* @see Flightgear Manual http://mapserver.flightgear.org/getstart.pdf
* @author Lorenz Meier <mavteam@student.ethz.ch> * @author Lorenz Meier <mavteam@student.ethz.ch>
* *
*/ */
...@@ -38,7 +39,9 @@ This file is part of the QGROUNDCONTROL project ...@@ -38,7 +39,9 @@ This file is part of the QGROUNDCONTROL project
#include <QHostInfo> #include <QHostInfo>
#include "MainWindow.h" #include "MainWindow.h"
QGCFlightGearLink::QGCFlightGearLink(UASInterface* mav, QString remoteHost, QHostAddress host, quint16 port) QGCFlightGearLink::QGCFlightGearLink(UASInterface* mav, QString remoteHost, QHostAddress host, quint16 port) :
process(NULL),
terraSync(NULL)
{ {
this->host = host; this->host = host;
this->port = port+mav->getUASID(); this->port = port+mav->getUASID();
...@@ -282,8 +285,15 @@ bool QGCFlightGearLink::disconnectSimulation() ...@@ -282,8 +285,15 @@ bool QGCFlightGearLink::disconnectSimulation()
delete process; delete process;
process = NULL; process = NULL;
} }
if (terraSync)
{
terraSync->close();
delete terraSync;
terraSync = NULL;
}
if (socket) if (socket)
{ {
socket->close();
delete socket; delete socket;
socket = NULL; socket = NULL;
} }
...@@ -309,6 +319,7 @@ bool QGCFlightGearLink::connectSimulation() ...@@ -309,6 +319,7 @@ bool QGCFlightGearLink::connectSimulation()
QObject::connect(socket, SIGNAL(readyRead()), this, SLOT(readBytes())); QObject::connect(socket, SIGNAL(readyRead()), this, SLOT(readBytes()));
process = new QProcess(this); process = new QProcess(this);
terraSync = new QProcess(this);
connect(mav, SIGNAL(hilControlsChanged(uint64_t, float, float, float, float, uint8_t, uint8_t)), this, SLOT(updateControls(uint64_t,float,float,float,float,uint8_t,uint8_t))); connect(mav, SIGNAL(hilControlsChanged(uint64_t, float, float, float, float, uint8_t, uint8_t)), this, SLOT(updateControls(uint64_t,float,float,float,float,uint8_t,uint8_t)));
connect(this, SIGNAL(hilStateChanged(uint64_t,float,float,float,float,float,float,int32_t,int32_t,int32_t,int16_t,int16_t,int16_t,int16_t,int16_t,int16_t)), mav, SLOT(sendHilState(uint64_t,float,float,float,float,float,float,int32_t,int32_t,int32_t,int16_t,int16_t,int16_t,int16_t,int16_t,int16_t))); connect(this, SIGNAL(hilStateChanged(uint64_t,float,float,float,float,float,float,int32_t,int32_t,int32_t,int16_t,int16_t,int16_t,int16_t,int16_t,int16_t)), mav, SLOT(sendHilState(uint64_t,float,float,float,float,float,float,int32_t,int32_t,int32_t,int16_t,int16_t,int16_t,int16_t,int16_t,int16_t)));
...@@ -317,62 +328,145 @@ bool QGCFlightGearLink::connectSimulation() ...@@ -317,62 +328,145 @@ bool QGCFlightGearLink::connectSimulation()
// Catch process error // Catch process error
QObject::connect( process, SIGNAL(error(QProcess::ProcessError)), QObject::connect( process, SIGNAL(error(QProcess::ProcessError)),
this, SLOT(processError(QProcess::ProcessError))); this, SLOT(processError(QProcess::ProcessError)));
QObject::connect( terraSync, SIGNAL(error(QProcess::ProcessError)),
this, SLOT(processError(QProcess::ProcessError)));
// Start Flightgear // Start Flightgear
QStringList processCall; QStringList processCall;
QString processFgfs; QString processFgfs;
QString processTerraSync;
QString fgRoot; QString fgRoot;
QString fgScenery; QString fgScenery;
QString aircraft("Rascal110-JSBSim"); QString aircraft;
if (mav->getSystemType() == MAV_TYPE_FIXED_WING)
{
aircraft = "Rascal110-JSBSim";
}
else if (mav->getSystemType() == MAV_TYPE_QUADROTOR)
{
aircraft = "arducopter";
}
else
{
aircraft = "Rascal110-JSBSim";
}
#ifdef Q_OS_MACX #ifdef Q_OS_MACX
processFgfs = "/Applications/FlightGear.app/Contents/Resources/fgfs"; processFgfs = "/Applications/FlightGear.app/Contents/Resources/fgfs";
fgRoot = "--fg-root=/Applications/FlightGear.app/Contents/Resources/data"; processTerraSync = "/Applications/FlightGear.app/Contents/Resources/terrasync";
fgScenery = "--fg-scenery=/Applications/FlightGear.app/Contents/Resources/data/Scenery:/Applications/FlightGear.app/Contents/Resources/data/Scenery-Terrasync"; fgRoot = "/Applications/FlightGear.app/Contents/Resources/data";
//fgScenery = "/Applications/FlightGear.app/Contents/Resources/data/Scenery";
fgScenery = "/Applications/FlightGear.app/Contents/Resources/data/Scenery-TerraSync";
// /Applications/FlightGear.app/Contents/Resources/data/Scenery:
#endif #endif
#ifdef Q_OS_WIN32 #ifdef Q_OS_WIN32
processFgfs = "C:\\Program Files (x86)\\FlightGear\\bin\\Win32\\fgfs"; processFgfs = "C:\\Program Files (x86)\\FlightGear\\bin\\Win32\\fgfs";
fgRoot = "--fg-root=C:\\Program Files (x86)\\FlightGear\\data"; fgRoot = "C:\\Program Files (x86)\\FlightGear\\data";
fgScenery = "C:\\Program Files (x86)\\FlightGear\\data\\Scenery-Terrasync";
#endif #endif
#ifdef Q_OS_LINUX #ifdef Q_OS_LINUX
processFgfs = "fgfs"; processFgfs = "fgfs";
fgRoot = "--fg-root=/usr/share/flightgear/data"; fgRoot = "/usr/share/flightgear/data";
fgScenery = "/usr/share/flightgear/data/Scenery-Terrasync";
#endif #endif
processCall << fgRoot; // Sanity checks
processCall << fgScenery; bool sane = true;
processCall << QString("--generic=socket,out,50,127.0.0.1,%1,udp,qgroundcontrol").arg(port); QFileInfo executable(processFgfs);
processCall << QString("--generic=socket,in,50,127.0.0.1,%1,udp,qgroundcontrol").arg(currentPort); if (!executable.isExecutable())
{
MainWindow::instance()->showCriticalMessage(tr("FlightGear Failed to Start"), tr("FlightGear was not found at %1").arg(processFgfs));
sane = false;
}
QFileInfo root(fgRoot);
if (!root.isDir())
{
MainWindow::instance()->showCriticalMessage(tr("FlightGear Failed to Start"), tr("FlightGear data directory was not found at %1").arg(fgRoot));
sane = false;
}
QFileInfo scenery(fgScenery);
if (!scenery.isDir())
{
MainWindow::instance()->showCriticalMessage(tr("FlightGear Failed to Start"), tr("FlightGear scenery directory was not found at %1").arg(fgScenery));
sane = false;
}
if (!sane) return false;
// --atlas=socket,out,1,localhost,5505,udp
// terrasync -p 5505 -S -d /usr/local/share/TerraSync
processCall << QString("--fg-root=%1").arg(fgRoot);
processCall << QString("--fg-scenery=%1").arg(fgScenery);
if (mav->getSystemType() == MAV_TYPE_QUADROTOR)
{
// FIXME ADD QUAD-Specific protocol here
processCall << QString("--generic=socket,out,50,127.0.0.1,%1,udp,qgroundcontrol").arg(port);
processCall << QString("--generic=socket,in,50,127.0.0.1,%1,udp,qgroundcontrol").arg(currentPort);
}
else
{
processCall << QString("--generic=socket,out,50,127.0.0.1,%1,udp,qgroundcontrol").arg(port);
processCall << QString("--generic=socket,in,50,127.0.0.1,%1,udp,qgroundcontrol").arg(currentPort);
}
processCall << "--atlas=socket,out,1,localhost,5505,udp";
processCall << "--in-air"; processCall << "--in-air";
processCall << "--roll=0";
processCall << "--pitch=0";
processCall << "--vc=90"; processCall << "--vc=90";
processCall << "--heading=300"; processCall << "--heading=300";
processCall << "--timeofday=noon"; processCall << "--timeofday=noon";
processCall << "--disable-hud-3d"; processCall << "--disable-hud-3d";
processCall << "--disable-fullscreen"; processCall << "--disable-fullscreen";
// processCall << "--control=mouse"; processCall << "--geometry=400x300";
// processCall << "--disable-intro-music"; processCall << "--disable-anti-alias-hud";
// processCall << "--disable-sound"; processCall << "--wind=0@0";
// processCall << "--disable-anti-alias-hud"; processCall << "--turbulence=0.0";
// processCall << "--disable-random-objects"; processCall << "--prop:/sim/frame-rate-throttle-hz=30";
// processCall << "--disable-ai-models"; processCall << "--control=mouse";
// processCall << "--wind=0@0"; processCall << "--disable-intro-music";
processCall << "--disable-sound";
processCall << "--disable-random-objects";
processCall << "--disable-ai-models";
processCall << "--shading-flat";
processCall << "--fog-disable";
processCall << "--disable-specular-highlight";
//processCall << "--disable-skyblend";
processCall << "--disable-random-objects";
processCall << "--disable-panel";
//processCall << "--disable-horizon-effect";
processCall << "--disable-clouds";
processCall << "--fdm=jsb"; processCall << "--fdm=jsb";
processCall << "--prop:/engines/engine/running=true";
processCall << "--units-meters"; processCall << "--units-meters";
if (mav->getSystemType() == MAV_TYPE_QUADROTOR) if (mav->getSystemType() == MAV_TYPE_QUADROTOR)
{ {
// Start the remaining three motors of the quad // Start all engines of the quad
processCall << "--prop:/engines/engine[0]/running=true";
processCall << "--prop:/engines/engine[1]/running=true"; processCall << "--prop:/engines/engine[1]/running=true";
processCall << "--prop:/engines/engine[2]/running=true"; processCall << "--prop:/engines/engine[2]/running=true";
processCall << "--prop:/engines/engine[3]/running=true"; processCall << "--prop:/engines/engine[3]/running=true";
} }
else
{
processCall << "--prop:/engines/engine/running=true";
}
processCall << QString("--lat=%1").arg(UASManager::instance()->getHomeLatitude()); processCall << QString("--lat=%1").arg(UASManager::instance()->getHomeLatitude());
processCall << QString("--lon=%1").arg(UASManager::instance()->getHomeLongitude()); processCall << QString("--lon=%1").arg(UASManager::instance()->getHomeLongitude());
processCall << QString("--altitude=%1").arg(UASManager::instance()->getHomeAltitude()); processCall << QString("--altitude=%1").arg(UASManager::instance()->getHomeAltitude());
// Add new argument with this: processCall << ""; // Add new argument with this: processCall << "";
processCall << QString("--aircraft=%2").arg(aircraft); processCall << QString("--aircraft=%2").arg(aircraft);
QStringList terraSyncArguments;
terraSyncArguments << "-p 5505";
terraSyncArguments << "-S";
terraSyncArguments << QString("-d=%1").arg(fgScenery);
terraSync->start(processTerraSync, terraSyncArguments);
process->start(processFgfs, processCall); process->start(processFgfs, processCall);
......
...@@ -109,6 +109,7 @@ protected: ...@@ -109,6 +109,7 @@ protected:
QTimer refreshTimer; QTimer refreshTimer;
UASInterface* mav; UASInterface* mav;
QProcess* process; QProcess* process;
QProcess* terraSync;
void setName(QString name); void setName(QString name);
......
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