Commit 11fa19c3 authored by pixhawk's avatar pixhawk

Major refactoring of the waypoint code. The new design fits the...

Major refactoring of the waypoint code. The new design fits the model-view-controller pattern better.
parent 77f57fe8
......@@ -31,6 +31,7 @@ This file is part of the PIXHAWK project
*/
#include "Waypoint.h"
#include <QStringList>
Waypoint::Waypoint(quint16 _id, float _x, float _y, float _z, float _yaw, bool _autocontinue, bool _current, float _orbit, int _holdTime)
: id(_id),
......@@ -50,6 +51,30 @@ Waypoint::~Waypoint()
}
void Waypoint::save(QTextStream &saveStream)
{
saveStream << "\t" << this->getId() << "\t" << this->getX() << "\t" << this->getY() << "\t" << this->getZ() << "\t" << this->getYaw() << "\t" << this->getAutoContinue() << "\t" << this->getCurrent() << "\t" << this->getOrbit() << "\t" << this->getHoldTime() << "\n";
}
bool Waypoint::load(QTextStream &loadStream)
{
const QStringList &wpParams = loadStream.readLine().split("\t");
if (wpParams.size() == 10)
{
this->id = wpParams[1].toInt();
this->x = wpParams[2].toDouble();
this->y = wpParams[3].toDouble();
this->z = wpParams[4].toDouble();
this->yaw = wpParams[5].toDouble();
this->autocontinue = (wpParams[6].toInt() == 1 ? true : false);
this->current = (wpParams[7].toInt() == 1 ? true : false);
this->orbit = wpParams[8].toDouble();
this->holdTime = wpParams[9].toInt();
return true;
}
return false;
}
void Waypoint::setId(quint16 id)
{
this->id = id;
......
......@@ -35,6 +35,7 @@ This file is part of the PIXHAWK project
#include <QObject>
#include <QString>
#include <QTextStream>
class Waypoint : public QObject
{
......@@ -54,6 +55,10 @@ public:
float getOrbit() const { return orbit; }
float getHoldTime() const { return holdTime; }
void save(QTextStream &saveStream);
bool load(QTextStream &loadStream);
private:
quint16 id;
float x;
......
This diff is collapsed.
......@@ -75,7 +75,23 @@ public:
void handleWaypointCurrent(quint8 systemId, quint8 compId, mavlink_waypoint_current_t *wpc); ///< Handles received set current waypoint messages
/*@}*/
QVector<Waypoint *> &getWaypointList(void) { return waypoints; } ///< Returns a reference to the local waypoint list. Gives full access to the internal data structure - Subject to change: Public const access and friend access for the waypoint list widget.
/** @name Remote operations */
/*@{*/
void clearWaypointList(); ///< Sends the waypoint clear all message to the MAV
void readWaypoints(); ///< Requests the MAV's current waypoint list
void writeWaypoints(); ///< Sends the local waypoint list to the MAV
int setCurrentWaypoint(quint16 seq); ///< Changes the current waypoint and sends the sequence number of the waypoint that should get the new target waypoint to the UAS
/*@}*/
/** @name Local waypoint list operations */
/*@{*/
const QVector<Waypoint *> &getWaypointList(void) { return waypoints; } ///< Returns a const reference to the local waypoint list.
void localAddWaypoint(Waypoint *wp); ///< locally adds a new waypoint to the end of the list and changes its sequence number accordingly
int localRemoveWaypoint(quint16 seq); ///< locally remove the specified waypoint from the storage
void localMoveWaypoint(quint16 cur_seq, quint16 new_seq); ///< locally move a waypoint from its current position cur_seq to a new position new_seq
void localSaveWaypoints(const QString &saveFile); ///< saves the local waypoint list to saveFile
void localLoadWaypoints(const QString &loadFile); ///< loads a waypoint list from loadFile
/*@}*/
private:
/** @name Message send functions */
......@@ -91,15 +107,11 @@ private:
public slots:
void timeout(); ///< Called by the timer if a response times out. Handles send retries.
void setCurrent(quint16 seq); ///< Sends the sequence number of the waypoint that should get the new target waypoint
void clearWaypointList(); ///< Sends the waypoint clear all message to the MAV
void readWaypoints(); ///< Requests the MAV's current waypoint list
void writeWaypoints(); ///< Sends the local waypoint list to the MAV
signals:
void waypointUpdated(quint16,double,double,double,double,bool,bool,double,int); ///< Adds a waypoint to the waypoint list widget
void currentWaypointChanged(quint16); ///< emits the new current waypoint sequence number
void updateStatusString(const QString &); ///< emits the current status string
void waypointListChanged(void); ///< emits signal that the local waypoint list has been changed
void currentWaypointChanged(quint16); ///< emits the new current waypoint sequence number
void updateStatusString(const QString &); ///< emits the current status string
private:
UAS &uas; ///< Reference to the corresponding UAS
......
......@@ -632,7 +632,7 @@ void HSIDisplay::drawWaypoints(QPainter& painter)
{
if (uas)
{
QVector<Waypoint*>& list = uas->getWaypointManager().getWaypointList();
const QVector<Waypoint*>& list = uas->getWaypointManager().getWaypointList();
QColor color;
painter.setBrush(Qt::NoBrush);
......
This diff is collapsed.
......@@ -55,7 +55,6 @@ class WaypointList : public QWidget {
public slots:
void setUAS(UASInterface* uas);
void redrawList();
//UI Buttons
void saveWaypoints();
......@@ -73,23 +72,18 @@ public slots:
void updateStatusLabel(const QString &string);
void changeCurrentWaypoint(quint16 seq); ///< The user wants to change the current waypoint
void currentWaypointChanged(quint16 seq); ///< The waypointplanner changed the current waypoint
void setWaypoint(quint16 id, double x, double y, double z, double yaw, bool autocontinue, bool current, double orbit, int holdTime);
void addWaypoint(Waypoint* wp);
void currentWaypointChanged(quint16 seq); ///< The waypoint planner changed the current waypoint
void waypointListChanged(void); ///< The waypoint manager informs that the waypoint list was changed
void removeWaypoint(Waypoint* wp);
void waypointReached(quint16 waypointId);
void updateLocalPosition(UASInterface*, double x, double y, double z, quint64 usec);
void updateAttitude(UASInterface*, double roll, double pitch, double yaw, quint64 usec);
signals:
void sendWaypoints();
void requestWaypoints();
void clearWaypointList();
void setCurrent(quint16);
protected:
virtual void changeEvent(QEvent *e);
protected:
QMap<Waypoint*, WaypointView*> wpViews;
QVBoxLayout* listLayout;
UASInterface* uas;
......
......@@ -48,15 +48,7 @@ WaypointView::WaypointView(Waypoint* wp, QWidget* parent) :
this->wp = wp;
// Read values and set user interface
m_ui->xSpinBox->setValue(wp->getX());
m_ui->ySpinBox->setValue(wp->getY());
m_ui->zSpinBox->setValue(wp->getZ());
m_ui->yawSpinBox->setValue(wp->getYaw()/M_PI*180.);
m_ui->selectedBox->setChecked(wp->getCurrent());
m_ui->autoContinue->setChecked(wp->getAutoContinue());
m_ui->idLabel->setText(QString("%1").arg(wp->getId()));\
m_ui->orbitSpinBox->setValue(wp->getOrbit());
m_ui->holdTimeSpinBox->setValue(wp->getHoldTime());
updateValues();
connect(m_ui->xSpinBox, SIGNAL(valueChanged(double)), wp, SLOT(setX(double)));
connect(m_ui->ySpinBox, SIGNAL(valueChanged(double)), wp, SLOT(setY(double)));
......@@ -110,15 +102,30 @@ void WaypointView::changedCurrent(int state)
{
if (state == 0)
{
wp->setCurrent(false);
//m_ui->selectedBox->setChecked(true);
//m_ui->selectedBox->setCheckState(Qt::Checked);
//wp->setCurrent(false);
}
else
{
wp->setCurrent(true);
//wp->setCurrent(true);
emit changeCurrentWaypoint(wp->getId()); //the slot changeCurrentWaypoint() in WaypointList sets all other current flags to false
}
}
void WaypointView::updateValues()
{
m_ui->xSpinBox->setValue(wp->getX());
m_ui->ySpinBox->setValue(wp->getY());
m_ui->zSpinBox->setValue(wp->getZ());
m_ui->yawSpinBox->setValue(wp->getYaw()/M_PI*180.);
m_ui->selectedBox->setChecked(wp->getCurrent());
m_ui->autoContinue->setChecked(wp->getAutoContinue());
m_ui->idLabel->setText(QString("%1").arg(wp->getId()));\
m_ui->orbitSpinBox->setValue(wp->getOrbit());
m_ui->holdTimeSpinBox->setValue(wp->getHoldTime());
}
void WaypointView::setCurrent(bool state)
{
if (state)
......
......@@ -57,6 +57,7 @@ public slots:
void remove();
void changedAutoContinue(int);
void changedCurrent(int);
void updateValues(void);
void setYaw(int); //hidden degree to radian conversion
......
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