forked from askubis/RESpecTa
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPose.h
240 lines (228 loc) · 7.26 KB
/
Pose.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
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
231
232
233
234
235
236
237
238
239
240
class Pose;
#ifndef POSE_H
#define POSE_H
#include "globals.h"
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <vector>
/**
* Class holding parameters of one Pose in the movement by robot.
*/
class Pose
{
public:
Pose(){}
Pose(const Pose& other)
{
for(unsigned int i=0; i<other.a.size();i++)
{
this->a.push_back(other.a[i]);
this->v.push_back(other.v[i]);
this->coordinates.push_back(other.coordinates[i]);
}
}
std::vector<double> getA(){return a;}
void setA(std::vector<double> newA){a=newA;}
std::vector<double> getV(){return v;}
void setV(std::vector<double> newV){v=newV;}
std::vector<double> getC(){return coordinates;}
void setC(std::vector<double> newC){coordinates=newC;}
/**
* Creates a string describing the coordinates attributes.
* @returns String with the description of the Pose
*/
std::string Print()
{
unsigned int i=0;
std::string x;
char w[12];
std::vector<double> tmp = a;
x+="\nPOSE:";
x+="\nAccelerations: ";
for ( i=0;i<tmp.size();i++)
{
sprintf(w, "%lf", tmp[i]);
x+=w;
x+=" ";
}
tmp = v;
x+="\nVelocities: ";
for (i=0;i<tmp.size();i++)
{
sprintf(w, "%lf", tmp[i]);
x+=w;
x+=" ";
}
tmp = coordinates;
x+="\nCoords: ";
for (i=0;i<tmp.size();i++)
{
sprintf(w, "%lf", tmp[i]);
x+=w;
x+=" ";
}
return x;
}
/**
* Writes the data of the state to the XML stream.
* @param writer Stream to which the data is written
*/
void Print(QXmlStreamWriter * writer)
{
unsigned int i;
char w[12];
std::string x;
writer->writeStartElement("Pose");
std::vector<double> tmp = a;
for (i=0;i<tmp.size();i++)
{
sprintf(w, "%lf", tmp[i]);
x+=w;
x+=" ";
}
writer->writeTextElement("Accelerations", QString().fromStdString(x));
x.clear();
tmp = v;
for (i=0;i<tmp.size();i++)
{
sprintf(w, "%lf", tmp[i]);
x+=w;
x+=" ";
}
writer->writeTextElement("Velocities", QString().fromStdString(x));
x.clear();
tmp = coordinates;
for (i=0;i<tmp.size();i++)
{
sprintf(w, "%lf", tmp[i]);
x+=w;
x+=" ";
}
writer->writeTextElement("Coordinates", QString().fromStdString(x));
writer->writeEndElement();
}
/**
* Loads from XML Stream the data and passes it to the Poses(if any).
* @param reader Stream from which the data is read
* @returns List of errors, which occured while loading
*/
QStringList LoadFromXML(QXmlStreamReader * reader)
{
QStringList errors;
bool wasA=false;
bool wasC=false;
bool wasV=false;
while (!reader->atEnd())
{
//get coordinateType and motionType
reader->readNextStartElement();
if(reader->name().toString()=="Pose"&&reader->isEndElement())
{
if(!wasA||!wasV||!wasC)
{
char linenum[30];
sprintf(linenum,"; line: %lld", reader->lineNumber());
errors.push_back(QString("no A, C or V in this pose")+=linenum);
}
if(a.size()!=v.size()||a.size()!=coordinates.size())
{
char linenum[30];
sprintf(linenum,"; line: %lld", reader->lineNumber());
errors.push_back(QString("a, c and v vectors are not of the same length")+=linenum);
}
return errors;
}
else if (reader->name()=="Accelerations"&&reader->isStartElement())
{
if(wasA)
{
char linenum[30];
sprintf(linenum,"; line: %lld", reader->lineNumber());
errors.push_back(QString("the accelerations were twice defined")+=linenum);
}
else
{
wasA=true;
QString tmpString = reader->readElementText();
QStringList strList = tmpString.split(QRegExp("\\s+"), QString::SkipEmptyParts);
foreach(QString str, strList)
{
a.push_back(str.toDouble());
}
}
}
else if (reader->name()=="Velocity"&&reader->isStartElement())
{
if(wasV)
{
char linenum[30];
sprintf(linenum,"; line: %lld", reader->lineNumber());
errors.push_back(QString("the velocities were twice defined")+=linenum);
}
else
{
wasV=true;
QString tmpString = reader->readElementText();
QStringList strList = tmpString.split(QRegExp("\\s+"), QString::SkipEmptyParts);
foreach(QString str, strList)
{
v.push_back(str.toDouble());
}
}
}
else if (reader->name()=="Coordinates"&&reader->isStartElement())
{
if(wasC)
{
char linenum[30];
sprintf(linenum,"; line: %lld", reader->lineNumber());
errors.push_back(QString("the Coordinates were twice defined")+=linenum);
}
else
{
wasC=true;
QString tmpString = reader->readElementText();
QStringList strList = tmpString.split(QRegExp("\\s+"),QString::SkipEmptyParts);
foreach(QString str, strList)
{
coordinates.push_back(str.toDouble());
}
}
}
else if (reader->isStartElement())
{
char linenum[30];
sprintf(linenum,"; line: %lld", reader->lineNumber());
errors.push_back((QString("unexpected name while reading <pose>: ")+=reader->name())+=linenum);
}
}
if(!wasA||!wasV||!wasC)
{
char linenum[30];
sprintf(linenum,"; line: %lld", reader->lineNumber());
errors.push_back(QString("no A, C or V in this pose")+=linenum);
}
if(a.size()!=v.size()||a.size()!=coordinates.size())
{
char linenum[30];
sprintf(linenum,"; line: %lld", reader->lineNumber());
errors.push_back(QString("a, c and v vectors are not of the same length")+=linenum);
}
return errors;
}
private:
/**
* Vector representing Accelerations.
*/
std::vector<double> a;
/**
* Vector representing Velocities.
*/
std::vector<double> v;
/**
* Vector representing Coordinates.
*/
std::vector<double> coordinates;
};
#endif // POSE_H