Intermediate Tier Exercises
This document consolidates all exercises from the Intermediate tier lessons for hands-on practice with ROS 2 workflow implementation.
Exercise 01: Delivery Robot State Machine
Objective: Implement a complete state machine for a delivery robot in ROS 2.
Scenario: A delivery robot needs to navigate to a destination, deliver a package, and return to base.
Requirements:
- States: IDLE, NAVIGATING_TO_DESTINATION, DELIVERING, NAVIGATING_TO_BASE, CHARGING, ERROR
- Transitions: Define clear transition conditions
- ROS 2 Integration: Publish current state on
/robot_statetopic - Simulation: Test in Gazebo or similar
Tasks:
- Create a ROS 2 Python node with state machine logic
- Implement state transitions based on events (battery level, goal reached, etc.)
- Publish state changes to a topic
- Add logging for debugging
- Test all state transitions
Acceptance Criteria:
- All 6 states implemented
- State transitions work correctly
- State published on topic
- Tested in simulation
- Code is well-documented
Starter Code:
import rclpy
from rclpy.node import Node
from std_msgs.msg import String
from enum import Enum
class RobotState(Enum):
IDLE = "idle"
NAVIGATING_TO_DESTINATION = "navigating_to_destination"
DELIVERING = "delivering"
NAVIGATING_TO_BASE = "navigating_to_base"
CHARGING = "charging"
ERROR = "error"
class DeliveryRobotStateMachine(Node):
def __init__(self):
super().__init__('delivery_robot_sm')
self.state = RobotState.IDLE
# TODO: Create state publisher
# TODO: Create timers for state updates
# TODO: Create subscribers for events
def update_state(self):
# TODO: Implement state transition logic
pass
def publish_state(self):
# TODO: Publish current state
pass
def main():
rclpy.init()
node = DeliveryRobotStateMachine()
rclpy.spin(node)
rclpy.shutdown()
if __name__ == '__main__':
main()
Exercise 02: Sensor Processing Pipeline
Objective: Create a multi-node pipeline that processes sensor data through multiple stages.
Pipeline Stages:
- Sensor Node: Publishes simulated LIDAR data
- Filter Node: Filters out noise and invalid readings
- Processor Node: Detects obstacles from filtered data
- Controller Node: Makes decisions based on obstacles
Requirements:
- Each stage is a separate ROS 2 node
- Nodes communicate via topics
- Launch file starts all nodes
- Parameters configure each node
Tasks:
- Implement all 4 nodes
- Create appropriate message types or use standard messages
- Write a launch file to start the pipeline
- Add parameters for tuning (filter threshold, detection range, etc.)
- Test the complete pipeline
Acceptance Criteria:
- All 4 nodes implemented and working
- Data flows correctly through pipeline
- Launch file starts entire system
- Parameters are configurable
- Pipeline tested end-to-end
Exercise 03: Multi-Node Launch File
Objective: Create a comprehensive launch file for a robotic workflow.
System Components:
- State machine node
- Sensor nodes (camera, LIDAR)
- Navigation node
- Controller node
Requirements:
- Start all nodes with one command
- Configure parameters for each node
- Remap topics for proper connections
- Set up logging and output
Tasks:
- Write a Python launch file
- Configure each node with appropriate parameters
- Set up topic remappings
- Add conditional node launching (e.g., simulation vs. real hardware)
- Test the launch file
Acceptance Criteria:
- All nodes start correctly
- Parameters are properly set
- Topics are correctly remapped
- Conditional launching works
- System operates as expected
Starter Code:
from launch import LaunchDescription
from launch_ros.actions import Node
from launch.actions import DeclareLaunchArgument
from launch.substitutions import LaunchConfiguration
def generate_launch_description():
# TODO: Declare launch arguments
# TODO: Create node configurations
# TODO: Return LaunchDescription with all nodes
return LaunchDescription([
# Add nodes here
])
Exercise 04: Debug a Broken Workflow
Objective: Identify and fix issues in a multi-node workflow.
Scenario: You're given a workflow that doesn't work correctly. Your job is to debug and fix it.
Common Issues to Look For:
- Topic name mismatches
- Message type incompatibilities
- Missing dependencies
- Incorrect QoS settings
- Race conditions
- Parameter errors
Tasks:
- Run the provided broken workflow
- Use ROS 2 debugging tools to identify issues
- Fix all problems
- Verify the workflow works correctly
Debugging Tools to Use:
ros2 node list
ros2 topic list
ros2 topic info /topic_name
ros2 topic echo /topic_name
ros2 node info /node_name
ros2 param list /node_name
Acceptance Criteria:
- All issues identified
- All issues fixed
- Workflow operates correctly
- Documentation of what was wrong and how it was fixed
Capstone Project: Complete Navigation Workflow
Objective: Build a complete navigation workflow with state machine, sensors, planning, and control.
System Architecture:
Sensor Nodes → Perception → State Machine → Path Planner → Controller → Robot
↓ ↓
Raw Data Feedback
Requirements:
- State Machine: Manages robot behavior (IDLE, PLANNING, NAVIGATING, AVOIDING, GOAL_REACHED)
- Sensor Processing: Processes LIDAR/camera data
- Path Planning: Calculates paths to goals
- Controller: Executes motion commands
- Launch System: Orchestrates all components
- Error Handling: Handles sensor failures, planning failures, etc.
Tasks:
- Design the complete system architecture
- Implement all nodes
- Create launch files
- Test in simulation
- Document the system
Acceptance Criteria:
- Complete system implemented
- All components communicate correctly
- State machine manages workflow
- Robot navigates to goals successfully
- Error handling works
- System is well-documented
Deliverables:
- Source code for all nodes
- Launch files
- Configuration files
- README with setup and usage instructions
- Video demonstration in simulation
Self-Assessment Checklist
After completing all intermediate exercises, verify you can:
State Machine Implementation
- Implement FSM in ROS 2 Python nodes
- Manage state transitions based on events
- Publish state information for monitoring
- Handle edge cases and errors
Multi-Node Systems
- Create multi-node workflows
- Write launch files for orchestration
- Configure nodes with parameters
- Remap topics for flexible connections
Communication Patterns
- Choose appropriate communication patterns (topics/services/actions)
- Design effective message structures
- Configure QoS for reliability
- Debug communication issues
Ready for Advanced?
If you checked all boxes above, you're ready to proceed to the Advanced tier where you'll add fault tolerance and production-ready features!
Next Steps
Continue to Advanced Tier: Fault Tolerance & Production Systems