ROS 2: Some tips and tricks

18th November, 2024
Disclaimer: The below topics are relatable to ROS 2 Disto Jazzy Jalisco. It might work in other distributions also.. More Updates to this post yet to come.


1. Bash Aliases

We often use the same program to run part of the entire project (the reasons could be anything). So, we use bookkeeping to save the commands in a text file (of course, this is the best method, and I tend to follow it even). The other way to make our commands easy to use is to bash aliases. For example, in ROS 2, we need to use regularly colcon build <args>. It becomes irritating when we constantly change the path and repeat it. So, one easy-to-go method I have been using bash aliases, where I turn running this colcon build <args> at the start of the WORKSPACE directory to anywhere with this simple script.

Following this I put it in .bash_aliases to use the command after sourcing the .bashrc file.

alias compile="source ~/<WORKSPACE>/compile2.sh"

Remember that these lines should be present in the .bashrc file; otherwise, this won't work.

if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
fi

Hurray! You can just use compile being in any part of the directory.


Disclaimer : If you feel there is room for improvement in this article and mistakes in delivering the post (grammatical, concept, or technical errors). Please report them to me. I will take the necessary actions at the earliest.