Ubuntu18.04-編譯安裝支持Python運動規劃庫OMPL
- 簡介
- 開始安裝
- 1. 坑1 源碼安裝沒有提及依賴項,安裝文檔相對簡單,安裝門檻較高。
- 2. 坑2 ubutun apt管理源沒有支持app和Python binding
- 第一步:去[官網下載源](https://ompl.kavrakilab.org/)碼包:目前是1.4.2版本。
- 第二步:去官網[拷貝安裝腳本](https://ompl.kavrakilab.org/installation.html)
- 第三步:開始安裝----
- 第四步:安裝依賴
- 第五步:真正開始安裝:
- 第六步:編譯完畢後,檢查這個路徑下ompl-1.4.2-Source/build/Release/lib,是否有如下文件。
- 第七步:由於需要直接使用我們還希望把動態鏈接庫拷貝到方便調用的地方。我們運行make install。
- 第八步:去ompl-1.4.2-Source/build/Release/bin下面先測試是否C++ 版本的庫已編譯好。如下圖我們選擇demo_RigidBodyPlanning 進行測試:
- 第九步:出現已下結果證明已編譯成功
- 第十步:去路徑:omplapp-1.4.2-Source/ompl-1.4.2-Source/demos下找到RigidBodyPlanning.py,使用如下命令進行測試:
- 最後
簡介
最近需要使用到運動規劃庫,於是選擇使用OMPL。主要原因基於兩個點:一、這個庫是ROS默認支持的庫;二、雖然還有CHOMP和STOMP,對比三者OMPL具有更快更穩定的規劃路徑。可以參考這裏看具體差異。下面介紹如何安裝OMPL,這個庫支持多個品臺,Mac,Windows,Ubuntu等。
這個庫安裝太多坑了,文章最後可以留言獲取我編譯好的鏈接庫,可以直接使用。需要的可以留言或者添加公衆號(追逐雅克比)獲取。
開始安裝
1. 坑1 源碼安裝沒有提及依賴項,安裝文檔相對簡單,安裝門檻較高。
這個庫目前是我安裝過最坑爹的庫暫時沒有之一,大家看看這個安裝官方教程,那是相當簡單,太有迷惑性了。只需要下載一個安裝腳本即可,看着相當簡單,其實等你真正安裝哭死你。
2. 坑2 ubutun apt管理源沒有支持app和Python binding
本以爲可以直接使用apt安裝,然後哪一行小小的字提醒你,如果你想用Python,那這是不行的。
第一步:去官網下載源碼包:目前是1.4.2版本。
下載後看到的目錄如下:
第二步:去官網拷貝安裝腳本
第三步:開始安裝----
如果你這就開始安裝,恭喜你,你馬上會遇到各種各樣的錯誤。哪怕最後編譯成功,也可以看到很多依賴庫沒有編譯完成,尤其是python-bindings這個東東。
第四步:安裝依賴
必須要安裝依賴:PyQt5 OpenGL numpy pyplusplus pygccxml flask celery fcl libspot ccd boost eigen3 flann pkg-config
可選依賴:
* pypy, <http://pypy.org>
Used to speed up the generation of python bindings.
* Triangle, <http://www.cs.cmu.edu/~quake/triangle.html>
Used to create triangular decompositions of polygonal 2D environments.
* MORSE, <https://www.openrobots.org/wiki/morse>
OMPL includes a plugin for the MORSE Robot Simulation engine.
* Drawstuff, <http://ode.org>
Part of the ODE source distribution, used in one demo program.
* PQP, <http://gamma.cs.unc.edu/SSV/>
Used as an alternative, additional collision checking library (the default is FCL).
* Doxygen, <http://doxygen.org>
Used to create the OMPL documentation (i.e., http://ompl.kavrakilab.org).
上述依賴有的可以使用apt-get 安裝,有的使用pip安裝,有的安裝完前一個,後面的即可自動安裝:
- 安裝libspot ,可以參考這裏;
wget -q -O - https://www.lrde.epita.fr/repo/debian.gpg | sudo apt-key add - echo 'deb http://www.lrde.epita.fr/repo/debian/ stable/' >> /etc/apt/sources.list apt-get update apt-get install spot libspot-dev spot-doc python3-spot(這個庫可以不裝,我沒安裝也成功了,需要Python版本3.7以上) # Or a subset of those
其他的都可以使用apt-get安裝就不一一寫在這裏了
第五步:真正開始安裝:
在那之前使用如下命令檢查一下配置有沒有遺漏:
cmake -DOMPL_BUILD_PYBINDINGS=ON . && make update_util_bindings VERBOSE=1
如果沒有遺漏,在經過一波操作後會出現如下圖所示:
然後接下來就是漫長的等待,官方告知安裝這個庫編譯需要5-8個小時,可以出去浪一下,讓你們感受一下絕望,連庫自己都擔心你等太久,把程序關了:
第六步:編譯完畢後,檢查這個路徑下ompl-1.4.2-Source/build/Release/lib,是否有如下文件。
注意:兩個紅色箭頭是後面使用python版本的關鍵。如果Python-bindings沒有正確生成Python調用的依賴的話,你後面會出現兩個致命錯誤,爲了解決這兩個錯誤,查看了各種論壇和文檔,才解決,不容易啊。
第一個:
No module named _util
第二個:
No module named _base
第七步:由於需要直接使用我們還希望把動態鏈接庫拷貝到方便調用的地方。我們運行make install。
第八步:去ompl-1.4.2-Source/build/Release/bin下面先測試是否C++ 版本的庫已編譯好。如下圖我們選擇demo_RigidBodyPlanning 進行測試:
第九步:出現已下結果證明已編譯成功
OMPL version: 1.4.2
Info: RRTConnect: Space information setup was not yet called. Calling now.
Debug: RRTConnect: Planner range detected to be 1.006980
Settings for the state space 'SE3CompoundSpace0'
- state validity check resolution: 1%
- valid segment count factor: 1
- state space:
Compound state space 'SE3CompoundSpace0' of dimension 6 (locked) [
Real vector state space 'RealVectorSpace1' of dimension 3 with bounds:
- min: -1 -1 -1
- max: 1 1 1
of weight 1
SO(3) state space 'SO3Space2' (represented using quaternions)
of weight 1
]
Registered projections:
- <default>
Projection of dimension 3
Cell sizes (computed defaults): [0.1 0.1 0.1]
Declared parameters:
longest_valid_segment_fraction = 0.01
projection.cellsize.0 = 0.1
projection.cellsize.1 = 0.1
projection.cellsize.2 = 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.180145 -0.00048426 0.686778]
SO3State [0.706146 0.432641 -0.505694 -0.241771]
]
Goal state, threshold = 2.22045e-16, memory address = 0x55d917523fd0, state =
Compound state [
RealVectorState [-0.564755 0.867481 0.0330055]
SO3State [0.364372 0.697109 -0.366705 0.496789]
]
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.180145 -0.00048426 0.686778]
SO3State [0.706146 0.432641 -0.505694 -0.241771]
]
Compound stadishibute [
RealVectorState [0.430851 0.370329 0.617361]
SO3State [0.434015 0.688351 -0.231927 -0.53293]
]
Compound state [
RealVectorState [0.287885 0.441718 0.533449]
SO3State [0.457808 0.747085 -0.274936 -0.395836]
]
Compound state [
RealVectorState [-0.138435 0.654599 0.283227]
SO3State [0.460797 0.809409 -0.359613 0.0565803]
]
Compound state [
RealVectorState [-0.564755 0.867481 0.0330055]
SO3State [0.364372 0.697109 -0.366705 0.496789]
]
Info: No planner specified. Using default.
Info: LBKPIECE1: Attempting to use default projection.
Debug: LBKPIECE1: Planner range detected to be 1.006980
Properties of the state space 'SE3CompoundSpace3'
- signature: 6 5 6 1 3 3 3
- dimension: 6
- extent: 5.0349
- sanity checks for state space passed
- probability of valid states: 1
- average length of a valid motion: 2.51125
- average number of samples drawn per second: sampleUniform()=4.55243e+06 sampleUniformNear()=2.65e+06 sampleGaussian()=2.73573e+06
Settings for the state space 'SE3CompoundSpace3'
- state validity check resolution: 1%
- valid segment count factor: 1
- state space:
Compound state space 'SE3CompoundSpace3' of dimension 6 (locked) [
Real vector state space 'RealVectorSpace4' of dimension 3 with bounds:
- min: -1 -1 -1
- max: 1 1 1
of weight 1
SO(3) state space 'SO3Space5' (represented using quaternions)
of weight 1
]
Registered projections:
- <default>
Projection of dimension 3
Cell sizes (computed defaults): [0.1 0.1 0.1]
Declared parameters:
longest_valid_segment_fraction = 0.01
projection.cellsize.0 = 0.1
projection.cellsize.1 = 0.1
projection.cellsize.2 = 0.1
projection.cellsize_factor = 0
valid_segment_count_factor = 1
Valid state sampler named uniform with parameters:
nr_attempts = 100
Planner LBKPIECE1 specs:
Multithreaded: No
Reports approximate solutions: No
Can optimize solutions: No
Aware of the following parameters: border_fraction min_valid_path_fraction range
Declared parameters for planner LBKPIECE1:
border_fraction = 0.9
min_valid_path_fraction = 0.5
range = 1.00698
Start states:
Compound state [
RealVectorState [-0.0730456 -0.836679 0.0699345]
SO3State [0.473221 -0.507003 0.0264253 0.719939]
]
Goal state, threshold = 2.22045e-16, memory address = 0x55d917523fd0, state =
Compound state [
RealVectorState [0.35548 -0.13107 -0.521166]
SO3State [-0.198537 -0.608689 0.0027985 0.768162]
]
OptimizationObjective = nullptr
There are 0 solutions
Info: LBKPIECE1: Starting planning with 1 states already in datastructure
Info: LBKPIECE1: Created 187 (93 start + 94 goal) states in 185 cells (92 start (92 on boundary) + 93 goal (93 on boundary))
Info: Solution found in 0.000627 seconds
Found solution:
Info: SimpleSetup: Path simplification took 0.002024 seconds and changed from 133 to 2 states
Geometric path with 2 states
Compound state [
RealVectorState [-0.0730456 -0.836679 0.0699345]
SO3State [0.473221 -0.507003 0.0264253 0.719939]
]
Compound state [
RealVectorState [0.35548 -0.13107 -0.521166]
SO3State [-0.198537 -0.608689 0.0027985 0.768162]
]
第十步:去路徑:omplapp-1.4.2-Source/ompl-1.4.2-Source/demos下找到RigidBodyPlanning.py,使用如下命令進行測試:
python 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 35 (22 start + 13 goal) states in 32 cells (20 start (20 on boundary) + 12 goal (12 on boundary))
Info: Solution found in 0.000430 seconds
Info: SimpleSetup: Path simplification took 0.001344 seconds and changed from 13 to 2 states
Geometric path with 2 states
Compound state [
RealVectorState [0.5 0.521332]
SO2State [0.0343937]
]
Compound state [
RealVectorState [-0.5 0.00545857]
SO2State [-1.72727]
]
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.690274 0.216669]
SO2State [-1.3863]
]
Goal state, threshold = 2.22045e-16, memory address = 0x55981fa6d9c0, state =
Compound state [
RealVectorState [-0.98753 -0.931353]
SO2State [-2.71132]
]
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.690274 0.216669]
SO2State [-1.3863]
]
Compound state [
RealVectorState [-0.821073 0.0697578]
SO2State [-0.0200162]
]
Compound state [
RealVectorState [-0.863441 -0.185053]
SO2State [-0.705029]
]
Compound state [
RealVectorState [-0.925485 -0.558203]
SO2State [-1.70817]
]
Compound state [
RealVectorState [-0.98753 -0.931353]
SO2State [-2.71132]
]
- 注意這裏 有可能出現找不到解的情況,這是正常的,多嘗試幾次即可。
最後
由於有的小夥伴實在不想等那絕望的幾個小時,又想直接使用Python版本的ompl可以私信或者留言找我獲取編譯好的安裝包,只需要解壓到Python依賴庫即可。如果有什麼問題也歡迎大家留言,我有時間看到會進行回覆。
參考鏈接
[1] https://bitbucket.org/ompl/ompl/issues/488/no-module-named-_util
[2] https://www.twblogs.net/a/5b83659c2b71776c51e2d839
[3] https://spot.lrde.epita.fr/install.html
[4] http://ubuntuhandbook.org/index.php/2019/02/install-python-3-7-ubuntu-18-04/
[5] https://sourceforge.net/p/ompl/mailman/message/34837507/