这篇文章转自 https://blog.csdn.net/id9502/article/details/80410989
简直就是ros源码阅读顺序表
1. 首先安装基本依赖包:
安装ros依赖:
sudo apt install python3-rosdep2 python3-rosinstall-generator python3-rosinstall build-essential python3-defusedxml python3-netifaces
安装编译依赖:
sudo apt install libeigen3-dev libboost-thread-dev libgtest-dev libconsole-bridge-dev libpoco-dev python3-sip-dev libboost-filesystem-dev libboost-program-options-dev libtinyxml2-dev libtinyxml-dev pyqt5-dev libcurl4-openssl-dev libboost-regex-dev liblz4-dev libbz2-dev libboost-singals-dev liburdfdom-headers-dev liburdfdom-dev uuid-dev libassimp-dev libogre-1.9-dev libyaml-cpp-dev
2. 配置rosdep
mkdir setups
cd setups
touch rosdep
chmod +x ./rosdep
添加脚本内容:
#!/usr/bin/env python3
from rosdep2.main import rosdep_main
rosdep_main()
执行
sudo ./rosdep init
./rosdep update
3. 获取基本ros环境的源码
首先下载执行文件
wget https://raw.githubusercontent.com/ros-infrastructure/rosinstall_generator/master/bin/rosinstall_generator
wget https://raw.githubusercontent.com/vcstools/wstool/master/scripts/wstool
wget https://raw.githubusercontent.com/ros-infrastructure/rospkg/master/scripts/rosversion
wget https://raw.githubusercontent.com/ros-infrastructure/catkin_pkg/master/bin/catkin_find_pkg
wget https://raw.githubusercontent.com/ros-infrastructure/catkin_pkg/master/bin/catkin_create_pkg
wget https://raw.githubusercontent.com/ros-infrastructure/catkin_pkg/master/bin/catkin_generate_changelog
wget https://raw.githubusercontent.com/ros-infrastructure/catkin_pkg/master/bin/catkin_tag_changelog
wget https://raw.githubusercontent.com/ros-infrastructure/catkin_pkg/master/bin/catkin_test_changelog
chmod +x ./rosinstall_generator
chmod +x ./wstool
chmod +x ./rosversion
chmod +x ./catkin_find_pkg
chmod +x ./catkin_create_pkg
chmod +x ./catkin_generate_changelog
chmod +x ./catkin_tag_changelog
chmod +x ./catkin_test_changelog
记得修改第一行引用的python 为python3,并把下面的from _future_ import 行删除
新建总工程目录并执行ros源代码下载
mkdir ../workspace
cd ../workspace
../setups/rosinstall_generator desktop_full --rosdistro melodic --deps --tar > melodic-desktop-full.rosinstall
../setups/wstool init -j8 src melodic-desktop-full.rosinstall
如果安装失败的话,可以试试继续安装:
../setups/wstool update -j 8 -t src
接下来解决依赖
../setups/rosdep install --from-paths src --ignore-src --rosdistro melodic -y
4. 安装Catkin
从Github Catkin上下载源码,cmake并选择python版本为3,安装地址选为自己的环境文件夹env
export ROS_PYTHON_VERSION=3
mkdir build
cd build
cmake ..
make DESTDIR=xxxxxxx
make install
然后回到workspace目录
修改 ./src/orocos_kinematics_dynamics/python_orocos_kdl/CMakeLists.txt 中
SET(PYTHON_VERSION 2 CACHE STRING "Python Version")
改为
SET(PYTHON_VERSION 3 CACHE STRING "Python Version")
修改 src/dynamic_reconfigure/cfg/Test.cfg 和 src/nodelet_core/nodelet_topic_tools/cfg/NodeletThrottle.cfg 第一行为
#! /usr/bin/env python3
添加 regex 依赖到 src/ros_comm/rosconsole/CMakeLists.txt 72 行后(维持其他不变,添加boost_regex)
target_link_libraries(rosconsole ${rosconsole_backend_LIBRARIES} ${catkin_LIBRARIES} ${Boost_LIBRARIES} boost_regex)
修改 src/vision_opencv/cv_bridge/CMakeLists.txt 11 行为
find_package(Boost REQUIRED python-py36)
../env/setup.sh 最后一行添加
export ROS_PYTHON_VERSION=3
5. 开始编译
source ../env/setup.zsh
catkin_make_isolated --install -DCMAKE_BUILD_TYPE=Release
mv ../setups/* ../env/bin/
如果想更换安装地点的话,可以在最后catkin之后加 –install-space xxxxxxx
6. 开始使用ROS
以后任何新Term执行ROS命令前都要载入配置环境(也可以加入~/.bashrc或者~/.zshrc里面自动执行)
source ../env/setup.zsh
启动 ros 调度核心
roscore
开新窗口启动 rviz 来测试
rosrun rviz rviz
若能成功启动,万事大吉!
备注:rqt 系列的 ros 程序似乎没有自动修改第一行为 python3, 需要手动修改。
1’. 懒人福利
简单编译后打包好的 deb 文件(不对安装结果负责,因为依赖太多了数不清,所以如果有不能运行的按照log添加添加吧,另外欢迎随意修正这个 deb),如果你和我一样用的 debian testing 系统,欢迎直接 copy 我编译完的二进制包:https://pan.baidu.com/s/1WmZAA7J-2uvSz8S9-XmdWQ
原文地址:https://www.cnblogs.com/shepherd2015/p/11257356.html