CartesianPlanner 复现
一、基本情况论文链接Autonomous Driving on Curvy Roads Without Reliance on Frenet Frame: A Cartesian-Based Trajectory Planning Methodgithub 链接Cartesian Planner ROS Package复现环境Ubuntu 22.04 的宿主机使用 docker 的 ROS Melodic 镜像相关资料① 论文阅读220403_Autonomous Driving on Curvy Roads Without Reliance on Frenet Frame: A Cartesian-Based② 论文推土机A Cartesian-Based Trajectory Planning Method③ CartesianPlanner 复现本文给出了详细的复现过程记录了每一个步骤。④ CartesianPlanner项目教程⑤ DeepWiki libai1943/CartesianPlanner李柏老师的另一篇论文《Economical Motion Planning for On-Road Autonomous Driving with Distance-Sensitive Spatio-Temporal Resolutions》复现过程几乎和本篇博客一致只需要额外安装aptinstallnlohmann-json3-dev仿真效果就是论文中的类似操场的环道。不过最后发布 Nav2 Point 没成功没有继续研究了。二、复现创建 docker 容器dockerrun-it\--nameCartesianPlanner\--gpusall\-eNVIDIA_DRIVER_CAPABILITIESall\--networkhost\--privilegedtrue\-eDISPLAY$DISPLAY\-eWAYLAND_DISPLAY$WAYLAND_DISPLAY\-eXDG_RUNTIME_DIR$XDG_RUNTIME_DIR\-ePULSE_SERVER$PULSE_SERVER\-v/tmp/.X11-unix:/tmp/.X11-unix\-v/home/xiaobai/projects/CartesianPlanner:/catkin_ws/src/CartesianPlanner\osrf/ros:melodic-desktop-full\/bin/bash安装依赖1apt 安装sudoaptupdatesudoaptinstallgcc g gfortrangitpatchwgetpkg-config liblapack-dev libmetis-dev libblas-dev-y2安装 python3 包因为 Cartesian Planner 使用 python3而 ROS Melodic 默认使用 python2因此需要安装 python3 的包此外numpy 的版本一定是 1.11 及以前的否则会有错误详情见三、的问题记录。sudoaptinstallpython3-pip pip3installpyyamlnumpy1.11.33安装 Ipopt① 在项目目录下新创建一个目录专门存放第三方库cd/catkin_ws/src/CartesianPlannermkdir-pthirdparty/Ipopt_pkgcdthirdparty/Ipopt_pkg② 安装 ASLgitclone https://github.com/coin-or-tools/ThirdParty-ASL.gitcdThirdParty-ASLsudo./get.ASLsudo./configuresudomakesudomakeinstallcd..③ 安装 HSLi.gitclone https://github.com/coin-or-tools/ThirdParty-HSL.gitcdThirdParty-HSLii. 在 STFC IP Store 申请Coin-HSL Archive 类型的 license笔者下载的是coinhsl-archive-2023.11.17.zip。将其移动到宿主机上的 docker 挂载目录 /catkin_ws/src/CartesianPlanner 下。解压缩并重命名# 在宿主机执行cd~/projects/CartesianPlanner/thirdparty/Ipopt_pkg/ThirdParty-HSL/sudomv~/Downloads/coinhsl-archive-2023.11.17.zip ./coinhsl.zipsudounzipcoinhsl.zipsudomvcoinhsl-archive-2023.11.17/ coinhsliii.# docker 容器内cd/catkin_ws/src/CartesianPlanner/thirdparty/Ipopt_pkg/ThirdParty-HSL/sudo./configuresudomakesudomakeinstallcd..④ 安装 MUMPSgitclone https://github.com/coin-or-tools/ThirdParty-Mumps.gitcdThirdParty-Mumpssudo./get.Mumpssudo./configuresudomakesudomakeinstallcd..⑤ 安装 Ipoptgitclone https://github.com/coin-or/Ipopt.gitcdIpoptmkdirbuildcdbuildsudo../configuresudomakesudomaketestsudomakeinstall⑥ 完善环境cd/usr/local/includesudocpcoin-or coin-rsudoln-s/usr/local/lib/libcoinmumps.so.3 /usr/lib/libcoinmumps.so.3sudoln-s/usr/local/lib/libcoinhsl.so.2 /usr/lib/libcoinhsl.so.2sudoln-s/usr/local/lib/libipopt.so.3 /usr/lib/libipopt.so.34安装 Casadicd/catkin_ws/src/CartesianPlanner/thirdparty/wgethttps://github.com/casadi/casadi/releases/download/3.5.5/casadi-3.5.5-1.tar.gztar-xzvfcasadi-3.5.5-1.tar.gzcdcasadi-3.5.5.1mkdirbuildcdbuild cmake..-DWITH_IPOPTON-DWITH_EXAMPLESOFFmake-j4sudomakeinstallsudoldconfigcd../..sudormcasadi-3.5.5-1.tar.gz5 升级 CMake# 添加 Kitware 官方 APT 仓库Bionic 是 Ubuntu18.04 的名称sudoaptupdatesudoaptinstall-yapt-transport-https ca-certificates gnupg software-properties-commonwgetwget-O- https://apt.kitware.com/keys/kitware-archive-latest.asc|sudoapt-keyadd-sudoadd-apt-repositorydeb https://apt.kitware.com/ubuntu/ bionic main# 安装 CMakesudoaptupdatesudoaptinstall-ycmake编译、测试1编译工作区source/opt/ros/melodic/setup.bashcd/catkin_wscatkin_make-DWITH_HSLONsource/catkin_ws/devel/setup.bash2将 source 加载 ros 运行时变量写入 .bashrc 中docker 容器的默认用户是 rootecho-e\n# ROS\nsource /opt/ros/melodic/setup.bash\nsource /catkin_ws/devel/setup.bash/root/.bashrc3示例 1roslaunch cartesian_planner pedestrian_test.launch4示例 2roslaunch cartesian_planner random_pedestrian_test.launch三、复现过程记录遇到问题 解决方法docker 创建容器dockerrun-it\--nameCartesianPlanner\--gpusall\-eNVIDIA_DRIVER_CAPABILITIESall\--networkhost\--privilegedtrue\-eDISPLAY$DISPLAY\-eWAYLAND_DISPLAY$WAYLAND_DISPLAY\-eXDG_RUNTIME_DIR$XDG_RUNTIME_DIR\-ePULSE_SERVER$PULSE_SERVER\-v/tmp/.X11-unix:/tmp/.X11-unix\-v/home/xiaobai/projects/CartesianPlanner:/catkin_ws/src/CartesianPlanner\osrf/ros:melodic-desktop-full\/bin/bash安装依赖sudoaptupdatesudoaptinstallgcc g gfortrangitpatchwgetpkg-config liblapack-dev libmetis-dev-y编译工作区cd/catkin_ws catkin_make1报错bash: catkin_make: command not found这是因为没有正确配置 ROS 环境变量source/opt/ros/melodic/setup.bash2再次执行catkin_make报错如下– Could NOT find Ipopt (missing: Ipopt_DIR)– Found PkgConfig: /usr/bin/pkg-config (found version “0.29.1”)– Checking for one of the modules ‘ipopt’– Could NOT find IPOPT (missing: IPOPT_LIBRARIES IPOPT_INCLUDE_DIRS)get_property(PKG_HELP CACHE WITH_BUILD_IPOPT PROPERTY HELPSTRING)– Looking for MUMPS– Could not find MUMPS include dir– Could not find MUMPS libraries– MUMPS: Cound not find MUMPS. Try setting MUMPS env var.get_property(PKG_HELP CACHE WITH_BUILD_MUMPS PROPERTY HELPSTRING)METIS: find via CONFIG– Could NOT find METIS (missing: METIS_DIR)METIS: 0– Found METIS: /usr/lib/x86_64-linux-gnu/libmetis.so– Found METIS include dir: /usr/includeCMake Error at cmake/FindMETIS.cmake:52 (target_link_libraries):Cannot specify link libraries for target “metis::metis” which is not builtby this project.Call Stack (most recent call first):CMakeLists.txt:884 (find_package)– Configuring incomplete, errors occurred!See also “/catkin_ws/build/vendor/src/casadi-external-build/CMakeFiles/CMakeOutput.log”.CartesianPlanner/CMakeFiles/casadi-external.dir/build.make:108: recipe for target ‘vendor/src/casadi-external-stamp/casadi-external-configure’ failedmake[2]: *** [vendor/src/casadi-external-stamp/casadi-external-configure] Error 1CMakeFiles/Makefile2:917: recipe for target ‘CartesianPlanner/CMakeFiles/casadi-external.dir/all’ failedmake[1]: *** [CartesianPlanner/CMakeFiles/casadi-external.dir/all] Error 2Makefile:140: recipe for target ‘all’ failedmake: *** [all] Error 2Invoking“make -j24 -l24”failed说明在构建 CasADi 库时METIS 库的配置有问题解决方案安装 casadi 库。根据 Ubuntu 20.04 源码安装 ipopt 和 CasADi成功安装了 Ipopt.# 1. 安装所需依赖sudoapt-getinstall-ygcc g gfortrangitpatchwgetpkg-config liblapack-dev libmetis-dev libblas-dev# 2. 创建一个存放所有跟 ipopt 相关的文件夹cd/catkin_ws/src/CartesianPlannermkdirthirdparty/Ipopt_pkgcdthirdparty/Ipopt_pkg# 3. 安装 ASLgitclone https://github.com/coin-or-tools/ThirdParty-ASL.gitcdThirdParty-ASLsudo./get.ASLsudo./configuresudomakesudomakeinstallcd..# 4. 安装 HSLgitclone https://github.com/coin-or-tools/ThirdParty-HSL.gitcdThirdParty-HSL# 接下来需要下载 coinhsl 文件并解压到 ThirdParty-HSL 目录下。# 其中 coinhsl 文件下载方式如下 想要下载 coinhsl 文件需要申请许可证许可证申请网址为[STFC IP Store](https://licences.stfc.ac.uk/products/Software/HSL)其中可以申请的类型为 Coin-HSL 或者 Coin-HSL Archive 类型。# Coin-HSL 类型只有学术机构可以免费申请其它机构则需要付费而且需要经过审批时间较长。# Coin-HSL Archive 类型的申请马上就可以通过着急使用可以申请这个。# 笔者下载的是 coinhsl-archive-2023.11.17.zip# 申请通过后将 coinhsl 文件在 ThirdParty-HSL 目录解压并将解压后的文件夹重命名为 coinhsl。# 在宿主机上将 coinhsl 文件拷贝到容器的挂载目录下cd~/projects/CartesianPlanner/thirdparty/Ipopt_pkg/ThirdParty-HSL/sudomv~/Downloads/coinhsl-archive-2023.11.17.zip ./coinhsl.zipsudounzipcoinhsl.zipsudomvcoinhsl-archive-2023.11.17/ coinhsl# 之后再在 ThirdParty-HSL 目录下执行以下命令。sudo./configuresudomakesudomakeinstallcd..# 5. 安装 MUMPSgitclone https://github.com/coin-or-tools/ThirdParty-Mumps.gitcdThirdParty-Mumpssudo./get.Mumpssudo./configuresudomakesudomakeinstallcd..# 6. 安装 Ipoptgitclone https://github.com/coin-or/Ipopt.gitcdIpoptmkdirbuildcdbuildsudo../configuresudomakesudomaketestsudomakeinstall# 7. 完善环境cd/usr/local/includesudocpcoin-or coin-rsudoln-s/usr/local/lib/libcoinmumps.so.3 /usr/lib/libcoinmumps.so.3sudoln-s/usr/local/lib/libcoinhsl.so.2 /usr/lib/libcoinhsl.so.2sudoln-s/usr/local/lib/libipopt.so.3 /usr/lib/libipopt.so.3该教程后半段安装 casadi 时用的自动化脚本因此没采用。实际上后续将脚本中的指令单独执行也成功安装。cd/catkin_ws/src/CartesianPlanner/thirdparty/wgethttps://github.com/casadi/casadi/releases/download/3.5.5/casadi-3.5.5-1.tar.gztar-xzvfcasadi-3.5.5-1.tar.gzcdcasadi-3.5.5.1mkdirbuildcdbuild cmake..-DWITH_IPOPTON-DWITH_EXAMPLESOFFmake-j4sudomakeinstallsudoldconfigcd../..sudormcasadi-3.5.5-1.tar.gz3根据 InstallationLinux 安装了 casadi3.4.5因为安装最新版的时候error 说使用的 cmake3.10 太老了。gitclone https://github.com/casadi/casadi.git casadicdcasadigitcheckout3.4.5cdcasadimkdirbuild cmake-DWITH_PYTHONON-DWITH_PYTHON3ON-DWITH_IPOPTON..makemakeinstall但在执行 catkin_make 时报错CMake Error at external_packages/tinyxml2-9.0.0/CMakeLists.txt:1 (cmake_minimum_required):CMake 3.15 or higher is required. You are running version 3.10.2– Configuring incomplete, errors occurred!还是要升级 CMake# 添加 Kitware 官方 APT 仓库sudoaptupdatesudoaptinstall-yapt-transport-https ca-certificates gnupg software-properties-commonwgetwget-O- https://apt.kitware.com/keys/kitware-archive-latest.asc|sudoapt-keyadd-sudoadd-apt-repositorydeb https://apt.kitware.com/ubuntu/ bionic main# 安装 CMakesudoaptupdatesudoaptinstall-ycmake4重新编译工作区成功cd/catkin_wscatkin_make-DWITH_HSLON在 .bashrc 中添加 rosecho-e\n# ROS\nsource /opt/ros/melodic/setup.bash\nsource /catkin_ws/devel/setup.bash/root/.bashrc测试1示例测试roslaunch cartesian_planner pedestrian_test.launchRViz 上只显示栅格没有其他物体终端显示问题如下Traceback (most recent call last):File “/catkin_ws/src/CartesianPlanner/script/pickle_publisher.py”, line 14, inimport rospyFile “/opt/ros/melodic/lib/python2.7/dist-packages/rospy/init.py”, line 47, infrom std_msgs.msg import HeaderFile “/opt/ros/melodic/lib/python2.7/dist-packages/std_msgs/msg/init.py”, line 1, infrom ._Bool import *File “/opt/ros/melodic/lib/python2.7/dist-packages/std_msgs/msg/_Bool.py”, line 6, inimport genpyFile “/opt/ros/melodic/lib/python2.7/dist-packages/genpy/init.py”, line 34, infrom . message import Message, SerializationError, DeserializationError, MessageException, struct_IFile “/opt/ros/melodic/lib/python2.7/dist-packages/genpy/message.py”, line 48, inimport yamlModuleNotFoundError: No module named ‘yaml’QStandardPaths: XDG_RUNTIME_DIR points to non-existing path ‘/run/user/1000’, please create it with 0700 permissions.[reference_publisher_node-2] process has died [pid 39895, exit code 1, cmd /catkin_ws/src/CartesianPlanner/script/pickle_publisher.py /catkin_ws/src/CartesianPlanner/script/example.pickle __name:reference_publisher_node __log:/root/.ros/log/f8c9b756-28be-11f1-93f0-f44eb4e0ca3d/reference_publisher_node-2.log].log file: /root/.ros/log/f8c9b756-28be-11f1-93f0-f44eb4e0ca3d/reference_publisher_node-2*.log[rviz-4] process has finished cleanlylog file: /root/.ros/log/f8c9b756-28be-11f1-93f0-f44eb4e0ca3d/rviz-4*.logROS Melodic 基于 Python 2.7而系统中缺少 Python 2 的 yaml 库PyYAML。aptinstall-ypython-pip python-yaml pipinstallpyyaml但是分明保证安装好了 yaml还是报错 ModuleNotFoundError: No module named ‘yaml’可能是 ROS 的 setup.bash 覆盖了系统路径Qwen 的回答# 临时追加系统 Python 包路径exportPYTHONPATH/usr/lib/python2.7/dist-packages:$PYTHONPATH笔者在整理笔记时重新看这段当时在终端添加 python 包路径能解决找不到 yaml 库是因为终端的 python 环境变量的优先级大于 .py 脚本第一句指定的解释器版本又遇到问题Traceback (most recent call last):File “/catkin_ws/src/CartesianPlanner/script/pickle_publisher.py”, line 12, inimport pickleFile “/usr/lib/python3.6/pickle.py”, line 34, inimport reFile “/usr/lib/python3.6/re.py”, line 142, inprocess[cartesian_planner_node-3]: started with pid [41125]class RegexFlag(enum.IntFlag):AttributeError: module ‘enum’ has no attribute ‘IntFlag’process[rviz-4]: started with pid [41126][reference_publisher_node-2] process has died [pid 41124, exit code 1, cmd /catkin_ws/src/CartesianPlanner/script/pickle_publisher.py /catkin_ws/src/CartesianPlanner/script/example.pickle __name:reference_publisher_node __log:/root/.ros/log/e0fafbaa-28c1-11f1-90f4-f44eb4e0ca3d/reference_publisher_node-2.log].log file: /root/.ros/log/e0fafbaa-28c1-11f1-90f4-f44eb4e0ca3d/reference_publisher_node-2*.log根据博客 【ROS 踩坑记录】ImportError: No module named yaml - Introduction to tf 进行修复。可以发现CartesianPlanner 项目的 python 代码使用的是#!/usr/bin/env python3而 ROS Melodic 默认使用的是 python2.7。并且文章提供的方法sudo apt install python-is-python3对于 ros melodic 镜像所属的 ubuntu 18.04 并没有提供。所以只需要在 python3 环境中安装好所需要的包即可。aptinstallpython3-pip pip3installrospkg numpy最终执行roslaunch命令结果如下2roslaunch cartesian_planner random_pedestrian_test.launchRViz 没有显示遇到问题Traceback (most recent call last):File “/catkin_ws/src/CartesianPlanner/script/reference_publisher.py”, line 256, inmain()File “/catkin_ws/src/CartesianPlanner/script/reference_publisher.py”, line 210, in maincenter_line generate_center_line(config)File “/catkin_ws/src/CartesianPlanner/script/reference_publisher.py”, line 51, in generate_center_lineangles np.linspace(start_angle, end_angle, point_count)File “array_functioninternals”, line 6, in linspaceFile “/usr/local/lib/python3.6/dist-packages/numpy/core/function_base.py”, line 113, in linspacenum operator.index(num)TypeError: ‘numpy.float64’ object cannot be interpreted as an integer[reference_publisher_node-2] process has died [pid 53733, exit code 1, cmd /catkin_ws/src/CartesianPlanner/script/reference_publisher.py path static pedestrian dynamic serialize __name:reference_publisher_node __log:/root/.ros/log/6debefc4-28e0-11f1-864f-f44eb4e0ca3d/reference_publisher_node-2.log].log file: /root/.ros/log/6debefc4-28e0-11f1-864f-f44eb4e0ca3d/reference_publisher_node-2*.logQwen 提供的回答如下因此决定降级 numpy 到 1.11# 卸载当前的 numpypip3 uninstall numpy# 安装旧版本pip3installnumpy1.11.3解决了刚刚的问题。但是出现的 RViz 界面只显示了一条曲线同时终端显示问题如下[ WARN] [1774508387.118569653]: Shutdown request received.[ WARN] [1774508387.120875176]: Shutdown request received.[ WARN] [1774508387.121062994]: Reason given for shutdown: [[/cartesian_planner_node] Reason: new node registered with same name][ WARN] [1774508387.124072875]: Reason given for shutdown: [[/cartesian_planner_node] Reason: new node registered with same name]terminate called after throwing an instance of ‘boost::exception_detail::clone_implboost::exception_detail::error_info_injectorboost::lock_error ’what(): boost: mutex lock failed in pthread_mutex_lock: Invalid argumentterminate called after throwing an instance of ‘boost::exception_detail::clone_implboost::exception_detail::error_info_injectorboost::lock_error ’what(): boost: mutex lock failed in pthread_mutex_lock: Invalid argument[cartesian_planner_node-2] process has died [pid 53843, exit code -6, cmd /catkin_ws/devel/lib/cartesian_planner/node __name:cartesian_planner_node __log:/root/.ros/log/6debefc4-28e0-11f1-864f-f44eb4e0ca3d/cartesian_planner_node-2.log].log file: /root/.ros/log/6debefc4-28e0-11f1-864f-f44eb4e0ca3d/cartesian_planner_node-2*.log这是因为节点名称冲突 Root 用户环境导致的 Boost 互斥锁崩溃。# 杀掉相关的 ROS 进程pkill-fcartesian_plannerpkill-frosoutpkill-frosmaster重新运行roslaunch命令得到下面的展示效果补充安装 Ipopt 遇到的问题根据 CartesianPlanner 复现 可知还需安装 Ipopt 和 Casadi该博客的作者同时提供了安装脚本 非线性求解器 Casadi (c使用例子)。# 在 CartesianPlanner 目录下创建 thirdparty 目录用于安装cd/catkin_ws/src/CartesianPLannermkdirthirdparty# 安装 Ipoptsudoapt-getinstallcppad gfortranunzip-ywgethttps://www.coin-or.org/download/source/Ipopt/Ipopt-3.12.8.zip-OIpopt-3.12.8.zipunzipIpopt-3.12.8.zip# Step by steppushdIpopt-3.12.8/ThirdParty/Blas ./get.Blascd../Lapack ./get.Lapackcd../Mumps ./get.Mumps# 这里会一直卡住因为下载链接 http://mumps.enseeiht.fr/MUMPS_4.10.0.tar.gz 已经失效cd../Metis ./get.Metis# 这里会报 ERROR 404: Not Foundcd../ASL ./get.ASL