This repository is a collection of ROS 2 packages created as part of a journey to learn the fundamental concepts of the Robot Operating System 2. Each package demonstrates a specific feature, serving as a practical, hands-on reference.
This workspace covers the following key areas of ROS 2:
A ROS 2 workspace is a directory containing ROS 2 packages. This workspace (learning_ros_ws) is a standard example.
- Packages: The fundamental unit of organization in ROS 2. Each subdirectory in
src/is a package (e.g.,py_pubsub,learning_tf2_py). package.xml: Provides meta-information about the package (name, version, dependencies).setup.py/CMakeLists.txt: Contains build information for Python and C++ packages, respectively.
Nodes are the main executable programs in a ROS 2 system. They are responsible for a single, modular purpose (e.g., controlling a wheel motor, publishing sensor data).
- Example:
my_package/my_package/my_node.pyis a basic implementation of a ROS 2 node.
Topics provide an anonymous, asynchronous communication bus. Nodes can publish messages to a topic, and any node can subscribe to that topic to receive them.
- Implementation: The
py_pubsubpackage demonstrates a simple publisher (publisher_member_function.py) and subscriber (subscriber_member_function.py).
Services are used for synchronous, request/reply communication. A client sends a request and waits for a response from a server.
- Implementation: The
py_srvclipackage shows how to create a service server (service_member_function.py) and a client (client_member_function.py).
Actions are used for long-running, asynchronous tasks that provide feedback. They are like services but include feedback and the ability to preempt the goal.
- Implementation: The
fibonacci_action_server.pyandfibonacci_action_client.pyprovide a clear example of an action.
ROS 2 allows you to define your own data structures for communication.
- Custom Messages (
.msg): Defines the data structure for a topic.- Example:
tutorial_interfaces/msg/Num.msg
- Example:
- Custom Services (
.srv): Defines the request and response data structures for a service.- Example:
tutorial_interfaces/srv/AddThreeInts.srv
- Example:
- Custom Actions (
.action): Defines the goal, result, and feedback data structures for an action.- Example:
custom_action_interfaces/action/Fibonacci.action
- Example:
Parameters allow you to configure a node's settings externally at startup or runtime without changing the code.
- Implementation: The
python_parameterspackage demonstrates how to declare, set, and use parameters in a node. - Event Handling: The
python_parameter_event_handlerpackage shows how to respond to parameter changes dynamically.
Launch files are used to start and configure multiple nodes at once, creating a complex system from simple parts.
- Implementation: The
py_launch_exampleandlearning_tf2_py/launchdirectories contain Python-based launch files that demonstrate how to launch nodes and set up a system liketurtlesim.
TF2 is a system that manages and keeps track of multiple coordinate frames over time. It's essential for any robot that needs to reason about the relationship between different parts (e.g., base, arm, gripper) and the world.
- Implementation: The
learning_tf2_pypackage usesturtlesimto show:- Broadcasting: Publishing the relationship between coordinate frames.
- Listening: Subscribing to transforms to compute the difference between frames.
This workspace includes packages for a real robot (Yahboom Rosmaster), demonstrating how the core concepts are applied to hardware.
- URDF (
.urdf): The Unified Robot Description Format is an XML file used to model a robot's physical structure.- Example:
yahboom_rosmaster_description/urdf/
- Example:
- Gazebo Simulation: Gazebo is a powerful 3D robot simulator. The
yahboom_rosmaster_gazebopackage contains the necessary files to simulate the robot in a virtual environment.
-
Clone the repository (if you haven't already):
git clone <your-repo-url> learning_ros_ws cd learning_ros_ws
-
Build the workspace: From the root of the workspace (
learning_ros_ws), run thecolconbuild tool.colcon build
-
Source the environment: After a successful build, source the overlay to make the packages available in your terminal session.
source install/setup.bash -
Run a launch file: You can now run executables or launch files from any package. For example, to run the
turtlesimTF2 demo:ros2 launch learning_tf2_py turtle_tf2_demo_launch.py
custom_action_interfaces: Defines a custom action for the Fibonacci sequence.learning_tf2_py: Demonstrates how to use TF2 withturtlesimto broadcast and listen for coordinate frame transformations.mecanum_drive_controller: A controller for a mecanum-drive mobile base, allowing for omnidirectional movement.my_package: A basic "Hello World" ROS 2 node, serving as a minimal example of a package.py_launch_example: Contains a Python-based launch file for starting ROS 2 nodes.py_pubsub: Implements a simple publisher and subscriber to demonstrate topic-based communication.py_srvcli: Provides a simple service and client for request/reply communication.python_parameter_event_handler: Shows how to dynamically respond to parameter changes.python_parameters: Demonstrates how to declare, set, and use parameters in a ROS 2 node.turtlesim: A tool for teaching and learning ROS 2 concepts in a simple, visual environment.tutorial_interfaces: Defines custom message and service types for inter-node communication.yahboom_rosmaster: A metapackage that groups all the packages related to the Yahboom Rosmaster robot.yahboom_rosmaster_bringup: Contains launch files for starting the Yahboom Rosmaster robot.yahboom_rosmaster_description: Contains the URDF (robot model) and other description files for the Yahboom Rosmaster.yahboom_rosmaster_gazebo: Provides the necessary files to simulate the Yahboom Rosmaster robot in the Gazebo environment.yahboom_rosmaster_system_tests: Contains system-level tests for the Yahboom Rosmaster robot.