ForkLift.c
10.9 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
#include "ForkLift.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;
agv.Public.i_UpdatePathSig = 1;
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 = 1;
LiftOffset1 = agv.Public.i_LiftHeightFirst - agv.Parameter.SetLift1Height; //前举升与目标高度差
//第一层举升
if (LiftOffset1 < -LIFTARRIVEVALUE) //上升
{
if (LiftOffset1 < -30)
{
Motor1->Command.speed = agv.Parameter.LiftSpeed;
}
else
{
Motor1->Command.speed = mapping(LiftOffset1, 0, -30, 100, (float)agv.Parameter.LiftSpeed);
}
}
else if (LiftOffset1 > LIFTARRIVEVALUE) //下降
{
if (LiftOffset1 > 30)
{
Motor1->Command.speed = -agv.Parameter.LiftSpeed;
}
else
{
Motor1->Command.speed = mapping(LiftOffset1, 0, 30, -100, -(float)agv.Parameter.LiftSpeed);
}
}
else
Motor1->Command.speed = 0;
if (FirstToZero1 && agv.Public.i_StartFirst) //下层第一次上电归零
{
Motor1->Command.speed = -agv.Parameter.LiftSpeed;
}
//第一层升降限制
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 X_Input()
{
agv.Public.i_RadarSigFront_1 = MasterInput.IN1 = !X1;//前壁障减速1
agv.Public.i_RadarSigFront_2 = MasterInput.IN2 = !X2;//前壁障减速2
agv.Public.i_RadarSigFront_3 = MasterInput.IN3 = !X3;//前壁障减速3
agv.Public.i_RadarSigBack_1 = MasterInput.IN4 = !X4;//后壁障减速1
agv.Public.i_RadarSigBack_2 = MasterInput.IN5 = !X5;//后壁障减速2
agv.Public.i_RadarSigBack_3 = MasterInput.IN6 = !X6;//后壁障减速3
agv.Public.i_QuickStopSig = MasterInput.IN7 = !X7;// 急停 常开
agv.Public.i_BumperSig = MasterInput.IN8 = X8;//防撞条
agv.Public.i_StartSig = MasterInput.IN9 = X9;// 启动
agv.Public.i_StopSig = MasterInput.IN10 = X10;//暂停
agv.Public.i_LightStopFlagL = MasterInput.IN11 = X11;//左停靠
agv.Public.i_LightStopFlagR = MasterInput.IN12 = X12;//右停靠
agv.Public.i_Lift1UpLimit = MasterInput.IN13 = !X13;//升降1上限位
agv.Public.i_Lift1DownLimit = MasterInput.IN14 = !X14;//升降1下限位
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右到位对射
}
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.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 if(agv.Command.CurDirection == 2 || agv.Command.CurDirection == 9 || agv.Command.CurDirection == 10)//后退方向
{
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_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(0x0004);
}
if(agv.Public.i_StopSig)
{
SetAlarm(0x0004);//暂停
}
if(agv.Public.i_Lift1DownLimit)//拉线编码器清零
{
TIM_SetCounter(TIM1, 0);
}
//启动和暂停指示灯
if(agv.Command.Au_Hand&&(agv.Public.Error_Flag&0x0004)==0)//自动模式无异常显示启动灯
{
Y7(1);
Y8(0);
}
else
{
Y7(0);
Y8(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.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) > 100)//位置偏差大于10CM,脱轨
// {
// SetAlarm(0x0008);//脱轨报警
// }
// else
// Reset_Alarm(0x0008);//取消脱轨报警
// }
// else
// Reset_Alarm(0x0008);//取消脱轨报警
}
}
/*SETVMOT动作指令解析*/
void commandActionAnalysis(int dataOne, int dataTwo)
{
switch (dataOne)
{
case 1: //下层皮带
agv.Command.Shift1State = dataTwo;
break;
case 2: //上层皮带
agv.Command.Shift2State = dataTwo;
break;
case 3: //上层举升高度第二层
agv.Parameter.SetLift2Height = dataTwo;
break;
case 4: //打开充电状态
switch (dataTwo) //小车运动方式设置 //
{
case 0:
Y9(0); //关闭充电器触点
break;
case 1: //自动充电站停靠传感器选型 充电预停车指令
Y9(1); //打开充电器触点
break;
}
case 5: //下层举升高度第一层
agv.Parameter.SetLift1Height = dataTwo;
}
}
#endif