|
|
|
@ -36,6 +36,7 @@ This file is part of the QGROUNDCONTROL project
@@ -36,6 +36,7 @@ This file is part of the QGROUNDCONTROL project
|
|
|
|
|
#include "QGCXPlaneLink.h" |
|
|
|
|
#include "QGC.h" |
|
|
|
|
#include <QHostInfo> |
|
|
|
|
#include "UAS.h" |
|
|
|
|
#include "MainWindow.h" |
|
|
|
|
|
|
|
|
|
QGCXPlaneLink::QGCXPlaneLink(UASInterface* mav, QString remoteHost, QHostAddress localHost, quint16 localPort) : |
|
|
|
@ -199,9 +200,9 @@ void QGCXPlaneLink::writeBytes(const char* data, qint64 size)
@@ -199,9 +200,9 @@ void QGCXPlaneLink::writeBytes(const char* data, qint64 size)
|
|
|
|
|
ascii.append(219); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
qDebug() << "Sent" << size << "bytes to" << remoteHost.toString() << ":" << remotePort << "data:"; |
|
|
|
|
qDebug() << bytes; |
|
|
|
|
qDebug() << "ASCII:" << ascii; |
|
|
|
|
//qDebug() << "Sent" << size << "bytes to" << remoteHost.toString() << ":" << remotePort << "data:";
|
|
|
|
|
//qDebug() << bytes;
|
|
|
|
|
//qDebug() << "ASCII:" << ascii;
|
|
|
|
|
#endif |
|
|
|
|
if (connectState && socket) socket->writeDatagram(data, size, remoteHost, remotePort); |
|
|
|
|
} |
|
|
|
@ -232,7 +233,7 @@ void QGCXPlaneLink::readBytes()
@@ -232,7 +233,7 @@ void QGCXPlaneLink::readBytes()
|
|
|
|
|
// XPlane always has 5 bytes header: 'DATA@'
|
|
|
|
|
unsigned nsegs = (s-5)/36; |
|
|
|
|
|
|
|
|
|
qDebug() << "XPLANE:" << "LEN:" << s << "segs:" << nsegs; |
|
|
|
|
//qDebug() << "XPLANE:" << "LEN:" << s << "segs:" << nsegs;
|
|
|
|
|
|
|
|
|
|
#pragma pack(push, 1) |
|
|
|
|
struct payload { |
|
|
|
@ -248,6 +249,8 @@ void QGCXPlaneLink::readBytes()
@@ -248,6 +249,8 @@ void QGCXPlaneLink::readBytes()
|
|
|
|
|
float airspeed; |
|
|
|
|
float groundspeed; |
|
|
|
|
|
|
|
|
|
float man_roll, man_pitch, man_yaw; |
|
|
|
|
|
|
|
|
|
if (data[0] == 'D' && |
|
|
|
|
data[1] == 'A' && |
|
|
|
|
data[2] == 'T' && |
|
|
|
@ -262,24 +265,30 @@ void QGCXPlaneLink::readBytes()
@@ -262,24 +265,30 @@ void QGCXPlaneLink::readBytes()
|
|
|
|
|
|
|
|
|
|
if (p.index == 3) |
|
|
|
|
{ |
|
|
|
|
//qDebug() << "SPEEDS:" << p.f[0] << p.f[1] << p.f[2];
|
|
|
|
|
airspeed = p.f[6] * 0.44704f; |
|
|
|
|
groundspeed = p.f[7] * 0.44704; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
qDebug() << "SPEEDS:" << "airspeed" << airspeed << "m/s, groundspeed" << groundspeed << "m/s"; |
|
|
|
|
//qDebug() << "SPEEDS:" << "airspeed" << airspeed << "m/s, groundspeed" << groundspeed << "m/s";
|
|
|
|
|
} |
|
|
|
|
else if (p.index == 8) |
|
|
|
|
{ |
|
|
|
|
//qDebug() << "MAN:" << p.f[0] << p.f[3] << p.f[7];
|
|
|
|
|
man_roll = p.f[0]; |
|
|
|
|
man_pitch = p.f[1]; |
|
|
|
|
man_yaw = p.f[2]; |
|
|
|
|
UAS* uas = dynamic_cast<UAS*>(mav); |
|
|
|
|
if (uas) uas->setManualControlCommands(man_roll, man_pitch, man_yaw, 0.6); |
|
|
|
|
} |
|
|
|
|
else if (p.index == 16) |
|
|
|
|
{ |
|
|
|
|
qDebug() << "ANG VEL:" << p.f[0] << p.f[3] << p.f[7]; |
|
|
|
|
//qDebug() << "ANG VEL:" << p.f[0] << p.f[3] << p.f[7];
|
|
|
|
|
rollspeed = p.f[2]; |
|
|
|
|
pitchspeed = p.f[1]; |
|
|
|
|
yawspeed = p.f[0]; |
|
|
|
|
} |
|
|
|
|
else if (p.index == 17) |
|
|
|
|
{ |
|
|
|
|
qDebug() << "HDNG" << "pitch" << p.f[0] << "roll" << p.f[1] << "hding true" << p.f[2] << "hding mag" << p.f[3]; |
|
|
|
|
//qDebug() << "HDNG" << "pitch" << p.f[0] << "roll" << p.f[1] << "hding true" << p.f[2] << "hding mag" << p.f[3];
|
|
|
|
|
// XXX Feeding true heading - might need fix
|
|
|
|
|
pitch = (p.f[0] - 180.0f) / 180.0f * M_PI; |
|
|
|
|
roll = (p.f[1] - 180.0f) / 180.0f * M_PI; |
|
|
|
@ -292,30 +301,30 @@ void QGCXPlaneLink::readBytes()
@@ -292,30 +301,30 @@ void QGCXPlaneLink::readBytes()
|
|
|
|
|
// }
|
|
|
|
|
else if (p.index == 20) |
|
|
|
|
{ |
|
|
|
|
qDebug() << "LAT/LON/ALT:" << p.f[0] << p.f[1] << p.f[2]; |
|
|
|
|
//qDebug() << "LAT/LON/ALT:" << p.f[0] << p.f[1] << p.f[2];
|
|
|
|
|
lat = p.f[0]; |
|
|
|
|
lon = p.f[1]; |
|
|
|
|
alt = p.f[2] * 0.3048f; // convert feet (MSL) to meters
|
|
|
|
|
} |
|
|
|
|
else if (p.index == 12) |
|
|
|
|
{ |
|
|
|
|
qDebug() << "AIL/ELEV/RUD" << p.f[0] << p.f[1] << p.f[2]; |
|
|
|
|
//qDebug() << "AIL/ELEV/RUD" << p.f[0] << p.f[1] << p.f[2];
|
|
|
|
|
} |
|
|
|
|
else if (p.index == 25) |
|
|
|
|
{ |
|
|
|
|
qDebug() << "THROTTLE" << p.f[0] << p.f[1] << p.f[2] << p.f[3]; |
|
|
|
|
//qDebug() << "THROTTLE" << p.f[0] << p.f[1] << p.f[2] << p.f[3];
|
|
|
|
|
} |
|
|
|
|
else if (p.index == 0) |
|
|
|
|
{ |
|
|
|
|
qDebug() << "STATS" << "fgraphics/s" << p.f[0] << "fsim/s" << p.f[2] << "t frame" << p.f[3] << "cpu load" << p.f[4] << "grnd ratio" << p.f[5] << "filt ratio" << p.f[6]; |
|
|
|
|
//qDebug() << "STATS" << "fgraphics/s" << p.f[0] << "fsim/s" << p.f[2] << "t frame" << p.f[3] << "cpu load" << p.f[4] << "grnd ratio" << p.f[5] << "filt ratio" << p.f[6];
|
|
|
|
|
} |
|
|
|
|
else if (p.index == 11) |
|
|
|
|
{ |
|
|
|
|
qDebug() << "CONTROLS" << "ail" << p.f[0] << "elev" << p.f[1] << "rudder" << p.f[2] << "nwheel" << p.f[3]; |
|
|
|
|
//qDebug() << "CONTROLS" << "ail" << p.f[0] << "elev" << p.f[1] << "rudder" << p.f[2] << "nwheel" << p.f[3];
|
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
qDebug() << "UNKNOWN #" << p.index << p.f[0] << p.f[1] << p.f[2] << p.f[3]; |
|
|
|
|
//qDebug() << "UNKNOWN #" << p.index << p.f[0] << p.f[1] << p.f[2] << p.f[3];
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -360,12 +369,19 @@ bool QGCXPlaneLink::disconnectSimulation()
@@ -360,12 +369,19 @@ bool QGCXPlaneLink::disconnectSimulation()
|
|
|
|
|
{ |
|
|
|
|
if (!connectState) return true; |
|
|
|
|
|
|
|
|
|
connectState = false; |
|
|
|
|
|
|
|
|
|
if (process) disconnect(process, SIGNAL(error(QProcess::ProcessError)), |
|
|
|
|
this, SLOT(processError(QProcess::ProcessError))); |
|
|
|
|
if (mav) |
|
|
|
|
{ |
|
|
|
|
disconnect(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))); |
|
|
|
|
disconnect(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))); |
|
|
|
|
UAS* uas = dynamic_cast<UAS*>(mav); |
|
|
|
|
if (uas) |
|
|
|
|
{ |
|
|
|
|
uas->stopHil(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (process) |
|
|
|
@ -387,8 +403,6 @@ bool QGCXPlaneLink::disconnectSimulation()
@@ -387,8 +403,6 @@ bool QGCXPlaneLink::disconnectSimulation()
|
|
|
|
|
socket = NULL; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
connectState = false; |
|
|
|
|
|
|
|
|
|
emit simulationDisconnected(); |
|
|
|
|
emit simulationConnected(false); |
|
|
|
|
return !connectState; |
|
|
|
@ -402,6 +416,8 @@ bool QGCXPlaneLink::disconnectSimulation()
@@ -402,6 +416,8 @@ bool QGCXPlaneLink::disconnectSimulation()
|
|
|
|
|
bool QGCXPlaneLink::connectSimulation() |
|
|
|
|
{ |
|
|
|
|
if (!mav) return false; |
|
|
|
|
if (connectState) return false; |
|
|
|
|
|
|
|
|
|
socket = new QUdpSocket(this); |
|
|
|
|
connectState = socket->bind(localHost, localPort); |
|
|
|
|
if (!connectState) return false; |
|
|
|
@ -414,9 +430,11 @@ bool QGCXPlaneLink::connectSimulation()
@@ -414,9 +430,11 @@ bool QGCXPlaneLink::connectSimulation()
|
|
|
|
|
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))); |
|
|
|
|
|
|
|
|
|
// XXX ugly hack to set MAVLINK_MODE_HIL_FLAG_ENABLED
|
|
|
|
|
// without pulling MAVLINK dependencies in here
|
|
|
|
|
mav->setMode(32); |
|
|
|
|
UAS* uas = dynamic_cast<UAS*>(mav); |
|
|
|
|
if (uas) |
|
|
|
|
{ |
|
|
|
|
uas->startHil(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// XXX This will later be enabled to start X-Plane from within QGroundControl with the right arguments
|
|
|
|
|
|
|
|
|
|