SMT.c 10.5 KB
#include "SMT.h"
#if P_SETUP_PLATFORM_TYPE == 3
void initPlaformParam(void) //参数初始化
{
    Uart_Printf(COM1, "参数初始化\r\n");
    Y9(0); // 关闭agv自动充电触点

    agv.Command.standSiteID = 1;
    agv.Command.Au_Hand = 0;
		agv.Public.i_StartFirst = false;
    agv.Public.i_UpdatePathSig = 1;

    DriverMotor1.Command.speedSlope = 5;
    DriverMotor2.Command.speedSlope = 5;
    DriverLifter1.Command.speedSlope = 50;
    DriverShifter1.Command.speedSlope = 50;

		#if P_SETUP_SINGLE_PLAYER == 0 //0不开启单机测试  1开启
		SetAlarm(0x0040);
		#endif
}

void lifterRunManu(DriverStruct *Motor1) //举升手动运行
{
    /*第一层举升*/
    if (agv.Command.HandLiftState == 1) //上升
    {
        Motor1->Command.speed = agv.Parameter.LiftSpeed;
    }
    else if (agv.Command.HandLiftState == 2) //下降
    {
        Motor1->Command.speed = -agv.Parameter.LiftSpeed;
    }
    else
    {
        Motor1->Command.speed = 0;
    }

    //下层升降限制
    if (agv.Public.i_Lift1UpLimit && Motor1->Command.speed > 0)
    {
        Motor1->Command.speed = 0;
    }
    else if (agv.Public.i_Lift1DownLimit && Motor1->Command.speed < 0)
    {
        Motor1->Command.speed = 0;
    }
}

void lifterRunAuto(DriverStruct *Motor1) //举升自动运行
{
    static int LiftOffset1 = 0;

    static u8 FirstToZero1 = 1;

    LiftOffset1 = agv.Public.i_LiftHeightFirst  - agv.Parameter.SetLift1Height; //前举升与目标高度差

    //第一层举升
    if (LiftOffset1 < -LIFTARRIVEVALUE) //上升
    {
        if (LiftOffset1 < -30)
        {
            Motor1->Command.speed = agv.Parameter.LiftSpeed;
        }
        else
        {
            Motor1->Command.speed = mapping(LiftOffset1, 0, -30, 100, (float)agv.Parameter.LiftSpeed);
        }
    }
    else if (LiftOffset1 > LIFTARRIVEVALUE) //下降
    {
        if (LiftOffset1 > 30)
        {
            Motor1->Command.speed = -agv.Parameter.LiftSpeed;
        }
        else
        {
            Motor1->Command.speed = mapping(LiftOffset1, 0, 30, -100, -(float)agv.Parameter.LiftSpeed);
        }
    }
    else
        Motor1->Command.speed = 0;

    if (FirstToZero1 && agv.Public.i_StartFirst) //下层第一次上电归零
    {
        Motor1->Command.speed = -agv.Parameter.LiftSpeed;
    }
    //第一层升降限制
    if (agv.Public.i_Lift1UpLimit && Motor1->Command.speed > 0)
    {
        Motor1->Command.speed = 0;
    }
    else if (agv.Public.i_Lift1DownLimit && Motor1->Command.speed < 0)
    {
        FirstToZero1 = 0;
        Motor1->Command.speed = 0;
    }
}

void shifterRunManu(DriverStruct *Motor1) //滚筒手动运行
{
    if (agv.Command.HandShiftState == 1) //
    {
        Motor1->Command.speed = agv.Parameter.ShiftSpeed;
    }
    else if (agv.Command.HandShiftState == 2) //
    {
        Motor1->Command.speed = -agv.Parameter.ShiftSpeed;
    }
    else //停止
    {
        Motor1->Command.speed = 0;
    }
}
void shifterRunAuto(DriverStruct *Motor1) //滚筒自动运行
{
    //下层滚筒
    switch (agv.Command.Shift1State)
    {
    case 0: //无动作或者微挪料框
        Motor1->Command.speed = 0;
        if (agv.Public.i_Shift1ArrivalLeft && !agv.Public.i_Shift1ArrivalRight && !agv.Public.i_Shift1_LimitRight)
        {
            Motor1->Command.speed = agv.Parameter.ShiftSpeed;
        }
        else if (agv.Public.i_Shift1ArrivalRight && !agv.Public.i_Shift1ArrivalLeft && !agv.Public.i_Shift1_LimitLeft)
        {
            Motor1->Command.speed = -agv.Parameter.ShiftSpeed;
        }
        else
            Motor1->Command.speed = 0;
        break;

    case 1: //左边进框(右转)
        Motor1->Command.speed = agv.Parameter.ShiftSpeed;
        if ((agv.Public.i_Shift1ArrivalLeft && agv.Public.i_Shift1ArrivalRight)||agv.Public.i_Shift1_LimitRight) //左边到位右边到位停止
        {
            Motor1->Command.speed = 0;
            agv.Command.Shift1State = 0;
        }
        break;

    case -1: //左边出框(左转)
        Motor1->Command.speed = -agv.Parameter.ShiftSpeed;
        //四个传感器全部检测不到物料,认为出框完毕停止
        if (!agv.Public.i_Shift1ArrivalLeft && !agv.Public.i_Shift1ArrivalRight && !agv.Public.i_Shift1_LimitLeft && !agv.Public.i_Shift1_LimitRight)
        {
            Motor1->Command.speed = 0;
            agv.Command.Shift1State = 0;
        }
        break;

    case 2: //右边进框(左转)
        Motor1->Command.speed = -agv.Parameter.ShiftSpeed;
        if ((agv.Public.i_Shift1ArrivalLeft && agv.Public.i_Shift1ArrivalRight)||agv.Public.i_Shift1_LimitLeft) //左边到位右边到位停止
        {
            Motor1->Command.speed = 0;
            agv.Command.Shift1State = 0;
        }
        break;

    case -2: //右边出框(右转)
        Motor1->Command.speed = agv.Parameter.ShiftSpeed;
        //四个传感器全部检测不到物料,认为出框完毕停止
        if (!agv.Public.i_Shift1ArrivalLeft && !agv.Public.i_Shift1ArrivalRight && !agv.Public.i_Shift1_LimitLeft && !agv.Public.i_Shift1_LimitRight)
        {
            Motor1->Command.speed = 0;
            agv.Command.Shift1State = 0;
        }
        break;
    }
}

void checkMaterialState() //物料检测
{
    //下层物料检测
    if (agv.Public.i_Shift1ArrivalLeft && agv.Public.i_Shift1ArrivalRight)
    {
        agv.Public.i_MaterialFlagFirst = 1;
    }
    else if (!agv.Public.i_Shift1ArrivalLeft && !agv.Public.i_Shift1ArrivalRight && !agv.Public.i_Shift1_LimitLeft && !agv.Public.i_Shift1_LimitRight)
    {
        agv.Public.i_MaterialFlagFirst = 0;
    }
    else
        agv.Public.i_MaterialFlagFirst = 2;
}

void platformControlManual() //平台手动运行
{
    lifterRunManu(&DriverLifter1);
    shifterRunManu(&DriverShifter1);
}

void platformControlAuto() //平台自动对接
{
    lifterRunAuto(&DriverLifter1);
    shifterRunAuto(&DriverShifter1);
}

void X_Input()
{
	agv.Public.i_RadarSigFront_1 			= MasterInput.IN1 = !X1;//前壁障减速1
	agv.Public.i_RadarSigFront_2 			= MasterInput.IN2 = !X2;//前壁障减速2
	agv.Public.i_RadarSigFront_3 			= MasterInput.IN3 = !X3;//前壁障减速3
	
	agv.Public.i_RadarSigBack_1 			= MasterInput.IN4 = !X4;//后壁障减速1
	agv.Public.i_RadarSigBack_2 			= MasterInput.IN5 = !X5;//后壁障减速2
	agv.Public.i_RadarSigBack_3 			= MasterInput.IN6 = !X6;//后壁障减速3
	
	agv.Public.i_QuickStopSig 				= MasterInput.IN7 = X7;// 急停 常开
	agv.Public.i_BumperSig 						= MasterInput.IN8 = X8;//防撞条
	agv.Public.i_StartSig 						= MasterInput.IN9 = X9;// 启动 
	agv.Public.i_StopSig 							= MasterInput.IN10 = X10;//暂停
	agv.Public.i_LightStopFlagL 			= MasterInput.IN11 = X11;//左停靠
	agv.Public.i_LightStopFlagR 			= MasterInput.IN12 = X12;//右停靠
	
	agv.Public.i_Lift1UpLimit					= MasterInput.IN13 = X13;//升降平台上限位
	agv.Public.i_Lift1DownLimit				= MasterInput.IN14 = X14;//升降平台下限位
	agv.Public.i_Shift1_LimitLeft			= MasterInput.IN15 = X15;//左极限
	agv.Public.i_Shift1_LimitRight 		= MasterInput.IN18 = X18;//右极限
	agv.Public.i_Shift1ArrivalLeft 		= MasterInput.IN16 = X16;//左到位对射
	agv.Public.i_Shift1ArrivalRight 	= MasterInput.IN17 = !X17;//右到位对射
	
}

void platformDataProcess(void)
{
	X_Input();//IO输入信号
	//自动模式且开启红外,雷达避障信号
	if(agv.Command.Au_Hand&&agv.Command.Barrier_ONOFF)
	{
		if(agv.Command.CurDirection == 1 || agv.Command.CurDirection == 7 || agv.Command.CurDirection == 8)//前进方向
		{
			if(agv.Public.i_RadarSigFront_3)//最里层雷达避障
			{
				SetAlarm(0x0001);//停车
			}
			else
			{
				Reset_Alarm(0x0001);//取消停车避障
			}
			if(agv.Public.i_RadarSigFront_2)//二级减速
			{
				agv.Public.i_DoubleReduction = 1;//开启二级减速
			}
			else
			{
				agv.Public.i_DoubleReduction = 0;//取消二级减速
			}
			if(agv.Public.i_RadarSigFront_1)//一级减速
			{
				agv.Public.i_Reduction = 1;//开启一级减速
			}
			else
			{
				agv.Public.i_Reduction = 0;//取消一级减速
			}
		}
		else if(agv.Command.CurDirection == 2 || agv.Command.CurDirection == 9 || agv.Command.CurDirection == 10)//后退方向
		{
			if(agv.Public.i_RadarSigBack_3)//最里层雷达避障(后)
			{
				SetAlarm(0x0001);//停车
			}
			else
			{
				Reset_Alarm(0x0001);//取消停车避障
			}
			if(agv.Public.i_RadarSigBack_2)//二级减速
			{
				agv.Public.i_DoubleReduction = 1;//开启二级减速
			}
			else
			{
				agv.Public.i_DoubleReduction = 0;//取消二级减速
			}
			if(agv.Public.i_RadarSigBack_1)//一级减速
			{
				agv.Public.i_Reduction = 1;//开启一级减速
			}
			else
			{
				agv.Public.i_Reduction = 0;//取消一级减速
			}
		}
	}
	else//不开启避障
	{
		Reset_Alarm(0x0001);//取消停车避障
		
		agv.Public.i_Reduction = 0;//取消一级减速
		
		agv.Public.i_DoubleReduction = 0;//取消二级减速
	}
	//防撞条
	if(agv.Public.i_BumperSig)
	{
		SetAlarm(0x0006);//停车,防撞条报警和暂停触发
	}
	else
		Reset_Alarm(0x0002);//取消防撞条报警
	
	//急停触发
	if (agv.Public.i_QuickStopSig)
	{	
		SetAlarm(0x0104);//急停和暂停触发,防止再启动
	}
	else
	{
		Reset_Alarm(0x0100);//取消急停报警
	}
	if(agv.Public.i_StartSig)//启动
	{	
		Reset_Alarm(0x0004);
	}
	if(agv.Public.i_StopSig)
	{
		SetAlarm(0x0004);//暂停	
	}
	if(agv.Public.i_Lift1DownLimit)//拉线编码器清零
	{
		TIM_SetCounter(TIM1, 0);
	}

	//启动和暂停指示灯
	if(agv.Command.Au_Hand&&(agv.Public.Error_Flag&0x0004)==0)//自动模式无异常显示启动灯
	{
		Y7(1);
		Y8(0);
	}
	else
	{
		Y7(0);
		Y8(1);
	}
	
	agv.Public.i_quadEncoder1 = TIM_GetCounter(TIM1);
	agv.Public.i_quadEncoder2 = TIM_GetCounter(TIM2);
	agv.Public.i_quadEncoder3 = TIM_GetCounter(TIM3);
	agv.Public.i_quadEncoder4 = TIM_GetCounter(TIM4);
	agv.Public.i_LiftHeightFirst  = agv.Public.i_quadEncoder1/4;
	
  checkMaterialState(); //物料检测

    
	//自动模式脱轨判断
	if(agv.Command.Au_Hand)
	{
		//前进后退,弧线左右转做脱轨判断
//		if(agv.Command.CurDirection == 1||agv.Command.CurDirection == 2||agv.Command.CurDirection == 7
//			||agv.Command.CurDirection == 8||agv.Command.CurDirection == 9||agv.Command.CurDirection == 10)
//		{
//			if(fabs(navi.Public.CenterOffset) > 100)//位置偏差大于10CM,脱轨
//			{
//				SetAlarm(0x0008);//脱轨报警
//			}
//			else
//				Reset_Alarm(0x0008);//取消脱轨报警
//		}
//		else
//			Reset_Alarm(0x0008);//取消脱轨报警
	}
}


/*SETVMOT动作指令解析*/
void commandActionAnalysis(int dataOne, int dataTwo)
{
    switch (dataOne)
    {
    case 1: //下层皮带
        agv.Command.Shift1State = dataTwo;
        break;

    case 2: //上层皮带
        agv.Command.Shift2State = dataTwo;
        break;

    case 3: //上层举升高度第二层
        agv.Parameter.SetLift1Height = dataTwo;
        break;

    case 4:              //打开充电状态
        switch (dataTwo) //小车运动方式设置       //
        {
        case 0:
            Y9(0); //关闭充电器触点
            break;

        case 1:    //自动充电站停靠传感器选型   充电预停车指令
            Y9(1); //打开充电器触点
            break;
        }

    case 5: //下层举升高度第一层
        agv.Parameter.SetLift2Height = dataTwo;
    }
}
#endif