Trackless.c
7.59 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
#include "Trackless.h"
#if 1//P_SETUP_NAV_TYPE==2||P_SETUP_NAV_TYPE==3
//获取激光数据slam,此补偿不是将雷达位置补偿到车体中心而是工位坐标特殊补偿,每个工位的补偿值不一样,龙旗项目使用中
void laserDataUpdate() //
{
CurrentCenterPoint.TarX = agv.Public.Coordinate_X + agv.Command.X_compensation; //X补偿
CurrentCenterPoint.TarY = agv.Public.Coordinate_Y + agv.Command.Y_compensation; //Y补偿
CurrentCenterPoint.CurAngle = agv.Public.Coordinate_W + agv.Command.W_compensation; //W补偿
}
int LightArriveFlagL = 0,LightArriveFlagR = 0;
//到达判断
unsigned char ArriveJugement2()
{
static u8 lastStopFlagL = 0,lastStopFlagR = 0;
if(navi.Public.VerticalDistanceAgvToTARGET < LIGHT_STOP_SIGNAL_DIS)
{
if(agv.Command.LightStopSig == 1)//左光电停靠
{
if(agv.Public.i_LightStopFlagL == 1&&lastStopFlagL == 0)
{
LightArriveFlagL = 1;
}
if(LightArriveFlagL == 1)
{
Uart_Printf(COM1,"左光电到达 %d\r\n",agv.Command.LightStopSig);
return 1;
}
if(agv.Public.i_LightStopFlagL == 0 && navi.Public.VerticalDistanceAgvToTARGET < REFLECTIVE_RANGE)
{
navi.Private.FirstZeroPoint = 1;
}
if(navi.Private.FirstZeroPoint && navi.Public.VerticalDistanceAgvToTARGET > REFLECTIVE_RANGE*2)
{
Uart_Printf(COM1,"未扫到光电到达 %d\r\n",agv.Command.LightStopSig);
return 1;
}
}
else if(agv.Command.LightStopSig == 1)//右光电停靠
{
if(agv.Public.i_LightStopFlagR == 1&&lastStopFlagR == 0)
{
LightArriveFlagR = 1;
}
if(LightArriveFlagR == 1)
{
Uart_Printf(COM1,"右光电到达 %d\r\n",agv.Command.LightStopSig);
return 1;
}
}
else
{
if ((navi.Public.VerticalDistanceAgvToSTART >= (navi.Public.DistanceSTARTtoTARGET - POSARRIVE_RANGE)) && (navi.Public.VerticalDistanceAgvToTARGET < navi.Public.VerticalDistanceAgvToSTART))
{
Uart_Printf(COM1,"正常到达 %d\r\n",agv.Command.LightStopSig);
return 1;
}
}
lastStopFlagL = agv.Public.i_LightStopFlagL;
lastStopFlagR = agv.Public.i_LightStopFlagR;
}
return 0;
}
//更新执行站点
//计算偏移量 设置不同运动方式的pid值
u8 Anglevalue1 = 5;
void calculateOffsetValue2(unsigned char Direction)
{
switch (Direction)
{
case 0:
break;
case 1: //前进
navi.Private.TarAngle = CalculatingDirectionAngle(StartPoint, TargetPoint); //求出目标方向角度
navi.Public.AngleDifference = CalculatingCurrentAndTargetAngle(CurrentCenterPoint.CurAngle, navi.Private.TarAngle); //角度偏移
navi.Public.CenterOffset = -CalCoordinateDis(CurrentCenterPoint, StartPoint, TargetPoint); //车中心横向偏移量
if(fabs(navi.Public.CenterOffset) > 15)
Anglevalue1 = 5;
else
Anglevalue1 = 3;
//根据车身角度偏差设置舵轮差速补偿系数
if(navi.Public.AngleDifference > 0.017)//左偏
{
TongyiStruct1.compensationCoefficient = 1.1;
TongyiStruct3.compensationCoefficient = 0.9;
}
else if(navi.Public.AngleDifference < -0.017)
{
TongyiStruct1.compensationCoefficient = 0.9;
TongyiStruct3.compensationCoefficient = 1.1;
}
else
{
TongyiStruct1.compensationCoefficient = 1;
TongyiStruct3.compensationCoefficient = 1;
}
//根据车体位置偏差设置舵轮打舵角度
if(navi.Public.CenterOffset > 3)//左偏,右打舵
{
TongyiStruct2.angleNum = Anglevalue1;
TongyiStruct4.angleNum = Anglevalue1;
}
else if(navi.Public.CenterOffset <-3)
{
TongyiStruct2.angleNum = -Anglevalue1;
TongyiStruct4.angleNum = -Anglevalue1;
}
else
{
TongyiStruct2.angleNum = 0;
TongyiStruct4.angleNum = 0;
}
break;
case 2: //后退
navi.Private.TarAngle = CalculatingDirectionAngle(StartPoint, TargetPoint); //求出目标方向角度
navi.Public.AngleDifference = CalculatingCurrentAndTargetAngle(CurrentCenterPoint.CurAngle + PI, navi.Private.TarAngle); //角度偏移
navi.Public.CenterOffset = CalCoordinateDis(CurrentCenterPoint, StartPoint, TargetPoint); //车中心横向偏移量
if(fabs(navi.Public.CenterOffset) > 15)
Anglevalue1 = 5;
else
Anglevalue1 = 3;
if(navi.Public.AngleDifference > 0.017)//左偏
{
TongyiStruct1.compensationCoefficient = 0.9;
TongyiStruct3.compensationCoefficient = 1.1;
}
else if(navi.Public.AngleDifference < -0.017)
{
TongyiStruct1.compensationCoefficient = 1.1;
TongyiStruct3.compensationCoefficient = 0.9;
}
else
{
TongyiStruct1.compensationCoefficient = 1;
TongyiStruct3.compensationCoefficient = 1;
}
//根据车体位置偏差设置舵轮打舵角度
if(navi.Public.CenterOffset > 3)//左偏,右打舵
{
TongyiStruct2.angleNum = -Anglevalue1;
TongyiStruct4.angleNum = -Anglevalue1;
}
else if(navi.Public.CenterOffset <-3)
{
TongyiStruct2.angleNum = Anglevalue1;
TongyiStruct4.angleNum = Anglevalue1;
}
else
{
TongyiStruct2.angleNum = 0;
TongyiStruct4.angleNum = 0;
}
break;
case 3:
break;
case 4:
break;
case 5:
break;
case 6:
break;
case 7: //前进左转
navi.Private.TarAngle = CalculatingDirectionAngle(PointThree, PointFour); //求出目标方向角度
navi.Public.AngleDifference = CalculatingCurrentAndTargetAngle(CurrentCenterPoint.CurAngle, navi.Private.TarAngle); //角度偏移
navi.Public.CenterOffset = TwoPointDistance(CurrentCenterPoint, CircleCenterPoint) - navi.Private.SetCalculationRadius; //车中心横向偏移量
pid = navi.PIDPara[2];
break;
case 8: //前进右转
navi.Private.TarAngle = CalculatingDirectionAngle(PointThree, PointFour); //求出目标方向角度
navi.Public.AngleDifference = CalculatingCurrentAndTargetAngle(CurrentCenterPoint.CurAngle, navi.Private.TarAngle); //角度偏移
navi.Public.CenterOffset = TwoPointDistance(CurrentCenterPoint, CircleCenterPoint) - navi.Private.SetCalculationRadius; //车中心横向偏移量
pid = navi.PIDPara[2];
break;
case 9: //后退左转
navi.Private.TarAngle = CalculatingDirectionAngle(PointThree, PointFour); //求出目标方向角度
navi.Public.AngleDifference = CalculatingCurrentAndTargetAngle(CurrentCenterPoint.CurAngle + PI, navi.Private.TarAngle); //角度偏移
navi.Public.CenterOffset = TwoPointDistance(CurrentCenterPoint, CircleCenterPoint) - navi.Private.SetCalculationRadius; //车中心横向偏移量
pid = navi.PIDPara[2];
break;
case 10: //后退右转
navi.Private.TarAngle = CalculatingDirectionAngle(PointThree, PointFour); //求出目标方向角度
navi.Public.AngleDifference = CalculatingCurrentAndTargetAngle(CurrentCenterPoint.CurAngle + PI, navi.Private.TarAngle); //角度偏移
navi.Public.CenterOffset = TwoPointDistance(CurrentCenterPoint, CircleCenterPoint) - navi.Private.SetCalculationRadius; //车中心横向偏移量
pid = navi.PIDPara[2];
break;
default:
break;
}
}
void slamNavigation()
{
laserDataUpdate(); //获取激光数据,以及特殊工位定点补偿**************
calculateOffsetValue2(agv.Command.CurDirection); //计算偏移量和设置不同运动方式的pid值
// offsetCompensationOutput(&pid); //计算处理得到补偿值***********
CalculateDistance(); //计算起始点、目标点、agv之前的距离
}
#endif