Camera.c 4.42 KB
#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;
			
		}
	}
}