HardDifferential.c
12.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
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
#if P_SETUP_CHASSIS_MODE == 0
#include "HardDifferential.h"
//点动
extern int RecodeHandTime;
extern void AGVRunStateStopHand(int Time);
float arriveAngle = 0.015;
void chassisControlManual(void)
{
static float curAngle1 = 0,curAngle2 = 0;
switch (agv.Command.HandMotorState)
{
case 0x00:
TongyiStruct1.setSpeed = 0;
TongyiStruct3.setSpeed = 0;
TongyiStruct2.setSpeed = 5000;
TongyiStruct4.setSpeed = 5000;
break;
case 0x01: //前进
TongyiStruct1.setSpeed = agv.Parameter.HandSpeed;
TongyiStruct3.setSpeed = agv.Parameter.HandSpeed;
break;
case 0x02: //后退
TongyiStruct1.setSpeed = -agv.Parameter.HandSpeed;
TongyiStruct3.setSpeed = -agv.Parameter.HandSpeed;
break;
case 0x03: //左转
TongyiStruct2.angleNum = 90;
TongyiStruct4.angleNum = 90;
break;
case 0x04: //右转
TongyiStruct2.angleNum = 0;
TongyiStruct4.angleNum = 0;
break;
case 0x05: //
TongyiStruct2.angleNum = 56;//TongyiStruct2.encodeAngleNum-5;//角度一直比当前角度加5度,不超过限制
TongyiStruct4.angleNum = 56;
break;
case 0x06: //左旋转
TongyiStruct1.setSpeed = 100;
TongyiStruct3.setSpeed = -100;
break;
case 0x07: //右旋转
TongyiStruct1.setSpeed = -100;
TongyiStruct3.setSpeed = 100;
break;
default:
break;
}
setMotorSpeedSlope(agv.Parameter.HandSpeedSlope);
}
void chassisControlAutoSlamPPC()
{
static float SpeedDifValue = 0;//根据转弯半径大小,计算固定速度差值
//根据转弯半径大小,计算固定速度差值
static int i = 0;
if(navi.Private.SetCalculationRadius != 0)
SpeedDifValue = P_SETUP_WHEEL_Y_DIS * ((float)agv.Command.SetBaseSpeed) / (navi.Private.SetCalculationRadius) / 2;
else
SpeedDifValue = 0;
if(i++ > 10)
{
i = 0;
Uart_Printf(COM1,"转弯半径 = %.2f 速度差 = %.2f\r\n",navi.Private.SetCalculationRadius,SpeedDifValue);
}
switch (agv.Command.CurDirection)
{
case 0:
KincoStruct1.setSpeed = 0;
KincoStruct2.setSpeed = 0;
break;
case 1:
if (agv.Command.SetBaseSpeed == 0)
{
KincoStruct1.setSpeed = 0;
KincoStruct2.setSpeed = 0;
}
else
{
KincoStruct1.setSpeed = agv.Command.SetBaseSpeed + SpeedDifValue; //设定速度加补偿值
KincoStruct2.setSpeed = agv.Command.SetBaseSpeed - SpeedDifValue; //设定速度减补偿值
}
break;
case 2:
if (agv.Command.SetBaseSpeed == 0)
{
KincoStruct1.setSpeed = 0;
KincoStruct2.setSpeed = 0;
}
else
{
KincoStruct1.setSpeed = -(agv.Command.SetBaseSpeed);// - navi.Private.OutputOffset); //设定速度加补偿值,后退要给负速度
KincoStruct2.setSpeed = -(agv.Command.SetBaseSpeed);// + navi.Private.OutputOffset); //设定速度减补偿值,后退要给负速度
}
break;
case 3:
KincoStruct1.setSpeed = -agv.Command.SetBaseSpeed; //前进原地左转,左轮给负速度,以当前行进方向分左右
KincoStruct2.setSpeed = agv.Command.SetBaseSpeed; //前进原地左转,右轮给正速度,以当前行进方向分左右
break;
case 4:
KincoStruct1.setSpeed = agv.Command.SetBaseSpeed; //前进原地右转,左轮给正速度,以当前行进方向分左右
KincoStruct2.setSpeed = -agv.Command.SetBaseSpeed; //前进原地右转,右轮给负速度,以当前行进方向分左右
break;
default:
KincoStruct1.setSpeed = 0;
KincoStruct2.setSpeed = 0;
break;
}
}
void chassisControlAuto(void)
{
switch (agv.Command.CurDirection)
{
case 0:
TongyiStruct1.setSpeed = 0;
TongyiStruct3.setSpeed = 0;
TongyiStruct2.setSpeed = 5000;
TongyiStruct4.setSpeed = 5000;
break;
case 1:
if (agv.Command.SetBaseSpeed == 0)
{
TongyiStruct1.setSpeed = 0;
TongyiStruct3.setSpeed = 0;
}
else
{
TongyiStruct1.setSpeed = agv.Command.SetBaseSpeed*TongyiStruct1.compensationCoefficient; //设定速度加补偿值
TongyiStruct3.setSpeed = agv.Command.SetBaseSpeed*TongyiStruct3.compensationCoefficient; //设定速度减补偿值
}
break;
case 2:
if (agv.Command.SetBaseSpeed == 0)
{
TongyiStruct1.setSpeed = 0;
TongyiStruct3.setSpeed = 0;
}
else
{
TongyiStruct1.setSpeed = -(agv.Command.SetBaseSpeed*TongyiStruct1.compensationCoefficient);// - navi.Private.OutputOffset); //设定速度加补偿值,后退要给负速度
TongyiStruct3.setSpeed = -(agv.Command.SetBaseSpeed*TongyiStruct3.compensationCoefficient);// + navi.Private.OutputOffset); //设定速度减补偿值,后退要给负速度
}
break;
case 3:
TongyiStruct1.setSpeed = -agv.Command.SetBaseSpeed; //前进原地左转,左轮给负速度,以当前行进方向分左右
TongyiStruct3.setSpeed = agv.Command.SetBaseSpeed; //前进原地左转,右轮给正速度,以当前行进方向分左右
break;
case 4:
TongyiStruct1.setSpeed = agv.Command.SetBaseSpeed; //前进原地右转,左轮给正速度,以当前行进方向分左右
TongyiStruct3.setSpeed = -agv.Command.SetBaseSpeed; //前进原地右转,右轮给负速度,以当前行进方向分左右
break;
case 5:
TongyiStruct1.setSpeed = -agv.Command.SetBaseSpeed; //后退原地左转,左轮给正速度,以当前行进方向分左右
TongyiStruct3.setSpeed = agv.Command.SetBaseSpeed; //后退原地左转,右轮给负速度,以当前行进方向分左右
break;
case 6:
TongyiStruct1.setSpeed = agv.Command.SetBaseSpeed; //后退原地右转,左轮给负速度,以当前行进方向分左右
TongyiStruct3.setSpeed = -agv.Command.SetBaseSpeed; //后退原地右转,右轮给正速度,以当前行进方向分左右
break;
default:
TongyiStruct1.setSpeed = 0;
TongyiStruct3.setSpeed = 0;
break;
}
}
//硬差速直行
void HardDifferentialSpeedStraight()
{
float DIS = TwoPointDistance(StartPoint, TargetPoint);
if(DIS > 10000)
navi.Public.DistanceAgvToTARGET = DIS - fabs(navi.Public.DistanceAgvToSTART);
else
navi.Public.DistanceAgvToTARGET = DIS - fabs(navi.Public.DistanceAgvToSTART);
if (agv.Command.CurDirection == agv.Command.NextDirection) //如果当前方向和下次方向相同
{
agv.Command.SetBaseSpeed = agv.Command.DispatchSpeed; //设定速度为系统下发速度
} //如果记下来是弧线转弯,做减速处理
else if (agv.Command.NextDirection == 7 || agv.Command.NextDirection == 8 || agv.Command.NextDirection == 9 || agv.Command.NextDirection == 10)
{
if (navi.Public.DistanceAgvToTARGET >= agv.Parameter.AdvanceParkPos) //agv到终点距离大于预停车距离
{
agv.Command.SetBaseSpeed = agv.Command.DispatchSpeed; //按系统下发速度走
}
else //agv到终点距离小于预停车距离,减速到设定自动转弯速度
{
agv.Command.SetBaseSpeed = mapping(navi.Public.DistanceAgvToTARGET, 0, agv.Parameter.AdvanceParkPos, agv.Command.NextDispatchSpeed, agv.Command.DispatchSpeed);
}
}
else //停车或者原地转
{
if (navi.Public.DistanceAgvToTARGET >= agv.Parameter.AdvanceParkPos) //如果agv到目标点距离大于预停车距离
{
agv.Command.SetBaseSpeed = agv.Command.DispatchSpeed; //设定速度等于系统下发速度
}
else if (navi.Public.DistanceAgvToTARGET <= agv.Parameter.AdvanceParkPos && navi.Public.DistanceAgvToTARGET > LIGHT_STOP_SIGNAL_DIS ) //小于预停车距离,大于到点判断范围10MM,驱动器不能给太小速度,不能直接到0,设置了预停车速度
{
agv.Command.SetBaseSpeed = mapping(navi.Public.DistanceAgvToTARGET, LIGHT_STOP_SIGNAL_DIS, agv.Parameter.AdvanceParkPos, agv.Parameter.AdvanceParkSpeed, agv.Command.DispatchSpeed);
}
else
agv.Command.SetBaseSpeed = agv.Parameter.AdvanceParkSpeed;
}
if (navi.Public.DistanceAgvToSTART < START_SPEEDUP_RANGE)
{
agv.Command.SetBaseSpeed = 100;
// if (fabs(TongyiStruct1.encodeSpeed - TongyiStruct3.encodeSpeed) > START_SPEEDDIFF_LIMIT) //速度差太大
// {
// agv.Command.SetBaseSpeed = fabs(TongyiStruct1.encodeSpeed + TongyiStruct3.encodeSpeed) / 2;
// }
// setMotorSpeedSlope(0.3);
}
// else
// setMotorSpeedSlope(1.5);
if(Rotate1.setSpeed != 0)
{
agv.Command.SetBaseSpeed = 0;
}
}
//硬差速弧线转弯
void HardDifferentialSpeedRunTurnning()
{
if (fabs(navi.Public.AngleDifference) >= ADVANCE_STOPSLOPE_ANGLE) //如果agv角度差大于预停车角度差
{
agv.Command.SetBaseSpeed = agv.Command.DispatchSpeed;
setMotorSpeedSlope(0.5);
}
else //如果agv角度差小于预停车角度差,开始减速至设定出弯速度
{
agv.Command.SetBaseSpeed = mapping(fabs(navi.Public.AngleDifference), 0, ADVANCE_STOPSLOPE_ANGLE, ARC_TURNSPEED_MIN, agv.Command.DispatchSpeed);
setMotorSpeedSlope(0.2);
}
}
u8 TurnStep = 0;
//硬差速原地转弯
void HardDifferentialSpeedPirouette()
{
static float agvInAngle = 0,turnAngleDiff = 0,lastAngleDiff = 0;
static u8 TurnArriveFlag = 0,turnState = 0;
static int lastTime = 0;
if (TurnStep == 0) //求出位置信息
{
navi.Private.TarAngle = CalculatingDirectionAngle(StartPoint, TargetPoint); //求出目标方向角度
agv.Command.SetBaseSpeed = 0;
TurnArriveFlag = 0;
if(fabs(TongyiStruct1.encodeSpeed) < 5 && fabs(TongyiStruct3.encodeSpeed) < 5)
{
agv.Command.SetPlatformTurnAngle = fabs(CalculatingCurrentAndTargetAngle(Camera.angle, navi.Private.TarAngle))*57.3;
if(agv.Command.SetPlatformTurnAngle > 70 && agv.Command.SetPlatformTurnAngle < 110)
{
agv.Command.SetPlatformTurnAngle = 90;
}
else if(agv.Command.SetPlatformTurnAngle > 160)
{
agv.Command.SetPlatformTurnAngle = 180;
}
else
agv.Command.SetPlatformTurnAngle = 0;
TongyiStruct2.angleNum = 55.814;
TongyiStruct4.angleNum = 55.814;
if((fabs)(TongyiStruct2.encodeAngleNum - TongyiStruct2.angleNum) <= 1)
{
TurnStep = 1;
turnState = 1;
}
}
}
else if (TurnStep == 1) //开始转弯
{
if (agv.Command.CurDirection == 3 || agv.Command.CurDirection == 4) //前进左右转
{
turnAngleDiff = CalculatingCurrentAndTargetAngle(CurrentCenterPoint.CurAngle, navi.Private.TarAngle);
agvInAngle = fabs(CalculatingCurrentAndTargetAngle(CurrentCenterPoint.CurAngle, navi.Private.TarAngle));
}
else //后退左右转
{
turnAngleDiff = CalculatingCurrentAndTargetAngle(CurrentCenterPoint.CurAngle + PI, navi.Private.TarAngle);
agvInAngle = fabs(CalculatingCurrentAndTargetAngle(CurrentCenterPoint.CurAngle + PI, navi.Private.TarAngle));
}
if (agvInAngle >= PI * 2)
agvInAngle -= PI * 2;
if(turnState)
{
if (agvInAngle >= ADVANCE_STOPSLOPE_ANGLE)
{
agv.Command.SetBaseSpeed = agv.Parameter.HandTurnSpeed;
}
else if ((agvInAngle < ADVANCE_STOPSLOPE_ANGLE) && (agvInAngle > TURNINGOFF_ANGLE))
{
agv.Command.SetBaseSpeed = (int)mapping(agvInAngle, TURNINGOFF_ANGLE, ADVANCE_STOPSLOPE_ANGLE, TURNSPEED_MIN, agv.Parameter.HandTurnSpeed);
}
// if (agvInAngle > TURNINGOFF_ANGLE)
// {
// agv.Command.SetBaseSpeed = agv.Parameter.HandTurnSpeed;
// }
else if ((agvInAngle <= TURNINGOFF_ANGLE))//||(turnAngleDiff*lastAngleDiff < 0))
{
turnState = 0;
}
}
else
{
agv.Command.SetBaseSpeed = 0;
TongyiStruct2.angleNum = 0;
TongyiStruct4.angleNum = 0;
if(fabs(TongyiStruct1.encodeSpeed) < 5 && fabs(TongyiStruct3.encodeSpeed) < 5)
{
if((fabs)(TongyiStruct2.encodeAngleNum - TongyiStruct2.angleNum) <= 1)
TurnArriveFlag = 1;
}
}
lastAngleDiff = turnAngleDiff;
//出弯
if (TurnArriveFlag == 1)
{
//出弯
lastAngleDiff = 0;
agv.Command.SetBaseSpeed = 0;
if (fabs(TongyiStruct1.encodeSpeed) < 5 && fabs(TongyiStruct3.encodeSpeed) < 5 )
{
if (agv.Public.SystemTime - lastTime > 1500)
{
if (agv.Command.CurDirection == 3 || agv.Command.CurDirection == 4)
{
traffic_land_marks.land_marks[agv.Command.standSiteID - 1].Direction = 1;
TurnStep = 0;
}
else if (agv.Command.CurDirection == 5 || agv.Command.CurDirection == 6)
{
traffic_land_marks.land_marks[agv.Command.standSiteID - 1].Direction = 2;
TurnStep = 0;
}
}
}
}
else
lastTime = agv.Public.SystemTime;
}
setMotorSpeedSlope(1.5);
}
//无轨硬差速模型运动控制
void chassisGetAutoSpeed(u8 *CurrentDir)
{
static u8 StopoverFlag = 1;
if (*CurrentDir == 1 || *CurrentDir == 2) //直行
{
HardDifferentialSpeedStraight(); //硬差速直行
}
else if (*CurrentDir == 3 || *CurrentDir == 4 || *CurrentDir == 5 || *CurrentDir == 6) //原地旋转
{
HardDifferentialSpeedPirouette(); //硬差速原地旋转
}
else if (*CurrentDir == 7 || *CurrentDir == 8 || *CurrentDir == 9 || *CurrentDir == 10) //弧线转弯
{
HardDifferentialSpeedRunTurnning(); //弧线转弯
}
else if(*CurrentDir == 11 || *CurrentDir == 12)//停车
{
if(StopoverFlag)
SetAlarm(0x0004);
}
}
#endif