Paramater.c
14.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
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
#include "Paramater.h"
AGVStruct agv;
navigationPID pid;
navigationStruct navi;
/*定义用于计算的点
StartPoint TargetPoint直线运行当前点(起点)和下一个点(目标点)
CurrentCenterPoint agv运动中心实时坐标
PointOne,PointTwo,PointThree,PointFour弧线转弯用的四个点,上一个点,当前点,下一个点,下两个点
A,B为单机测试时,放置屏幕可以调整的坐标
*/
CoordinatePoints StartPoint, TargetPoint, CurrentCenterPoint, PointOne, PointTwo, PointThree, PointFour, CircleCenterPoint,FrontViewPoint;
void initPidData()
{
navi.PIDPara[0].Kp = 0.5;//高速
navi.PIDPara[0].Ki = 0;
navi.PIDPara[0].Kd = 0;
navi.PIDPara[0].PosCofficient = 1;
navi.PIDPara[0].AngleCofficient = 12;
navi.PIDPara[0].MaxLimit = 40;
navi.PIDPara[1].Kp = 0.5;//低速
navi.PIDPara[1].Ki = 0;
navi.PIDPara[1].Kd = 0;
navi.PIDPara[1].PosCofficient = 1;
navi.PIDPara[1].AngleCofficient =10;
navi.PIDPara[1].MaxLimit = 40;
navi.PIDPara[2].Kp = 0.5;
navi.PIDPara[2].Ki = 0;
navi.PIDPara[2].Kd = 0;
navi.PIDPara[2].PosCofficient = 1;
navi.PIDPara[2].AngleCofficient = 15;
navi.PIDPara[2].MaxLimit = 40;
navi.PIDPara[3].Kp = 0.35;
navi.PIDPara[3].Ki = 0;
navi.PIDPara[3].Kd = 0;
navi.PIDPara[3].PosCofficient = 0;
navi.PIDPara[3].AngleCofficient = 15;
navi.PIDPara[3].MaxLimit = 40;
}
void initAgvData()
{
Uart_Printf(COM1, "参数初始化\r\n");
agv.Command.standSiteID = 1;
agv.Command.Au_Hand = 1;
agv.Public.i_StartSig = 0;
agv.Public.i_StopSig = 0;
agv.Public.i_UpdatePathSig = 1;
agv.Command.CurDirection = 0;
Lifter1.initState = 0;
Rotate1.initState = 0;
agv.Parameter.HandSpeed = 300;//手动速度 你看调多少 按比例
agv.Parameter.HandTurnSpeed = 100;
agv.Parameter.HandSpeedSlope = 1;
agv.Parameter.AutoSpeedSlope = 5;
agv.Command.LaserState = 0;
agv.Parameter.AdvanceParkPos = 1500;//预停车距离100
agv.Parameter.AdvanceParkSpeed = 100;//预停车速度20
agv.Parameter.OnlyAnglePos = 500;//只纠偏角度距离
agv.Parameter.LiftSpeed = 10000; //举升速度600
agv.Command.Barrier_ONOFF = 1;
agv.Command.Vol = 31;
agv.Command.Music_ONOFF = 1;
agv.Command.LaserArea = 0;
agv.Parameter.AGVID = 0xA001;
if(agv.Parameter.AGVID == 0xA006 )
{
agv.Parameter.anglecompensation = 3;
agv.Parameter.platcompensation = 2;
}
else if(agv.Parameter.AGVID == 0xA004)
{
agv.Parameter.anglecompensation = 1.5;
}
else if(agv.Parameter.AGVID == 0xA001)
{
agv.Parameter.anglecompensation = 2;
agv.Command.Width4 = 40;
}
else if(agv.Parameter.AGVID == 0xA002)
{
agv.Parameter.anglecompensation = 3.1;
agv.Parameter.SetLift2Height = 4;
}
else if(agv.Parameter.AGVID == 0xA003)
{
agv.Parameter.anglecompensation = 3;
agv.Parameter.platcompensation = 1;
}
else if(agv.Parameter.AGVID == 0xA005)
{
agv.Command.Width4 = 40;
}
}
void InitParamater()
{
initPidData();
initAgvData();
}
extern u8 TurnStep;
void clearPathInfomation()
{
agv.Command.standSiteID = 1; //执行点位置1复位
agv.Public.i_UpdatePathSig = 1; //路径更新标志置1复位
Reset_Alarm(0x06A8); //清除脱线,停稳,系统停车
agv.Public.i_PlatformStopFlag = 0;
agv.Public.i_QRCodeCenterStopFlag = 0;
memset(&traffic_land_marks, 0, sizeof(traffic_land_marks)); //清除所有路径信息
SetAlarm(0x0040); //手动模式下给一个系统停车报警代码,方便系统下发路径指令
navi.Public.DistanceAgvToSTART = 0;
TurnStep = 0;
}
#if P_SETUP_SINGLE_PLAYER == 1
void initPathInfo()
{
#if 1
traffic_land_marks.land_marks[0].LightStopSig = 0;//起点
traffic_land_marks.land_marks[0].pose[0] = -8400;
traffic_land_marks.land_marks[0].pose[1] = 6000;
traffic_land_marks.land_marks[0].Direction = 3;
traffic_land_marks.land_marks[0].DispatchSpeed = 500;
traffic_land_marks.land_marks[0].RunState = 0;
traffic_land_marks.land_marks[1].LightStopSig = 0;
traffic_land_marks.land_marks[1].pose[0] = -8400;
traffic_land_marks.land_marks[1].pose[1] = 1200;
traffic_land_marks.land_marks[1].Direction = 3;
traffic_land_marks.land_marks[1].DispatchSpeed = 500;
traffic_land_marks.land_marks[1].RunState = 0;
traffic_land_marks.land_marks[2].LightStopSig = 0;
traffic_land_marks.land_marks[2].pose[0] = -1200;
traffic_land_marks.land_marks[2].pose[1] = 1200;
traffic_land_marks.land_marks[2].Direction = 3;
traffic_land_marks.land_marks[2].DispatchSpeed = 500;
traffic_land_marks.land_marks[2].RunState = 0;
traffic_land_marks.land_marks[3].LightStopSig = 0;
traffic_land_marks.land_marks[3].pose[0] = -8400;
traffic_land_marks.land_marks[3].pose[1] = 1200;
traffic_land_marks.land_marks[3].Direction = 4;
traffic_land_marks.land_marks[3].DispatchSpeed = 500;
traffic_land_marks.land_marks[3].RunState = 0;
traffic_land_marks.land_marks[4].LightStopSig = 0;
traffic_land_marks.land_marks[4].pose[0] = -8400;
traffic_land_marks.land_marks[4].pose[1] = 6000;
traffic_land_marks.land_marks[4].Direction = 0;
traffic_land_marks.land_marks[4].DispatchSpeed = 0;
traffic_land_marks.land_marks[4].RunState = 0;
#endif
SetAlarm(0x0004);
traffic_land_marks.size = 5;
}
#elif P_SETUP_SINGLE_PLAYER == 0
void initPathInfo()
{
memset(&traffic_land_marks,0,sizeof(traffic_land_marks));
SetAlarm(0x0040);
}
#endif
void SendDataToHMI()
{
u8 sendbuff[100];
sendbuff[0] = 0xAA;
sendbuff[1] = 0x00;
sendbuff[2] = agv.Public.SOC;
// sendbuff[3] = 0x00;
// sendbuff[4] = 0x00;
// sendbuff[5] = 0x00;
// sendbuff[6] = 0x00;
// sendbuff[7] = 0x00;
// sendbuff[8] = 0x00;
// sendbuff[9] = 0x00;
//
// sendbuff[10] = 0x00;
sendbuff[11] = agv.Command.RunMode;//导航方式
sendbuff[12] = agv.Command.standSiteID ;//当前站点
sendbuff[13] = agv.Command.CurDirection ;//当前方向
sendbuff[14] = agv.Public.Error_Flag & 0xff;//报警代码
sendbuff[15] = (int)agv.Public.locT;//致信度
sendbuff[16] = agv.Public.OnlinePointSig;//上线点位
sendbuff[17] = agv.Public.SOC;//电量SOC
sendbuff[18] = agv.Command.LaserArea;//避障区域
sendbuff[19] = 0x00;
sendbuff[20] = 0x00;
sendbuff[21] = 0x00;
sendbuff[22] = 0x00;
sendbuff[23] = 0x00;
sendbuff[24] = 0x00;
//车号
sendbuff[25] = (agv.Parameter.AGVID >> 8) & 0xff;
sendbuff[26] = (agv.Parameter.AGVID >> 0) & 0xff;
// sendbuff[25] = 0x01;
// sendbuff[26] = 0x01;
//距离终点距离
sendbuff[27] = ((int) navi.Public.DistanceAgvToTARGET >> 8) & 0xff;
sendbuff[28] = ((int) navi.Public.DistanceAgvToTARGET >> 0) & 0xff;
//距离起点距离
sendbuff[29] = ((int) navi.Public.VerticalDistanceAgvToSTART >> 8) & 0xff;
sendbuff[30] = ((int) navi.Public.VerticalDistanceAgvToSTART ) & 0xff;
sendbuff[31] = 0x00;
sendbuff[32] = 0x00;
sendbuff[33] = 0x00;
sendbuff[34] = 0x00;
//置信度
sendbuff[35] = (int)agv.Public.locT;
sendbuff[36] = 0x00;
sendbuff[37] = 0x00;
sendbuff[38] = 0x00;
sendbuff[39] = 0x00;
//
sendbuff[40] = 0x01;
//报警代码
sendbuff[41] = agv.Public.Error_Flag >> 8 & 0xff;
sendbuff[42] = agv.Public.Error_Flag & 0xff;
sendbuff[43] = agv.Public.Error_Flag >> 24 & 0xff;
sendbuff[44] = agv.Public.Error_Flag >> 16 & 0xff;
//姿态角
tuconvert32.fValue = (agv.Public.Coordinate_W*57.3) ;
sendbuff[45] = tuconvert32.wValue[0]>> 8 & 0xff;//d800
sendbuff[46] = tuconvert32.wValue[0] & 0xff;
sendbuff[47] = tuconvert32.wValue[1]>> 8 & 0xff;
sendbuff[48] = tuconvert32.wValue[1] & 0xff;
//X坐标
// sendbuff[49] = ((int)agv.Public.Coordinate_X )>> 8 & 0xff;
// sendbuff[50] = ((int)agv.Public.Coordinate_X) & 0xff;
// sendbuff[51] = ((int)agv.Public.Coordinate_X )>> 24 & 0xff;
// sendbuff[52] = ((int)agv.Public.Coordinate_X )>> 16 & 0xff;
tuconvert32.fValue = agv.Public.Coordinate_X;
sendbuff[49] = tuconvert32.wValue[0]>> 8 & 0xff;
sendbuff[50] = tuconvert32.wValue[0] & 0xff;
sendbuff[51] = tuconvert32.wValue[1]>> 8 & 0xff;
sendbuff[52] = tuconvert32.wValue[1] & 0xff;
//Y坐标
tuconvert32.fValue = agv.Public.Coordinate_Y;
sendbuff[53] = tuconvert32.wValue[0]>> 8 & 0xff;
sendbuff[54] = tuconvert32.wValue[0] & 0xff;
sendbuff[55] = tuconvert32.wValue[1]>> 8 & 0xff;
sendbuff[56] = tuconvert32.wValue[1] & 0xff;
//起点X
tuconvert32.fValue = StartPoint.TarX;
sendbuff[57] = tuconvert32.wValue[0]>> 8 & 0xff;
sendbuff[58] = tuconvert32.wValue[0] & 0xff;
sendbuff[59] = tuconvert32.wValue[1]>> 8 & 0xff;
sendbuff[60] = tuconvert32.wValue[1] & 0xff;
//起点Y
tuconvert32.fValue = StartPoint.TarY;
sendbuff[61] = tuconvert32.wValue[0]>> 8 & 0xff;
sendbuff[62] = tuconvert32.wValue[0] & 0xff;
sendbuff[63] = tuconvert32.wValue[1]>> 8 & 0xff;
sendbuff[64] = tuconvert32.wValue[1] & 0xff;
//目标点X
tuconvert32.fValue = TargetPoint.TarX;
sendbuff[65] = tuconvert32.wValue[0]>> 8 & 0xff;
sendbuff[66] = tuconvert32.wValue[0] & 0xff;
sendbuff[67] = tuconvert32.wValue[1]>> 8 & 0xff;
sendbuff[68] = tuconvert32.wValue[1] & 0xff;
//目标点Y
tuconvert32.fValue = TargetPoint.TarY;
sendbuff[69] = tuconvert32.wValue[0]>> 8 & 0xff;
sendbuff[70] = tuconvert32.wValue[0] & 0xff;
sendbuff[71] = tuconvert32.wValue[1]>> 8 & 0xff;
sendbuff[72] = tuconvert32.wValue[1] & 0xff;
//偏差位置
tuconvert32.fValue = navi.Public.CenterOffset;
sendbuff[73] = tuconvert32.wValue[0]>> 8 & 0xff;
sendbuff[74] = tuconvert32.wValue[0] & 0xff;
sendbuff[75] = tuconvert32.wValue[1]>> 8 & 0xff;
sendbuff[76] = tuconvert32.wValue[1] & 0xff;
//偏差角度
tuconvert32.fValue = navi.Public.AngleDifference;
sendbuff[77] = tuconvert32.wValue[0]>> 8 & 0xff;
sendbuff[78] = tuconvert32.wValue[0] & 0xff;
sendbuff[79] = tuconvert32.wValue[1]>> 8 & 0xff;
sendbuff[80] = tuconvert32.wValue[1] & 0xff;
//相机X坐标
sendbuff[81] = Camera.XCoordingData >> 8 & 0xff;
sendbuff[82] = Camera.XCoordingData & 0xff;
sendbuff[83] = Camera.XCoordingData >> 24 & 0xff;
sendbuff[84] = Camera.XCoordingData >> 16 & 0xff;
//相机Y坐标
sendbuff[85] = Camera.YCoordingData >> 8 & 0xff;
sendbuff[86] = Camera.YCoordingData & 0xff;
sendbuff[87] = Camera.YCoordingData >> 24 & 0xff;
sendbuff[88] = Camera.YCoordingData >> 16 & 0xff;
WriteUart(COM1,sendbuff,sizeof(sendbuff));
}
u8 realbuff[150],recvbuff[200];
void ReceiDataformHMI()
{
static u8 i,j,checkdata,testFlag,len,analysFlag;
len = ReadUart(COM1,recvbuff,200);
if(len > 0)
{
for(i = 0;i < len;i++)
{
if(recvbuff[i] == 0xAA&&recvbuff[i+1] == 0xAA&&recvbuff[i+2] == 0xBB&&recvbuff[i+3] == 0xBB&&recvbuff[i+4] == 0xCC&&recvbuff[i+5] == 0xCC)
{
analysFlag = 1;
break;
}
}
if(analysFlag)//开始解析
{
for(j=0;j<99;j++)
{
realbuff[j] = recvbuff[i];
i += 1;
checkdata += realbuff[j];
}
realbuff[99] = recvbuff[i];
if(realbuff[0]==0xAA&&realbuff[99]==0xEE)//checkdata==realbuff[99])
{
// agv.Parameter.HandSpeed = realbuff[6]<<8 | realbuff[8];//点动直行速度
// agv.Parameter.HandTurnSpeed = realbuff[10]<<8 | realbuff[12];//点动转弯速度
// agv.Parameter.HandSpeedSlope = realbuff[14]<<8 | realbuff[16];//加速斜坡
// agv.Parameter.AutoSpeedSlope = realbuff[18]<<8 | realbuff[20];//减速斜坡
// realbuff[22]<<8 | realbuff[24]; //脱轨阈值
// agv.Parameter.AdvanceParkPos = realbuff[26]<<8 | realbuff[28];//预停车距离
// agv.Parameter.AdvanceParkSpeed = realbuff[30]<<8 | realbuff[32];//预停车速度
// agv.Parameter.OnlyAnglePos = realbuff[34]<<8 | realbuff[36];//只纠偏角度距离
// agv.Parameter.anglecompensation = (realbuff[38]<<8 | realbuff[40])*0.01;//相机角度补偿
// if(agv.Parameter.anglecompensation>100)
// {
// agv.Parameter.anglecompensation = 100 - agv.Parameter.anglecompensation;
// }
//
// agv.Parameter.AGVID = realbuff[46]<<8 | realbuff[48];//小车ID
//
// realbuff[15];
// realbuff[16];
// realbuff[17];
// realbuff[18];
// realbuff[19];
// realbuff[20];
// realbuff[21];
// realbuff[22];
// realbuff[23];
// realbuff[24];
// realbuff[25];
// realbuff[26];
testFlag = 1;
}
analysFlag = 0;
}
}
// if(agv.Parameter.AGVID!=0xA006)
// {
// testFlag = 1;
// }
}
#if P_SETUP_PLATFORM_TYPE == 1 //不同平台IO信号获取
#elif P_SETUP_PLATFORM_TYPE == 5
//上报Rptpose信息,参数为间隔多少毫秒上报一次
void reportRPTPose(u16 IntervalTime)
{
static int LastTime1 = 0, LastTime2 = 0, StopOKFlag = 0;
if (agv.Public.Error_Flag & 0x200)
StopOKFlag = 1;
else
StopOKFlag = 0;
if (agv.Public.SystemTime - LastTime1 >= IntervalTime)
{
LastTime1 = agv.Public.SystemTime;
//上报方向换向
Create_BodyTreaty(false, et_smtagv, sort_Send, ct_rptpos, ParameterTransform("%d_%d_%0.2f::%d::%d::%d::%d::%04x::%d::%d::%d::%d::%d::%d::%d::%d::%.1f_%.1f::%.1f_%.1f::%d_%d::%d_%d::%d_%d_%.2f::%d",
(int)agv.Public.Coordinate_X,(int)agv.Public.Coordinate_Y,agv.Public.Coordinate_W*57.3,
agv.Command.LandMarkID, //地图号
(int)agv.Command.SetBaseSpeed, //速度
agv.Command.CurDirection, //方向
agv.Command.LaserArea, //激光避障区域
agv.Public.Error_Flag,
agv.Command.Au_Hand, //手自动
traffic_land_marks.ChargingState, //充电状态
agv.Public.SOC, //电压
1, //定位状态
Lifter1.liftState, //举升状态0最低点1最高点2举升过程中
Rotate1.rotateState, //旋转状态 0旋转完成(静止)1旋转中
agv.Public.i_MaterialTesting, //物料状态 0没料 1有料
StopOKFlag, //停稳信号1停稳
StartPoint.TarX,
StartPoint.TarY,
TargetPoint.TarX,
TargetPoint.TarY,
agv.Command.standSiteID,
traffic_land_marks.size,
(int)TongyiStruct1.encodeSpeed,
(int)TongyiStruct3.encodeSpeed,
TongyiStruct2.encodeAngleNum,
TongyiStruct4.encodeAngleNum,
TongyiStruct2.angleNum,
agv.Command.Number
));
//
}
}
#endif