OMPL RRTConnet 生成路径和可视化
默认规划路径算法和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 生成路径和可视化的更多相关文章
- (转载)phpcms v9两步实现专题栏目生成路径去掉html和special
相信很多人都知道,phpcms v9专题是不支持自定义URL的,生成的专题路径是以/HTML/special/开头的.那么如何实现专题栏目生成路径去掉html和special呢?通过修改程序的PHP源 ...
- Xcode如何找到默认的生成路径?
我最近刚刚入门ObjectiveC,在研习<Objective C程序设计(第6版)>一书. 今天看到有关文件和归档的章节,但是我对XCode的生成文件路径并不了解,然后,在调试代码的时候 ...
- npm run build生成路径问题
vue项目中可以使用npm run build 命令生成静态文件夹dist,开发者可以直接点击dist文件夹下面的index.html问价来访问自己的项目,但是用vue-cli生成的项目,当运行npm ...
- mac自动生成路径问题
使用myBatis的逆向工程,一直无法生成.最后找同事帮忙,最终发现是 :路径前面少加一个反斜杠... 也就是 mac的绝对路径 前面需要加上 反斜杠.
- Linux下设置Core文件生成路径及文件名
修改core dump文件路径: 方法1:临时修改: 修改/proc/sys/kernel/core_pattern文件/proc目录本身动态加载每次系统重启都会重新加载因此种方法只能作临时修改/p ...
- Cadence Allegro小技巧之指定Gerber生成路径
Allegro生成Gerber数据时,默认会保存在与pcb文件相同目录路径下,Gerber数据本身就会生成好几个文件,然后与pcb文件,log文件,临时文件等混杂在一起,不易整理打包Gerber数据, ...
- 修改maven的war包生成路径
因为要配合jenkins,所以控制了war包的生成目录: <plugins> <!--打war包到指定的目录下 --> <plugin> <groupId&g ...
- symfony中模板生成路径两种方式
1. 使用url('route_a_b_c') 这种方式会是全路径 : http://www.test.com/a/b/c 2. 使用path('route_a_b_c') 这种方式只是路径: /a ...
- .NetCore利用Swagger生成 XML文档需要注意生成路径的地址
发布的时候如果用 release dotnet publish --configuration release dotnet publish 默认都是debug 会出现 XML丢失问题,其实可以看下工 ...
随机推荐
- docker安装之mariadb
https://hub.docker.com/_/mariadb?tab=description Supported tags and respective Dockerfile links 10.4 ...
- 【转】Http和Https下的cookie的写入问题
网站https:// 可以登陆, 但是切换到http的时候不能登陆. 原因是:https访问的时候,返回的cookie设置了secure=1, 切换成http访问的时候, 这个时候不能操作那个cook ...
- solrconfig.xml配置文件
部分来自http://www.jianshu.com/p/8cf609207497 一.总览 solr的配置重要的有三个:solr.xml.solrConfig.xml.schema.xml solr ...
- Java - 基础到进阶
# day01 一:基本操作 package _01.java基本操作; /** * 文档注释 */ public class _01Alls { public static void main(St ...
- bzoj 1072: [SCOI2007]排列perm 状压dp
code: #include <bits/stdc++.h> #define N 1005 using namespace std; void setIO(string s) { stri ...
- learning java AWT Dialog
import java.awt.*; public class DialogTest { Frame f = new Frame("test"); Dialog d1 = new ...
- saltstack 基础模块
Salt 在 linux 系统下 基础操作 1.更改权限 # salt 2.更改用户 # salt '172.16.3.9' file.chown /root/test test test 3.复制文 ...
- [TJOI2019]甲苯先生和大中锋的字符串
有个叫asuldb的神仙来嘲讽我 说这题SAM水题,而且SA过不了 然后我就用SA过了 显然是一个Height数组上长为k的滑块,判一下两边,差分一下就可以了 #include"cstdio ...
- 生成ROM时修改参数
在Xilinx ISE中生成ROM后,如果修改参数,可能会出现错误: “The Memory Initialization vector can contain between 1 to Write” ...
- [WC2010]重建计划(长链剖分版)
传送门 Description Solution 时隔多年,补上了这题的长链剖分写法 感觉比点分治要好写的多 我们假设\(pos\)是当前点的\(dfn\),它距离所在链的底端的边的数量是\(len\ ...