Camera.c
4.42 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 "Camera.h"
CameraParameter Camera,CameraTwo;
float CurAngle;
void ProcessCameraData(unsigned char *data,unsigned int length)
{
static int i = 0;
float XbiasFromros = 0, YbiasFromros = 0, TheataFromros = 0;
int calcuTime = 0,timeStamp = 0;
int LocationSig = 0,CordingSig = 0,ROISig = 0;
static int XCoordingData = 0,YCoordingData = 0;
sscanf((const char *)data, "<%dXY%d@(%fx%f)%f@%x@%x@%d-%d-%d>",
&XCoordingData, &YCoordingData, &XbiasFromros, &YbiasFromros, &TheataFromros, &calcuTime, &timeStamp, &LocationSig, &CordingSig,&ROISig);
if(XCoordingData!=9999)
{
Camera.XCoordingData = XCoordingData;
Camera.YCoordingData = YCoordingData;
}
//if(!(XCoordingData == 0&&YCoordingData == 0) && LocationSig == 1)
if(LocationSig == 1)
{
// Camera.UpdataFlag = 1;
// if(agv.Command.RunState == 0 || agv.Command.RunState == 2)
// Camera.Y_pixel = -(XbiasFromros-400)*0.2125 - 15;
// else
Camera.Y_pixel = -(XbiasFromros-400)*0.2125;
Camera.X_pixel = -(YbiasFromros-300)*0.2125;
// if(agv.Command.RunState == 1 || agv.Command.RunState == 3)
Camera.angle = (TheataFromros + 0)/57.3;
// else
// Camera.angle = (TheataFromros+1)/57.3;
CurAngle = TheataFromros;
Camera.LocationSig = LocationSig;
if(i++>20)
{
i = 0;
Uart_Printf(COM1,"识别二维码 坐标 = %d %d,位置偏移 = %.2f %.2f,角度 = %.2f,定位状态 = %d %d,二维码 = %d\r\n",
XCoordingData,YCoordingData,Camera.X_pixel,Camera.Y_pixel,TheataFromros,LocationSig,ROISig,Camera.UpdataFlag);
}
}
}
float testX,testY;
void ProcessCameraData2(unsigned char *data,unsigned int length)
{
static int i = 0;
float XbiasFromros = 0, YbiasFromros = 0, TheataFromros = 0;
int calcuTime = 0,timeStamp = 0;
int LocationSig = 0,CordingSig = 0,ROISig = 0;
static int XCoordingData = 0,YCoordingData = 0;
sscanf((const char *)data, "<%dXY%d@(%fx%f)%f@%x@%x@%d-%d-%d>",
&XCoordingData, &YCoordingData, &XbiasFromros, &YbiasFromros, &TheataFromros, &calcuTime, &timeStamp, &LocationSig, &CordingSig,&ROISig);
if(LocationSig == 1)
{
testX = XbiasFromros;
testY = YbiasFromros;
CameraTwo.XCoordingData = XCoordingData;
CameraTwo.Y_pixel = -(XbiasFromros-400)*0.2125;
CameraTwo.X_pixel = -(YbiasFromros-300)*0.2125;
CameraTwo.angle = (TheataFromros + 0);
CameraTwo.LocationSig = LocationSig;
if(i++>50)
{
i = 0;
Uart_Printf(COM1,"识别货架二维码 ID = %d,位置偏移 = %.2f %.2f,角度 = %.2f,定位状态 = %d\r\n",
XCoordingData,CameraTwo.X_pixel,CameraTwo.Y_pixel,TheataFromros,LocationSig);
}
}
}
void UpdateCameraData()//地面
{
unsigned char buff[120],recvBuff[120];
unsigned int len;
unsigned int i;
static int StepFlag = 0,iii = 0,lastTime = 0;
len = ReadUart(COM3,buff,120);
if(len > 0)
{
// WriteUart(COM1,buff,sizeof(buff));
for(i = 0;i<len;i++)
{
if(buff[i] == 0x3c)
{
iii = 0;
StepFlag = 1;
}
else if(buff[i] == 0x3e&&StepFlag == 1)
{
StepFlag = 2;
// Uart_Printf(COM1,"一帧数据完成\r\n");
}
if(iii>110)
{
StepFlag = 0;
iii = 0;
}
if(StepFlag == 1)
{
recvBuff[iii++] = buff[i];
}
else if(StepFlag == 2)
{
recvBuff[iii++] = buff[i];
ProcessCameraData(recvBuff,iii);
StepFlag = 0;
// Camera.UpdataFlag = 1;
// Uart_Printf(COM1,"%s\r\n",recvBuff);
}
}
lastTime = agv.Public.SystemTime;
}
else
{
if(agv.Public.SystemTime - lastTime > 500)
{
lastTime = agv.Public.SystemTime;
// memset(&Camera,0,sizeof(Camera));
Camera.UpdataFlag = 0;
}
}
}
void UpdateCameraData2()//天花板
{
unsigned char buff[120],recvBuff[120];
unsigned int len;
unsigned int i;
static int StepFlag = 0,iii = 0,lastTime = 0;
len = ReadUart(COM4,buff,120);
if(len > 0)
{
// WriteUart(COM1,buff,sizeof(buff));
for(i = 0;i<len;i++)
{
if(buff[i] == '<')
{
iii = 0;
StepFlag = 1;
}
else if(buff[i] == '>')
{
StepFlag = 2;
// Uart_Printf(COM1,"一帧数据完成\r\n");
}
if(iii>100)
{
StepFlag = 0;
iii = 0;
}
if(StepFlag == 1)
{
recvBuff[iii++] = buff[i];
}
else if(StepFlag == 2)
{
recvBuff[iii++] = buff[i];
ProcessCameraData2(recvBuff,iii);
StepFlag = 0;
CameraTwo.UpdataFlag = 1;
// Uart_Printf(COM1,"%s\r\n",recvBuff);
}
}
lastTime = agv.Public.SystemTime;
}
else
{
if(agv.Public.SystemTime - lastTime > 500)
{
lastTime = agv.Public.SystemTime;
// memset(&CameraTwo,0,sizeof(CameraTwo));
CameraTwo.UpdataFlag = 0;
CameraTwo.Number = 0;
}
}
}