A personal guide to refer while working on ROS Noetic
and ROS2 Humble
Note
For Auto Completion
cd /usr/share/colcon_argcomplete/hook
add "source /usr/share/colcon_argcomplete/hook/colcon-argcomplete.bash" in gedit ~/.bashrc
- Create a new workspace:
mkdir -p workspace_name/src cd workspace_name
Important
Next two steps to be done from the root of your workspace
-
Resolve dependencies:
cd .. rosdep install -i --from-path src --rosdistro humble -y
-
Build the workspace with colcon:
colcon build
First, source the ROS Noetic environment setup file. It's recommended to add this to your .bashrc
file for automatic sourcing:
echo "source /opt/ros/noetic/setup.bash" >> ~/.bashrc
source ~/.bashrc
Tip
Alternatively, you can choose to run this command on every new shell you open to have access to the ROS commands. This process allows you to install several ROS distributions (e.g. indigo and kinetic) on the same computer and switch between them.
source /opt/ros/kinetic/setup.bash
-
Create a new workspace:
mkdir -p workspace_name/src cd workspace_name catkin_make
-
Source the workspace setup file:
source devel/setup.bash
-
Navigate to the
src
directory within your workspace:cd src
-
Create a new package:
catkin_create_pkg package_name std_msgs rospy roscpp
-
Build the workspace:
cd .. catkin_make
-
Source the setup file again:
source devel/setup.bash
-
You can view first-order dependencies in
package.xml
:<build_depend>roscpp</build_depend> <build_depend>rospy</build_depend> <build_depend>std_msgs</build_depend>
Note
Your workspace structure should look like this:
workspace_folder/
src/
CMakeLists.txt
package_1/
include
src
CMakeLists.txt
package.xml
...
package_n/
include
src
CMakeLists.txt
package.xml
-
Inside your package, create a
scripts
directory:cd src/package_name mkdir scripts cd scripts
-
Create a new Python node:
touch node_name.py chmod +x node_name.py
-
Add additional dependencies to
package.xml
:<build_depend>opencv</build_depend> <build_depend>python3-numpy</build_depend> <build_export_depend>opencv</build_export_depend> <build_export_depend>python3-numpy</build_export_depend> <exec_depend>opencv</exec_depend> <exec_depend>python3-numpy</exec_depend>
-
Modify CMakeLists.txt to install the Python node:
catkin_package( CATKIN_DEPENDS roscpp rospy std_msgs ) catkin_install_python(PROGRAMS scripts/node_name.py DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION} )
-
Go to the workspace and build it:
cd ../../.. catkin_make
-
Make sure that a
roscore
is up and running:roscore
-
Source the workspace's
setup.sh
filecd workspace_name source devel/setup.bash
-
Run the node!
rosrun package_name node_name.py
Important
roscore
is the first thing you should run when using ROS.
roscore