当前位置: 首页>>代码示例>>C++>>正文


C++ NodeTree::getRamdomSample方法代码示例

本文整理汇总了C++中NodeTree::getRamdomSample方法的典型用法代码示例。如果您正苦于以下问题:C++ NodeTree::getRamdomSample方法的具体用法?C++ NodeTree::getRamdomSample怎么用?C++ NodeTree::getRamdomSample使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在NodeTree的用法示例。


在下文中一共展示了NodeTree::getRamdomSample方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: rrtgrow

	NodeTree* rrtgrow(const std::vector<float> &start,const std::vector<float> &goal,float goalbias,std::vector<float> upper,std::vector<float> lower,OpenRAVE::EnvironmentBasePtr env, OpenRAVE::RobotBasePtr robot)
	{
		RRTNode* startNode = new RRTNode(start);
		RRTNode* goalNode = new RRTNode(goal);
		setgoalConfig(goal);
		setGoalBias(goalbias);
		NodeTree* initPath = new NodeTree(startNode);
		
		NodeTree* path= new NodeTree();
		NodeTree* finalPath=new NodeTree();
		RRTNode* nearestNode = NULL;
		
		// initPath->setgoalflag(false);
		goalflag = false;

		std::vector<float>::const_iterator it;
		std::cout<<std::endl<<"Given:"<<std::endl<<"Goal:"<<goal[0]<<","<<goal[1]<<","<<goal[2]<<","<<goal[3]<<","<<goal[4]<<","<<goal[5]<<","<<goal[6]<<std::endl;
		std::cout<<std::endl<<"Start:"<<start[0]<<","<<start[1]<<","<<start[2]<<","<<start[3]<<","<<start[4]<<","<<start[5]<<","<<start[6]<<std::endl;


		for (int i=0; i<10000;++i){
			std::cout<<std::endl<<"RRT-iteration"<<i<<std::endl;
			
			RRTNode* sampledNode = initPath->getRamdomSample(upper,lower,goalNode);
			
			if(!checkifCollision(sampledNode->getConfig(),env,robot)){
				nearestNode = initPath->nearestNeighbour(sampledNode);

				std::vector<float> nn(nearestNode->getConfig().begin(),nearestNode->getConfig().end());
				std::cout<<"Nearest found:["<<nn[0]<<","<<nn[1]<<","<<nn[2]<<","<<nn[3]<<","<<nn[4]<<","<<nn[5]<<","<<nn[6]<<"]"<<std::endl;
				// std::cout<<"Nearest Node found..."<<std::endl;
				
				path = initPath->connectNodes(sampledNode, nearestNode, goalNode,initPath->stepSize(),env,robot);
				
				
			}
			else
				continue;
						 
			if(path->sizeNodes()==1){
				std::cout<<"restart subpath.."<<std::endl;
			 	continue;
			}
			else if(getNearestDistance(path->lastNode()->getConfig(),goal)==0){
				// std::cout<<"found found..."<<std::endl;
				initPath->addNodeTree(path);
				std::cout<<"...Final..."<<std::endl;
				
				for(it=path->lastNode()->getConfig().begin(); it!=path->lastNode()->getConfig().end(); ++it){
					std::cout<<"final Node:"<<(*it)<<std::endl;
				}
				
				break;
			}
			else{
				initPath->addNodeTree(path);
				std::cout<<"Intermediate Tree..."<<std::endl;
				// finalPath = initPath->getPath(initPath->sizeNodes()-1);
			}			
		}
		std::cout<<" Path found..."<<std::endl;

		finalPath = initPath->getPath(initPath->sizeNodes()-1);
		std::cout<<" initPath Size..."<<initPath->sizeNodes()<<std::endl;

		std::cout<<" FinalPath Size..."<<finalPath->sizeNodes()<<std::endl;
		
		return finalPath;
	}
开发者ID:varunverlencar,项目名称:MotionPlanning,代码行数:69,代码来源:myrrt.hpp


注:本文中的NodeTree::getRamdomSample方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。