一、安装ROS Melodic
1. 设置Ros的软件源
sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
2. 设置密钥
sudo apt install curl # if you haven't already installed curl
curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | sudo apt-key add -
3. 安装
sudo apt-get update
sudo apt install ros-melodic-desktop-full #Desktop-Full Install: (Recommended) : ROS, rqt, rviz, robot-generic libraries, 2D/3D simulators and 2D/3D
sudo apt-get install ros-melodic-rqt*
4. 添加Ros到环境变量
echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc
source ~/.bashrc
5. 安装ROS的依赖包
sudo apt install python-rosdep python-rosinstall python-rosinstall-generator python-wstool build-essential
6. 初始化rosdep
sudo rosdep init
rosdep update
rosdep update会出现timeout现象,找了很多解决方案,最终通过以下方案解决:
由于近期国内Github Raw的可用IP越来越少,通过修改hosts文件解决rosdep update超时问题的方法已经不太好用,本文通过修改rosdep源码中下载资源的函数来解决这一问题。
网站https://ghproxy.com/支持github的资源代理,非常好用,我们将用此代理加速rosdep对Github Raw的访问,进而解决rosdep update超时问题。
首先定位rosdep资源下载函数。从报错信息中得知,该函数名为download_rosdep_data,位于/usr/lib/python2.7/dist-packages/rosdep2/sources_list.py。我们修改这一函数,添加:
url="https://ghproxy.com/"+url
应用ghproxy的代理服务。
用同样的方法修改/usr/lib/python2.7/dist-packages/rosdistro/init.py里面的DEFAULT_INDEX_URL
即将DEFAULT_INDEX_URL 进行如下替换:
DEFAULT_INDEX_URL = 'https://ghproxy.com/https://raw.githubusercontent.com/ros/rosdistro/master/index-v4.yaml'
除此处外,下述文件中也含有github地址,分别是:
/usr/lib/python2.7/dist-packages/rosdep2/gbpdistro_support.py 36行
/usr/lib/python2.7/dist-packages/rosdep2/sources_list.py 72行
/usr/lib/python2.7/dist-packages/rosdep2/rep3.py 39行
/usr/lib/python2.7/dist-packages/rosdistro/manifest_provider/github.py 68行 119行
均可通过在地址前添加https://ghproxy.com/前缀来应用代理服务。
再次尝试执行rosdep update,问题解决。
7. 创建并初始化工作目录
mkdir -p ~/catkin_ws/src
cd ~/catkin_ws/src
catkin_init_workspace
cd ~/catkin_ws/
catkin_make
打开.bashrc
vim ~/.bashrc
设置如下内容
# Set ROS melodic
source ~/catkin_ws/devel/setup.bash
# Set ROS Network
export ROS_HOSTNAME=192.168.3.75 #为ifconfig自己主机的ipv4地址
export ROS_MASTER_URI=http://${ROS_HOSTNAME}:11311
7. 验证
开启三个终端,分别输入:
roscore #开启ros
rosrun turtlesim turtlesim_node #开启小乌龟节点
rosrun turtlesim turtle_teleop_key #开启键盘输入节点
二、 编译ROS环境下的 ORB SLAM3
1. 添加ORB SLAM3到ROS编译环境
export ROS_PACKAGE_PATH=${ROS_PACKAGE_PATH}:"your install path"/ORB_SLAM3/Examples/ROS
2. 运行
#进入ORB_SLAM3目录
./build.sh # ROS需要libORB_SLAM3.so
./build_ros.sh
最终会生成可执行文件如图:
参考:
https://blog.csdn.net/leida_wt/article/details/115120940
https://blog.csdn.net/qq_41450811/article/details/99079041