๐ ROS2 Basics
Welcome to ROS2โthe backbone of your robotics development!
Here's a crisp, practical overview so you can hit the ground running, build safely, and actually understand what's going on.
๐งฉ What is ROS2?โ
ROS2 (Robot Operating System 2) is a modular robotics middleware for building robot applicationsโfrom simulation to real-world deployment.
It provides a standard for nodes, messaging, sensors, actuators, and distributed computation.
๐ ๏ธ ROS2 Workspace Structureโ
A typical ROS2 workspace looks like this:
~/limo_ws/
โโโ src/ # All your source code (packages, nodes, launch, config)
โโโ build/ # Auto-generated build files (never touch)
โโโ install/ # Installed executables, setup scripts
โโโ log/ # Build logs
Always develop in your own workspace (~/limo_ws), never in vendor or /opt/ros folders!
๐ฆ Creating a Workspaceโ
# 1. Create the workspace and src folder
mkdir -p ~/limo_ws/src
cd ~/limo_ws
# 2. Build (initial empty build is fine)
colcon build
# 3. Source it (activate environment variables)
source install/setup.bash
Add this to your ~/.bashrc for convenience:
echo "source ~/limo_ws/install/setup.bash" >> ~/.bashrc
๐๏ธ ROS2 Core Conceptsโ
| Term | What it is | Example |
|---|---|---|
| Node | A single process/module | object_detector, mission_manager |
| Topic | Pub/Sub message channel | /cmd_vel, /image_raw, /target_pose |
| Message | Data packet exchanged between nodes | geometry_msgs/Twist, sensor_msgs/Image |
| Service | Synchronous request/response between nodes | Resetting a sensor, start/stop commands |
| Action | Asynchronous long-running task (with feedback) | Navigation goal, arm movement |
| Launch | Script to start multiple nodes at once | full_system.launch.py |
| Parameter | Config variable, can be set at runtime | Navigation speed, sensor thresholds |
๐ก Pub/Sub: Topics & Messagesโ
Nodes communicate using topics (publish/subscribe pattern).
- Publisher: Sends messages on a topic.
- Subscriber: Listens for messages on a topic.
Example:
/cmd_vel (velocity commands) uses geometry_msgs/Twist messages.
# Publish a Twist message (move forward)
ros2 topic pub /cmd_vel geometry_msgs/msg/Twist "linear: {x: 0.1, y: 0.0, z: 0.0} angular: {x: 0.0, y: 0.0, z: 0.0}"
๐ค Running Nodes & Launch Filesโ
Running a Node Directlyโ
ros2 run <package_name> <executable>
# Example:
ros2 run object_detector object_detector_node
Using Launch Filesโ
ros2 launch <package_name> <launch_file>
# Example:
ros2 launch nav_handler full_system.launch.py
๐ Parametersโ
Parameters let you adjust node behavior at runtime (e.g., detection thresholds, map files).
Set with launch files, YAML configs, or the command line.
ros2 param set /node_name param_name value
๐ง Useful ROS2 Commandsโ
| Command | Description |
|---|---|
ros2 topic list | List all topics |
ros2 topic echo <topic> | Print messages published on a topic |
ros2 node list | List all running nodes |
ros2 service list | List available services |
ros2 param list | List all parameters |
ros2 run ... | Run a single node |
ros2 launch ... | Launch multiple nodes |
๐บ๏ธ Visualization: RViz & RQTโ
RViz: 3D visualization of maps, robot pose, sensors, goals, etc.
rviz2
RQT: Graphical tools for inspecting topics, TF trees, node graphs, and more
rqt_graph # Show node-topic relationships
rqt_tf_tree # Visualize TF frames
๐ Creating & Building Packagesโ
Create a new package:
cd ~/limo_ws/src
ros2 pkg create --build-type ament_python <package_name>
Build all packages:
cd ~/limo_ws
colcon build
source install/setup.bash
๐ฆ Safety & Shutdownโ
- Always stop all nodes with Ctrl+C before disconnecting hardware
- Shut down the robot before removing the SD card or power