Commit 06a542bf authored by pixhawk's avatar pixhawk

Added initialization and safety checks to remove clutter from UAS view

parent f8a80de5
......@@ -323,14 +323,33 @@ void UAS::receiveMessage(LinkInterface* link, mavlink_message_t message)
{
mavlink_gps_raw_t pos;
mavlink_msg_gps_raw_decode(&message, &pos);
// SANITY CHECK
// only accept values in a realistic range
// quint64 time = getUnixTime(pos.usec);
quint64 time = MG::TIME::getGroundTimeNow();
emit valueChanged(uasId, "lat", pos.lat, time);
emit valueChanged(uasId, "lon", pos.lon, time);
// Check for NaN
int alt = pos.alt;
if (alt != alt)
{
alt = 0;
emit textMessageReceived(uasId, 255, "GCS ERROR: RECEIVED NaN FOR ALTITUDE");
}
emit valueChanged(uasId, "alt", pos.alt, time);
emit valueChanged(uasId, "speed", pos.v, time);
//qDebug() << "GOT GPS RAW";
emit globalPositionChanged(this, pos.lon, pos.lat, pos.alt, time);
// Smaller than threshold and not NaN
if (pos.v < 1000000 && pos.v == pos.v)
{
emit valueChanged(uasId, "speed", pos.v, time);
//qDebug() << "GOT GPS RAW";
emit speedChanged(this, (double)pos.v, 0.0, 0.0, time);
}
else
{
emit textMessageReceived(uasId, 255, QString("GCS ERROR: RECEIVED INVALID SPEED OF %1 m/s").arg(pos.v));
}
emit globalPositionChanged(this, pos.lon, pos.lat, alt, time);
}
break;
case MAVLINK_MSG_ID_GPS_STATUS:
......
......@@ -40,16 +40,26 @@ This file is part of the PIXHAWK project
UASView::UASView(UASInterface* uas, QWidget *parent) :
QWidget(parent),
startTime(0),
timeRemaining(0),
chargeLevel(0),
uas(uas),
load(0),
state("UNKNOWN"),
stateDesc(tr("Unknown system state")),
mode("MAV_MODE_UNKNOWN"),
thrust(0),
isActive(false),
x(0),
y(0),
z(0),
totalSpeed(0),
lat(0),
lon(0),
alt(0),
groundDistance(0),
m_ui(new Ui::UASView)
{
this->uas = uas;
m_ui->setupUi(this);
// Setup communication
......@@ -316,9 +326,37 @@ void UASView::refresh()
position = position.sprintf("%02.2f %02.2f %02.2f m", x, y, z);
m_ui->positionLabel->setText(position);
QString globalPosition;
globalPosition = globalPosition.sprintf("%02.2f %02.2f %02.2f m", lon, lat, alt);
QString latIndicator;
if (lat > 0)
{
latIndicator = "N";
}
else
{
latIndicator = "S";
}
QString lonIndicator;
if (lon > 0)
{
lonIndicator = "E";
}
else
{
lonIndicator = "W";
}
globalPosition = globalPosition.sprintf("%02.2f%s %02.2f%s %02.2f m", lon, lonIndicator.toStdString().c_str(), lat, latIndicator.toStdString().c_str(), alt);
m_ui->gpsLabel->setText(globalPosition);
// Altitude
if (groundDistance == 0 && alt != 0)
{
m_ui->groundDistanceLabel->setText(QString("%1 m").arg(alt));
}
else
{
m_ui->groundDistanceLabel->setText(QString("%1 m").arg(groundDistance));
}
// Speed
QString speed;
speed = speed.sprintf("%02.2f m/s", totalSpeed);
......
......@@ -93,6 +93,7 @@ protected:
float lat;
float lon;
float alt;
float groundDistance;
void mouseDoubleClickEvent (QMouseEvent * event);
......
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