This is a collection from src files that I have written with the help of a) ROS Documentation b) YouTube and c) "ROS 2 from Scratch" book.
- Ubuntu 24.04
- ROS 2 Jazzy
- Clone the repository
- Build the workspace with
colcon build
$ cd ~/ROS2
$ colcon build- Source the workspace
$ source ~/ROS2/install/setup.bash- or add the following line to your .bashrc
$ echo "source ~/ROS2/install/setup.bash" >> ~/.bashrc- Create a package (folder) for the nodes
cd src/
# python
ros2 pkg create my_py_pkg --build-type ament_python --dependencies rclpy
# or cpp
ros2 pkg create my_cpp_pkg --build-type ament_cmake --dependencies rclcpp- Create a file for the node and make it executable
cd src/my_robot_controller/my_robot_controller
# create file
touch my_first_node.py
# make it excecutive VERY IMPORTANT
chmod +x my_first_node.py- Write the code for the node, add the reference to the setup.py and load dependencies (if necessary) in package.xml
- Bd everything in development mode
cd ~/ros2_ws
colcon build --symlink-install
# or optional
colcoun build --symlink-install --packages-select my_robot_controller- Source the file (in bashrc)
source ~/.bashrc
# there must be a line:
source ~/path/to/ros2_ws/install/setup.bashlike
# start ros2
source /opt/ros/jazzy/setup.bash
source /usr/share/colcon_cd/function/colcon_cd-argcomplete.bash
# install my ROS workspace
source ~/Desktop/GitHub/ros2_ws/install/setup.bashIn this repository, I cover the topics:
- ROS Terminology, Concepts and Programming
- ROS Visualization Tools
- Building a Robot with URDF
- Improving the URDF file with Xacro
And this is enough for getting started with ROS 2. The following topics, about Gazebo and Robot simulations will happen in a new workspace, since it makes sense to seperate workspaces for every robot we build. This workspace is already quite full with turtlesim and my_robot_controller, as well as the URDF files on top of it. So lets start a new workspace for the next robot.
The workspace, we are working with, is sourced in .bashrc when opening a terminal.
# start ros2
source /opt/ros/jazzy/setup.bash
source /usr/share/colcon_cd/function/colcon_cd-argcomplete.bash
# install my ROS workspace
source ~/Desktop/GitHub/ros2_ws/install/setup.bashNever source 2 workspaces together, so make sure to comment out the old workspace, when starting a new one.
# source ~/Desktop/GitHub/ros2_ws/install/setup.bash
source ~/Desktop/GitHub/my_new_workspace_name/install/setup.bash