默认规划路径算法和RRTConnet路径规划算法生成路径

1.  源代码

#include <ompl/base/SpaceInformation.h>
#include <ompl/base/spaces/SE3StateSpace.h>
#include <ompl/geometric/planners/rrt/RRTConnect.h>
#include <ompl/geometric/SimpleSetup.h>

#include <ompl/config.h>
#include <iostream>

#include <fstream>
#include <ostream>

namespace ob = ompl::base;
namespace og = ompl::geometric;

bool isStateValid(const ob::State *state)
{
	// cast the abstract state type to the type we expect
	const auto *se3state = state->as<ob::SE3StateSpace::StateType>();

	// extract the first component of the state and cast it to what we expect
	const auto *pos = se3state->as<ob::RealVectorStateSpace::StateType>(0);

	// extract the second component of the state and cast it to what we expect
	const auto *rot = se3state->as<ob::SO3StateSpace::StateType>(1);

	// check validity of state defined by pos & rot

	// return a value that is always true but uses the two variables we define, so we avoid compiler warnings
	return (const void*)rot != (const void*)pos;
}

void planWithSimpleSetup()
{
	// construct the state space we are planning in
	auto space(std::make_shared<ob::SE3StateSpace>());

	// set the bounds for the R^3 part of SE(3)
	ob::RealVectorBounds bounds(3);
	bounds.setLow(-1);
	bounds.setHigh(1);

	space->setBounds(bounds);

	// define a simple setup class
	og::SimpleSetup ss(space);

	// set state validity checking for this space
	ss.setStateValidityChecker([](const ob::State *state) { return isStateValid(state); });

	// create a random start state
	ob::ScopedState<> start(space);
	start.random();

	// create a random goal state
	ob::ScopedState<> goal(space);
	goal.random();

	// set the start and goal states
	ss.setStartAndGoalStates(start, goal);

	// this call is optional, but we put it in to get more output information
	ss.setup();
	ss.print();

	// set planner
	ob::PlannerPtr planner(new og::RRTConnect(ss.getSpaceInformation()));
	ss.setPlanner(planner);

	// attempt to solve the problem within one second of planning time
	ob::PlannerStatus solved = ss.solve(1.0);

	if (solved)
	{
		std::cout << "Found solution:" << std::endl;

		std::ofstream ofs0("../plot/path0.dat");
		ss.getSolutionPath().printAsMatrix(ofs0);

		// print the path to screen
		ss.simplifySolution();
		ss.getSolutionPath().print(std::cout);

		std::ofstream ofs("../plot/path.dat");
		ss.getSolutionPath().printAsMatrix(ofs);
	}
	else
		std::cout << "No solution found" << std::endl;
}

int main(int /*argc*/, char ** /*argv*/)
{
	std::cout << "OMPL version: " << OMPL_VERSION << std::endl;

	planWithSimpleSetup();

	return 0;
}

2. Python可视化生成的原始路径和简化路径

from mpl_toolkits.mplot3d import Axes3D
import numpy
import matplotlib.pyplot as plt
data = numpy.loadtxt('path.dat')
data1 = numpy.loadtxt('path0.dat')
fig = plt.figure()
ax = fig.gca(projection='3d')
ax.plot(data[:,0],data[:,1],data[:,2],'.-')
plt.hold('on')
plt.grid('on')
ax.plot(data1[:,0],data1[:,1],data1[:,2],'r-')
plt.show()

路径可视化方法可以参考官网 http://ompl.kavrakilab.org/pathVisualization.html

OMPL 参考列表

1. http://ompl.kavrakilab.org/group__demos.html

2. http://ompl.kavrakilab.org/tutorials.html

3. http://ompl.kavrakilab.org/gui.html#gui_paths

OMPL RRTConnet 生成路径和可视化的更多相关文章

  1. (转载)phpcms v9两步实现专题栏目生成路径去掉html和special

    相信很多人都知道,phpcms v9专题是不支持自定义URL的,生成的专题路径是以/HTML/special/开头的.那么如何实现专题栏目生成路径去掉html和special呢?通过修改程序的PHP源 ...

  2. Xcode如何找到默认的生成路径?

    我最近刚刚入门ObjectiveC,在研习<Objective C程序设计(第6版)>一书. 今天看到有关文件和归档的章节,但是我对XCode的生成文件路径并不了解,然后,在调试代码的时候 ...

  3. npm run build生成路径问题

    vue项目中可以使用npm run build 命令生成静态文件夹dist,开发者可以直接点击dist文件夹下面的index.html问价来访问自己的项目,但是用vue-cli生成的项目,当运行npm ...

  4. mac自动生成路径问题

    使用myBatis的逆向工程,一直无法生成.最后找同事帮忙,最终发现是 :路径前面少加一个反斜杠... 也就是 mac的绝对路径 前面需要加上 反斜杠.

  5. Linux下设置Core文件生成路径及文件名

    修改core dump文件路径:  方法1:临时修改: 修改/proc/sys/kernel/core_pattern文件/proc目录本身动态加载每次系统重启都会重新加载因此种方法只能作临时修改/p ...

  6. Cadence Allegro小技巧之指定Gerber生成路径

    Allegro生成Gerber数据时,默认会保存在与pcb文件相同目录路径下,Gerber数据本身就会生成好几个文件,然后与pcb文件,log文件,临时文件等混杂在一起,不易整理打包Gerber数据, ...

  7. 修改maven的war包生成路径

    因为要配合jenkins,所以控制了war包的生成目录: <plugins> <!--打war包到指定的目录下 --> <plugin> <groupId&g ...

  8. symfony中模板生成路径两种方式

    1. 使用url('route_a_b_c')  这种方式会是全路径 : http://www.test.com/a/b/c 2. 使用path('route_a_b_c') 这种方式只是路径: /a ...

  9. .NetCore利用Swagger生成 XML文档需要注意生成路径的地址

    发布的时候如果用 release dotnet publish --configuration release dotnet publish 默认都是debug 会出现 XML丢失问题,其实可以看下工 ...

随机推荐

  1. Oracle数据库使用游标查询结果集所有数据

    --Oracle使用游标查询结果集所有数据 DECLARE myTabelName NVARCHAR2():=''; --表名 myTableRowComment NVARCHAR2():=''; - ...

  2. 《CoderXiaoban》第八次团队作业:Alpha冲刺 2

    项目 内容 这个作业属于哪个课程 任课教师博客主页链接 这个作业的要求在哪里 实验十二 团队作业8:软件测试与ALPHA冲刺 团队名称 Coderxiaoban团队 作业学习目标 (1)掌握软件测试基 ...

  3. machine learning (4)---feature scaling

    feature scaling:缩小或扩大feature的值,使所有的feature处于类似的范围,这样进行gradient descnet时更快趋向最小值.因为不同的feature的范围相差很大时, ...

  4. .net框架 - File类与FileInfo类异同

    System.IO命名空间中提供的文件操作类有File和FileInfo,这两个类的功能基本相同,只是File是静态类,其中所有方法都是静态的,可以通过类名直接调用,不需要实例化.而FileInfo是 ...

  5. c语言中字符串转数字的函数

    ANSI C 规范定义了 atof().atoi().atol().strtod().strtol().strtoul() 共6个可以将字符串转换为数字的函数,大家可以对比学习.另外在 C99 / C ...

  6. Zookeeper数据类型、节点类型、角色、watcher监听机制

    1.Zookeeper数据类型:层次化目录结构+少量数据 Zookeeper包含层次化的目录结构,每个Znode都有唯一的路径标识,Znode可以包含数据和子节点. 其中Znode数据可以有多个版本, ...

  7. C 语言程序设计

    C 语言数据类型: 整数: char(也是字符型) short int long 浮点型: float double 指针 自定义类型 输入输出格式化: int ->%d long ->% ...

  8. C# 避免程序重复启动

    using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; using ...

  9. saltstack 基础模块

    Salt 在 linux 系统下 基础操作 1.更改权限 # salt 2.更改用户 # salt '172.16.3.9' file.chown /root/test test test 3.复制文 ...

  10. PHP安装mysql.so扩展及相关PHP.ini 配置参数说明

    在PHP中mysql_connect模块已经逐渐被弃用,我在搭建环境时也没有再安装mysql扩展,但是今天在维护一个老项目时,出现报错 Fatal error: Uncaught Error: Cal ...