Trackless.c 7.59 KB
#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