-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrobot.h
More file actions
373 lines (349 loc) · 9.55 KB
/
robot.h
File metadata and controls
373 lines (349 loc) · 9.55 KB
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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
#ifndef ROBOT_H
#define ROBOT_H
#include <QVector>
#include "qcurvedatacus.h"
#include <qmutex.h>
#include "qHostAddress.h"
class QwtPointCus;
class QCurveDataCus;
class RobotPoint
{
public:
double x;
double y;
double phi;
public:
RobotPoint()
{
}
RobotPoint(double px,double py)
{
x=px;
y=py;
phi=0;
}
RobotPoint(double px,double py, double ph)
{
x=px;
y=py;
phi=ph;
}
public:
RobotPoint& operator =(const RobotPoint& a)
{
this->x=a.x;
this->y=a.y;
this->phi=a.phi;
return *this;
}
RobotPoint operator +(const RobotPoint& a)
{
RobotPoint ret;
ret.x = this->x + a.x * cos(this->phi) - a.y * sin(this->phi);
ret.y = this->y + a.x * sin(this->phi) + a.y * cos(this->phi);
ret.phi = a.phi + this->phi;
return ret;
}
/*
TPose2D TPose2D_Add(const TPose2D a,const TPose2D b)
{
TPose2D ret;
//ret.x = a.x + b.x * cos(a.phi) - b.y * sin(a.phi);
//ret.y = a.y + b.x * sin(a.phi) + b.y * cos(a.phi);
ret.x = a.x + b.x * m_cos(a.phi) - b.y * m_sin(a.phi);
ret.y = a.y + b.x * m_sin(a.phi) + b.y * m_cos(a.phi);
ret.phi = a.phi + b.phi;
//ret.phi = radAdd(a.phi,b.phi);
return ret;
}*/
};
class RobotDestPoint
{
public:
RobotPoint point;
int id;
public:
inline int getId() const
{
return id;
}
inline void setId(int a)
{
id=a;
}
};
class RobotPathPoint
{
public:
enum {SIZE = 10};
RobotPoint point;
int id;
int mainPathId;
int d_net[SIZE];
int d_robotId;
public:
RobotPathPoint()
{
this->point.x=0;
this->point.y=0;
this->point.phi=0;
this->id=0;
this->mainPathId=0;
this->d_robotId=0;
for(int i=0;i<SIZE;i++)
{
this->d_net[i]=0;
}
}
RobotPathPoint& operator =(const RobotPathPoint& a)
{
this->point=a.point;
this->id=a.id;
this->mainPathId=a.mainPathId;
this->d_robotId=a.d_robotId;
for(int i=0;i<SIZE;i++)
{
this->d_net[i]=a.d_net[i];
}
return *this;
}
RobotPathPoint& operator =(const QwtPointCus& a)
{
this->point.x=a.x();
this->point.y=a.y();
this->point.phi=a.phi();
this->id=a.id();
this->mainPathId=a.id();
this->d_robotId=0;
for(int i=0;i<SIZE;i++)
{
this->d_net[i]=a.net(i);
}
return *this;
}
RobotPathPoint( const QwtPointCus a)
{
this->point.x=a.x();
this->point.y=a.y();
this->point.phi=a.phi();
this->id=a.id();
this->mainPathId=a.id();
this->d_robotId=0;
for(int i=0;i<SIZE;i++)
{
this->d_net[i]=a.net(i);
}
}
//! \return The z-coordinate of the point.
inline int netSize() const
{
return SIZE;
}
//! \return The z-coordinate of the point.
inline int net(int n) const
{
if(n<SIZE)
return d_net[n];
}
//! \return The z-coordinate of the point.
inline int &rnet(int n)
{
if(n>SIZE-1)
{
n=SIZE-1;
}
return d_net[n];
}
//! Sets the z-coordinate of the point to the value specified by z.
inline void setNet( int n,int net )
{
if(n<SIZE)
{
d_net[n] = net;
}
}
//! \return The id the point.
inline int mpid() const
{
return mainPathId;
}
//! \return The x-coordinate of the point.
inline double x() const
{
return point.x;
}
//! \return The y-coordinate of the point.
inline double y() const
{
return point.y;
}
//! \return The z-coordinate of the point.
inline int getRobotId() const
{
return d_robotId;
}
//! \return The z-coordinate of the point.
inline void setRobotId(int a)
{
d_robotId=a;
}
};
class RobotPath
{
public:
enum RobotState{AtStartPoint=0,AtDestPoint,GoToDestPoint,GoToStartPoint};
enum RobotType{Guide=0,Waiter};
QHostAddress ip;
//robot id
int robotId;
//path
QVector<RobotPathPoint> point;
int id;
int num;
//state
RobotPoint curPose;
int pathIdToGo;
RobotState robotState;
RobotType robotType;
double leftSpeed;
double rightSpeed;
int robotControl;//
int updateTime;
////////////////////
RobotPath& operator =(RobotPath a)
{
for(int i=0;i<a.point.size();i++)
{
this->point.append(a.point.at(i));
}
this->id=a.id;
this->num=a.num;
this->robotId=a.robotId;
this->curPose=a.curPose;
this->pathIdToGo=a.pathIdToGo;
this->robotState=a.robotState;
this->robotType=a.robotType;
this->leftSpeed=a.leftSpeed;
this->rightSpeed=a.rightSpeed;
this->robotControl=a.robotControl;
this->updateTime=a.updateTime;
////////////////////
return *this;
}
QVector<RobotPathPoint> getNearPointById(int id);
QVector<RobotPathPoint> getNearPointById();
QVector<int> getNearPointIdById();
QVector<int> getNearPointIdById(int id);
int getPointNumToLastById();
};
class RobotMainPath
{
public:
QVector<RobotPathPoint> point;
RobotMainPath& operator =(const RobotMainPath& a)
{
for(int i=0;i<a.point.size();i++)
{
this->point.append(a.point.at(i));
}
return *this;
}
};
class RobotState
{
public:
};
class Robot: public QObject
{
public:
#define MAX_MAIN_PATH_ID (9999)
#define MIN_DIS_TWO_PATH (0.6)
#define MIN_DIS_ROBOT_NEED_CHECK (3.0)
#define NEXT_PATH_NEED_CHECK (3)
#define MIN_DIS_ROBOT_COLLIDE (0.8)
#define MAX_DIS (1000.0)
#define PI_M (3.1415926535897932384626)
#define PI_M_2 (M_PI/2)
Robot();
int insertPathPoint(QHostAddress address,int robotId,int pathId,RobotPoint point,int maxPointNum,int pointId);
int insertPathPoint(QHostAddress address,int robotId,int pathId,int mainPathId,int maxPointNum,int pointId);
//QVector<RobotPath> *getPathVector();
int getPathNum();
int getPathPointNum(int index);
int getPathPointNumMax(int index);
int getPathIdByIndex(int index);
int getPathRobotIdByIndex(int index);
int findPathIndexById(int robotId,int id,int &index);
const QVector<RobotPath> getPath();
int insertPathPointByIndex(int index,RobotPoint point,int maxPointNum,int pointId);
int insertPathPointFrommainPathIdByIndex(int index,RobotPoint point,int mainPathId,int maxPointNum,int pointId);
QStringList pathToString(int index);
void clearPath(int index);
void initMainPath();
//QVector<RobotPathPoint>* getMainPathHandle();
void clearMainPath();
void insertMainPath(RobotPathPoint rp);
void loadData(QCurveDataCus *data,QwtPointCus::PointStyle type);
QStringList mainPathToString();
int getMainPathNum();
int deletePath(int robotId);
bool erasePathByIndex(int index);
RobotPath getPathByIndex(int index);
bool findRobotId(int robotId, int &index);
int insertRobotState(QHostAddress address,int robotId,int pathId,RobotPoint point,double left,double right,int goMainPathId,int robotState,int robotType,int time);
bool insertRobotStateByIndex(int index,RobotPoint point,double left,double right,int goMainPathId,int robotState,int robotType,int time);
QString robotStateToString(int index);
double estimateMinDis(RobotPoint a,RobotPoint b);
double calcuMinDisWithTwoPath(int indexA,int indexB);
void pathControl();
QVector<int>& getRobotControl();
bool calcuNearIndex(int indexA,int indexB,int &nearIndex);
bool dirIdentical(RobotPoint pa,RobotPoint pb);
bool controlRun(int indexA,int indexB,int& ctrlA,int &ctrlB);
QString getMsg();
int frontRobot(RobotPoint pa,RobotPoint pb);
QVector<RobotPoint> getPose(int n);
void estimateRobotPose(int num);
void computeFromEncoder(RobotPoint &out_incr_odom,
double left,
double right);
bool getMainPathPointById(int id ,RobotPoint &p);
void resetControlValue();
void updateControlNum();
void setRobotControl(int i,int val);
bool getMainPathMainIdByPoint(RobotPoint p, int &id);
void setPathRobotIdById(int id,int robotId);
int getPathRobotIdById(int id);
int getMainPathRobotIdByIndex(int index);
bool getPathById(int robotId,RobotPath&rp);
void resetAllPathRobotId(int robotId);
int getRobotControl(int i);
int findPathIndexById(int robotId);
bool checkMovableById(int robotId);
bool checkMovableByIndex(int index);
QVector<QVector<RobotPathPoint>> getPose();
void estimateRobotPose();
bool getDestPointById(int id ,RobotPoint &p);
int insertPathPointList(QHostAddress address,int robotId,int pathId,QVector<int> pointIdList,int time);
bool findIpByRobotId(int robotId, QHostAddress &address);
public:
void clearDest();
void insertDest(RobotDestPoint rp);
QStringList destToString();
int getDestNum();
int getPathPointTime(int index);
bool findRobotPathIndexById(int pathId ,int &index);
int getPathToGoIndex(int index);
QHostAddress getPathIpByIndex(int index);
private:
QVector<RobotPath> path;
QVector<RobotPathPoint> mainPath;
QMutex mutex;
QVector<int>robotControl;
QString robotMsg;
QVector<RobotPoint> vectorPoseA;
QVector<RobotPoint> vectorPoseB;
QVector<QVector<RobotPathPoint>> vectorPose;
QVector<RobotDestPoint> dest;
};
#endif // ROBOT_H