Commit 49d61d9e authored by pixhawk's avatar pixhawk

Merge branch 'master' of pixhawk.ethz.ch:qgroundcontrol

parents 425e32bd 96522cf7
...@@ -35,6 +35,7 @@ This file is part of the PIXHAWK project ...@@ -35,6 +35,7 @@ This file is part of the PIXHAWK project
#include <QDebug> #include <QDebug>
#include <QTime> #include <QTime>
#include <QApplication>
#include "MG.h" #include "MG.h"
#include "MAVLinkProtocol.h" #include "MAVLinkProtocol.h"
...@@ -56,7 +57,9 @@ This file is part of the PIXHAWK project ...@@ -56,7 +57,9 @@ This file is part of the PIXHAWK project
MAVLinkProtocol::MAVLinkProtocol() : MAVLinkProtocol::MAVLinkProtocol() :
heartbeatTimer(new QTimer(this)), heartbeatTimer(new QTimer(this)),
heartbeatRate(MAVLINK_HEARTBEAT_DEFAULT_RATE), heartbeatRate(MAVLINK_HEARTBEAT_DEFAULT_RATE),
m_heartbeatsEnabled(false) m_heartbeatsEnabled(false),
m_loggingEnabled(false),
m_logfile(NULL)
{ {
start(QThread::LowPriority); start(QThread::LowPriority);
// Start heartbeat timer, emitting a heartbeat at the configured rate // Start heartbeat timer, emitting a heartbeat at the configured rate
...@@ -77,12 +80,23 @@ MAVLinkProtocol::MAVLinkProtocol() : ...@@ -77,12 +80,23 @@ MAVLinkProtocol::MAVLinkProtocol() :
MAVLinkProtocol::~MAVLinkProtocol() MAVLinkProtocol::~MAVLinkProtocol()
{ {
if (m_logfile)
{
m_logfile->close();
delete m_logfile;
}
} }
void MAVLinkProtocol::run() void MAVLinkProtocol::run()
{ {
}
QString MAVLinkProtocol::getLogfileName()
{
return QCoreApplication::applicationDirPath()+"/mavlink.log";
} }
/** /**
...@@ -111,6 +125,15 @@ void MAVLinkProtocol::receiveBytes(LinkInterface* link) ...@@ -111,6 +125,15 @@ void MAVLinkProtocol::receiveBytes(LinkInterface* link)
if (decodeState == 1) if (decodeState == 1)
{ {
// Log data
if (m_loggingEnabled)
{
uint8_t buf[MAVLINK_MAX_PACKET_LEN];
mavlink_msg_to_send_buffer(buf, &message);
m_logfile->write((const char*) buf);
qDebug() << "WROTE LOGFILE";
}
// ORDER MATTERS HERE! // ORDER MATTERS HERE!
// If the matching UAS object does not yet exist, it has to be created // If the matching UAS object does not yet exist, it has to be created
// before emitting the packetReceived signal // before emitting the packetReceived signal
...@@ -316,11 +339,32 @@ void MAVLinkProtocol::enableHeartbeats(bool enabled) ...@@ -316,11 +339,32 @@ void MAVLinkProtocol::enableHeartbeats(bool enabled)
emit heartbeatChanged(enabled); emit heartbeatChanged(enabled);
} }
void MAVLinkProtocol::enableLogging(bool enabled)
{
if (enabled && !m_loggingEnabled)
{
m_logfile = new QFile(getLogfileName());
m_logfile->open(QIODevice::WriteOnly | QIODevice::Append);
}
else
{
m_logfile->close();
delete m_logfile;
m_logfile = NULL;
}
m_loggingEnabled = enabled;
}
bool MAVLinkProtocol::heartbeatsEnabled(void) bool MAVLinkProtocol::heartbeatsEnabled(void)
{ {
return m_heartbeatsEnabled; return m_heartbeatsEnabled;
} }
bool MAVLinkProtocol::loggingEnabled(void)
{
return m_loggingEnabled;
}
/** /**
* The default rate is 1 Hertz. * The default rate is 1 Hertz.
* *
......
...@@ -37,6 +37,7 @@ This file is part of the PIXHAWK project ...@@ -37,6 +37,7 @@ This file is part of the PIXHAWK project
#include <QMutex> #include <QMutex>
#include <QString> #include <QString>
#include <QTimer> #include <QTimer>
#include <QFile>
#include <QMap> #include <QMap>
#include <QByteArray> #include <QByteArray>
#include "ProtocolInterface.h" #include "ProtocolInterface.h"
...@@ -65,6 +66,10 @@ public: ...@@ -65,6 +66,10 @@ public:
int getHeartbeatRate(); int getHeartbeatRate();
/** @brief Get heartbeat state */ /** @brief Get heartbeat state */
bool heartbeatsEnabled(void); bool heartbeatsEnabled(void);
/** @brief Get logging state */
bool loggingEnabled(void);
/** @brief Get the name of the packet log file */
static QString getLogfileName();
public slots: public slots:
/** @brief Receive bytes from a communication interface */ /** @brief Receive bytes from a communication interface */
...@@ -79,14 +84,19 @@ public slots: ...@@ -79,14 +84,19 @@ public slots:
/** @brief Enable / disable the heartbeat emission */ /** @brief Enable / disable the heartbeat emission */
void enableHeartbeats(bool enabled); void enableHeartbeats(bool enabled);
/** @brief Enable/disable binary packet logging */
void enableLogging(bool enabled);
/** @brief Send an extra heartbeat to all connected units */ /** @brief Send an extra heartbeat to all connected units */
void sendHeartbeat(); void sendHeartbeat();
protected: protected:
QTimer* heartbeatTimer; ///< Timer to emit heartbeats QTimer* heartbeatTimer; ///< Timer to emit heartbeats
int heartbeatRate; ///< Heartbeat rate, controls the timer interval int heartbeatRate; ///< Heartbeat rate, controls the timer interval
bool m_heartbeatsEnabled; ///< Enabled/disable heartbeat emission bool m_heartbeatsEnabled; ///< Enabled/disable heartbeat emission
QMutex receiveMutex; ///< Mutex to protect receiveBytes function bool m_loggingEnabled; ///< Enable/disable packet logging
QFile* m_logfile; ///< Logfile
QMutex receiveMutex; ///< Mutex to protect receiveBytes function
int lastIndex[256][256]; int lastIndex[256][256];
int totalReceiveCounter; int totalReceiveCounter;
int totalLossCounter; int totalLossCounter;
...@@ -98,6 +108,8 @@ signals: ...@@ -98,6 +108,8 @@ signals:
void messageReceived(LinkInterface* link, mavlink_message_t message); void messageReceived(LinkInterface* link, mavlink_message_t message);
/** @brief Emitted if heartbeat emission mode is changed */ /** @brief Emitted if heartbeat emission mode is changed */
void heartbeatChanged(bool heartbeats); void heartbeatChanged(bool heartbeats);
/** @brief Emitted if logging is started / stopped */
void loggingChanged(bool enabled);
}; };
#endif // MAVLINKPROTOCOL_H_ #endif // MAVLINKPROTOCOL_H_
...@@ -38,6 +38,7 @@ This file is part of the PIXHAWK project ...@@ -38,6 +38,7 @@ This file is part of the PIXHAWK project
#include <QDebug> #include <QDebug>
#include "MG.h" #include "MG.h"
#include "LinkManager.h" #include "LinkManager.h"
#include "MAVLinkProtocol.h"
#include "MAVLinkSimulationLink.h" #include "MAVLinkSimulationLink.h"
// MAVLINK includes // MAVLINK includes
#include <mavlink.h> #include <mavlink.h>
...@@ -92,6 +93,10 @@ MAVLinkSimulationLink::MAVLinkSimulationLink(QString readFile, QString writeFile ...@@ -92,6 +93,10 @@ MAVLinkSimulationLink::MAVLinkSimulationLink(QString readFile, QString writeFile
maxTimeNoise = 0; maxTimeNoise = 0;
this->id = getNextLinkId(); this->id = getNextLinkId();
LinkManager::instance()->add(this); LinkManager::instance()->add(this);
// Open packet log
mavlinkLogFile = new QFile(MAVLinkProtocol::getLogfileName());
mavlinkLogFile->open(QIODevice::ReadOnly);
} }
MAVLinkSimulationLink::~MAVLinkSimulationLink() MAVLinkSimulationLink::~MAVLinkSimulationLink()
...@@ -121,6 +126,21 @@ void MAVLinkSimulationLink::run() ...@@ -121,6 +126,21 @@ void MAVLinkSimulationLink::run()
if (_isConnected) if (_isConnected)
{ {
mainloop(); mainloop();
// FIXME Hacky code to read from packet log file
// readyBufferMutex.lock();
// for (int i = 0; i < streampointer; i++)
// {
// readyBuffer.enqueue(*(stream + i));
// }
// readyBufferMutex.unlock();
emit bytesReady(this); emit bytesReady(this);
} }
last = MG::TIME::getGroundTimeNow(); last = MG::TIME::getGroundTimeNow();
......
...@@ -98,6 +98,7 @@ protected: ...@@ -98,6 +98,7 @@ protected:
QTimer* timer; QTimer* timer;
/** File which contains the input data (simulated robot messages) **/ /** File which contains the input data (simulated robot messages) **/
QFile* simulationFile; QFile* simulationFile;
QFile* mavlinkLogFile;
QString simulationHeader; QString simulationHeader;
/** File where the commands sent by the groundstation are stored **/ /** File where the commands sent by the groundstation are stored **/
QFile* receiveFile; QFile* receiveFile;
......
...@@ -338,7 +338,7 @@ void UAS::receiveMessage(LinkInterface* link, mavlink_message_t message) ...@@ -338,7 +338,7 @@ void UAS::receiveMessage(LinkInterface* link, mavlink_message_t message)
emit valueChanged(uasId, "lon", pos.lon, time); emit valueChanged(uasId, "lon", pos.lon, time);
emit valueChanged(uasId, "alt", pos.alt, time); emit valueChanged(uasId, "alt", pos.alt, time);
emit valueChanged(uasId, "speed", pos.v, time); emit valueChanged(uasId, "speed", pos.v, time);
qDebug() << "GOT GPS RAW"; //qDebug() << "GOT GPS RAW";
emit globalPositionChanged(this, pos.lon, pos.lat, pos.alt, time); emit globalPositionChanged(this, pos.lon, pos.lat, pos.alt, time);
} }
break; break;
...@@ -346,7 +346,8 @@ void UAS::receiveMessage(LinkInterface* link, mavlink_message_t message) ...@@ -346,7 +346,8 @@ void UAS::receiveMessage(LinkInterface* link, mavlink_message_t message)
{ {
mavlink_gps_status_t pos; mavlink_gps_status_t pos;
mavlink_msg_gps_status_decode(&message, &pos); mavlink_msg_gps_status_decode(&message, &pos);
for(int i = 0; i < pos.satellites_visible && i < sizeof(pos.satellite_used); i++) //qDebug() << "GOT GPS STATUS FOR "<< pos.satellites_visible << "SATELLITES";
for(int i = 0; i < (int)pos.satellites_visible; i++)
{ {
emit gpsSatelliteStatusChanged(uasId, i, pos.satellite_azimuth[i], pos.satellite_direction[i], pos.satellite_snr[i], static_cast<bool>(pos.satellite_used[i])); emit gpsSatelliteStatusChanged(uasId, i, pos.satellite_azimuth[i], pos.satellite_direction[i], pos.satellite_snr[i], static_cast<bool>(pos.satellite_used[i]));
} }
......
...@@ -43,7 +43,7 @@ HSIDisplay::HSIDisplay(QWidget *parent) : ...@@ -43,7 +43,7 @@ HSIDisplay::HSIDisplay(QWidget *parent) :
gpsSatellites(), gpsSatellites(),
satellitesUsed(0) satellitesUsed(0)
{ {
connect(UASManager::instance(), SIGNAL(activeUASSet(UASInterface*)), this, SLOT(setActiveUAS(UASInterface*)));
} }
void HSIDisplay::paintEvent(QPaintEvent * event) void HSIDisplay::paintEvent(QPaintEvent * event)
...@@ -134,6 +134,8 @@ void HSIDisplay::setActiveUAS(UASInterface* uas) ...@@ -134,6 +134,8 @@ void HSIDisplay::setActiveUAS(UASInterface* uas)
//disconnect(uas, SIGNAL(valueChanged(UASInterface*,QString,double,quint64)), this, SLOT(updateValue(UASInterface*,QString,double,quint64))); //disconnect(uas, SIGNAL(valueChanged(UASInterface*,QString,double,quint64)), this, SLOT(updateValue(UASInterface*,QString,double,quint64)));
} }
connect(uas, SIGNAL(gpsSatelliteStatusChanged(int,int,float,float,float,bool)), this, SLOT(updateSatellite(int,int,float,float,float,bool)));
// Now connect the new UAS // Now connect the new UAS
//if (this->uas != uas) //if (this->uas != uas)
...@@ -147,7 +149,14 @@ void HSIDisplay::setActiveUAS(UASInterface* uas) ...@@ -147,7 +149,14 @@ void HSIDisplay::setActiveUAS(UASInterface* uas)
void HSIDisplay::updateSatellite(int uasid, int satid, float azimuth, float direction, float snr, bool used) void HSIDisplay::updateSatellite(int uasid, int satid, float azimuth, float direction, float snr, bool used)
{ {
Q_UNUSED(uasid); Q_UNUSED(uasid);
//qDebug() << "UPDATED SATELLITE";
// If slot is empty, insert object // If slot is empty, insert object
if (gpsSatellites.size() <= satid)
{
gpsSatellites.resize(satid+1);
// gpsSatellites.insert(satid, new GPSSatellite(satid, azimuth, direction, snr, used));
}
if (gpsSatellites.at(satid) == NULL) if (gpsSatellites.at(satid) == NULL)
{ {
gpsSatellites.insert(satid, new GPSSatellite(satid, azimuth, direction, snr, used)); gpsSatellites.insert(satid, new GPSSatellite(satid, azimuth, direction, snr, used));
...@@ -161,11 +170,30 @@ void HSIDisplay::updateSatellite(int uasid, int satid, float azimuth, float dire ...@@ -161,11 +170,30 @@ void HSIDisplay::updateSatellite(int uasid, int satid, float azimuth, float dire
QColor HSIDisplay::getColorForSNR(float snr) QColor HSIDisplay::getColorForSNR(float snr)
{ {
return QColor(200, 250, 200); QColor color;
if (snr < 10)
{
color = QColor(250, 200, 200);
}
else if (snr > 20)
{
color = QColor(200, 250, 200);
}
else if (snr > 30)
{
color = QColor(100, 250, 100);
}
else
{
color = QColor(180, 180, 180);
}
return color;
} }
void HSIDisplay::drawGPS() void HSIDisplay::drawGPS()
{ {
float xCenter = vwidth/2.0f;
float yCenter = vwidth/2.0f;
QPainter painter(this); QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing, true); painter.setRenderHint(QPainter::Antialiasing, true);
painter.setRenderHint(QPainter::HighQualityAntialiasing, true); painter.setRenderHint(QPainter::HighQualityAntialiasing, true);
...@@ -173,7 +201,8 @@ void HSIDisplay::drawGPS() ...@@ -173,7 +201,8 @@ void HSIDisplay::drawGPS()
// Max satellite circle radius // Max satellite circle radius
const float margin = 0.2f; // 20% margin of total width on each side const float margin = 0.2f; // 20% margin of total width on each side
float radius = (vwidth - vwidth * 2.0f * margin) / 2.0f; float radius = (vwidth - vwidth * 2.0f * margin) / 4.0f;
radius = radius;
// Draw satellite labels // Draw satellite labels
// QString label; // QString label;
...@@ -201,10 +230,10 @@ void HSIDisplay::drawGPS() ...@@ -201,10 +230,10 @@ void HSIDisplay::drawGPS()
painter.setPen(color); painter.setPen(color);
painter.setBrush(brush); painter.setBrush(brush);
float xPos = sin(sat->direction) * sat->azimuth * radius; float xPos = xCenter + sin(sat->direction/180.0f * M_PI) * (sat->azimuth/180.0f * M_PI) * radius;
float yPos = cos(sat->direction) * sat->azimuth * radius; float yPos = yCenter + cos(sat->direction/180.0f * M_PI) * (sat->azimuth/180.0f * M_PI) * radius;
drawCircle(xPos, yPos, vwidth/10.0f, 1.0f, color, &painter); drawCircle(xPos, yPos, vwidth*0.02f, 1.0f, color, &painter);
} }
} }
} }
......
...@@ -49,6 +49,7 @@ public: ...@@ -49,6 +49,7 @@ public:
public slots: public slots:
void setActiveUAS(UASInterface* uas); void setActiveUAS(UASInterface* uas);
void updateSatellite(int uasid, int satid, float azimuth, float direction, float snr, bool used);
void paintEvent(QPaintEvent * event); void paintEvent(QPaintEvent * event);
protected slots: protected slots:
...@@ -59,7 +60,6 @@ protected slots: ...@@ -59,7 +60,6 @@ protected slots:
protected: protected:
void updateSatellite(int uasid, int satid, float azimuth, float direction, float snr, bool used);
static QColor getColorForSNR(float snr); static QColor getColorForSNR(float snr);
/** /**
...@@ -69,11 +69,11 @@ protected: ...@@ -69,11 +69,11 @@ protected:
{ {
public: public:
GPSSatellite(int id, float azimuth, float direction, float snr, bool used) : GPSSatellite(int id, float azimuth, float direction, float snr, bool used) :
id(id), id(id),
azimuth(azimuth), azimuth(azimuth),
direction(direction), direction(direction),
snr(snr), snr(snr),
used(used) used(used)
{ {
} }
......
...@@ -11,9 +11,12 @@ MAVLinkSettingsWidget::MAVLinkSettingsWidget(MAVLinkProtocol* protocol, QWidget ...@@ -11,9 +11,12 @@ MAVLinkSettingsWidget::MAVLinkSettingsWidget(MAVLinkProtocol* protocol, QWidget
// Connect actions // Connect actions
connect(protocol, SIGNAL(heartbeatChanged(bool)), m_ui->heartbeatCheckBox, SLOT(setChecked(bool))); connect(protocol, SIGNAL(heartbeatChanged(bool)), m_ui->heartbeatCheckBox, SLOT(setChecked(bool)));
connect(m_ui->heartbeatCheckBox, SIGNAL(toggled(bool)), protocol, SLOT(enableHeartbeats(bool))); connect(m_ui->heartbeatCheckBox, SIGNAL(toggled(bool)), protocol, SLOT(enableHeartbeats(bool)));
connect(protocol, SIGNAL(loggingChanged(bool)), m_ui->loggingCheckBox, SLOT(setChecked(bool)));
connect(m_ui->loggingCheckBox, SIGNAL(toggled(bool)), protocol, SLOT(enableLogging(bool)));
// Initialize state // Initialize state
m_ui->heartbeatCheckBox->setChecked(protocol->heartbeatsEnabled()); m_ui->heartbeatCheckBox->setChecked(protocol->heartbeatsEnabled());
m_ui->loggingCheckBox->setChecked(protocol->loggingEnabled());
} }
MAVLinkSettingsWidget::~MAVLinkSettingsWidget() MAVLinkSettingsWidget::~MAVLinkSettingsWidget()
......
...@@ -24,6 +24,13 @@ ...@@ -24,6 +24,13 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QCheckBox" name="loggingCheckBox">
<property name="text">
<string>Log all MAVLink packets</string>
</property>
</widget>
</item>
<item> <item>
<spacer name="verticalSpacer"> <spacer name="verticalSpacer">
<property name="orientation"> <property name="orientation">
......
...@@ -85,7 +85,7 @@ settings() ...@@ -85,7 +85,7 @@ settings()
waypoints->setVisible(false); waypoints->setVisible(false);
info = new UASInfoWidget(this); info = new UASInfoWidget(this);
info->setVisible(false); info->setVisible(false);
detection = new ObjectDetectionView("test", this); detection = new ObjectDetectionView("patterns", this);
detection->setVisible(false); detection->setVisible(false);
hud = new HUD(640, 480, this); hud = new HUD(640, 480, this);
hud->setVisible(false); hud->setVisible(false);
......
...@@ -94,7 +94,6 @@ void ObjectDetectionView::newDetection(int uasId, QString patternPath, int x1, i ...@@ -94,7 +94,6 @@ void ObjectDetectionView::newDetection(int uasId, QString patternPath, int x1, i
{ {
//qDebug() << "REDETECTED"; //qDebug() << "REDETECTED";
/*
QList<QAction*> actions = m_ui->listWidget->actions(); QList<QAction*> actions = m_ui->listWidget->actions();
// Find action and update it // Find action and update it
foreach (QAction* act, actions) foreach (QAction* act, actions)
...@@ -107,7 +106,9 @@ void ObjectDetectionView::newDetection(int uasId, QString patternPath, int x1, i ...@@ -107,7 +106,9 @@ void ObjectDetectionView::newDetection(int uasId, QString patternPath, int x1, i
act->setText(patternPath + separator + "(#" + QString::number(count) + ")" + separator + QString::number(confidence)); act->setText(patternPath + separator + "(#" + QString::number(count) + ")" + separator + QString::number(confidence));
} }
} }
QPixmap image = QPixmap(patternFolder + "/" + patternPath); QString filePath = MG::DIR::getSupportFilesDirectory() + "/" + patternFolder + "/" + patternPath.split("/").last();
qDebug() << "Loading:" << filePath;
QPixmap image = QPixmap(filePath);
image = image.scaledToWidth(m_ui->imageLabel->width()); image = image.scaledToWidth(m_ui->imageLabel->width());
m_ui->imageLabel->setPixmap(image); m_ui->imageLabel->setPixmap(image);
QString patternName = patternPath.split("//").last(); // Remove preceding folder names QString patternName = patternPath.split("//").last(); // Remove preceding folder names
...@@ -115,7 +116,6 @@ void ObjectDetectionView::newDetection(int uasId, QString patternPath, int x1, i ...@@ -115,7 +116,6 @@ void ObjectDetectionView::newDetection(int uasId, QString patternPath, int x1, i
// Set name and label // Set name and label
m_ui->nameLabel->setText(patternName); m_ui->nameLabel->setText(patternName);
*/
} }
else else
{ {
......
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