SingleSteering.c
8.89 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
#include "SingleSteering.h"
#if P_SETUP_CHASSIS_MODE == 2
void chassisControlManual()//单舵轮点动
{
static int lastDir = 0;
DriverSteering1.Command.angle = usRegHoldingBuf[22];//设置舵轮角度
switch (agv.Command.HandMotorState)
{
case 0x00:
break;
case 10:
DriverSteering1.Command.speed = 0;
DriverSteering1.Command.angle = 0;
break;
case 0x02://前动力左转
DriverSteering1.Command.speed = agv.Parameter.HandSpeed*lastDir;
DriverSteering1.Command.angle = usRegHoldingBuf[22];//设置舵轮角度
break;
case 0x01://前动力右转
DriverSteering1.Command.speed = agv.Parameter.HandSpeed*lastDir;
DriverSteering1.Command.angle = -usRegHoldingBuf[22];//设置舵轮角度
break;
case 0x03://前进
DriverSteering1.Command.speed = agv.Parameter.HandSpeed;
DriverSteering1.Command.angle = 0;
lastDir = 1;
break;
case 0x04://后退
DriverSteering1.Command.speed = -agv.Parameter.HandSpeed;
lastDir = -1;
DriverSteering1.Command.angle = 0;
break;
default:
break;
}
setMotorSpeedSlope(agv.Parameter.HandSpeedSlope);
}
//设置驱动器自动速度
float AngleDifValue;
int angleOffset = 0;
void chassisControlAuto()
{
// LaserSlowDownProcess();//雷达避障减速处理
if(navi.Private.OutputOffset > 0)
{
angleOffset = (int)(mapping(navi.Private.OutputOffset,0,100,2,20)*10);
}
else if(navi.Private.OutputOffset < 0)
{
angleOffset = (int)(mapping(navi.Private.OutputOffset,-100,0,-20,-2)*10);
}
//根据转弯半径大小,计算打舵角度
if(navi.Private.SetCalculationRadius != 0)
AngleDifValue = atan(DISWHEELTOCENTER/navi.Private.SetCalculationRadius)*57.3*10;//打舵角度
if(AngleDifValue>0) AngleDifValue+=20;
if(AngleDifValue<0) AngleDifValue-=20;
switch (agv.Command.CurDirection)
{
case 0:
DriverSteering1.Command.speed = 0;
break;
case 1:
if(agv.Command.SetBaseSpeed == 0)
{
DriverSteering1.Command.speed = 0;
}
else
{
DriverSteering1.Command.angle = -angleOffset;
DriverSteering1.Command.speed = agv.Command.SetBaseSpeed;
}
break;
case 2:
if(agv.Command.SetBaseSpeed == 0)
{
DriverSteering1.Command.speed = 0;
}
else
{
DriverSteering1.Command.angle = -angleOffset;
DriverSteering1.Command.speed = -agv.Command.SetBaseSpeed;
}
break;
case 3:
break;
case 4:
break;
case 5:
break;
case 6:
break;
case 7://前进弧线左转,左轮设定速度-固定速度差-补偿值
DriverSteering1.Command.angle = -AngleDifValue;
DriverSteering1.Command.speed = agv.Command.SetBaseSpeed;
break;
case 8://前进弧线右转,左轮设定速度+固定速度差+补偿值
DriverSteering1.Command.angle = -AngleDifValue;
DriverSteering1.Command.speed = agv.Command.SetBaseSpeed;
break;
case 9://后退弧线左转,左轮设定速度+固定速度差-补偿值,给负速度
DriverSteering1.Command.angle = -AngleDifValue;
DriverSteering1.Command.speed = -agv.Command.SetBaseSpeed;
break;
case 10://后退弧线右转,左轮设定速度-固定速度差+补偿值,给负速度
DriverSteering1.Command.angle = -AngleDifValue;
DriverSteering1.Command.speed = -agv.Command.SetBaseSpeed;
break;
default:
DriverSteering1.Command.angle = 0;
DriverSteering1.Command.speed = 0;
break;
}
}
//单舵轮直行
void SingleSteeringRunStraight()
{
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.VerticalDistanceAgvToTARGET >= agv.Parameter.AdvanceParkPos) //agv到终点距离大于预停车距离
{
agv.Command.SetBaseSpeed = agv.Command.DispatchSpeed; //按系统下发速度走
}
else //agv到终点距离小于预停车距离,减速到设定自动转弯速度
{
agv.Command.SetBaseSpeed = mapping(navi.Public.VerticalDistanceAgvToTARGET, 0, agv.Parameter.AdvanceParkPos, agv.Command.NextDispatchSpeed, agv.Command.DispatchSpeed);
}
}
else //停车或者原地转
{
if (navi.Public.VerticalDistanceAgvToTARGET >= agv.Parameter.AdvanceParkPos) //如果agv到目标点距离大于预停车距离
{
agv.Command.SetBaseSpeed = agv.Command.DispatchSpeed; //设定速度等于系统下发速度
}
else if (navi.Public.VerticalDistanceAgvToTARGET <= agv.Parameter.AdvanceParkPos && navi.Public.VerticalDistanceAgvToTARGET > POSARRIVE_RANGE) //小于预停车距离,大于到点判断范围10MM,驱动器不能给太小速度,不能直接到0,设置了预停车速度
{
agv.Command.SetBaseSpeed = mapping(navi.Public.VerticalDistanceAgvToTARGET, 0, agv.Parameter.AdvanceParkPos, agv.Parameter.AdvanceParkSpeed, agv.Command.DispatchSpeed);
}
else
agv.Command.SetBaseSpeed = 0;
}
if (navi.Public.VerticalDistanceAgvToSTART < START_SPEEDUP_RANGE)
{
if (fabs(DriverMotor1.Public.encoderSpeed - DriverMotor2.Public.encoderSpeed) > START_SPEEDDIFF_LIMIT) //速度差太大
{
agv.Command.SetBaseSpeed = fabs(DriverMotor1.Public.encoderSpeed + DriverMotor2.Public.encoderSpeed) / 2;
}
setMotorSpeedSlope(2);
}
else
setMotorSpeedSlope(5);
}
//单舵轮弧线转弯
void SingleSteeringRunTurnning()
{
if (fabs(navi.Public.AngleDifference) >= ADVANCE_STOPSLOPE_ANGLE) //如果agv角度差大于预停车角度差
{
agv.Command.SetBaseSpeed = agv.Command.DispatchSpeed;
setMotorSpeedSlope(2);
}
else //如果agv角度差小于预停车角度差,开始减速至设定出弯速度
{
agv.Command.SetBaseSpeed = mapping(fabs(navi.Public.AngleDifference), 0, ADVANCE_STOPSLOPE_ANGLE, ARC_TURNSPEED_MIN, agv.Command.DispatchSpeed);
setMotorSpeedSlope(5);
}
}
//单舵轮原地转弯
void SingleSteeringPirouette()
{
static float agvInAngle = 0,turnAngleDiff = 0,lastAngleDiff = 0;
static u8 TurnStep = 0, TurnArriveFlag = 0;
if (TurnStep == 0) //求出位置信息
{
navi.Private.TarAngle = CalculatingDirectionAngle(StartPoint, TargetPoint); //求出目标方向角度
agv.Command.SetBaseSpeed = 0;
TurnArriveFlag = 0;
if(agv.Command.CurDirection == 3||agv.Command.CurDirection == 6)//打舵
DriverSteering1.Command.angle = 900;
else
DriverSteering1.Command.angle = -900;
if(fabs(DriverSteering1.Public.encoderPose*57.3*10 - DriverSteering1.Command.angle)<10)//打舵到位,目标舵轮角度和实际舵轮角度差小于1度
{
TurnStep = 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 (agvInAngle >= ADVANCE_STOPSLOPE_ANGLE)
{
agv.Command.SetBaseSpeed = TURNSPEED_MAX;
}
else if ((agvInAngle < ADVANCE_STOPSLOPE_ANGLE) && (agvInAngle > TURNINGOFF_ANGLE))
{
agv.Command.SetBaseSpeed = (int)mapping(agvInAngle, TURNINGOFF_ANGLE, ADVANCE_STOPSLOPE_ANGLE, TURNSPEED_MIN, TURNSPEED_MAX);
}
else if ((agvInAngle <= TURNINGOFF_ANGLE)||(turnAngleDiff*lastAngleDiff < 0))
{
TurnArriveFlag = 1;
}
lastAngleDiff = turnAngleDiff;
//出弯
if (TurnArriveFlag == 1)
{
//出弯
lastAngleDiff = 0;
agv.Command.SetBaseSpeed = 0;
if (fabs(DriverMotor1.Public.encoderSpeed) < 5 && fabs(DriverMotor2.Public.encoderSpeed) < 5)
{
DriverSteering1.Command.angle = 0;//回舵
if(fabs(DriverSteering1.Public.encoderPose)<0.03)//回舵完成
{
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;
}
}
}
}
}
setMotorSpeedSlope(5);
}
void chassisGetAutoSpeed(u8 *CurrentDir)
{
if(*CurrentDir == 1||*CurrentDir == 2)//直行
{
SingleSteeringRunStraight();//硬差速直行
}
else if(*CurrentDir == 3||*CurrentDir == 4||*CurrentDir == 5||*CurrentDir == 6)//原地旋转
{
}
else if(*CurrentDir == 7||*CurrentDir == 8||*CurrentDir == 9||*CurrentDir == 10)//弧线转弯
{
SingleSteeringRunTurnning();//弧线转弯
}
}
#endif