Skip to content

Sarbe5/RISC_ROS2_WORKSHOP

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

27 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

RISC_ROS2_WORKSHOP

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.

πŸ“‹ Table of Contents

πŸ“ Repository Structure

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

πŸ”§ Prerequisites

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

Verify ROS2 Installation

# 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 version

πŸš€ Installation & Setup

Prerequisites: Docker Environment Setup

This repository is designed to work with the franka_ros2 Docker environment. Make sure you have already set up the Docker workspace:

  1. Clone the franka_ros2 repository:

    git clone https://github.com/Sarbe5/franka_ros2.git
    cd franka_ros2
  2. 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

Setting Up This Learning Repository

Inside the Docker container:

  1. Navigate to the workspace source directory:

    cd ~/ros2_ws/src
  2. Clone this learning repository:

    git clone https://github.com/Sarbe5/RISC_ROS2_WORKSHOP
    cd RISC_BOOTCAMP_ROS
  3. 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/
  4. Build the packages:

    cd ~/ros2_ws
    colcon build --packages-select publisher_node pub_sub
    source install/setup.bash

πŸ“¦ Package Overview

1. pack/ - Basic Scripts

Collection of standalone Python scripts demonstrating:

  • Publisher-Subscriber communication (talker.py, listner.py)
  • Turtle movement patterns (circle, spiral, square, straight line)

2. publisher_node/ - Complete ROS2 Package

A properly structured ROS2 Python package showing:

  • Package creation best practices
  • Publisher node implementation
  • Proper package.xml and setup.py configuration

3. pub_sub/ - Publisher-Subscriber Package

Demonstrates the fundamental ROS2 communication pattern:

  • Publisher node (pub.py) - Sends messages
  • Subscriber node (sub.py) - Receives messages

πŸ—οΈ Creating Your Own ROS2 Package

Step 1: Navigate to Your Workspace (Inside Docker Container)

cd ~/ros2_ws/src

Step 2: Create a New Python Package

# 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_msgs

Step 3: Package Structure

Your 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

Step 4: Edit setup.py

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',
        ],
    },
)

Step 5: Create Your Node

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()

Step 6: Make It Executable

# 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.py

πŸƒβ€β™‚οΈ Running the Examples

Running Basic Scripts (pack/ directory)

All 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 terminal

Running Package Nodes

Inside 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)

πŸ› οΈ Common Commands

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 build

πŸ› Troubleshooting

Common Issues and Solutions

Working with Docker Environment:

  1. "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
  2. Import errors:

    # Check if the package is properly built (inside container)
    cd ~/ros2_ws
    colcon build --packages-select your_package
  3. Permission denied:

    # Make scripts executable (inside container)
    chmod +x your_script.py
  4. Turtle not moving:

    # Make sure turtlesim is running (inside container)
    ros2 run turtlesim turtlesim_node
  5. Need multiple terminals:

    # Open additional container sessions as needed
    docker exec -it franka_ros2 /bin/bash

Environment Setup

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" >> ~/.bashrc

For 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 ID

πŸ“š Learning Resources

πŸ“„ License

This 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

About

ROS2 Workshop Solutions

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages