投稿日:2025年3月5日

Basics of “ROS” and ROS2 programming practice

What is ROS?

ROS, which stands for Robot Operating System, is an open-source framework that is widely used in robotics.
It provides services designed for managing complex robotic functionalities like hardware abstraction, device control, communication between processes, and package management.
It essentially acts as the backbone that connects all parts of a robot’s software system.
ROS was developed by Willow Garage and rapidly became a staple in the robotics industry due to its robust toolset and active community support.

The unique aspect of ROS is its modular design.
This makes it highly versatile, as developers can easily mix and match different software modules to tailor the system to their specific needs.
Also, because it is open-source, ROS benefits from constant improvements and updates provided by a global community of contributors.

Key Features of ROS

One of the standout features of ROS is its peer-to-peer network structure.
This allows different parts of the system to communicate efficiently and operate independently, yet cohesively.
This architecture promotes scalability, enabling ROS to work with robots of varying sizes and complexities.

Another critical aspect is its vast repository of software packages.
These pre-built packages cater to a wide range of functionalities and robotic applications, from vision processing to autonomous navigation.
Developers can save significant time by reusing existing packages rather than building each functionality from scratch.

Furthermore, ROS supports multiple programming languages including C++, Python, and LISP, allowing developers to use their language of preference or the language best suited for a specific task.
This multi-language support also enables groups of developers with different skill sets to work together seamlessly.

The Evolution to ROS2

As robotics technology advanced, the limitations of the original ROS became apparent, which led to the development of ROS2.
ROS2 was designed to address the shortcomings of its predecessor and to provide a more robust framework for modern robotic applications.

Improvements in ROS2

ROS2 comes with several improvements that cater to today’s growing demands for robotic systems.
One of the main enhancements is the switch to the Data Distribution Service (DDS) as the communication layer, which provides improved real-time support and reliability.
This change makes ROS2 more suitable for industrial and safety-critical applications.

Additionally, ROS2 offers better support for multi-robot systems.
It natively supports distributed systems, which allows for easy coordination and communication between different robots.
This is particularly beneficial for applications that involve fleets of robots working together, such as those in warehouses or autonomous vehicle fleets.

Safety and security have also been prioritized in ROS2.
It includes features that protect against unauthorized data access and ensures data integrity, which is especially important in environments where robots operate alongside humans.

Installing ROS and ROS2

Setting up ROS or ROS2 involves several steps but is straightforward once you understand the basics.
Both systems are available on popular operating systems, but they are primarily used on Unix-based systems like Ubuntu.

Installing ROS

1. **Update and upgrade your system**: Ensure your Linux system is up-to-date to avoid conflicts.

2. **Set up the sources.list**: Add the ROS repository to your system’s source list.

3. **Install the package**: Use the package manager to install ROS, typically a full-desktop version if you want comprehensive tools and libraries.

4. **Initialize rosdep**: This tool helps in managing dependencies, making it a crucial step.

5. **Environment setup**: Configure your environment by sourcing the setup.bash script provided in the installation directory.

Installing ROS2

1. **Prepare your system**: Similar to ROS, ensure your system is updated.

2. **Download the ROS2 package**: The packages are available through the official ROS2 website or standard repository for your operating system.

3. **Setup for installation**: Configure the system environment and install necessary packages for ROS2.

4. **Build the workspace**: If you plan to customize or develop packages, setting up a workspace is essential.

5. **Source the environment**: Similar to ROS, source the setup file to configure your session.

Basic Programming Practices with ROS and ROS2

Programming a robot using ROS or ROS2 involves understanding the fundamental concepts such as nodes, topics, services, and actions.

Understanding Nodes

Nodes are individual processes that perform specific functions within the ROS ecosystem.
They can be thought of as small programs that do a particular job such as reading sensor data or controlling actuators.
In ROS, communication between nodes occurs through a Master node, whereas ROS2 uses a more decentralized approach with direct node-to-node communication.

Communicating through Topics

Topics are channels through which nodes exchange messages.
A publisher node sends data to a topic, while a subscriber node receives data from the topic.
This decoupling of publishers and subscribers allows for flexible integration and reduced complexity in network communication.

Using Services and Actions

While topics are used for continuous data flow, services are employed for short-lived interactions between nodes.
For instance, if a node needs to request data from another node, a service call would be suitable.

Actions, on the other hand, are employed for tasks that take longer to complete.
They allow for feedback and cancellations during the process, adding a layer of control over longer operations.

Getting Started with Your First ROS or ROS2 Project

To start a new project, first, set up a new package using the catkin build system for ROS or the colcon build system for ROS2.
These systems help manage, build, and install software packages efficiently.

Create a workspace directory where your projects will reside.
Initialize it by running the setup script provided by whichever ROS version you are using.
From here, you can begin creating nodes, writing scripts, and configuring them to communicate over defined topics and services.

By combining an understanding of the basic concepts with hands-on practice, you can develop robust robotic applications tailored to a variety of needs.
With ever-evolving capabilities and ongoing community contributions, both ROS and ROS2 are invaluable tools for modern robotics programming.

You cannot copy content of this page