Waypoint.cc 5.28 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

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

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

pixhawk's avatar
pixhawk committed
54 55
}

56 57
void Waypoint::save(QTextStream &saveStream)
{
58 59 60 61 62 63
    QString position("%1\t%2\t%3\t%4");
    position = position.arg(x, 0, 'g', 18);
    position = position.arg(y, 0, 'g', 18);
    position = position.arg(z, 0, 'g', 18);
    position = position.arg(yaw, 0, 'g', 8);
    saveStream << this->getId() << "\t" << this->getFrame() << "\t" << this->getAction() << "\t"  << this->getOrbit() << "\t" << /*Orbit Direction*/ 0 << "\t" << this->getOrbit() << "\t" << this->getHoldTime() << "\t" << this->getCurrent() << "\t" << position  << "\t" << this->getAutoContinue() << "\r\n";
64 65 66 67 68
}

bool Waypoint::load(QTextStream &loadStream)
{
    const QStringList &wpParams = loadStream.readLine().split("\t");
69
    if (wpParams.size() == 13)
70
    {
71 72 73 74 75 76 77
        this->id = wpParams[0].toInt();
        this->frame = (MAV_FRAME) wpParams[1].toInt();
        this->action = (MAV_ACTION) wpParams[2].toInt();
        this->orbit = wpParams[3].toDouble();
        //TODO: orbit direction
        //TODO: param1
        this->holdTime = wpParams[6].toInt();
78
        this->current = (wpParams[7].toInt() == 1 ? true : false);
79 80 81 82 83
        this->x = wpParams[8].toDouble();
        this->y = wpParams[9].toDouble();
        this->z = wpParams[10].toDouble();
        this->yaw = wpParams[11].toDouble();
        this->autocontinue = (wpParams[12].toInt() == 1 ? true : false);
84 85 86 87 88
        return true;
    }
    return false;
}

89

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

pixhawk's avatar
pixhawk committed
97
void Waypoint::setX(double x)
pixhawk's avatar
pixhawk committed
98
{
99 100 101 102 103
    if (this->x != x)
    {
        this->x = x;
        emit changed(this);
    }
pixhawk's avatar
pixhawk committed
104 105
}

pixhawk's avatar
pixhawk committed
106
void Waypoint::setY(double y)
pixhawk's avatar
pixhawk committed
107
{
108 109 110 111 112
    if (this->y != y)
    {
        this->y = y;
        emit changed(this);
    }
pixhawk's avatar
pixhawk committed
113 114
}

pixhawk's avatar
pixhawk committed
115
void Waypoint::setZ(double z)
pixhawk's avatar
pixhawk committed
116
{
117 118 119 120 121
    if (this->z != z)
    {
        this->z = z;
        emit changed(this);
    }
pixhawk's avatar
pixhawk committed
122 123
}

pixhawk's avatar
pixhawk committed
124
void Waypoint::setYaw(double yaw)
pixhawk's avatar
pixhawk committed
125
{
126 127 128 129 130
    if (this->yaw != yaw)
    {
        this->yaw = yaw;
        emit changed(this);
    }
pixhawk's avatar
pixhawk committed
131 132
}

133
void Waypoint::setAction(MAV_ACTION action)
James Goppert's avatar
James Goppert committed
134
{
135 136 137 138 139
    if (this->action != action)
    {
        this->action = action;
        emit changed(this);
    }
140 141 142 143
}

void Waypoint::setFrame(MAV_FRAME frame)
{
144 145 146 147 148
    if (this->frame != frame)
    {
        this->frame = frame;
        emit changed(this);
    }
James Goppert's avatar
James Goppert committed
149 150
}

pixhawk's avatar
pixhawk committed
151 152
void Waypoint::setAutocontinue(bool autoContinue)
{
153 154 155 156 157
    if (this->autocontinue != autocontinue)
    {
        this->autocontinue = autoContinue;
        emit changed(this);
    }
pixhawk's avatar
pixhawk committed
158 159 160 161
}

void Waypoint::setCurrent(bool current)
{
162 163 164 165 166
    if (this->current != current)
    {
        this->current = current;
        emit changed(this);
    }
pixhawk's avatar
pixhawk committed
167
}
168

pixhawk's avatar
pixhawk committed
169
void Waypoint::setOrbit(double orbit)
pixhawk's avatar
pixhawk committed
170
{
171 172 173 174 175
    if (this->orbit != orbit)
    {
        this->orbit = orbit;
        emit changed(this);
    }
pixhawk's avatar
pixhawk committed
176 177 178 179
}

void Waypoint::setHoldTime(int holdTime)
{
180 181 182 183 184
    if (this->holdTime != holdTime)
    {
        this->holdTime = holdTime;
        emit changed(this);
    }
pixhawk's avatar
pixhawk committed
185 186
}

pixhawk's avatar
pixhawk committed
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230
//void Waypoint::setX(double x)
//{
//    if (this->x != static_cast<double>(x))
//    {
//        this->x = x;
//        emit changed(this);
//    }
//}

//void Waypoint::setY(double y)
//{
//    if (this->y != static_cast<double>(y))
//    {
//        this->y = y;
//        emit changed(this);
//    }
//}

//void Waypoint::setZ(double z)
//{
//    if (this->z != static_cast<double>(z))
//    {
//        this->z = z;
//        emit changed(this);
//    }
//}

//void Waypoint::setYaw(double yaw)
//{
//    if (this->yaw != static_cast<double>(yaw))
//    {
//        this->yaw = yaw;
//        emit changed(this);
//    }
//}

//void Waypoint::setOrbit(double orbit)
//{
//    if (this->orbit != static_cast<double>(orbit))
//    {
//        this->orbit = orbit;
//        emit changed(this);
//    }
//}