1. Ubuntu 18.04 LTS上添加安装源到source.list
sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
2. 添加秘钥到本地的trusted数据库中并加以验证
sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
curl -sSL 'http://keyserver.ubuntu.com/pks/lookup?op=get&search=0xC1CF6E31E6BADE8868B172B4F42ED6FBAB17C654' | sudo apt-key add -
3. 更新列表
sudo apt update
4. 安装ros依赖库
sudo apt install libvtk6-jni libvtk6-java libvtk6-dev libvtk6-qt-dev libpcl-dev
sudo apt install ros-melodic-pcl-conversions ros-melodic-pcl-ros ros-melodic-perception-pcl ros-melodic-perception
5. 开始安装ROS Melodic
sudo apt install ros-melodic-desktop-full
或者
sudo apt install ros-melodic-desktop
6. 安装核心组件rosdep
sudo apt install python-rosdep
sudo rosdep init
rosdep update
其它依赖
sudo apt install python-rosdep python-rosinstall python-rosinstall-generator python-wstool build-essential
7. 配置环境变量
echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc
source ~/.bashrc
8. 创建ROS工作空间
mkdir -p ~/catkin_ws/src
cd ~/catkin_ws/
catkin_make
9. 测试小海龟,终端里输入
roscore
再开一个终端
rosrun turtlesim turtlesim_node
这是小海龟出来
再开一个终端
rosrun turtlesim turtle_teleop_key
可以方向键操控就成功了。
问题及解决:
1) ImportError: "from catkin_pkg.package import parse_package" failed: No module named 'catkin_pkg' Make sure that you have installed "catkin_pkg", it is up to date and on the PYTHONPATH. CMake Error at /opt/ros/melodic/share/catkin/cmake/safe_execute_proces
终端里输入
dpkg -L python-catkin-pkg
python -V
查看依赖的和默认的python版本是否一致
如果不一致,则
conda install setuptools
pip install -U rosdep rosinstall_generator wstool
之后就OK了。
也可以修改catkin_make的python版本指定
catkin_make -DPYTHON_EXECUTABLE=/usr/bin/python2.7
就可以了。
2)apt get update出现ERR的问题
此类问题基本都是apt源的问题,需要更换apt源
sudo gedit /etc/apt/sources.list
国内好用的几个源如清华的 阿里的等,我实测清华源是OK的。
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
有时apt get update会出现ppa源的报错,这时需要删去对应的ppa
cd /etc/apt/sources.list.d/
查看是否有与报错ppa一致的,一般是两个,都删掉
sudo rm -i /etc/apt/sources.list.d/xxxx.list
sudo rm -i /etc/apt/sources.list.d/xxxx.list_save
之后重新 sudo apt-get update 就OK了。