ros1与ros2共存[Ubuntu20.04]

ros1与ros2共存

  • 系统环境20.04
  • ros1版本 ros-noetic
  • ros2版本 ros-galactic

为了省事,我们习惯将source写到.bashrc文件(若是不同的解释器如zsh,则为.zshrc文件)

sudo gedit ~/.bashrc

在bashrc末尾加入:

source /opt/ros/noetic/setup.bash

每次打开terminal时如何切换版本?

sudo gedit ~/.bashrc

在.bashrc末尾加入:

echo "ros noetic(1) or ros2 galactic(2)?"
read edition
if [ "$edition" -eq "1" ];then
  source /opt/ros/noetic/setup.bash
else
  source /opt/ros/galactic/setup.bash
fi

如果解释器为zsh,则

sudo gedit ~/.zshrc

在.zshrc末尾加入:

echo "ros noetic(1) or ros2 galactic(2)?"
read edition
if [ "$edition" -eq "1" ];then
  source /opt/ros/noetic/setup.zsh
else
  source /opt/ros/galactic/setup.zsh
fi

实现效果:

ros1与ros2共存[Ubuntu20.04]_第1张图片

输入1则选择ros-noetic

输入2则选择ros-galactic

你可能感兴趣的:(ROS,C++,编程)