前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >室内清扫机器人环境搭建与算法测试简易代码

室内清扫机器人环境搭建与算法测试简易代码

作者头像
zhangrelay
发布2019-01-23 10:14:51
4430
发布2019-01-23 10:14:51
举报

室内清扫机器人简易代码,由于时间紧张,地图构建和智能规划算法还没有研究,

给出已经完成的部分内容,抛砖引玉吧。

代码语言:javascript
复制
MazeBuilder  
//zhangrelay
AddiRobotCreate    ir1  	/Position:0  0.1  0
	/Procedure_Bumper_SensorNotify:wall1
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////AddNewEntity    enthwf  	/Position:0  0.1  -0.1
////	/Orientation:0    0    0
////	/ParentEntity:ir1
////AddBoxShape  
////	/Dimensions:0.001  0.001  0.001  	/Mass:0.01
AddInfraredRangeEntity    hwf
	/Position:0  0.1  -0.1
	/ParentEntity:ir1	

AddNewEntity    enthwl  	/Position:-0.1  0.1  0
	/Orientation:0    90    0
	/ParentEntity:ir1
AddBoxShape  
	/Dimensions:0.001  0.001  0.001  	/Mass:0.01
AddInfraredRangeEntity    hwl
	/ParentEntity:enthwl	

AddNewEntity    enthwr  	/Position:0.1  0.1  0
	/Orientation:0    270    0
	/ParentEntity:ir1
AddBoxShape  
	/Dimensions:0.001  0.001  0.001  	/Mass:0.01
AddInfraredRangeEntity    hwr
	/ParentEntity:enthwr	
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//AddInfraredRangeEntity    hwl
//	/Position:-0.3  0.2  0.0
//	/ParentEntity:ir1

//AddInfraredRangeEntity    hwr
//	/Position:0.3  0.2  0.0
//	/ParentEntity:ir1

FlushScript
double iswall=0
double hwfd=0
double hwld=0
double hwrd=0
double SimTime=10000
double turnf=0
double turnfl=0
wait 40000

call proc_main  with concur

Procedure  proc_main

	call proc_robot_0

End

Procedure  wall1
//	   print value.Pressed. ToString()
	   iswall=4
End

Procedure  proc_robot_0

	for (i = 0; i < SimTime; i++)
	{
		hwfd=hwf.Get()
		hwrd=hwr.Get()
		hwld=hwl.Get()
//////////		print "f" + hwfd. ToString()
//////////		print "l" + hwld. ToString()
//////////		print "r" + hwrd. ToString()
		if(hwfd>0.4)
		{
			iswall=0
		}
		if(hwfd<0.2)
		{
			if(turnfl==0)
			{
				turnf=1
			}
			if(turnfl==1)
			{
				turnf=2
			}
			if(turnfl==2)
			{
				turnf=1
			}
			if(hwld<0.2)
			{
				turnf=3
			}
			if(hwrd<0.2)
			{
				turnf=4
			}
			if(turnfl==3)
			{
				if(turnf==3)
				{
					turnf=34
				}
			}
			if(turnfl==4)
			{
				if(turnf==4)
				{
					turnf=44
				}
			}
		}
		if(iswall<1)
		{
			ir1.Go(0.4)
//			ir1.Go(0)
			if(turnf==1)
			{
				ir1.Go(0)
				ir1.RotateDegrees(90, 0.4)
				hwfd=hwf.Get()
				if(hwfd>0.4)
				{
					ir1.GoTo(0.2, 0.4)
				}
				else
				{
					ir1.GoTo((hwfd-0.14), 0.2)
				}
				ir1.RotateDegrees(90, 0.4)
				turnfl=turnf
				turnf=0
			}
			if(turnf==2)
			{
				ir1.Go(0)
				ir1.RotateDegrees(-90, 0.4)
				hwfd=hwf.Get()
				if(hwfd>0.4)
				{
					ir1.GoTo(0.2, 0.4)
				}
				else
				{
					ir1.GoTo((hwfd-0.14), 0.2)
				}
				ir1.RotateDegrees(-90, 0.4)
				turnfl=turnf
				turnf=0
			}
			if(turnf==3)
			{
				ir1.Go(0)
				ir1.RotateDegrees(-90, 0.4)
				turnfl=turnf
				turnf=0
			}		
			if(turnf==34)
			{
				ir1.Go(0)
				ir1.RotateDegrees(-90, 0.4)
				ir1.GoTo(0.2, 0.4)
				ir1.RotateDegrees(-90, 0.4)
				turnfl=2
				turnf=0
			}	
			if(turnf==4)
			{
				ir1.Go(0)
				ir1.RotateDegrees(90, 0.4)
				turnfl=turnf
				turnf=0
			}		
			if(turnf==44)
			{
				ir1.Go(0)
				ir1.RotateDegrees(90, 0.4)
				ir1.GoTo(0.2, 0.4)
				ir1.RotateDegrees(90, 0.4)
				turnfl=1
				turnf=0
			}	
		}
		else
		{
			ir1.Go(0)
		}
		wait 50
	}

End
代码语言:javascript
复制
StartSimulationEngine  /FileName:"ch001.xml"
// zhangrelay
AddiRobotCreate    ir1  	/Position:7  0.04  12
	/Orientation:0    270    0
	/Procedure_Bumper_SensorNotify:wall1
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////AddNewEntity    enthwf  	/Position:0  0.1  -0.1
////	/Orientation:0    0    0
////	/ParentEntity:ir1
////AddBoxShape  
////	/Dimensions:0.001  0.001  0.001  	/Mass:0.01
AddInfraredRangeEntity    hwf
	/Position:0  0.1  -0.1
	/ParentEntity:ir1	

AddNewEntity    enthwl  	/Position:-0.1  0.1  0
	/Orientation:0    90    0
	/ParentEntity:ir1
AddBoxShape  
	/Dimensions:0.001  0.001  0.001  	/Mass:0.01
AddInfraredRangeEntity    hwl
	/ParentEntity:enthwl	

AddNewEntity    enthwr  	/Position:0.1  0.1  0
	/Orientation:0    270    0
	/ParentEntity:ir1
AddBoxShape  
	/Dimensions:0.001  0.001  0.001  	/Mass:0.01
AddInfraredRangeEntity    hwr
	/ParentEntity:enthwr	
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//AddInfraredRangeEntity    hwl
//	/Position:-0.3  0.2  0.0
//	/ParentEntity:ir1

//AddInfraredRangeEntity    hwr
//	/Position:0.3  0.2  0.0
//	/ParentEntity:ir1

FlushScript
double iswall=0
double hwfd=0
double hwld=0
double hwrd=0
double SimTime=10000
double turnf=0
double turnfl=0
wait 40000

call proc_main  with concur

Procedure  proc_main

	call proc_robot_0

End

Procedure  wall1
//	   print value.Pressed. ToString()
	   iswall=4
End

Procedure  proc_robot_0

	for (i = 0; i < SimTime; i++)
	{
		hwfd=hwf.Get()
		hwrd=hwr.Get()
		hwld=hwl.Get()
////		print "f" + hwfd. ToString()
////		print "l" + hwld. ToString()
////		print "r" + hwrd. ToString()
		if(hwfd>0.4)
		{
			iswall=0
		}
		if(hwfd<0.2)
		{
			if(turnfl==0)
			{
				turnf=1
			}
			if(turnfl==1)
			{
				turnf=2
			}
			if(turnfl==2)
			{
				turnf=1
			}
			if(hwld<0.2)
			{
				turnf=3
			}
			if(hwrd<0.2)
			{
				turnf=4
			}
			if(turnfl==3)
			{
				if(turnf==3)
				{
					turnf=34
				}
			}
			if(turnfl==4)
			{
				if(turnf==4)
				{
					turnf=44
				}
			}
		}
		if(iswall<1)
		{
			ir1.Go(0.4)
//			ir1.Go(0)
			if(turnf==1)
			{
				ir1.Go(0)
				ir1.RotateDegrees(90, 0.4)
				hwfd=hwf.Get()
				if(hwfd>0.4)
				{
					ir1.GoTo(0.2, 0.4)
				}
				else
				{
					ir1.GoTo((hwfd-0.14), 0.2)
				}
				ir1.RotateDegrees(90, 0.4)
				turnfl=turnf
				turnf=0
			}
			if(turnf==2)
			{
				ir1.Go(0)
				ir1.RotateDegrees(-90, 0.4)
				hwfd=hwf.Get()
				if(hwfd>0.4)
				{
					ir1.GoTo(0.2, 0.4)
				}
				else
				{
					ir1.GoTo((hwfd-0.14), 0.2)
				}
				ir1.RotateDegrees(-90, 0.4)
				turnfl=turnf
				turnf=0
			}
			if(turnf==3)
			{
				ir1.Go(0)
				ir1.RotateDegrees(-90, 0.4)
				turnfl=turnf
				turnf=0
			}		
			if(turnf==34)
			{
				ir1.Go(0)
				ir1.RotateDegrees(-90, 0.4)
				ir1.GoTo(0.2, 0.4)
				ir1.RotateDegrees(-90, 0.4)
				turnfl=2
				turnf=0
			}	
			if(turnf==4)
			{
				ir1.Go(0)
				ir1.RotateDegrees(90, 0.4)
				turnfl=turnf
				turnf=0
			}		
			if(turnf==44)
			{
				ir1.Go(0)
				ir1.RotateDegrees(90, 0.4)
				ir1.GoTo(0.2, 0.4)
				ir1.RotateDegrees(90, 0.4)
				turnfl=1
				turnf=0
			}	
		}
		else
		{
			ir1.Go(0)
		}
		wait 50
	}

End
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2016年05月09日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档