Newer
Older
/*===================================================================
(c) 2009, 2010 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
QGROUNDCONTROL is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
QGROUNDCONTROL is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.
======================================================================*/
/**
* @file
* @brief Waypoint class
*
* @author Benjamin Knecht <mavteam@student.ethz.ch>
* @author Petri Tanskanen <mavteam@student.ethz.ch>
#include <QStringList>
Waypoint::Waypoint(quint16 _id, double _x, double _y, double _z, double _yaw, bool _autocontinue, bool _current, double _orbit, int _holdTime, MAV_FRAME _frame, MAV_CMD _action)
: id(_id),
x(_x),
y(_y),
z(_z),
yaw(_yaw),
frame(_frame),
action(_action),
autocontinue(_autocontinue),
current(_current),
orbit(0),
param1(_orbit),
param2(_holdTime),
name(QString("WP%1").arg(id, 2, 10, QChar('0')))
void Waypoint::save(QTextStream &saveStream)
{
position = position.arg(x, 0, 'g', 18);
position = position.arg(y, 0, 'g', 18);
position = position.arg(z, 0, 'g', 18);
parameters = parameters.arg(param1, 0, 'g', 18).arg(param2, 0, 'g', 18).arg(orbit, 0, 'g', 18).arg(yaw, 0, 'g', 18);
// FORMAT: <INDEX> <CURRENT WP> <COORD FRAME> <COMMAND> <PARAM1> <PARAM2> <PARAM3> <PARAM4> <PARAM5/X/LONGITUDE> <PARAM6/Y/LATITUDE> <PARAM7/Z/ALTITUDE> <AUTOCONTINUE>
// as documented here: http://qgroundcontrol.org/waypoint_protocol
saveStream << this->getId() << "\t" << this->getCurrent() << "\t" << this->getFrame() << "\t" << this->getAction() << "\t" << parameters << "\t" << position << "\t" << this->getAutoContinue() << "\r\n";
}
bool Waypoint::load(QTextStream &loadStream)
{
const QStringList &wpParams = loadStream.readLine().split("\t");
this->id = wpParams[0].toInt();
this->current = (wpParams[1].toInt() == 1 ? true : false);
this->frame = (MAV_FRAME) wpParams[2].toInt();
this->action = (MAV_CMD) wpParams[3].toInt();
this->param1 = wpParams[4].toDouble();
this->param2 = wpParams[5].toDouble();
this->orbit = wpParams[6].toDouble();
this->yaw = wpParams[7].toDouble();
this->x = wpParams[8].toDouble();
this->y = wpParams[9].toDouble();
this->z = wpParams[10].toDouble();
return true;
}
return false;
}
this->name = QString("WP%1").arg(id, 2, 10, QChar('0'));
emit changed(this);
if (this->x != x)
{
this->x = x;
emit changed(this);
}
if (this->y != y)
{
this->y = y;
emit changed(this);
}
if (this->z != z)
{
this->z = z;
emit changed(this);
}
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
void Waypoint::setLatitude(double lat)
{
if (this->x != lat)
{
this->x = lat;
emit changed(this);
}
}
void Waypoint::setLongitude(double lon)
{
if (this->y != lon)
{
this->y = lon;
emit changed(this);
}
}
void Waypoint::setAltitude(double altitude)
{
if (this->z != altitude)
{
this->z = altitude;
emit changed(this);
}
}
if (this->yaw != yaw)
{
this->yaw = yaw;
emit changed(this);
}
void Waypoint::setAction(int action)
{
emit changed(this);
}
}
if (this->action != action)
{
this->action = action;
emit changed(this);
}
}
void Waypoint::setFrame(MAV_FRAME frame)
{
if (this->frame != frame)
{
this->frame = frame;
emit changed(this);
}
if (this->autocontinue != autocontinue)
{
this->autocontinue = autoContinue;
emit changed(this);
}
if (this->current != current)
{
this->current = current;
emit changed(this);
}
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
void Waypoint::setAcceptanceRadius(double radius)
{
if (this->param1 != radius)
{
this->param1 = radius;
emit changed(this);
}
}
void Waypoint::setParam1(double param1)
{
if (this->param1 != param1)
{
this->param1 = param1;
emit changed(this);
}
}
void Waypoint::setParam2(double param2)
{
if (this->param2 != param2)
{
this->param2 = param2;
emit changed(this);
}
}
void Waypoint::setParam3(double param3)
{
if (this->orbit != param3)
this->orbit = param3;
emit changed(this);
}
}
void Waypoint::setParam4(double param4)
{
emit changed(this);
}
}
void Waypoint::setParam5(double param5)
{
{
emit changed(this);
}
}
void Waypoint::setParam6(double param6)
{
if (this->z != param6)
{
this->z = param6;
emit changed(this);
}
}
void Waypoint::setParam7(double param7)
{
if (this->z != param7)
{
this->z = param7;
emit changed(this);
}
}
void Waypoint::setLoiterOrbit(double orbit)
if (this->orbit != orbit)
{
this->orbit = orbit;
emit changed(this);
}
}
void Waypoint::setHoldTime(int holdTime)
{
if (this->param2 != holdTime)
{
this->param2 = holdTime;
emit changed(this);
}
}
void Waypoint::setTurns(int turns)
{
if (this->param1 != turns)
this->param1 = turns;