Welcome to the ROS2 Bootcamp repository! This repository contains practical examples and exercises to help you learn ROS2 (Robot Operating System 2) fundamentals, including publisher-subscriber patterns, turtle movement control, and package creation.
- Repository Structure
- Prerequisites
- Installation & Setup
- Package Overview
- Creating Your Own ROS2 Package
- Running the Examples
- Common Commands
- Troubleshooting
- Learning Resources
RISC_BOOTCAMP_ROS/
βββ pack/ # Basic ROS2 scripts collection
β βββ __init__.py
β βββ listner.py # Subscriber example
β βββ move_circle.py # Turtle circular movement
β βββ move_spiral.py # Turtle spiral movement
β βββ move_square.py # Turtle square movement
β βββ move_st.py # Turtle straight line movement
β βββ sf.py # Additional functionality
β βββ talker.py # Publisher example
βββ publisher_node/ # Complete ROS2 package example
β βββ package.xml # Package metadata
β βββ setup.py # Python package setup
β βββ setup.cfg # Setup configuration
β βββ publisher_node/ # Python module
β β βββ __init__.py
β β βββ publisher_hello_node.py # Publisher node implementation
β βββ resource/ # Package resources
β βββ test/ # Unit tests
βββ pub_sub/ # Publisher-Subscriber package
β βββ package.xml
β βββ setup.py
β βββ pub_sub/
β β βββ __init__.py
β β βββ pub.py # Publisher node
β β βββ sub.py # Subscriber node
β βββ resource/
β βββ test/
βββ README.md
Before you begin, ensure you have the following installed:
- Ubuntu 22.04 (recommended) or compatible Linux distribution
- ROS2 (Humble/Iron/Rolling) - Installation Guide
- Python 3.8+
- Git
# Check if ROS2 is properly installed
ros2 --version
# Source ROS2 environment (add this to your ~/.bashrc)
source /opt/ros/humble/setup.bash # Replace 'humble' with your ROS2 versionThis repository is designed to work with the franka_ros2 Docker environment. Make sure you have already set up the Docker workspace:
-
Clone the franka_ros2 repository:
git clone https://github.com/Sarbe5/franka_ros2.git cd franka_ros2 -
Set up Docker environment:
# Save current user ID echo -e "USER_UID=$(id -u $USER)\nUSER_GID=$(id -g $USER)" > .env # Build the container docker compose build # Run the container docker compose up -d # Open shell inside container docker exec -it franka_ros2 /bin/bash
Inside the Docker container:
-
Navigate to the workspace source directory:
cd ~/ros2_ws/src
-
Clone this learning repository:
git clone https://github.com/Sarbe5/RISC_ROS2_WORKSHOP cd RISC_BOOTCAMP_ROS -
Copy packages to workspace:
# Copy the complete packages to your workspace src directory cp -r publisher_node ~/ros2_ws/src/ cp -r pub_sub ~/ros2_ws/src/
-
Build the packages:
cd ~/ros2_ws colcon build --packages-select publisher_node pub_sub source install/setup.bash
Collection of standalone Python scripts demonstrating:
- Publisher-Subscriber communication (
talker.py,listner.py) - Turtle movement patterns (circle, spiral, square, straight line)
A properly structured ROS2 Python package showing:
- Package creation best practices
- Publisher node implementation
- Proper package.xml and setup.py configuration
Demonstrates the fundamental ROS2 communication pattern:
- Publisher node (
pub.py) - Sends messages - Subscriber node (
sub.py) - Receives messages
cd ~/ros2_ws/src# Basic package creation
ros2 pkg create --build-type ament_python <package_name>
# Create package with dependencies
ros2 pkg create --build-type ament_python <package_name> --dependencies rclpy std_msgs geometry_msgsYour new package will have this structure:
your_package/
βββ package.xml # Package metadata and dependencies
βββ setup.py # Python package configuration
βββ setup.cfg # Setup configuration
βββ your_package/ # Python module directory
β βββ __init__.py
βββ resource/ # Package marker files
β βββ your_package
βββ test/ # Unit tests directory
from setuptools import setup
package_name = 'your_package'
setup(
name=package_name,
version='0.0.0',
packages=[package_name],
data_files=[
('share/ament_index/resource_index/packages',
['resource/' + package_name]),
('share/' + package_name, ['package.xml']),
],
install_requires=['setuptools'],
zip_safe=True,
maintainer='Your Name',
maintainer_email='your.email@example.com',
description='Package description',
license='License declaration',
tests_require=['pytest'],
entry_points={
'console_scripts': [
'node_name = your_package.script_name:main',
],
},
)Create a Python file in your_package/your_node.py:
import rclpy
from rclpy.node import Node
from std_msgs.msg import String
class YourNode(Node):
def __init__(self):
super().__init__('your_node')
# Your node logic here
def main(args=None):
rclpy.init(args=args)
node = YourNode()
rclpy.spin(node)
node.destroy_node()
rclpy.shutdown()
if __name__ == '__main__':
main()# Build the package
cd ~/ros2_ws
colcon build --packages-select your_package
# Source the workspace
source install/setup.bash
# Make the script executable (if running directly)
chmod +x src/your_package/your_package/your_node.pyAll commands should be run inside the Docker container:
# First, open the Docker container shell
docker exec -it franka_ros2 /bin/bash
# Start turtlesim (required for turtle movement examples)
ros2 run turtlesim turtlesim_node
# In another terminal/container session, run movement scripts
docker exec -it franka_ros2 /bin/bash
cd ~/ros2_ws/src/RISC_BOOTCAMP_ROS/pack/
python3 move_circle.py
python3 move_square.py
python3 move_spiral.py
# For publisher-subscriber examples
python3 talker.py # In one terminal
python3 listner.py # In another terminalInside the Docker container:
# Source your workspace first
source ~/ros2_ws/install/setup.bash
# Run publisher node
ros2 run publisher_node publisher_hello_node
# Run pub_sub package
ros2 run pub_sub pub # Publisher
ros2 run pub_sub sub # Subscriber (in another container session)All commands should be run inside the Docker container:
# Access the container
docker exec -it franka_ros2 /bin/bash
# List all available packages
ros2 pkg list
# List all running nodes
ros2 node list
# List all topics
ros2 topic list
# Echo messages from a topic
ros2 topic echo /topic_name
# Show topic information
ros2 topic info /topic_name
# Build specific package
cd ~/ros2_ws
colcon build --packages-select package_name
# Build with verbose output
colcon build --event-handlers console_direct+
# Clean build
rm -rf build/ install/ log/
colcon buildWorking with Docker Environment:
-
"Package not found" error:
# Make sure you're inside the Docker container docker exec -it franka_ros2 /bin/bash # Source your workspace source ~/ros2_ws/install/setup.bash
-
Import errors:
# Check if the package is properly built (inside container) cd ~/ros2_ws colcon build --packages-select your_package
-
Permission denied:
# Make scripts executable (inside container) chmod +x your_script.py -
Turtle not moving:
# Make sure turtlesim is running (inside container) ros2 run turtlesim turtlesim_node -
Need multiple terminals:
# Open additional container sessions as needed docker exec -it franka_ros2 /bin/bash
Inside the Docker container, the ROS2 environment should already be configured. However, you may need to source your workspace:
# Add this to your container's ~/.bashrc if needed
echo "source ~/ros2_ws/install/setup.bash" >> ~/.bashrcFor Development Outside Container:
If you want to work outside the Docker container, add these lines to your ~/.bashrc:
# ROS2 Environment Setup
source /opt/ros/humble/setup.bash # Replace 'humble' with your ROS2 version
source ~/ros2_ws/install/setup.bash
export ROS_DOMAIN_ID=0 # Optional: set domain IDThis project is licensed under the MIT License - see the LICENSE file for details.
Happy Learning! π
This repository is designed to help you get started with ROS2. Practice with the examples, experiment with the code, and don't hesitate to ask questions