四房间自动灭火回家.docx

上传人:b****5 文档编号:27716668 上传时间:2023-07-04 格式:DOCX 页数:18 大小:17.61KB
下载 相关 举报
四房间自动灭火回家.docx_第1页
第1页 / 共18页
四房间自动灭火回家.docx_第2页
第2页 / 共18页
四房间自动灭火回家.docx_第3页
第3页 / 共18页
四房间自动灭火回家.docx_第4页
第4页 / 共18页
四房间自动灭火回家.docx_第5页
第5页 / 共18页
点击查看更多>>
下载资源
资源描述

四房间自动灭火回家.docx

《四房间自动灭火回家.docx》由会员分享,可在线阅读,更多相关《四房间自动灭火回家.docx(18页珍藏版)》请在冰豆网上搜索。

四房间自动灭火回家.docx

四房间自动灭火回家

/**四房间自动灭火回家**/

intW6=220,W7=250,L=450,psd=270,fpsd=240,V=98,V2=98,m_m=1023,

q,m_0,m_1,m_2,m_3,m_4,m_5,p,M1,M4,ii,Fn,H,bx,qh,cw,F;

floatt,t1;

/*★主函数★*/

voidmain()

{SetMotor(0x1111,10,10,0,0);DO(0x1,1);wait(0.03);DO(0x11,0);wait(0.07);

SetMotor(0x1111,-10,-10,0,0);DO(0x10,1);wait(0.03);DO(0x11,0);wait(0.07);

StopMotor(0x1111);wait(1.0);

if(AI(23)>500){qh=1;}/*qh=1光滑;qh=0粗糙*/

printf("\t开始:

亮度%d;左%d;中%d;右%d灰度:

前%d后%d切换%d%d",L,AI(9),AI(10),AI(11),AI(6),AI(7),AI(23),qh);

while(AI(12)<820){}/*显示传感器数值及声控启动*/

resettime();

Drive(30,0);Drive(60,0);Drive(100,0);

while(AI(7)

{Drive(100,0);}

m4();}/*去4号房间迷宫*/

/*★4号迷宫★*/

voidm4()

{while

(1)

{if(AI(6)

{if(AI(9)>L&&AI(10)>L&&AI(11)>L)/*门口检测火源的存在*/

{StopMotor(0x1111);t=seconds();

while((seconds()-t)<.2)

{if(AI(9)

if(F==4){mo(15,80,.2);fire4();}

while(AI(6)>W6)

{mL2(0,50,30,25,80);}moo(30,80,.2);moo(40,80,.2);

m3();}/*去3号房间迷宫*/

mo(15,80,.2);fire4();}/*4号房间灭火*/

else

{if((seconds()>3.2)&&(ii==0))

{if(AI(0)>600){while(AI(0)>500){mot(0,-50);}ii=2;}

else

{if((AI(9)

else{moo(40,85,.35);m3();}}}

else{if(ii==3){fpsd=240;mR(0,V,V,80,20);}

else{if(seconds()>1.2){fpsd=240;mL(0,50,50,20,80);}/*★接近4号减速★*/

else

{if(AI

(1)<180){mL(0,90,90,18,75);}

else{fpsd=300;mL(0,60,60,18,80);}}}}}}}/*左手法则*/

/*★3号迷宫★*/

voidm3()

{fpsd=240;while

(1)

{if(AI(7)

{if(AI(13)

{Fn=3;}

StopMotor(0x1111);t=seconds();/*★3号退出★*/

while((seconds()-t)<=.1)

{if(AI(13)

if(F==3){Fn=3;}

while(AI(7)>W7)

{mL(0,50,40,30,80);}m32();}/*去2号房间*/

else{mR2(0,V,V,80,19);}}}/*后右手法则*/

/*★3号到2号迷宫★*/

voidm32()

{t=seconds();

while((seconds()-t)<.8){mR(0,V,V,80,20);}

while

(1)

{if(AI(6)

{if(AI(9)

{Fn=2;}

StopMotor(0x1111);t=seconds();

while((seconds()-t)<=.1)

{if(AI(9)

if(F==2){Fn=2;}

while(AI(6)>W6)/*★2号退出★*/

{mR2(0,40,50,80,50);}t=seconds();m1();}/*去1号房间灭火*/

else{mR(0,V,V,80,19);}}}

/*★2号到1号迷宫★*/

voidm1()

{while

(1)

{if(AI(7)

{if(AI(13)>L&&AI(14)>L&&AI(15)>L)/*门口测火*/

{StopMotor(0x1111);t=seconds();

while((seconds()-t)<.2)

{if(AI(13)

if(F==1)

{t=seconds();

while(AI(6)>W6)

{if(((seconds()-t)>1.0)&&(H<2)){moo(-80,0,.25);moo(80,30,.2);H=2;}

if(AI(3)>400){mott(30,-30);}else{mR2(0,-30,30,80,30);}}fire1();}

if(Fn==3)

/****************************************************************************/

/*1号到3号门口转弯参数,根据摩擦力大小调整右侧电机和时间*/

/****************************************************************************/

{if(qh==1)

{while(AI(7)>W7)

{mR(0,50,50,80,40);}

while(AI(0)>200){mot(80,10);}

mo(80,40,.4);}/*★光滑★*/

/****************************************************************************/

else

{while(AI(7)>W7)

{mR(0,50,50,80,30);}

while(AI

(2)>100){mot(80,8);}

t=seconds();

while((seconds()-t)<.35)

{mot(80,40);

if((AI

(1)>fpsd)&&(AI(0)>psd))break;}}/*★粗糙★*/

/****************************************************************************/

if((AI

(1)>600)||(AI

(2)>600)){mo(30,-50,.25);}}

else

/****************************************************************************/

/*1号到2号门口转弯参数,根据摩擦力大小调整左侧电机和时间*/

/****************************************************************************/

{if(qh==1)

{while(AI(7)>W7)

{mL(0,30,50,3,80);}mo(40,80,.25);}/*★光滑★*/

/****************************************************************************/

else

{while(AI(7)>W7)

{mL(0,30,50,5,80);}

t=seconds();

while((seconds()-t)<.25)

{mot(30,80);if((AI(6).08))break;}}}/*★粗糙★*/

/****************************************************************************/

m2();}/*没有火去23号房间*/

else

{t=seconds();

while(AI(6)>W6)

{if(((seconds()-t)>1.0)&&(H<2)){moo(-80,0,.25);moo(80,30,.2);H=2;}

if(AI(3)>400){mott(30,-30);}else{mR2(0,-30,30,80,30);}}

fire1();}}/*1号房间灭火*/

else

{if((seconds()-t)>1.8)

{if(H==0){moo(-60,0,.25);H=1;}else{mR2(0,-10,65,80,25);}}

else{mR2(0,12,60,80,25);}}}}/*后右手迷宫*/

/*★1号到23号迷宫★*/

voidm2()

{if(Fn==3)

{t=seconds();

while((seconds()-t)<.5)

{mL(0,80,80,18,80);}}

while(AI(6)>W6)

{mL(0,85,85,18,80);if(AI(7)

if(Fn==3){if(bx==0){mo(80,30,.2);}else{mo(80,0,.2);}mo(80,10,.1);fire3();}

else

{if(bx==0){mo(100,20,.2);mo(100,30,.22);}

else{mo(80,15,.22);}fire2();}}/*左手迷宫*/

/*★4号灭火★*/

voidfire4()

{fpsd=240;while

(1)

{if(AI(6)

{DO(0x1,1);StopMotor(0x1111);

while(AI

(2)<400)

{p=AI(9)-AI(11);

if(p<-1){mot(40,25);}

else{mot(40,10);}}StopMotor(0x1111);

t=seconds();H=0;jy4();}/*4号回家*/

else{p=AI(9)-AI(11);

if(p<-10){mot(-10,90);}

else{if(p>10){mot(90,-10);}

else{mot(90,90);}}}}}

/*★★4号搜救★★*/

voidjy4()

{while((AI(4)<300)||(AI(5)<300)){mot(40,-10);}/*靠墙*/

while(AI(5)<625){mot(-10,-50);}

while(AI(4)>500){mot(30,-30);}/*调姿*/

while

(1)

{if(AI(5)>700){mot(-40,0);}

else{if(AI(5)>550){mot(-60,-60);}

else{mot(0,-40);}}

if(AI(4)>700)break;}

mo(-60,-60,.1);t1=seconds();h4();}

/*★4号回家★*/

voidh4()

{while((M1==0)||(M4==0))

{if((seconds()-t1)>.5){DO(0x1,0);}

if((seconds()-t1)>1.2)

{if(H==0){moo(-60,0,.3);H=1;}else{mR2(0,-20,50,60,20);}}/*★4号回家超时说明卡死★*/

else{mR2(0,20,50,60,20);}

if(AI(7)

DO(0x1,0);

while(AI(5)>250)

{if(qh==1)

{mott(80,10);}/*★光滑★*/

else{mott(80,0);}}/*★粗糙★*/

H=0;t1=seconds();

while

(1)

{if((AI(7)

{ps();}

else

{if((seconds()-t1)>3.5)

{if(H==0){moo(-70,0,.3);H=1;}

else{mR2(0,30,50,60,19);}}

else{mR2(0,V2,V2,80,20);}}}}/*后右手迷宫*/

/*★3号灭火★*/

voidfire3()

{if(bx==1)

{p=AI(9)-AI(11);

while((p>20)||(p<-20)||(AI(10)>300))

{p=AI(9)-AI(11);

if(p<0){mot(-50,50);}

else{mot(50,-50);}}}

while

(1)

{if(AI(6)

{DO(0x1,1);StopMotor(0x1111);

while(AI(0)<400)

{p=AI(9)-AI(11);

if(p>1){mot(25,40);}

else{mot(15,40);}}StopMotor(0x1111);

t=seconds();H=0;jy3();}/*3号回家*/

else{p=AI(9)-AI(11);

if(p<-10){mot(-10,90);}

else{if(p>10){mot(90,-10);}

else{mot(90,90);}}}}}

/*★★3号搜救★★*/

voidjy3()

{while((AI(3)<300)||(AI(4)<300)){mot(-10,40);}/*靠墙*/

while(AI(3)<600){mot(-50,-10);}

while(AI(4)>400){mot(30,-30);}/*调姿*/

while

(1)

{if(AI(3)>600){mot(0,-40);}

else{if(AI(3)>550){mot(-60,-60);}

else{mot(-40,0);}}

if(AI(4)>650)break;}/*后退到适当位置*/

mo(-80,-80,0.1);t1=seconds();h3();}

/*★3号回家★*/

voidh3()

{while((M1==0)||(M4==0))

{if((seconds()-t1)>.5){DO(0x1,0);}

mL2(0,50,10,21,80);

if(AI(7)

/****************************************************************************/

/*3号回家门口转弯参数,根据摩擦力大小调整左侧电机和时间*/

/****************************************************************************/

DO(0x1,0);

while(AI(5)>250)

{if(qh==1){mott(20,80);}/*★光滑★*/

else{mott(15,80);}}/*★粗糙★*/

t1=seconds();

while(((seconds()-t1)<.4)||(AI(4)>200)){mL2(0,60,60,19,80);}

/****************************************************************************/

while(AI(21)>100)

{if(AI(3)>psd){mott(70,60);}

else{mott(50,70);}}du(.02);

while(AI(4)>200)

{mott(80,5);}

while

(1)

{if(AI(7)

{wait(.01);m_m=AI(7);}

if(m_m

else{mL2(0,V2,V2,20,80);}}}

/*★2号灭火★*/

voidfire2()

{p=AI(9)-AI(11);

while((p>20)||(p<-20)||(AI(10)>300))

{p=AI(9)-AI(11);

if(p<0){mot(-50,50);}

else{mot(50,-50);}}

t=seconds();

while

(1)

{if((AI(6)

{DO(0x1,1);StopMotor(0x1111);

while(AI

(1)<420)

{p=AI(9)-AI(11);

if(p>1){mot(25,40);}

else{mot(10,40);}}StopMotor(0x1111);t=seconds();H=0;jy2();}/*2号回家*/

else

{if((seconds()-t)>1.8)

{if(H==0){mo(-80,0,.4);}mo(60,50,.1);H=1;}

p=AI(9)-AI(11);

if(p<-10){mot(10,70);}

else{if(p>10){mot(70,10);}

else{mot(100,100);}}}}}

/*★★2号搜救★★*/

voidjy2()

{while(AI(3)<600){mot(-50,-10);}/*靠墙*/

while(AI(4)>250){mot(30,-30);}/*调姿*/

while

(1)

{if((seconds()-t)>1.5){DO(0x1,0);}

if(AI(3)>650){mot(-50,-60);}

else{if(AI(3)<250){mot(-70,-70);}

else{mot(-60,-50);}}

if(AI(4)>580)break;}/*后退到适当位置*/

DO(0x1,0);mo(30,-30,0.1);while(AI(4)>300){mot(30,-30);}

while(AI(23)>200)

{if(AI(3)>700){mot(-40,-25);}

else{mot(-40,-18);}}mo(50,50,.1);

t1=seconds();

while(AI(5)<500){mot(-60,0);if((seconds()-t1)>0.4)break;}

mo(-80,-10,.25);

while(AI(4)>300){mot(80,0);}h2();}

/*★2号回家★*/

voidh2()

{while((M1==0)||(M4==0))

{mR(0,50,50,60,20);

if(AI(6)

H=0;t1=seconds();

while(AI(6)>W6)

{if((seconds()-t1)>1.8)

{if(H==0){mo(-60,0,.3);H=1;}else{mR(1,-10,60,80,25);}}/*★2号回家超时说明卡死★*/

else{mR(0,12,60,80,25);}}

/****************************************************************************/

/*2号回家1号门口转弯参数,根据摩擦力大小调整右侧电机数值*/

/****************************************************************************/

StopMotor(0x1111);wait(0.2);

if(qh==1)

{while(AI(0)<200)

{mot(80,12);}mo(80,18,.15);}/*★光滑★*/

else

{t1=seconds();

while((AI(0)<200)&&((seconds()-t1)<.22))

{mott(80,0);if(AI(5)>400){cw=1;break;}}

t1=seconds();

while(AI(0)>200){mott(80,20);if(AI(5)>400){cw=1;break;}}

if(cw==1)

{while(AI(5)>400){mott(-40,40);}}

moo(80,10,.2);}/*★粗糙★*/

t1=seconds();

while((seconds()-t1)<.3){mR2(0,10,50,60,18);}

t1=seconds();H=0;

while

(1)

{if(AI(7)

{wait(.01);m_m=AI(7);}

if(m_m

else

{if((seconds()-t1)>3.5)

{if(H==0){moo(-60,0,.3);H=1;}

else{mR2(0,30,50,60,20);}}else{mR2(0,V2,V2,80,20);}}}}

/*★1号灭火★*/

voidfire1()

{while

(1)

{if(AI(7)

{DO(0x10,1);StopMotor(0x1111);

while(AI(3)<400)

{p=AI(9)-AI(11);

if(p>1){mott(25,40);}

else{mott(10,40);}}StopMotor(0x1111);

t=seconds();H=0;jy1();}/*1号回家*/

else

{p=AI(13)-AI(15);

if(p<-15){mott(-10,100);}

else{if(p>15){mott(100,-10);}

else{mott(100,100);}}}}}

/*★★1号搜救★★*/

voidjy1()

{while

(1){if(AI(0)>500){break;}else{mot(10,50);}}/*靠墙*/

while(AI

(1)>300){mot(30,-30);}/*调姿*/

while

(1)

{if((seconds()-t)>1.5){

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 高等教育 > 教育学

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1