ForkLift.c
15.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
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
#include "ForkLift.h"
#include "DisplacementSensor.h"
#if P_SETUP_PLATFORM_TYPE == 4
void initPlaformParam(void) //参数初始化
{
Uart_Printf(COM1, "参数初始化\r\n");
Y9(0); // 关闭agv自动充电触点
agv.Command.standSiteID = 1;
agv.Command.Au_Hand = 0;
agv.Public.i_StartFirst = false;
DriverMotor1.Command.speedSlope = 5;
DriverMotor2.Command.speedSlope = 5;
DriverLifter1.Command.speedSlope = 50;
DriverShifter1.Command.speedSlope = 50;
#if P_SETUP_SINGLE_PLAYER == 0 //0不开启单机测试 1开启
SetAlarm(0x0040);
#endif
}
void lifterRunManu(DriverStruct *Motor1) //举升手动运行
{
/*第一层举升*/
if (agv.Command.HandLiftState == 1) //上升
{
Motor1->Command.speed = agv.Parameter.LiftSpeed;
}
else if (agv.Command.HandLiftState == 2) //下降
{
Motor1->Command.speed = -agv.Parameter.LiftSpeed;
}
else
{
Motor1->Command.speed = 0;
}
//下层升降限制
if (agv.Public.i_Lift1UpLimit && Motor1->Command.speed > 0)
{
Motor1->Command.speed = 0;
}
else if (agv.Public.i_Lift1DownLimit && Motor1->Command.speed < 0)
{
Motor1->Command.speed = 0;
}
}
void lifterRunAuto(DriverStruct *Motor1) //举升自动运行
{
static int LiftOffset1 = 0;
static u8 FirstToZero1 = 0;
LiftOffset1 = DriverLifter1.Public.encoderPose - agv.Parameter.SetLift1Height; //前举升与目标高度差
//第一层举升
if (LiftOffset1 < -9) //上升
{
if(LiftOffset1 < -150)
{
Motor1->Command.speed = 90;
}
else
{
Motor1->Command.speed = agv.Parameter.SpeedUpMin;
}
if(DriverLifter1.Public.encoderPose > 1600 && DriverLifter1.Public.encoderPose < 1800)
{
Motor1->Command.speed = 40;
}
}
else if (LiftOffset1 > 9) //下降
{
if(LiftOffset1 > 150)
{
Motor1->Command.speed = -90;
}
else
{
Motor1->Command.speed = -agv.Parameter.SpeedDownMin;
}
if(DriverLifter1.Public.encoderPose > 1600 && DriverLifter1.Public.encoderPose < 2000)
{
Motor1->Command.speed = -30;
}
}
else
Motor1->Command.speed = 0;
// if (FirstToZero1 && agv.Public.i_StartFirst) //下层第一次上电归零
if(agv.Parameter.SetLift1Height == 0)
{
Motor1->Command.speed = -50;
}
//第一层升降限制
if (agv.Public.i_Lift1UpLimit && Motor1->Command.speed > 0)
{
Motor1->Command.speed = 0;
}
else if (agv.Public.i_Lift1DownLimit && Motor1->Command.speed < 0)
{
FirstToZero1 = 0;
Motor1->Command.speed = 0;
}
}
void shifterRunManu(DriverStruct *Motor1) //滚筒手动运行
{
if (agv.Command.HandShiftState == 1) //
{
Motor1->Command.speed = agv.Parameter.ShiftSpeed;
}
else if (agv.Command.HandShiftState == 2) //
{
Motor1->Command.speed = -agv.Parameter.ShiftSpeed;
}
else //停止
{
Motor1->Command.speed = 0;
}
}
void shifterRunAuto(DriverStruct *Motor1) //滚筒自动运行
{
//下层滚筒
switch (agv.Command.Shift1State)
{
case 0: //无动作或者微挪料框
Motor1->Command.speed = 0;
if (agv.Public.i_Shift1ArrivalLeft && !agv.Public.i_Shift1ArrivalRight && !agv.Public.i_Shift1_LimitRight)
{
Motor1->Command.speed = agv.Parameter.ShiftSpeed;
}
else if (agv.Public.i_Shift1ArrivalRight && !agv.Public.i_Shift1ArrivalLeft && !agv.Public.i_Shift1_LimitLeft)
{
Motor1->Command.speed = -agv.Parameter.ShiftSpeed;
}
else
Motor1->Command.speed = 0;
break;
case 1: //左边进框(右转)
Motor1->Command.speed = agv.Parameter.ShiftSpeed;
if (agv.Public.i_Shift1ArrivalLeft && agv.Public.i_Shift1ArrivalRight) //左边到位右边到位停止
{
Motor1->Command.speed = 0;
agv.Command.Shift1State = 0;
}
break;
case -1: //左边出框(左转)
Motor1->Command.speed = -agv.Parameter.ShiftSpeed;
//四个传感器全部检测不到物料,认为出框完毕停止
if (!agv.Public.i_Shift1ArrivalLeft && !agv.Public.i_Shift1ArrivalRight && !agv.Public.i_Shift1_LimitLeft && !agv.Public.i_Shift1_LimitRight)
{
Motor1->Command.speed = 0;
agv.Command.Shift1State = 0;
}
break;
case 2: //右边进框(左转)
Motor1->Command.speed = -agv.Parameter.ShiftSpeed;
if (agv.Public.i_Shift1ArrivalLeft && agv.Public.i_Shift1ArrivalRight) //左边到位右边到位停止
{
Motor1->Command.speed = 0;
agv.Command.Shift1State = 0;
}
break;
case -2: //右边出框(右转)
Motor1->Command.speed = agv.Parameter.ShiftSpeed;
//四个传感器全部检测不到物料,认为出框完毕停止
if (!agv.Public.i_Shift1ArrivalLeft && !agv.Public.i_Shift1ArrivalRight && !agv.Public.i_Shift1_LimitLeft && !agv.Public.i_Shift1_LimitRight)
{
Motor1->Command.speed = 0;
agv.Command.Shift1State = 0;
}
break;
}
}
void checkMaterialState() //物料检测
{
//下层物料检测
if (agv.Public.i_Shift1ArrivalLeft && agv.Public.i_Shift1ArrivalRight)
{
agv.Public.i_MaterialFlagFirst = 1;
}
else if (!agv.Public.i_Shift1ArrivalLeft && !agv.Public.i_Shift1ArrivalRight && !agv.Public.i_Shift1_LimitLeft && !agv.Public.i_Shift1_LimitRight)
{
agv.Public.i_MaterialFlagFirst = 0;
}
else
agv.Public.i_MaterialFlagFirst = 2;
}
void platformControlManual() //平台手动运行
{
lifterRunManu(&DriverLifter1);
shifterRunManu(&DriverShifter1);
}
void platformControlAuto() //平台自动对接
{
lifterRunAuto(&DriverLifter1);
shifterRunAuto(&DriverShifter1);
}
void ForkliftAngleAdjustment()//叉车角度调整
{
static float curAngleQuadrant = 0,angleDif = 0;
static u8 AdjustStep = 1;
curAngleQuadrant = CalculateCurAngle(CurrentCenterPoint.CurAngle*57.3)/57.3;//求出当前所在象限
angleDif = CalculatingCurrentAndTargetAngle(CurrentCenterPoint.CurAngle,curAngleQuadrant);
if(angleDif > 0.01)//偏左大于0,右转
{
DriverSteering1.Command.angle = 895;
if(fabs(abs(DriverSteering1.Public.encoderPose) - fabs(DriverSteering1.Command.angle))<100)
DriverSteering1.Command.speed = -150;
}
else if(angleDif < -0.01)//偏右小于0,左转
{
DriverSteering1.Command.angle = 895;
if(fabs(abs(DriverSteering1.Public.encoderPose) - fabs(DriverSteering1.Command.angle))<100)
DriverSteering1.Command.speed = 150;
}
else
{
DriverSteering1.Command.angle = 0;
DriverSteering1.Command.speed = 0;
Reset_Alarm(0x020);
SetAlarm(0x200);
agv.Public.i_ForkliftAngleAdjustment = 0;
agv.Public.finishStatus = 1;
agv.Public.finishTaskSig = 1;
}
}
void sendCommandToCharging(u8 state)
{
static int lastTime = 0;
unsigned char string_out[100] = {0},i = 0;
static unsigned char string_len = 0,step = 1;
if(agv.Public.SystemTime - lastTime > 500)
{
lastTime = agv.Public.SystemTime;
if(state == 1)
{
if(step == 1)
{
string_len = sprintf((char *)string_out, "C001##,,C001,,s,,setvmot,,4::%d,,0000,,ZZ",0);
WriteUart(COM6,string_out,string_len);
step = 2;
}
else if(step == 2)
{
string_len = sprintf((char *)string_out, "C001##,,C001,,s,,setvmot,,4::%d,,0000,,ZZ",state);
WriteUart(COM6,string_out,string_len);
}
}
else
{
string_len = sprintf((char *)string_out, "C001##,,C001,,s,,setvmot,,4::%d,,0000,,ZZ",state);
WriteUart(COM6,string_out,string_len);
}
}
}
int chargingVol,chargingCurrent,startState,extendState,backState;
void ProccessChargingInfo(unsigned char *RecvBuffer, unsigned short BufferLength)
{
int data1,data2,data3,data4,data5,data9;
if (strncmp("#", (const char *)RecvBuffer, 1) == 0)
{
sscanf((const char *)RecvBuffer, "#,,C001,,s,,rptmt,,%d::%d::%d::%d::%d::%d::%d::%d::%d::%d,,%x,,ZZ", &chargingVol,&chargingCurrent,&data1,&data2,&data3,&startState,&data4,&data5,&extendState,&backState,&data9);
}
}
void ProccessChargingDATAInfo(unsigned char *Res)
{
static unsigned char Buffer2[120],ReceiveFlag = 0;
static unsigned short iii = 0;
if (iii > 100)
{
iii = 0;
ReceiveFlag = 0;
}
if (*Res == '#') // $
{
iii = 0;
ReceiveFlag = 0;
}
Buffer2[iii++] = *Res;
if (*Res == 'Z') // #
{
if(ReceiveFlag)
{
ProccessChargingInfo((unsigned char *)Buffer2, iii);
memset(Buffer2,0,sizeof(Buffer2));
iii = 0;
ReceiveFlag = 0;
}
else
ReceiveFlag = 1;
}
}
void receiveCommandFromCharging()
{
unsigned char buff[100];
unsigned int len;
unsigned i;
len = ReadUart(COM6, buff, 100);
if (len > 0)
{
for (i = 0; i < len; i++)
{
ProccessChargingDATAInfo(buff + i);
}
}
}
void X_Input()
{
agv.Public.i_RadarSigFront_1 = MasterInput.IN1 = !X19;//前壁障减速1
agv.Public.i_RadarSigFront_2 = MasterInput.IN2 = !X20;//前壁障减速2
agv.Public.i_RadarSigFront_3 = MasterInput.IN3 = !X21;//前壁障减速3
agv.Public.i_RadarSigBack_1 = MasterInput.IN4 = !X22;//后壁障减速1
agv.Public.i_RadarSigBack_2 = MasterInput.IN5 = !X23;//后壁障减速2
agv.Public.i_RadarSigBack_3 = MasterInput.IN6 = !X24;//后壁障减速3
agv.Command.Au_Hand = X5;//手自动切换
agv.Public.i_QuickStopSig = MasterInput.IN7 = !X6;// 急停 常开
agv.Public.i_BumperSig = MasterInput.IN8 = X14;//防撞条
agv.Public.i_StartSig = MasterInput.IN9 = X16;// 启动
agv.Public.i_StopSig = MasterInput.IN10 = X15;//暂停
// agv.Public.i_LightStopFlagL = MasterInput.IN13 = X1;//左停靠
// agv.Public.i_LightStopFlagR = MasterInput.IN14 = X2;//右停靠
//
agv.Public.i_Lift1UpLimit = MasterInput.IN12 = X4;//升降1上限位
agv.Public.i_Lift1DownLimit = MasterInput.IN11 = X3;//升降1下限位
agv.Public.i_materialArriveFlag = MasterInput.IN18 = X18;//物料到位信号
// agv.Public.i_Lift2UpLimit = MasterInput.IN15 = !X15;//升降2上限位
// agv.Public.i_Lift2DownLimit = MasterInput.IN16 = !X16;//升降2下限位
//
// agv.Public.i_Shift1_LimitLeft = MasterInput.IN17 = X17;//滚筒1左极限
// agv.Public.i_Shift1_LimitRight = MasterInput.IN18 = X18;//滚筒1右极限
// agv.Public.i_Shift2_LimitLeft = MasterInput.IN21 = X21;//滚筒2左极限
// agv.Public.i_Shift2_LimitRight = MasterInput.IN22 = X22;//滚筒2右极限
//
// agv.Public.i_Shift1ArrivalLeft = MasterInput.IN19 = X19;//滚筒1左到位对射
// agv.Public.i_Shift1ArrivalRight = MasterInput.IN20 = X20;//滚筒1右到位对射
// agv.Public.i_Shift2ArrivalLeft = MasterInput.IN23 = X23;//滚筒2左到位对射
// agv.Public.i_Shift2ArrivalRight = MasterInput.IN24 = X24;//滚筒2右到位对射
// if(!agv.Command.Au_Hand)
// {
// agv.Public.i_HandLiftSig = X7;
// agv.Public.i_HandDownSig = X8;
// if(agv.Public.i_HandLiftSig)
// Lifter1.runState = 1;
// else if(agv.Public.i_HandDownSig)
// Lifter1.runState = 2;
//
// agv.Public.i_HandFrontSig = X9;
// agv.Public.i_HandBackSig = X10;
// agv.Public.i_HandTurnLeftSig = X11;
// agv.Public.i_HandTurnRightSig = X12;
// if(agv.Public.i_HandFrontSig)
// agv.Command.HandMotorState = 1;
// else if(agv.Public.i_HandBackSig)
// agv.Command.HandMotorState = 2;
// else if(agv.Public.i_HandTurnLeftSig)
// agv.Command.HandMotorState = 3;
// else if(agv.Public.i_HandTurnRightSig)
// agv.Command.HandMotorState = 4;
// else
// agv.Command.HandMotorState = 0;
// ;
//
// }
}
void platformDataProcess(void)
{
X_Input();//IO输入信号
//自动模式且开启红外,雷达避障信号
if(agv.Command.Au_Hand&&agv.Command.Barrier_ONOFF)
{
if(agv.Command.CurDirection == 1 || agv.Command.CurDirection == 7 || agv.Command.CurDirection == 8)//前进方向
{
if((agv.Command.LaserArea!=0))
{
if(agv.Public.i_RadarSigFront_3)//最里层雷达避障
{
SetAlarm(0x0001);//停车
}
else
{
Reset_Alarm(0x0001);//取消停车避障
}
if(agv.Public.i_RadarSigFront_2)//二级减速
{
agv.Public.i_DoubleReduction = 1;//开启二级减速
}
else
{
agv.Public.i_DoubleReduction = 0;//取消二级减速
}
if(agv.Public.i_RadarSigFront_1)//一级减速
{
agv.Public.i_Reduction = 1;//开启一级减速
}
else
{
agv.Public.i_Reduction = 0;//取消一级减速
}
}
else
{
Reset_Alarm(0x0001);
agv.Public.i_DoubleReduction = 0;
agv.Public.i_Reduction = 0;
}
}
else if(agv.Command.CurDirection == 2 || agv.Command.CurDirection == 9 || agv.Command.CurDirection == 10)//后退方向
{
if(agv.Command.LaserArea!=0)
{
if(agv.Public.i_RadarSigBack_3)//最里层雷达避障(后)
{
SetAlarm(0x0001);//停车
}
else
{
Reset_Alarm(0x0001);//取消停车避障
}
if(agv.Public.i_RadarSigBack_2)//二级减速
{
agv.Public.i_DoubleReduction = 1;//开启二级减速
}
else
{
agv.Public.i_DoubleReduction = 0;//取消二级减速
}
if(agv.Public.i_RadarSigBack_1)//一级减速
{
agv.Public.i_Reduction = 1;//开启一级减速
}
else
{
agv.Public.i_Reduction = 0;//取消一级减速
}
}
else
{
Reset_Alarm(0x0001);
agv.Public.i_DoubleReduction = 0;
agv.Public.i_Reduction = 0;
}
}
}
else//不开启避障
{
Reset_Alarm(0x0001);//取消停车避障
agv.Public.i_Reduction = 0;//取消一级减速
agv.Public.i_DoubleReduction = 0;//取消二级减速
}
//防撞条
if(agv.Public.i_BumperSig)
{
SetAlarm(0x0006);//停车,防撞条报警和暂停触发
}
else
Reset_Alarm(0x0002);//取消防撞条报警
//急停触发
if (agv.Public.i_QuickStopSig)
{
SetAlarm(0x0104);//急停和暂停触发,防止再启动
}
else
{
Reset_Alarm(0x0100);//取消急停报警
}
if(agv.Public.i_StartSig)//启动
{
Reset_Alarm(0x1005);
}
if(agv.Public.i_StopSig)
{
SetAlarm(0x0004);//暂停
}
// if(agv.Public.i_Lift1DownLimit)//拉线编码器清零
// {
// SetLiftHeightZero();
// }
//启动和暂停指示灯
if(agv.Command.Au_Hand && (agv.Public.Error_Flag == 0 ))//自动模式无异常显示启动灯
{
Y6(1);
Y7(0);
}
else
{
Y6(0);
Y7(1);
}
agv.Public.i_quadEncoder1 = TIM_GetCounter(TIM1);
agv.Public.i_quadEncoder2 = TIM_GetCounter(TIM2);
agv.Public.i_quadEncoder3 = TIM_GetCounter(TIM3);
agv.Public.i_quadEncoder4 = TIM_GetCounter(TIM4);
// agv.Public.i_LiftHeightFirst = agv.Public.i_quadEncoder1/4;
checkMaterialState(); //物料检测
//自动模式脱轨判断
if(agv.Command.Au_Hand)
{
// if(!(agv.Command.LandMarkID == 40 || agv.Command.LandMarkID == 42 || agv.Command.LandMarkID == 44))
// {
// if(agv.Command.CurDirection == 2&& navi.Public.VerticalDistanceAgvToTARGET < 1100 && navi.Public.VerticalDistanceAgvToTARGET >600&&(traffic_land_marksReal.size==2||traffic_land_marksReal.size==3))
// {
// if(fabs(navi.Public.CenterOffset) > agv.Public.PosOffsetLimit || fabs(navi.Public.AngleDifference*57.3) > 3)
// {
// agv.Public.i_SecondCommunication = 1;
// SetAlarm(0x0080);//库位无法正常对接
// }
// }
// }
//前进后退距离脱轨判断
if(agv.Command.CurDirection == 1||agv.Command.CurDirection == 2)
{
if((navi.Public.DistanceAgvToSTART >= navi.Public.DistanceSTARTtoTARGET + 400) )//距离偏差大于40CM,脱轨
{
SetAlarm(0x8000);//脱轨报警
}
else
Reset_Alarm(0x8000);//取消脱轨报警
}
else
Reset_Alarm(0x8000);//取消脱轨报警
//前进后退,弧线左右转做脱轨判断
if(agv.Command.CurDirection == 1||agv.Command.CurDirection == 2)
// ||agv.Command.CurDirection == 7
// ||agv.Command.CurDirection == 8||agv.Command.CurDirection == 9||agv.Command.CurDirection == 10)
{
if((fabs(navi.Public.CenterOffset) > 300 ) )//位置偏差大于10CM,脱轨||
{
SetAlarm(0x0008);//脱轨报警
}
else
Reset_Alarm(0x0008);//取消脱轨报警
}
else
Reset_Alarm(0x0008);//取消脱轨报警
//9号输送线出来直行特殊处理
if(agv.Command.LandMarkID == 16 || agv.Command.LandMarkID == 18 || agv.Command.LandMarkID == 157)
Reset_Alarm(0x0008);
}
}
/*SETVMOT动作指令解析*/
#endif