赞
踩
项目需要想要在Ubuntu20.04安装OMPL运动规划库,官网链接安装十分简单,只需要下载安装文件运行即可。但是不知道什么原因,安装完成后缺少很多库,在Python中运行示例报错:ModuleNotFoundError: No module named ‘ompl.base._base’`。在参考几篇典型博文后仍没解决。后经过在OMPL的github中寻找到答案,问题解决。
前往OMPL的官方下载地址,在Ubuntu-From Source下载OMPL installation script,如图所是。
这里问题出现了,如果你按照官方教程,直接输入命令./install-ompl-ubuntu.sh --python,安装可能很快会完成,并且看不出明显报错,但是其实打开build-Release-lib,会发现少了好几个库,这里我附上我已成功安装后的库文件。
其中,你可能会缺少_base.so,_util.so等文件,且此时运行示例代码或直接在python中运行from ompl import base,均会报错ModuleNotFoundError: No module named ‘ompl.base._base’`。github上的分析讨论在这。不关心原因没有关系,咱们直接按着安装步骤即可。
首先,打开文件py-bindings/generate_bindings.py,修改代码如下:
为节省大家coding时间,下面附下代码:
self.ompl_ns.class_('SpecificParam< float >').rename('SpecificParamFloat')
self.ompl_ns.class_('SpecificParam< double >').rename('SpecificParamDouble')
self.ompl_ns.class_('SpecificParam< long double >').rename('SpecificParamLongDouble')
self.ompl_ns.class_(f'SpecificParam< {self.string_decl} >').rename('SpecificParamString')
try:
self.ompl_ns.class_(f'SpecificParam< std::string >').rename('SpecificParamString')
except:
self.ompl_ns.class_(f'SpecificParam< std::basic_string< char > >').rename('SpecificParamString')
for cls in self.ompl_ns.classes(lambda decl: decl.name.startswith('SpecificParam')):
cls.constructors().exclude()
# don't export variables that need a wrapper
然后,打开下载的安装文件install-ompl-ubuntu.sh,将安装文件中wget下载文件部分注释掉,如图所示。
这里如果不注释掉,那么每次运行安装文件,都会把我们第一步修改的内容改回去,因此这里一定要注意。
最后,完成上述修改后,直接再次运动安装文件即可。安装完成后可以去Demos文件夹内运行示例程序,我这里运行了RigidBodyPlanning.py文件,结果如图。
Info: No planner specified. Using default.
Info: LBKPIECE1: Attempting to use default projection.
Debug: LBKPIECE1: Planner range detected to be 0.879845
Info: LBKPIECE1: Starting planning with 1 states already in datastructure
Info: LBKPIECE1: Created 26 (14 start + 12 goal) states in 25 cells (13 start (13 on boundary) + 12 goal (12 on boundary))
Info: Solution found in 0.001533 seconds
Info: SimpleSetup: Path simplification took 0.000832 seconds and changed from 20 to 2 states
Geometric path with 2 states
Compound state [
RealVectorState [0.5 -0.0501096]
SO2State [1.59711]
]
Compound state [
RealVectorState [-0.5 0.29246]
SO2State [-0.828855]
]
Info: RRTConnect: Space information setup was not yet called. Calling now.
Debug: RRTConnect: Planner range detected to be 0.879845
Settings for the state space 'SE2CompoundSpace3'
- state validity check resolution: 1%
- valid segment count factor: 1
- state space:
Compound state space 'SE2CompoundSpace3' of dimension 3 (locked) [
Real vector state space 'RealVectorSpace4' of dimension 2 with bounds:
- min: -1 -1
- max: 1 1
of weight 1
SO2 state space 'SO2Space5'
of weight 0.5
]
Registered projections:
- <default>
Projection of dimension 2
Cell sizes (computed defaults): [0.1 0.1]
Declared parameters:
longest_valid_segment_fraction = 0.01
projection.cellsize.0 = 0.1
projection.cellsize.1 = 0.1
projection.cellsize_factor = 0
valid_segment_count_factor = 1
Valid state sampler named uniform with parameters:
nr_attempts = 100
Start states:
Compound state [
RealVectorState [-0.857957 -0.415686]
SO2State [2.4052]
]
Goal state, threshold = 2.22045e-16, memory address = 0x1545900, state =
Compound state [
RealVectorState [-0.578203 0.789117]
SO2State [1.6372]
]
OptimizationObjective = nullptr
There are 0 solutions
Info: RRTConnect: Starting planning with 1 states already in datastructure
Info: RRTConnect: Created 6 states (2 start + 4 goal)
Found solution:
Geometric path with 5 states
Compound state [
RealVectorState [-0.857957 -0.415686]
SO2State [2.4052]
]
Compound state [
RealVectorState [-0.466318 -0.283665]
SO2State [-2.94488]
]
Compound state [
RealVectorState [-0.476147 -0.189428]
SO2State [-3.09431]
]
Compound state [
RealVectorState [-0.527175 0.299844]
SO2State [2.41304]
]
Compound state [
RealVectorState [-0.578203 0.789117]
SO2State [1.6372]
]
这里附上修改完的两个文件(安装文件install-ompl-ubuntu.sh与generate_bindings.py)的下载链接。
事实上,如果是自己在github上下载ompl并安装的,可能并不会出现上述错误,因为我后来看到自己在github上下载的安装包里,我这里修改的文件已经默认修改了,只需要将安装文件修改一下即可。我没有试过用github上下载的安装包安装,不过应该是可以安装成功的。
另外,上述安装过程在本机环境进行,如果向安装在conda的虚拟环境,只需在本机上安装完成之后,将py-bindings/ompl文件放置到对应虚拟环境下的lib/pythonx.x/site-packages下即可。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。