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丢失问题,其实可以看下工 ...
随机推荐
- java.lang.NoClassDefFoundError: org/apache/zookeeper/proto/SetWatches
Session 0x16b21fa441900b6 for server 192.168.240.126/192.168.240.126:2181, unexpected error, closing ...
- 三.protobuf3标量值类型
Protobuf3 标量值类型 标量消息字段可以具有以下类型之一——该表显示了.proto文件中指定的类型,以及自动生成的类中的相应类型: .proto类型 说明 C++ 类型 Java 类型 Pyt ...
- Spring Boot MyBatis 通用Mapper 自动生成代码
一.在pom.xml文件中进入mybatis自动生成代码相关的jar包: 注意: <configurationFile>标签中配置的是“generatorConfig.xml”文件位置. ...
- 查看java的jar包源码
1.jd-gui (windows环境) 下载地址 https://files.cnblogs.com/files/indifferent/jd-gui-windows-1.5.1.zip 下载并解压 ...
- VS - Microsoft.Practices.EnterpriseLibrary.Logging
string fileName = AppDomain.CurrentDomain.BaseDirectory + "\\log.txt";File.AppendAllText(f ...
- asp.net使用WebUploader做大文件的分块和断点续传
HTML部分 <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="index.a ...
- 如何选择梯度下降法中的学习速率α(Gradient Descent Learning Rate Alpha)
梯度下降算法的任务是寻找参数θ,使之能够最小化损失函数. 那么梯度下降法中的学习速率α应该如何选择呢?通常我们画出损失函数随迭代次数增加而变化的曲线. 可能会得到如下的一条曲线,x轴表示迭代次数,y轴 ...
- A. Vasya and Book ( Codeforces Educational Codeforces Round 55 )
题意:当前在看书的第 x 页,每次可以向前或者向后翻 d 页,这个书一共 n 页,问能否用最小操作翻到第 y 页. 题解:三种情况:1.直接翻能到的一定最短. 2.先翻到第一页,然后往后翻,翻到第 y ...
- Git的使用(6) —— 自动填写远端Git用户名密码
1. 问题描述 公司项目组用私服的Git远程版本库,每一次推送和拉取服务都需要输入用户名和密码,过于繁琐. 2. 解决方法 Windows系统提供了"管理Windows凭据"的功能 ...
- ciscn2019华北赛区半决赛day2_web1题解
比赛结束以后采用非官方复现平台做的题,和比赛题有轻微不同,比赛中存放flag的table是ctf,这里是flag. 题目地址 buuoj.cn 解题过程 题目中只有一个页面,需要提交id. id为1, ...