logo资料库

灭火机器人c语言代码国赛一等奖.doc

第1页 / 共25页
第2页 / 共25页
第3页 / 共25页
第4页 / 共25页
第5页 / 共25页
第6页 / 共25页
第7页 / 共25页
第8页 / 共25页
资料共25页,剩余部分请下载后查看
灭火机器人 #include "MF12_LIB.h" /*头文件定义,请勿删除*/ int fire_count1_0=330;//房间 1 火焰预值(从 2 号房间出来对面无门) int fire_count1_1=330;//房间 1 火焰预值(从 2 号房间出来对面有门) int fire_count3=360;//房间 3 火焰预值 int fire_count2=360;//房间 2 火焰预值 int fire_count4=340;//房间 4 火焰预值 float t1=0;//调用系统时间(切记是 float 型) float t2=0;//调用系统时间(切记是 float 型) int wall1=0;//判断前方是否有墙 int wall=0;//房间 1 变门 int DB=170;//麦克风分贝 int AI0=1000;//前灰度标准 int AI1=1000;//后灰度标准 int AI2=1000;//感应器 2 墙距标准 int AI3=1000;//感应器 3 墙距标准 int AI4=1000;//感应器 4 墙距标准 int AI5=1000;//感应器 5 墙距标准 int AI6=1000;//感应器 6 墙距标准 int AI7=1000;//感应器 7 墙距标准 int AI8=1000;//感应器 8 墙距标准 int AI9=1000;//感应器 9 墙距标准 int AI10=1000;//感应器 10 墙距标准 int AI11=1000;//感应器 11 墙距标准 void go_room3(void);//从起点到房间 3 void right_wall3(void);//沿右墙到房间 3 void putfire_3(void);//房间 3 灭火 void go_home3(void);//房间 3 回家 void left_home3(void);//离开房间 3 回家沿左墙 void left_home3_after(void);//房间 3 回家沿左墙调用系统时间后 void go_room2(void);//从房间 3 到房间 2 void right_wall2(void);//沿右墙到房间 2 void right_wall2_1(void);//调用系统时间后到房间 2 void putfire_2(void);//房间 2 灭火 void go_home2(void);//房间 2 回家 void left_home2(void);//房间 2 回家沿左墙 void go_room1(void);//到房间 1 void right_wall1(void);//沿右墙到房间 1 void putfire1_0(void);//房间 wall=0 灭火 void go_home1_0(void);//房间 wall=0 回家 void right_wall_home1_0(void);//房间 wall=0 回家沿右墙
void putfire1_1(void);//房间 wall=1 灭火 void go_home1_1(void);//房间 wall=1 回家 void right_wall_home1_1(void);//房间 wall=1 回家沿右墙 void go_room4_0(void);//从房间 1wall=0 到房间 4 void right_wall4_0(void);//从房间 1wall=0 到房间 4 沿右墙到前面有墙停 void right_wall4_00(void);//接着到 4 房间 void putfire_4(void);//房间 4 灭火 void go_home4(void);//房间 4 回家 void right_wallhome4(void);//房间 4 回家沿右墙 void go_room4_1(void);//从房间 1wall=1 到房间 4 void right_wall4_1(void);//从房间 1wall=0 到房间 4 沿右墙到前面有墙停 void SetMoto_speed(int dyn0_speed,int dyn1_speed)//电机速度 { SetMoto(0,dyn0_speed);//电机 0 速度 SetMoto(1,dyn1_speed);//电机 1 速度 } void SetMoto_right(int speed0,int speed1)//驱动小车右 拐,|speed0|<|speed1|(绝对值) { if(speed0>0) { SetMoto_speed(speed0,speed1); } else { SetMoto_speed(speed1,speed0); } } void SetMoto_left(int speed0,int speed1)//驱动小车左 拐,|speed0|>|speed1|(绝对值) { if(speed0>0) { SetMoto_speed(speed0,speed1); } else { SetMoto_speed(speed1,speed0); } } void SetMoto_stright(int speed0,int speed1)//驱动小车前进和后退 { SetMoto_speed(speed0,speed1); }
void go_room3(void)//从起点到房间 3 { while(AI(0)>AI0) { right_wall3();//沿右墙到房间 3 } SetMoto_stright(0,0);//暂停缓冲机器 wait(0.08); } void right_wall3(void)//沿右墙到房间 3 { if(AI(4)>AI4)//前面无墙 { if((AI(5)>AI5)&&(AI(6)>AI6))//右边无墙 { SetMoto_right(20,80); } else if((AI(5)AI5)&&(AI(6)>AI6))//右边无墙 { SetMoto_right(30,80); } else if((AI(5)
void putfire_3(void)//房间 3 灭火 { int j=0,k=0;//j 接收最大火焰对应通道 k=EyeChMaxEx(EYE_0); while((AI(4)>AI4)||(j!=5))//利用火焰传感器和机器人正对传感器 (AI(4)/AI(9))作为标准 { j= EyeChMaxEx(EYE_0); if(j==5) { SetMoto_stright(30,30);//正对火焰直行 } else if(j<5) { SetMoto_left(60,5);//在左边左拐 } else if((j>5)&&(j<=10))//在右边右拐 { SetMoto_right(5,60); } } SetMoto_stright(0,0); beep(1);//启动蜂鸣器 SetMoto(2,100);//启动风扇 wait(2); beep(0);//关闭蜂鸣器 SetMoto(2,0);//关闭风扇 if(k>8) SetMoto_left(30,10); wait(0.13); while(AI(1)>AI1) { if(AI(0)AI9)//前面无墙 { if((AI(10)>AI10)&&(AI(11)>AI11))//右边无墙 { SetMoto_right(0,-50); } else if((AI(10)
else//直行 { SetMoto_stright(-30,-30); } } else//前面有墙 { if((AI(10)>AI10)&&(AI(11)>AI11))//右边无墙 { SetMoto_right(0,-50); } else if((AI(10)1.86) { break; } left_home3(); } while(AI(1)>AI1) { left_home3_after(); } while(1) { SetMoto_stright(0,0);
} } void left_home3(void)//房间 3 回家沿左墙 { if(AI(9)>AI9)//前面无墙 { if((AI(7)>AI7)&&(AI(8)>AI8))//左边无墙 { SetMoto_left(-35,-10); } else//左边有墙 { SetMoto_right(-5,-45); } } else//前面有墙 { SetMoto_left(-50,-5); } } void left_home3_after(void)//房间 3 回家沿左墙 { if(AI(9)>AI9)//前面无墙 { if((AI(7)>AI7)&&(AI(8)>AI8))//左边无墙 { SetMoto_left(-35,-10); } else if((AI(7)AI7)&&(AI(8)>AI8))//左边无墙 { SetMoto_left(-35,-10); } else if((AI(7)
{ SetMoto_right(-5,-45); } else//左边有墙 { SetMoto_stright(-30,-30); } } } void go_room2(void)//从房间 3 到房间 2 { t1=seconds(); while(1) { t2=seconds(); if(t2-t1>1.06) { break; } right_wall2(); } while(AI(1)>AI1) { right_wall2_1();//沿右墙到房间 2 } SetMoto_stright(0,0); wait(0.08); } void right_wall2()//沿右墙到房间 2(调用系统时间) { if(AI(9)>AI9)//前面无墙 { if((AI(10)>AI10)&&(AI(11)>AI11))//右边无墙 { SetMoto_right(-30,-70); } else if((AI(10)
} } else//前面有墙 { SetMoto_left(-80,-5); } } void right_wall2_1()//调用系统时间后到房间 2 { if(AI(9)>AI9)//前面无墙 { if((AI(10)>AI10)&&(AI(11)>AI11))//右边无墙 { SetMoto_right(-30,-70); } else if((AI(10)AI10)&&(AI(11)>AI11))//右边无墙 { SetMoto_right(-30,-70); } else if((AI(10)
分享到:
收藏