前期准备
=》
=》![](https://i-blog.csdnimg.cn/blog_migrate/1f1a304168729106045f354422b894dd.png)
设置软件源:
国外的:
sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
国内的,速度快:
sudo sh -c '. /etc/lsb-release && echo "deb http://mirrors.ustc.edu.cn/ros/ubuntu/ $DISTRIB_CODENAME main" > /etc/apt/sources.list.d/ros-latest.list'
清华的:
sudo sh -c '. /etc/lsb-release && echo "deb http://mirrors.tuna.tsinghua.edu.cn/ros/ubuntu/ $DISTRIB_CODENAME main" > /etc/apt/sources.list.d/ros-latest.list'
设置最新的密钥:
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys F42ED6FBAB17C654
安装:
sudo apt-get update
sudo apt-get install ros-melodic-desktop-full
sudo apt-get install ros-melodic-rqt*
初始化rosdep:
sudo rosdep init
rosdep update
如果出现下面情况,基本是网络问题,换个网络尝试下(PS:我用手机热点解决的):
lee@lee-TM1801:~$ sudo rosdep init
ERROR: cannot download default sources list from:
https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/sources.list.d/20-default.list
Website may be down.
访问 The Best IP Address, Email and Networking Tools - IPAddress.com, 查询 raw.githubusercontent.com 的ip地址
我的是185.199.108.133
sudo gedit /etc/hosts
185.199.108.133 raw.githubusercontent.com
安装rosinstall
sudo apt-get install python-rosinstall
加载环境设置文件
source /opt/ros/melodic/setup.bash
创建并初始化工作目录
ROS使用一个名为catkin的ROS专用构建系统。为了使用它,用户需要创建并初始化
catkin工作目录,如下所示。除非用户创建新的工作目录,否则此设置只需设置一次。
mkdir -p ~/catkin_ws/src
cd ~/catkin_ws/src
catkin_init_workspace
目前,只有src目录和CMakeLists.txt文件在catkin工作目录中,使用catkin_make命令来构建
cd ~/catkin_ws/
catkin_make
设置环境变量:
sudo apt install net-tools
gedit ~/.bashrc
# Set ROS melodic
source /opt/ros/melodic/setup.bash
source ~/catkin_ws/devel/setup.bash
# Set ROS Network
#ifconfig查看你的电脑ip地址
export ROS_HOSTNAME=192.168.89.135
export ROS_MASTER_URI=http://${ROS_HOSTNAME}:11311
# Set ROS alias command 快捷指令
alias cw='cd ~/catkin_ws'
alias cs='cd ~/catkin_ws/src'
alias cm='cd ~/catkin_ws && catkin_make'
小海龟测试,打开三个终端:
roscore
rosrun turtlesim turtlesim_node
rosrun turtlesim turtle_teleop_key