⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.txt

📁 智能吊车
💻 TXT
📖 第 1 页 / 共 2 页
字号:
		motor0dir = 1;//步进电机同步向左运行
		motor1dir = 0;
		while(weizhi)
		{
			motor0sp = 1;
			motor1sp = 1;
			Delay(SMOTOR);
			motor0sp = 0;
			motor1sp = 0;
			Delay(SMOTOR);	
			if(pred >= 3400) 
			{
				Delay(20000);
				stepmotortongbu(0,3400);
				stepmotor(1,0,3950);
				return 0;
		    }

			pred++;
		}
		Delay(20000);
		Delay(20000);
		stepmotortongbu(0,pred);//X轴回到初始位置
		pred += XIUZHENG;
		Delay(20000);
		Delay(20000);
 		stepmotor(1,1,250);//下降到检测绿球的位置
	}
	
	///识别绿色开始
	////前面要加入三个临时变量
	//unsinge int temp1,temp2,temp3;
	temp1 = 0;
	temp2 = 0;
	temp3 = 0;
	Delay(20000);
	Delay(20000);
	pgreen = 0;
	//stepmotor(1,1,4200);//从初始位置上升到检测绿球的位置
	Delay(20000);
	Delay(20000);
	/////////////////////////////////////////////////////////

	motor0dir = 1;//步进电机同步向左运行
	motor1dir = 0;
	while(weizhi)
	{
		motor0sp = 1;
		motor1sp = 1;
		Delay(SMOTOR);
		motor0sp = 0;
		motor1sp = 0;
		Delay(SMOTOR);	
		if(temp1 >= 3400) 
		{
			Delay(20000);
			stepmotortongbu(0,3400);
			stepmotor(1,0,4150);
			return 0;	
		}

		temp1++;  //第一个位置
		
	}

	stepmotortongbu(1,700);
	motor0dir = 1;//步进电机同步向左运行,////////继续前进
	motor1dir = 0;
	temp2 = temp1+700;
	while(weizhi)
	{
		motor0sp = 1;
		motor1sp = 1;
		Delay(SMOTOR);
		motor0sp = 0;
		motor1sp = 0;
		Delay(SMOTOR);	
		if(temp2 >= 3400)
		{
			Delay(20000);
			stepmotortongbu(0,3400);
			stepmotor(1,0,4200);
			return 0;
		}
		temp2++;  //第二个位置	
	}
	stepmotortongbu(1,700);
	motor0dir = 1;//步进电机同步向左运行,////////继续前进
	motor1dir = 0;
	temp3 = temp2+700;
	while(weizhi)
	{
		motor0sp = 1;
		motor1sp = 1;
		Delay(SMOTOR);
		motor0sp = 0;
		motor1sp = 0;
		Delay(SMOTOR);	
		if(temp3 >= 3400) 
		{
			Delay(20000);
			stepmotortongbu(0,3400);
			stepmotor(1,0,4200);
			return 0;
		}

		temp3++;  //第三个位置	
	}
	beep = 1;
	Delay(10000);
	beep = 0;
	Delay(10000);
	stepmotortongbu(0,temp3);
	stepmotor(1,0,4250);
	if((temp1 - (pred - XIUZHENG) < 400) || ((pred - XIUZHENG) - temp1 < 400))
	{
	  //第一个球是红球
	  if((temp2 - (pyellow - XIUZHENG) < 400) || ((pyellow -XIUZHENG) - temp2 < 400))
	  {
	    //第二个球是黄球,那么第三个球就是绿球
	    pgreen = temp3 + XIUZHENG;
	  }
	  else pgreen = temp2 + XIUZHENG;//如果第二个球不是黄球,那就是绿球
	}
	else if((temp1 - (pyellow - XIUZHENG) < 400) || ((pyellow - XIUZHENG) - temp1 < 400))
	{
	  //第一个球是黄球
	  if((temp2 - (pred - XIUZHENG) <400) || ((pred - XIUZHENG) - temp2 < 400))
	  {
	    //第二个球是红球,那么三个球就是绿球
	    pgreen = temp3 + XIUZHENG;
	  }
	  else pgreen = temp2 + XIUZHENG;
	}
	else
	   pgreen = temp1 + XIUZHENG;//如果第一个不是红球,也不是黄球,那么就是绿球
	}
/******************************************************************************/
//函数功能:步进电机走步函数
//入口参数:电机号、方向、步数
//出口参数:无
/******************************************************************************/
void stepmotor(char motorNo,char motordir,int bushu)
{
	if(motorNo)//1号motor
	{
		motor1dir = motordir;
		for(bushu;bushu >0;bushu--)
		{
			motor1sp = 1;
			Delay(SMOTOR);
			motor1sp = 0;
			Delay(SMOTOR);	
		}
	}

	else//0号motor
	{
		motor0dir = motordir;
		for(bushu;bushu >0;bushu--)
		{
			motor0sp = 1;
			Delay(SMOTOR);
			motor0sp = 0;
			Delay(SMOTOR);	
		}
	}

}
/******************************************************************************/
//函数功能:步进电机同步运行
//入口参数:方向、步数
//出口参数:无
/******************************************************************************/
void stepmotortongbu(char motordir,int bushu)//同步运行
{
	motor0dir = motordir;
	if(motordir)  motor1dir = 0;
	else          motor1dir = 1;
	for(bushu;bushu > 0;bushu--)
	{
		motor0sp = 1;
		motor1sp = 1;
		Delay(SMOTOR);
		motor0sp = 0;
		motor1sp = 0;
		Delay(SMOTOR);	
	}
}		
/****************************************************************************/
//函数功能:延时函数
//入口参数:延时时间
//出口参数:无
/****************************************************************************/
void Delay(int time)
{
	unsigned char i;
	for(time;time > 0;time--)
		for(i =0;i<10;i++);
}

/****************************************************************************/
//函数功能:完成基本功能一。机械手位于60cm处顶端。完成后恢复原位。
//入口参数:无
//出口参数:无
/****************************************************************************/
void functionone(void)
{
	///////////////////////////第一个
	
	jixieshou = 0;
	disp_string(10,3,"Ing");
	stepmotortongbu(1,650);
	Delay(20000);
	stepmotor(1,1,6100);
	Delay(20000);
	jixieshou = 1;
	Delay(10000);
	stepmotor(1,0,2100);
	Delay(10000);
	stepmotortongbu(0,2550);
	Delay(10000);
	//stepmotor(1,1,4000);
	jixieshou = 0;
	//stepmotor(1,0,4000);
	Delay(20000);
	stepmotortongbu(1,1900);
	Delay(10000);
	beep = 1;
	Delay(10000);
	beep = 0;
		//////////////////////////第三个
	Delay(20000);
	stepmotortongbu(1,2560);
	Delay(20000);
	stepmotor(1,1,2100);
	Delay(20000);
	jixieshou = 1;
	Delay(10000);
	stepmotor(1,0,2100);
	Delay(10000);
	stepmotortongbu(0,4460);
	Delay(10000);
	//stepmotor(1,1,4000);
	jixieshou = 0;
	//stepmotor(1,0,4000);
	Delay(10000);
	stepmotortongbu(1,1900);
	beep = 1;
	Delay(20000);
	beep = 0;
	
	///////////////////第二个
	Delay(20000);
	stepmotortongbu(1,1610);
	Delay(20000);
	Delay(20000);
	Delay(20000);
	Delay(20000);
	stepmotor(1,1,2100);
	Delay(20000);
	jixieshou = 1;
	Delay(10000);
	stepmotor(1,0,2100);
	Delay(10000);
	stepmotortongbu(0,3510);
	Delay(10000);
	//stepmotor(1,1,4000);
	jixieshou = 0;
	stepmotor(1,0,4000);
	Delay(20000);
	stepmotortongbu(1,1900);

	disp_string(10,3,"OK!!");
	beep = 1;
	Delay(5000);
	beep = 0;
	Delay(5000);
	beep = 1;
	Delay(5000);
	beep = 0;
	
}
/**************************************************/
//
//
//
/***************************************************/
void Interface0(void)
{
	
	disp_clear();
	disp_hanzi(4,0,9);
	disp_hanzi(6,0,10);
	disp_hanzi(8,0,11);
	disp_hanzi(10,0,12);//////
	disp_hanzi(4,2,0);
	disp_hanzi(6,2,1);
	disp_hanzi(8,2,2);/////////
	disp_hanzi(4,4,3);
	disp_hanzi(6,4,4);
	disp_hanzi(8,4,5);///////
	disp_hanzi(4,6,6);
	disp_hanzi(6,6,7);
	disp_hanzi(8,6,8);
}

void Interface1(void)
{
	disp_clear();
	disp_hanzi(4,0,9);
	disp_hanzi(6,0,10);
	disp_hanzi(8,0,11);
	disp_hanzi(10,0,12);//////
	
	disp_string(0,3,"1");
	disp_hanzi(2,2,13);
	disp_hanzi(4,2,14);
	disp_hanzi(6,2,11);
	disp_hanzi(8,2,15);
	
	disp_string(0,5,"2");
	disp_hanzi(2,4,16);
	disp_hanzi(4,4,17);
   	disp_hanzi(6,4,11);
	disp_hanzi(8,4,15);

	disp_string(0,7,"3");
	disp_hanzi(2,6,18);
	disp_hanzi(4,6,19);
   	disp_hanzi(6,6,20);
	disp_hanzi(8,6,21);

}

void Interface2(void)
{
	disp_clear();
	disp_hanzi(6,0,26);
	disp_hanzi(8,0,27);

	disp_string(0,3,"1");
	disp_hanzi(2,2,23);
	disp_hanzi(4,2,25);

	
	disp_string(0,5,"2");
	disp_hanzi(2,4,22);
	disp_hanzi(4,4,25);

	disp_string(0,7,"3");
	disp_hanzi(2,6,24);
	disp_hanzi(4,6,25);
}

void Interface3(void)
{
	disp_clear();
	disp_hanzi(2,0,18);
	disp_hanzi(4,0,19);
   	disp_hanzi(6,0,20);
	disp_hanzi(8,0,21);////////
	
	disp_string(0,3,"1. Up 50 steps");
	disp_string(0,5,"2. Down 50 steps");
	disp_string(0,7,"3. Left 50 steps");

}

///显示坐标
void disp_zuobiao(void)
{
	float aa,bb,cc;
	aa = 59.50 - ((float)pyellow/3525)*55.00;//黄球的坐标
	sprintf(dispbuf[0],"%.2fcm",aa);
    strcpy(disp,"");
	strcat(disp,dispbuf[0]);
	disp_string(6,3,disp);

	bb = 59.50 - ((float)pred/3525.00)*55.00;//红球的坐标
	sprintf(dispbuf[0],"%.2fcm",bb);
    strcpy(disp,"");
	strcat(disp,dispbuf[0]);
	disp_string(6,5,disp);

	cc = 59.50 - ((float)pgreen/3525.00)*55.00;//绿球的坐标
	sprintf(dispbuf[0],"%.2fcm",cc);
    strcpy(disp,"");
	strcat(disp,dispbuf[0]);
	disp_string(6,7,disp);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -