Waypoint.cc 7.01 KB
Newer Older
1
/*===================================================================
pixhawk's avatar
pixhawk committed
2
QGroundControl Open Source Ground Control Station
pixhawk's avatar
pixhawk committed
3

pixhawk's avatar
pixhawk committed
4
(c) 2009, 2010 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
pixhawk's avatar
pixhawk committed
5

pixhawk's avatar
pixhawk committed
6
This file is part of the QGROUNDCONTROL project
pixhawk's avatar
pixhawk committed
7

pixhawk's avatar
pixhawk committed
8
    QGROUNDCONTROL is free software: you can redistribute it and/or modify
pixhawk's avatar
pixhawk committed
9 10 11
    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.
pixhawk's avatar
pixhawk committed
12

pixhawk's avatar
pixhawk committed
13
    QGROUNDCONTROL is distributed in the hope that it will be useful,
pixhawk's avatar
pixhawk committed
14 15 16
    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.
pixhawk's avatar
pixhawk committed
17

pixhawk's avatar
pixhawk committed
18
    You should have received a copy of the GNU General Public License
pixhawk's avatar
pixhawk committed
19
    along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.
pixhawk's avatar
pixhawk committed
20

pixhawk's avatar
pixhawk committed
21 22 23 24 25 26 27
======================================================================*/

/**
 * @file
 *   @brief Waypoint class
 *
 *   @author Benjamin Knecht <mavteam@student.ethz.ch>
28
 *   @author Petri Tanskanen <mavteam@student.ethz.ch>
pixhawk's avatar
pixhawk committed
29 30 31 32
 *
 */

#include "Waypoint.h"
33
#include <QStringList>
pixhawk's avatar
pixhawk committed
34

lm's avatar
lm committed
35 36
Waypoint::Waypoint(quint16 _id, double _x, double _y, double _z, double _param1, double _param2, double _param3, double _param4,
                            bool _autocontinue, bool _current, MAV_FRAME _frame, MAV_CMD _action)
37 38 39 40
    : id(_id),
    x(_x),
    y(_y),
    z(_z),
lm's avatar
lm committed
41
    yaw(_param4),
42 43 44 45
    frame(_frame),
    action(_action),
    autocontinue(_autocontinue),
    current(_current),
lm's avatar
lm committed
46 47 48
    orbit(_param3),
    param1(_param1),
    param2(_param2),
49
    name(QString("WP%1").arg(id, 2, 10, QChar('0')))
pixhawk's avatar
pixhawk committed
50 51 52 53 54
{
}

Waypoint::~Waypoint()
{
pixhawk's avatar
pixhawk committed
55

pixhawk's avatar
pixhawk committed
56 57
}

58 59
void Waypoint::save(QTextStream &saveStream)
{
lm's avatar
lm committed
60
    QString position("%1\t%2\t%3");
61 62 63
    position = position.arg(x, 0, 'g', 18);
    position = position.arg(y, 0, 'g', 18);
    position = position.arg(z, 0, 'g', 18);
lm's avatar
lm committed
64
    QString parameters("%1\t%2\t%3\t%4");
lm's avatar
lm committed
65 66 67 68
    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";
69 70 71 72 73
}

bool Waypoint::load(QTextStream &loadStream)
{
    const QStringList &wpParams = loadStream.readLine().split("\t");
lm's avatar
lm committed
74
    if (wpParams.size() == 12)
75
    {
76
        this->id = wpParams[0].toInt();
lm's avatar
lm committed
77 78 79 80 81 82 83
        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();
84 85 86
        this->x = wpParams[8].toDouble();
        this->y = wpParams[9].toDouble();
        this->z = wpParams[10].toDouble();
lm's avatar
lm committed
87
        this->autocontinue = (wpParams[11].toInt() == 1 ? true : false);
88 89 90 91 92
        return true;
    }
    return false;
}

93

94
void Waypoint::setId(quint16 id)
pixhawk's avatar
pixhawk committed
95
{
96
    this->id = id;
97 98
    this->name = QString("WP%1").arg(id, 2, 10, QChar('0'));
    emit changed(this);
pixhawk's avatar
pixhawk committed
99 100
}

pixhawk's avatar
pixhawk committed
101
void Waypoint::setX(double x)
pixhawk's avatar
pixhawk committed
102
{
103 104 105 106 107
    if (this->x != x)
    {
        this->x = x;
        emit changed(this);
    }
pixhawk's avatar
pixhawk committed
108 109
}

pixhawk's avatar
pixhawk committed
110
void Waypoint::setY(double y)
pixhawk's avatar
pixhawk committed
111
{
112 113 114 115 116
    if (this->y != y)
    {
        this->y = y;
        emit changed(this);
    }
pixhawk's avatar
pixhawk committed
117 118
}

pixhawk's avatar
pixhawk committed
119
void Waypoint::setZ(double z)
pixhawk's avatar
pixhawk committed
120
{
121 122 123 124 125
    if (this->z != z)
    {
        this->z = z;
        emit changed(this);
    }
pixhawk's avatar
pixhawk committed
126 127
}

128 129 130 131 132
void Waypoint::setLatitude(double lat)
{
    if (this->x != lat)
    {
        this->x = lat;
133
        this->frame = MAV_FRAME_GLOBAL;
134 135 136 137 138 139 140 141 142
        emit changed(this);
    }
}

void Waypoint::setLongitude(double lon)
{
    if (this->y != lon)
    {
        this->y = lon;
143
        this->frame = MAV_FRAME_GLOBAL;
144 145 146 147 148 149 150 151 152
        emit changed(this);
    }
}

void Waypoint::setAltitude(double altitude)
{
    if (this->z != altitude)
    {
        this->z = altitude;
153
        this->frame = MAV_FRAME_GLOBAL;
154 155 156 157
        emit changed(this);
    }
}

lm's avatar
lm committed
158 159 160 161 162 163 164 165 166
void Waypoint::setYaw(int yaw)
{
    if (this->yaw != yaw)
    {
        this->yaw = yaw;
        emit changed(this);
    }
}

pixhawk's avatar
pixhawk committed
167
void Waypoint::setYaw(double yaw)
pixhawk's avatar
pixhawk committed
168
{
169 170 171 172 173
    if (this->yaw != yaw)
    {
        this->yaw = yaw;
        emit changed(this);
    }
pixhawk's avatar
pixhawk committed
174 175
}

176 177
void Waypoint::setAction(int action)
{
178
    if (this->action != (MAV_CMD)action)
179
    {
180
        this->action = (MAV_CMD)action;
181 182 183 184
        emit changed(this);
    }
}

185
void Waypoint::setAction(MAV_CMD action)
James Goppert's avatar
James Goppert committed
186
{
187 188 189 190 191
    if (this->action != action)
    {
        this->action = action;
        emit changed(this);
    }
192 193 194 195
}

void Waypoint::setFrame(MAV_FRAME frame)
{
196 197 198 199 200
    if (this->frame != frame)
    {
        this->frame = frame;
        emit changed(this);
    }
James Goppert's avatar
James Goppert committed
201 202
}

pixhawk's avatar
pixhawk committed
203 204
void Waypoint::setAutocontinue(bool autoContinue)
{
205 206 207 208 209
    if (this->autocontinue != autocontinue)
    {
        this->autocontinue = autoContinue;
        emit changed(this);
    }
pixhawk's avatar
pixhawk committed
210 211 212 213
}

void Waypoint::setCurrent(bool current)
{
214 215 216 217 218
    if (this->current != current)
    {
        this->current = current;
        emit changed(this);
    }
pixhawk's avatar
pixhawk committed
219
}
220

221 222
void Waypoint::setAcceptanceRadius(double radius)
{
223
    if (this->param2 != radius)
224
    {
225
        this->param2 = radius;
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249
        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)
{
250
    if (this->orbit != param3)
251
    {
252
        this->orbit = param3;
253 254 255 256 257 258
        emit changed(this);
    }
}

void Waypoint::setParam4(double param4)
{
lm's avatar
lm committed
259
    if (this->yaw != param4)
260
    {
lm's avatar
lm committed
261
        this->yaw = param4;
262 263 264 265 266 267
        emit changed(this);
    }
}

void Waypoint::setParam5(double param5)
{
lm's avatar
lm committed
268
    if (this->x != param5)
269
    {
lm's avatar
lm committed
270
        this->x = param5;
271 272 273 274 275 276 277 278 279
        emit changed(this);
    }
}

void Waypoint::setParam6(double param6)
{
    if (this->z != param6)
    {
        this->z = param6;
280 281 282 283
        emit changed(this);
    }
}

lm's avatar
lm committed
284 285 286 287 288 289 290 291 292
void Waypoint::setParam7(double param7)
{
    if (this->z != param7)
    {
        this->z = param7;
        emit changed(this);
    }
}

293
void Waypoint::setLoiterOrbit(double orbit)
pixhawk's avatar
pixhawk committed
294
{
295 296 297 298 299
    if (this->orbit != orbit)
    {
        this->orbit = orbit;
        emit changed(this);
    }
pixhawk's avatar
pixhawk committed
300 301 302 303
}

void Waypoint::setHoldTime(int holdTime)
{
304
    if (this->param1 != holdTime)
305
    {
306
        this->param1 = holdTime;
307 308 309 310
        emit changed(this);
    }
}

lm's avatar
lm committed
311 312 313 314 315 316 317 318 319
void Waypoint::setHoldTime(double holdTime)
{
    if (this->param1 != holdTime)
    {
        this->param1 = holdTime;
        emit changed(this);
    }
}

320 321 322
void Waypoint::setTurns(int turns)
{
    if (this->param1 != turns)
323
    {
324
        this->param1 = turns;
325 326
        emit changed(this);
    }
pixhawk's avatar
pixhawk committed
327
}