CommunicationWithACS.c
13.6 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
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
#include "CommunicationWithACS.h"
TrafficLandMarks1 traffic_land_marksSys,traffic_land_marksReal;
u8 DataFromACS[2000],DataToACS[200];
u8 runModeAnalysis()
{
CoordinatePoints firstPoint,secondPoint;
float lineAngle = 0;
u8 lineDir = 0;
u8 runMode = 0;
firstPoint.TarX = (float)traffic_land_marksReal.land_marks[0].pose[0];
firstPoint.TarY = (float)traffic_land_marksReal.land_marks[0].pose[1];
secondPoint.TarX = (float)traffic_land_marksReal.land_marks[1].pose[0];
secondPoint.TarY = (float)traffic_land_marksReal.land_marks[1].pose[1];
lineAngle = CalculatingDirectionAngle(firstPoint,secondPoint);//得到线路角度
lineDir = CalculateCurHeadDir(lineAngle*57.3);
if(traffic_land_marksReal.land_marks[0].headDir == lineDir)//车头与线路偏差不超过,认为是前进
{
runMode = 1;
}
else
runMode = 2;
}
void receiveNewTask()
{
float x1,y1,x2,y2,angle1;
u8 runDir = 0;//前进为1,后退为8
traffic_land_marksReal.lastSize = 0;
memset(&traffic_land_marksReal,0,sizeof(traffic_land_marksReal));
memcpy(&traffic_land_marksReal,&traffic_land_marksSys,sizeof(traffic_land_marksSys));
if(traffic_land_marksReal.lastSize > 1)
{
x1 = traffic_land_marksReal.land_marks[0].pose[0];
y1 = traffic_land_marksReal.land_marks[0].pose[1];
x2 = traffic_land_marksReal.land_marks[1].pose[0];
y2 = traffic_land_marksReal.land_marks[1].pose[1];
angle1 = CalculatingDirectionAngle2(x1,y1,x2,y2);
if(fabs(fabs(CurrentCenterPoint.CurAngle) - fabs(angle1)) < 0.3) runDir = 1;
else runDir = 8;
if(traffic_land_marksReal.land_marks[0].actionType != runDir)
SetAlarm(0x0080);
}
}
void continueTask()
{
u8 receiveSig = 0,receiveIndex = 0;
traffic_land_marksReal.lastSize = traffic_land_marksReal.size;
for(u8 i = 0;i < traffic_land_marksSys.size;i++)
{
if(traffic_land_marksReal.land_marks[traffic_land_marksReal.size - 1].LandMarkID == traffic_land_marksSys.land_marks[i].LandMarkID)
{
receiveSig = 1;
receiveIndex = i+1;
break;
}
}
for(u8 j = receiveIndex;j < traffic_land_marksSys.size;j++)
{
memcpy(&traffic_land_marksReal.land_marks[traffic_land_marksReal.size++],&traffic_land_marksSys.land_marks[j],sizeof(traffic_land_marksSys.land_marks[j]));
}
}
void setLandDirection()
{
float x1,y1,x2,y2,x3,y3;
float angle1 = 0,angle2 = 0,angleDiff = 0;
u8 num = 0;
if(traffic_land_marksReal.size == 1)
{
traffic_land_marksReal.land_marks[0].Direction = 0;
}
else if(traffic_land_marksReal.size == 2)
{
x1 = traffic_land_marksReal.land_marks[0].pose[0];
y1 = traffic_land_marksReal.land_marks[0].pose[1];
x2 = traffic_land_marksReal.land_marks[1].pose[0];
y2 = traffic_land_marksReal.land_marks[1].pose[1];
if(traffic_land_marksReal.land_marks[0].actionType == 1)//前进行走
{
traffic_land_marksReal.land_marks[0].Direction = 1;
traffic_land_marksReal.land_marks[1].Direction = 0;
}
else if(traffic_land_marksReal.land_marks[0].actionType == 8)
{
if(traffic_land_marksReal.land_marks[0].LandMarkID == 2236)
{
angle2 = CalculatingDirectionAngle2(x2,y2,x1,y1);//求反向目标角度
angleDiff = CalculatingCurrentAndTargetAngle(CurrentCenterPoint.CurAngle, angle2);
if(angleDiff < -0.3)//偏右小于0,左转
traffic_land_marksReal.land_marks[0].Direction = 5;
else if(angleDiff > 0.3)//偏左大于0,右转
traffic_land_marksReal.land_marks[0].Direction = 6;
else
traffic_land_marksReal.land_marks[0].Direction = 2;
traffic_land_marksReal.land_marks[1].Direction = 0;
}
else
{
traffic_land_marksReal.land_marks[0].Direction = 2;
traffic_land_marksReal.land_marks[1].Direction = 0;
}
}
}
else if(traffic_land_marksReal.size >= 3)
{
if(traffic_land_marksReal.land_marks[0].actionType == 1)//前进行走
{
traffic_land_marksReal.land_marks[0].Direction = 1;//第一个点
traffic_land_marksReal.land_marks[traffic_land_marksReal.size - 1].Direction = 0;//最后一个点
if(traffic_land_marksReal.lastSize > 1) num = traffic_land_marksReal.lastSize - 1;
else num = 1;
for(u8 i = num;i < traffic_land_marksReal.size - 1;i++)//下标0开始为第一个点,从第二个点开始,倒数第二个点结束
{
x1 = traffic_land_marksReal.land_marks[i - 1].pose[0];
y1 = traffic_land_marksReal.land_marks[i - 1].pose[1];
x2 = traffic_land_marksReal.land_marks[i].pose[0];
y2 = traffic_land_marksReal.land_marks[i].pose[1];
x3 = traffic_land_marksReal.land_marks[i + 1].pose[0];
y3 = traffic_land_marksReal.land_marks[i + 1].pose[1];
angle1 = CalculatingDirectionAngle2(x1,y1,x2,y2);
angle2 = CalculatingDirectionAngle2(x2,y2,x3,y3);
angleDiff = CalculatingCurrentAndTargetAngle(angle1, angle2);
switch(Point_Line_Pos(x3,y3,x1,y1,x2,y2))
{
case 0:
traffic_land_marksReal.land_marks[i].Direction = 1;
break;
case -1:
if(fabs(angleDiff) < 0.3) traffic_land_marksReal.land_marks[i].Direction = 1;
else
{
if(traffic_land_marksReal.land_marks[i].PointType == 13)
traffic_land_marksReal.land_marks[i].Direction = 7;
else
traffic_land_marksReal.land_marks[i].Direction = 3;
}
break;
case 1:
if(fabs(angleDiff) < 0.3) traffic_land_marksReal.land_marks[i].Direction = 1;
else
{
if(traffic_land_marksReal.land_marks[i].PointType == 13)
traffic_land_marksReal.land_marks[i].Direction = 8;
else
traffic_land_marksReal.land_marks[i].Direction = 4;
}
break;
}
}
}
else if(traffic_land_marksReal.land_marks[0].actionType == 8)//后退行走
{
traffic_land_marksReal.land_marks[0].Direction = 2;
traffic_land_marksReal.land_marks[traffic_land_marksReal.size - 1].Direction = 0;//最后一个点
if(traffic_land_marksReal.lastSize > 1) num = traffic_land_marksReal.lastSize - 1;
else num = 1;
for(u8 i = num;i < traffic_land_marksReal.size - 1;i++)//下标0开始为第一个点,从第二个点开始,倒数第二个点结束
{
x1 = traffic_land_marksReal.land_marks[i - 1].pose[0];
y1 = traffic_land_marksReal.land_marks[i - 1].pose[1];
x2 = traffic_land_marksReal.land_marks[i].pose[0];
y2 = traffic_land_marksReal.land_marks[i].pose[1];
x3 = traffic_land_marksReal.land_marks[i + 1].pose[0];
y3 = traffic_land_marksReal.land_marks[i + 1].pose[1];
angle1 = CalculatingDirectionAngle2(x1,y1,x2,y2);
angle2 = CalculatingDirectionAngle2(x2,y2,x3,y3);
angleDiff = CalculatingCurrentAndTargetAngle(angle1, angle2);
switch(Point_Line_Pos(x3,y3,x1,y1,x2,y2))
{
case 0:
traffic_land_marksReal.land_marks[i].Direction = 2;
break;
case -1:
if(fabs(angleDiff) < 0.3) traffic_land_marksReal.land_marks[i].Direction = 2;
else
{
if(traffic_land_marksReal.land_marks[i].PointType == 13)
traffic_land_marksReal.land_marks[i].Direction = 9;
else
traffic_land_marksReal.land_marks[i].Direction = 5;
}
break;
case 1:
if(fabs(angleDiff) < 0.3) traffic_land_marksReal.land_marks[i].Direction = 2;
else
{
if(traffic_land_marksReal.land_marks[i].PointType == 13)
traffic_land_marksReal.land_marks[i].Direction = 10;
else
traffic_land_marksReal.land_marks[i].Direction = 6;
}
break;
}
}
}
}
}
void DataProcessFromACS()
{
agv.Public.finishStatus = 0;
memcpy(&traffic_land_marksSys.dataLenth,DataFromACS,1);
memcpy(&traffic_land_marksSys.taskID,DataFromACS+1,4);
memcpy(&traffic_land_marksSys.clearTaskSig,DataFromACS+5,1);
memcpy(&traffic_land_marksSys.size,DataFromACS+6,1);
if(traffic_land_marksSys.size > 1)
Reset_Alarm(0x0240);
//五个地标信息
for(u8 i = 0;i < traffic_land_marksSys.size;i++)
{
memcpy(&traffic_land_marksSys.land_marks[i].LandMarkID,DataFromACS+7+i*24,2);
memcpy(&traffic_land_marksSys.land_marks[i].pose[0],DataFromACS+9+i*24,4);
memcpy(&traffic_land_marksSys.land_marks[i].pose[1],DataFromACS+13+i*24,4);
//
memcpy(&traffic_land_marksSys.land_marks[i].PointType,DataFromACS+17+i*24,1);
memcpy(&traffic_land_marksSys.land_marks[i].lookforCenterSig,DataFromACS+18+i*24,1);
memcpy(&traffic_land_marksSys.land_marks[i].actionType,DataFromACS+19+i*24,1);
memcpy(&traffic_land_marksSys.land_marks[i].liftHeight,DataFromACS+20+i*24,2);
memcpy(&traffic_land_marksSys.land_marks[i].LaserArea,DataFromACS+22+i*24,1);
memcpy(&traffic_land_marksSys.land_marks[i].headAngle,DataFromACS+23+i*24,2);
memcpy(&traffic_land_marksSys.land_marks[i].headDir,DataFromACS+25+i*24,1);
memcpy(&traffic_land_marksSys.land_marks[i].rotateAngle,DataFromACS+26+i*24,2);
memcpy(&traffic_land_marksSys.land_marks[i].rotateDir,DataFromACS+28+i*24,1);
memcpy(&traffic_land_marksSys.land_marks[i].connectDir,DataFromACS+29+i*24,1);
memcpy(&traffic_land_marksSys.land_marks[i].DispatchSpeed,DataFromACS+30+i*24,1);
}
memcpy(&traffic_land_marksSys.pickOrPlace,DataFromACS+130,1);
memcpy(&traffic_land_marksSys.checkCode,DataFromACS+137,1);
if(traffic_land_marksReal.taskID != traffic_land_marksSys.taskID)
{
receiveNewTask();
}
else
{
continueTask();
}
//给每个点位加方向
setLandDirection();
}
extern int errorCurangle,errorTarangle,errorAngle;
void DataProcessToACS()
{
DataToACS[0] = 120;
u16 angle = agv.Public.Coordinate_W*57.3*10;
if(angle < 0) angle += 3600;
// if(agv.Public.Error_Flag == 0)
if(agv.Public.finishTaskSig)
agv.Public.finishStatus = 1;
memcpy(DataToACS+1,&agv.Parameter.AGVID,2);
memcpy(DataToACS+3,&agv.Command.LandMarkID,2);
memcpy(DataToACS+5,&agv.Command.LandMarkID,2);
memcpy(DataToACS+7,&agv.Public.SOC,1);
if(!agv.Command.Au_Hand)
{
agv.Public.AgvStatus = 20;
}
else
{
if(!traffic_land_marksSys.taskID && 1)
{
agv.Public.AgvStatus = 11;
}
else if(traffic_land_marksSys.taskID)
{
if(agv.Public.Error_Flag & 0x0200)
agv.Public.AgvStatus = 11;
else
agv.Public.AgvStatus = 13;
}
//自动充电
if(agv.Public.chargeState)
agv.Public.AgvStatus = 14;
}
memcpy(DataToACS+8,&agv.Public.AgvStatus,1);
agv.Public.HeadDirection = CalculateCurHeadDir(agv.Public.Coordinate_W*57.3);
memcpy(DataToACS+9,&agv.Public.HeadDirection,1);
memcpy(DataToACS+10,&agv.Public.RotateDirection,1);
memcpy(DataToACS+11,&agv.Public.LiftStatus,1);
int errorData = agv.Public.Error_Flag&0x9808;
memcpy(DataToACS+12,&errorData,4);
memcpy(DataToACS+16,&agv.Public.Error_FlagTwo,4);
//相对距离
memcpy(DataToACS+22,&traffic_land_marksSys.taskID,4);
int pointX = agv.Public.Coordinate_X;
int pointY = agv.Public.Coordinate_Y;
memcpy(DataToACS+26,&agv.Public.finishStatus,1);//完成信号
memcpy(DataToACS+27,&pointX,4);
memcpy(DataToACS+31,&pointY,4);
//位置可信度
memcpy(DataToACS+36,&angle,2);
memcpy(DataToACS+38,&DriverLifter1.Public.encoderPose,2);
memcpy(DataToACS+40,&agv.Public.currentAction,1);//当前动作
memcpy(DataToACS+41,&agv.Public.i_materialArriveFlag,1);//是否有货
memcpy(DataToACS+51,&agv.Command.Au_Hand,1);
memcpy(DataToACS+52,&agv.Command.CurDirection,1);//当前动作
memcpy(DataToACS+53,&agv.Command.NextDirection,1);//是否有货
memcpy(DataToACS+54,&agv.Command.NextSecondDirection,1);
memcpy(DataToACS+55,&agv.Public.SOC,1);
memcpy(DataToACS+56,&agv.Command.standSiteID,1);
memcpy(DataToACS+57,&traffic_land_marksReal.size,1);
memcpy(DataToACS+58,&agv.Public.finishStatus,1);
memcpy(DataToACS+59,&agv.Public.chargeState,1);
memcpy(DataToACS+60,&agv.Public.i_materialArriveFlag,1);
// memcpy(DataToACS+61,&DriverLifter1.Public.encoderPose,1);
// memcpy(DataToACS+62,&DriverLifter1.Public.encoderPose,1);
// memcpy(DataToACS+63,&DriverLifter1.Public.encoderPose,1);
// memcpy(DataToACS+64,&DriverLifter1.Public.encoderPose,1);
// memcpy(DataToACS+65,&DriverLifter1.Public.encoderPose,1);
int data14 = (int)agv.Command.SetBaseSpeed;
memcpy(DataToACS+66,&agv.Public.Error_Flag,2);//当前动作
memcpy(DataToACS+68,&data14,2);//当前动作
int data1 = (int)DriverSteering1.Command.angle;
int data2 = DriverSteering1.Public.encoderPose;
memcpy(DataToACS+70,&data1,2);//当前动作
memcpy(DataToACS+72,&data2,2);//当前动作
memcpy(DataToACS+74,&agv.Parameter.SetLift1Height,2);//当前动作
memcpy(DataToACS+76,&DriverLifter1.Public.encoderPose,2);//当前动作
int data10 = (int)navi.Public.CenterOffset;
int data9 = (int)(navi.Public.AngleDifference*57.3);
memcpy(DataToACS+78,&data9,2);//当前动作
memcpy(DataToACS+80,&errorCurangle,2);//当前动作
memcpy(DataToACS+82,&errorTarangle,2);
memcpy(DataToACS+84,&errorAngle,2);
int data3 = (int)PointTwo.TarX;
int data4 = (int)PointTwo.TarY;
int data5 = (int)PointThree.TarX;
int data6 = (int)PointThree.TarY;
int data7 = (int)PointFour.TarX;
int data8 = (int)PointFour.TarY;
int data11 = (int)agv.Public.Coordinate_X;
int data12 = (int)agv.Public.Coordinate_Y;
int data13 = (int)(agv.Public.Coordinate_W*57.3);
memcpy(DataToACS+86,&data3,4);
memcpy(DataToACS+90,&data4,4);
memcpy(DataToACS+94,&data5,4);//
memcpy(DataToACS+98,&data6,4);//
memcpy(DataToACS+102,&data7,4);//
memcpy(DataToACS+106,&data8,4);//
memcpy(DataToACS+110,&data11,4);//
memcpy(DataToACS+114,&data12,4);//
memcpy(DataToACS+118,&data13,2);//
// memcpy(DataToACS+42,&agv.Public.currentAction,1);//滚筒转动
u8 checkResult = DataToACS[0]^DataToACS[1];
for(u8 j = 2;j < DataToACS[0];j++)
{
checkResult = checkResult^DataToACS[j];
}
DataToACS[DataToACS[0]] = checkResult;
// memcpy(DataToACS+49,&checkResult,1);
}
void _AppTaskEthernetCli(void)
{
if(DataFromACS[0] == 137 && agv.Public.receiveFlag)
{
u8 checkResult = DataFromACS[0]^DataFromACS[1];
for(u8 j = 2;j < DataFromACS[0];j++)
{
checkResult = checkResult^DataFromACS[j];
}
if(checkResult == DataFromACS[137])
{
agv.Public.receiveFlag = 0;
DataProcessFromACS();
}
}
DataProcessToACS();
if(traffic_land_marksSys.clearTaskSig)//清除任务
{
clearPathInfomation();
}
}