Vision.c
5.38 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
#include "Vision.h"
#if P_SETUP_NAV_TYPE == 3
#define PACK_POSE_BUFF 17
u8 vision_write[PACK_POSE_BUFF];
u8 relocation[14] = {0xAC, 0xED, 0x0C, 0x0B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
u8 StartSendRelocationSig = 1;
void SendDiffInfo(void)
{
static u8 i = 0, i1 = 0;
static bool send_ready = false;
static int last_time = 0, last_time1 = 0, last_time2 = 0;
u8 head1 = 0xac;
u8 head2 = 0xed;
u8 length = 14;
u8 cmd = 10;
int left = 0;
int right = 0;
int other = 0;
u8 check = 0;
left = (int)(DriverMotor1.Public.encoderSpeed);
right = (int)(DriverMotor2.Public.encoderSpeed);
if (i++ > 100)
{
i = 0;
// Uart_Printf(COM1,"实际速度 = %d %d 电流 = %.1f %.1f\r\n",left,right,DriverMotor1.Public.ampere,DriverMotor2.Public.ampere);
}
memset(vision_write, 0, sizeof(vision_write));
vision_write[0] = head1;
vision_write[1] = head2;
vision_write[2] = length;
vision_write[3] = cmd;
u8 *pdata = (u8 *)&left;
int temp_i = 0;
for (temp_i = 0; temp_i != 4; ++temp_i)
{
vision_write[7 - temp_i] = pdata[temp_i];
}
pdata = (u8 *)&right;
for (temp_i = 0; temp_i != 4; ++temp_i)
{
vision_write[11 - temp_i] = pdata[temp_i];
}
pdata = (u8 *)&other;
for (temp_i = 0; temp_i != 4; ++temp_i)
{
vision_write[15 - temp_i] = pdata[temp_i];
}
vision_write[16] = 0;
if (!send_ready && agv.Public.SystemTime - last_time < 50)
return;
send_ready = true;
last_time = agv.Public.SystemTime;
static uint16_t index = 0;
if (agv.Public.SystemTime - last_time2 >= 20)
{
WriteUart(COM3, vision_write, 17);
last_time2 = agv.Public.SystemTime;
}
//重定位上报**************
if (agv.Public.SystemTime - last_time1 > 5000)
{
if (agv.Public.OnlinePointSig && StartSendRelocationSig)
{
relocation[4] = agv.Public.OnlinePointSig;
WriteUart(COM3, relocation, 14);
Uart_Printf(COM1, "重定位ING*********\r\n");
}
else if (agv.Public.OnlinePointSig == 0)
{
StartSendRelocationSig = 1;
}
last_time1 = agv.Public.SystemTime;
}
if (index == PACK_POSE_BUFF)
{
send_ready = false;
}
}
void ProccessVisionDATAInfo(unsigned char *Res)
{
static unsigned char Buffer2[30];
static unsigned short iii = 0, count = 0;
static unsigned char LastRes = 0;
static unsigned char RecvSig = 0;
unsigned char i = 0, check_value = 0;
int XXX = 0, YYY = 0;
short WWW = 0;
static float LastX = 0, LastY = 0, LastW = 0;
// if(iii > 20)
// {
// iii = 0;
// }
if (*Res == 0xac)
{
LastRes = *Res;
}
if (LastRes == 0xac && *Res == 0xed)
{
LastRes = 0;
iii = 0;
RecvSig = 1;
}
if (RecvSig)
{
Buffer2[iii++] = *Res;
if (iii > 15)
{
RecvSig = 0;
{
for (i = 1; i < iii - 1; i++)
{
check_value ^= Buffer2[i];
}
if (check_value == Buffer2[iii - 1])
{
if (Buffer2[2] == 1)
{
WWW = (Buffer2[11] << 8) | Buffer2[12];
XXX = (Buffer2[3] << 24) | (Buffer2[4] << 16) | (Buffer2[5] << 8) | Buffer2[6];
YYY = (Buffer2[7] << 24) | (Buffer2[8] << 16) | (Buffer2[9] << 8) | Buffer2[10];
agv.Public.Coordinate_W = (float)WWW / 1000;
agv.Public.Coordinate_X = (float)XXX;
agv.Public.Coordinate_Y = (float)YYY;
// Uart_Printf(COM1,"X = %.2f Y = %.2f W = %.2f X变化 = %.2f Y变化 = %.2f W变化 = %.2f\r\n",agv.Public.Coordinate_X,agv.Public.Coordinate_Y,agv.Public.Coordinate_W,
// agv.Public.Coordinate_X - LastX,agv.Public.Coordinate_Y - LastY,agv.Public.Coordinate_W - LastW);
LastX = agv.Public.Coordinate_X;
LastY = agv.Public.Coordinate_Y;
LastW = agv.Public.Coordinate_W;
}
else if (Buffer2[2] == 2) //重定位下发
{
if (Buffer2[13] == 0)
{
StartSendRelocationSig = 0;
Uart_Printf(COM1, "视觉定位成功********\r\n");
}
}
}
}
}
}
}
void ProcessDataFormUartVision()
{
static int ConnectSlamTime = 0, iii = 0;
unsigned char buff[64];
unsigned int len;
unsigned i;
len = ReadUart(COM3, buff, 64);
if (len > 0)
{
for (i = 0; i < len; i++)
{
ProccessVisionDATAInfo(buff + i);
}
ConnectSlamTime = 0;
agv.Public.SlamConnectError = 0;
Reset_Alarm(0x2000);
}
else
{
ConnectSlamTime++;
if (ConnectSlamTime >= 1000)
{
agv.Public.SlamConnectError = 1; //SLAM连接中断
SetAlarm(0x2000);
if (iii++ > 300)
{
iii = 0;
Uart_Printf(COM1, "视觉通讯中断*********\r\n");
}
}
}
}
void SlamDataProcess()
{
SendDiffInfo();
ProcessDataFormUartVision();
}
#endif