Skip to main content

๐Ÿš€ 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
Important

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โ€‹

TermWhat it isExample
NodeA single process/moduleobject_detector, mission_manager
TopicPub/Sub message channel/cmd_vel, /image_raw, /target_pose
MessageData packet exchanged between nodesgeometry_msgs/Twist, sensor_msgs/Image
ServiceSynchronous request/response between nodesResetting a sensor, start/stop commands
ActionAsynchronous long-running task (with feedback)Navigation goal, arm movement
LaunchScript to start multiple nodes at oncefull_system.launch.py
ParameterConfig variable, can be set at runtimeNavigation 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โ€‹

CommandDescription
ros2 topic listList all topics
ros2 topic echo <topic>Print messages published on a topic
ros2 node listList all running nodes
ros2 service listList available services
ros2 param listList 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

๐Ÿค“ Learn Moreโ€‹


๐Ÿ“š Next Stepsโ€‹