ubuntu18.04同时安装ROS1和ROS2

一.安装ROS1,见前面的ROS1文章,此处不多做介绍
二.安装ROS2(见古月居相关文章)
1.设置编码
$ sudo apt update && sudo apt install locales
$ sudo locale-gen en_US en_US.UTF-8
$ sudo update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8
$ export LANG=en_US.UTF-8
2.添加源
$ sudo apt update && sudo apt install curl gnupg lsb-release
$ sudo curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg
$ echo “deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu $(source /etc/os-release && echo $UBUNTU_CODENAME) main” | sudo tee /etc/apt/sources.list.d/ros2.list > /dev/null
3.安装ROS2
$ sudo apt update
$ sudo apt upgrade
$ sudo apt install ros-dashing-desktop
4.设置环境变量
$ source /opt/ros/dashing/setup.bash
$ echo " source /opt/ros/dashing/setup.bash" >> ~/.bashrc
至此,ROS2安装就成功了
测试:
$ ros2 run demo_nodes_cpp talker
$ ros2 run demo_nodes_py listener
输出hello world说明通信是OK的
运行小海龟仿真示例:
$ ros2 run turtlesim turtlesim_node
$ ros2 run turtlesim turtle_teleop_key
可以操作小海龟就说明ROS2安装成功了
问题:ROS1和ROS2共存的问题解决
方法:
1.打开.bashrc文件
sudo gedit .bashrc
2.在.bashrc文件末尾添加以下代码(注意将之前ros1以及ros2的source ros的环境的代码去掉)
#source /opt/ros/melodic/setup.bash
echo “ros melodic(1) or ros2 dashing(2)?”
read edition
if [ “$edition” -eq “1” ]; then
source /opt/ros/melodic/setup.bash
echo “ros melodic(1) has been chosen!”
else
source /opt/ros/dashing/setup.bash
echo “ros2 dashing(2) has been chosen!”
fi
保存文件,再次打开终端就出现了ros1和ros2选择项

你可能感兴趣的:(ROS1,ROS2,ubuntu,linux,运维)