Introduction

bashrc file

When working with ROS, you may find yourself frequently needing to source the setup files in order to use ROS commands in the terminal. This can become tedious and time-consuming, especially if you are constantly switching between terminals or starting new terminals. To avoid having to manually source the setup files every time, you can set up the bashrc file to automatically source the files when you open a new terminal.

Editing the bashrc file

The bashrc file is a script that is run every time you start a new terminal. It is used to set up various environment variables and run commands. To edit the bashrc file, you can use a text editor such as nano or vim.

First, open the bashrc file by running the following command:

nano ~/.bashrc

This will open the bashrc file in the nano text editor. You can also use vi or vim if you're more comfortable with it.

At the end of the file, add the following line:

source /opt/ros/<distro>/setup.bash

Replace <distro> with your ROS distribution, for example noetic or melodic.

Additionally, when working with workspaces, you may also need to source the setup file located in the “devel” folder of your workspace. The command for this is:

source ~/blog_ws/devel/setup.bash

Replace "blog_ws" with the name of your workspace.

Save and close the file by pressing CTRL+X, then Y, then ENTER.

The next time you open a new terminal, the setup files will be automatically sourced and you will be able to use ROS commands without having to manually source the files.

Alternatively, you can also add the above command to your .bash_profile in case you are working on a macOS or Linux system that uses this file instead of .bashrc

It is also worth noting that if you are working on a Windows system, you will have to add the above command to your .bashrc file in your Windows subsystem Linux (WSL) home directory, usually /home/<username>/.bashrc

To build and run the node, navigate to the root of your catkin workspace and run the following command:

Conclusion

In conclusion, setting up the bashrc file can automate the process of sourcing the ROS setup files and streamline your workflow when working with ROS. Additionally, when working with catkin workspaces, it is important to also source the setup file located in the "devel" folder. By properly configuring the bashrc file, you can ensure a smooth and efficient experience when working with ROS.

Check out my next article about creating and designing your own robot's appearance HERE.