Commit 17bd4fa3 authored by pixhawk's avatar pixhawk

cleaned up the code

parent d94341d9
......@@ -91,11 +91,6 @@ WaypointList::~WaypointList()
delete m_ui;
}
void WaypointList::updateStatusLabel(const QString &string)
{
m_ui->statusLabel->setText(string);
}
void WaypointList::updateLocalPosition(UASInterface* uas, double x, double y, double z, quint64 usec)
{
Q_UNUSED(uas);
......@@ -129,17 +124,86 @@ void WaypointList::setUAS(UASInterface* uas)
}
}
void WaypointList::waypointReached(quint16 waypointId)
void WaypointList::saveWaypoints()
{
if (uas)
{
QString fileName = QFileDialog::getSaveFileName(this, tr("Save File"), "./waypoints.txt", tr("Waypoint File (*.txt)"));
uas->getWaypointManager().localSaveWaypoints(fileName);
}
}
void WaypointList::loadWaypoints()
{
if (uas)
{
QString fileName = QFileDialog::getOpenFileName(this, tr("Load File"), ".", tr("Waypoint File (*.txt)"));
uas->getWaypointManager().localLoadWaypoints(fileName);
}
}
void WaypointList::transmit()
{
if (uas)
{
uas->getWaypointManager().writeWaypoints();
}
}
void WaypointList::read()
{
if (uas)
{
uas->getWaypointManager().readWaypoints();
}
}
void WaypointList::add()
{
if (uas)
{
const QVector<Waypoint *> &waypoints = uas->getWaypointManager().getWaypointList();
if (waypoints.size() > 0)
{
Waypoint *last = waypoints.at(waypoints.size()-1);
Waypoint *wp = new Waypoint(0, last->getX(), last->getY(), last->getZ(), last->getYaw(), last->getAutoContinue(), false, last->getOrbit(), last->getHoldTime());
uas->getWaypointManager().localAddWaypoint(wp);
}
else
{
Waypoint *wp = new Waypoint(0, 1.1, 1.1, -0.8, 0.0, true, true, 0.15, 2000);
uas->getWaypointManager().localAddWaypoint(wp);
}
}
}
void WaypointList::addCurrentPositonWaypoint()
{
if (this->uas)
if (uas)
{
updateStatusLabel(QString("Waypoint %1 reached.").arg(waypointId));
const QVector<Waypoint *> &waypoints = uas->getWaypointManager().getWaypointList();
if (waypoints.size() > 0)
{
Waypoint *last = waypoints.at(waypoints.size()-1);
Waypoint *wp = new Waypoint(0, (qRound(mavX*100))/100., (qRound(mavY*100))/100., (qRound(mavZ*100))/100., (qRound(mavYaw*100))/100., last->getAutoContinue(), false, last->getOrbit(), last->getHoldTime());
uas->getWaypointManager().localAddWaypoint(wp);
}
else
{
Waypoint *wp = new Waypoint(0, (qRound(mavX*100))/100., (qRound(mavY*100))/100., (qRound(mavZ*100))/100., (qRound(mavYaw*100))/100., true, true, 0.15, 2000);
uas->getWaypointManager().localAddWaypoint(wp);
}
}
}
void WaypointList::updateStatusLabel(const QString &string)
{
m_ui->statusLabel->setText(string);
}
void WaypointList::changeCurrentWaypoint(quint16 seq)
{
if (this->uas)
if (uas)
{
uas->getWaypointManager().setCurrentWaypoint(seq);
}
......@@ -147,7 +211,7 @@ void WaypointList::changeCurrentWaypoint(quint16 seq)
void WaypointList::currentWaypointChanged(quint16 seq)
{
if (this->uas)
if (uas)
{
const QVector<Waypoint *> &waypoints = uas->getWaypointManager().getWaypointList();
......@@ -172,7 +236,7 @@ void WaypointList::currentWaypointChanged(quint16 seq)
void WaypointList::waypointListChanged()
{
if (this->uas)
if (uas)
{
const QVector<Waypoint *> &waypoints = uas->getWaypointManager().getWaypointList();
......@@ -203,6 +267,7 @@ void WaypointList::waypointListChanged()
}
}
// then add/update the views for each waypoint in the list
for(int i = 0; i < waypoints.size(); i++)
{
Waypoint *wp = waypoints[i];
......@@ -224,61 +289,6 @@ void WaypointList::waypointListChanged()
}
}
void WaypointList::read()
{
if (uas)
{
uas->getWaypointManager().readWaypoints();
}
}
void WaypointList::transmit()
{
if (uas)
{
uas->getWaypointManager().writeWaypoints();
}
}
void WaypointList::add()
{
// Only add waypoints if UAS is present
if (uas)
{
const QVector<Waypoint *> &waypoints = uas->getWaypointManager().getWaypointList();
if (waypoints.size() > 0)
{
Waypoint *last = waypoints.at(waypoints.size()-1);
Waypoint *wp = new Waypoint(0, last->getX(), last->getY(), last->getZ(), last->getYaw(), last->getAutoContinue(), false, last->getOrbit(), last->getHoldTime());
uas->getWaypointManager().localAddWaypoint(wp);
}
else
{
Waypoint *wp = new Waypoint(0, 1.1, 1.1, -0.8, 0.0, true, true, 0.15, 2000);
uas->getWaypointManager().localAddWaypoint(wp);
}
}
}
void WaypointList::addCurrentPositonWaypoint()
{
if (uas)
{
const QVector<Waypoint *> &waypoints = uas->getWaypointManager().getWaypointList();
if (waypoints.size() > 0)
{
Waypoint *last = waypoints.at(waypoints.size()-1);
Waypoint *wp = new Waypoint(0, (qRound(mavX*100))/100., (qRound(mavY*100))/100., (qRound(mavZ*100))/100., (qRound(mavYaw*100))/100., last->getAutoContinue(), false, last->getOrbit(), last->getHoldTime());
uas->getWaypointManager().localAddWaypoint(wp);
}
else
{
Waypoint *wp = new Waypoint(0, (qRound(mavX*100))/100., (qRound(mavY*100))/100., (qRound(mavZ*100))/100., (qRound(mavYaw*100))/100., true, true, 0.15, 2000);
uas->getWaypointManager().localAddWaypoint(wp);
}
}
}
void WaypointList::moveUp(Waypoint* wp)
{
if (uas)
......@@ -342,21 +352,3 @@ void WaypointList::changeEvent(QEvent *e)
}
}
void WaypointList::saveWaypoints()
{
if (uas)
{
QString fileName = QFileDialog::getSaveFileName(this, tr("Save File"), "./waypoints.txt", tr("Waypoint File (*.txt)"));
uas->getWaypointManager().localSaveWaypoints(fileName);
}
}
void WaypointList::loadWaypoints()
{
if (uas)
{
QString fileName = QFileDialog::getOpenFileName(this, tr("Load File"), ".", tr("Waypoint File (*.txt)"));
uas->getWaypointManager().localLoadWaypoints(fileName);
}
}
......@@ -54,31 +54,39 @@ class WaypointList : public QWidget {
virtual ~WaypointList();
public slots:
void updateLocalPosition(UASInterface*, double x, double y, double z, quint64 usec);
void updateAttitude(UASInterface*, double roll, double pitch, double yaw, quint64 usec);
void setUAS(UASInterface* uas);
//UI Buttons
//Waypoint list operations
/** @brief Save the local waypoint list to a file */
void saveWaypoints();
/** @brief Load a waypoint list from a file */
void loadWaypoints();
/** @brief Transmit the local waypoint list to the UAS */
void transmit();
/** @brief Read the remote waypoint list */
void read();
/** @brief Add a waypoint */
void add();
/** @brief Add a waypoint at the current MAV position */
void addCurrentPositonWaypoint();
void moveUp(Waypoint* wp);
void moveDown(Waypoint* wp);
//Update events
/** @brief sets statusLabel string */
void updateStatusLabel(const QString &string);
void changeCurrentWaypoint(quint16 seq); ///< The user wants to change the current waypoint
void currentWaypointChanged(quint16 seq); ///< The waypoint planner changed the current waypoint
void waypointListChanged(void); ///< The waypoint manager informs that the waypoint list was changed
/** @brief The user wants to change the current waypoint */
void changeCurrentWaypoint(quint16 seq);
/** @brief The waypoint planner changed the current waypoint */
void currentWaypointChanged(quint16 seq);
/** @brief The waypoint manager informs that the waypoint list was changed */
void waypointListChanged(void);
// Waypoint operations
void moveUp(Waypoint* wp);
void moveDown(Waypoint* wp);
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);
protected:
virtual void changeEvent(QEvent *e);
......
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