Setting up ROS-1, ROS-2, or both environments

Now that we have both ROS-1 and ROS-2, let's learn how to use both together and individually with ease.

In case you installed ROS-2 via the Debian package installation, try running roscore and see whether things are fine with the ROS-1 setup. You will receive an error. This is simply because your bash got confused with, ROS-1 and ROS-2 environments. One of the best practices to use here is to source either the ROS-1 environment when we're working with ROS-1 packages and source ROS-2 if we're working with ROS-2 packages.

Instead of typing the source command every time, we could make use of the alias command and add them to the bash script using the following steps:

  1. Invoke your bash script using the following command:
$ sudo gedit ~/.bashrc
  1. Add the following two lines to it:
$ alias initros1='source /opt/ros/melodic/setup.bash'
$ alias initros2='source ~/ros2_ws/install/local_setup.bash'
  1. Please delete or comment the following lines (that we added in the previous chapter) in the bash script:
$ source /opt/ros/melodic/setup.bash
$ source ~/catkin_ws/devel/setup.bash

Your bash file should look like this:

The bash file

Now, save and close the bash script. This is to ensure that, when you open your Terminal, neither the ROS-1 or ROS-2 workspace is invoked. Now that these changes have been made to the bash file, source the bash script once again to ensure we're able to use the alias commands:

$ source ~/.bashrc

Now, you can peacefully invoke the ROS-1 or ROS-2 environments using the initros1 or initros2 command in the Terminal to work with the ROS-1 or ROS-2 packages, respectively.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset