Robot Development at the Forefront: Transforming the future of system building with "ROS2"
2025.09.10
- 研究開発
As robotics technology is used in a wide range of industries, ROS is one of the key technologies at its core.
However, some may still be unfamiliar with ROS.
Therefore, this article will delve into the fundamental knowledge of ROS, focusing particularly on "ROS2," the current mainstream version, and will explain everything from its overview to development and practical application examples.
However, some may still be unfamiliar with ROS.
Therefore, this article will delve into the fundamental knowledge of ROS, focusing particularly on "ROS2," the current mainstream version, and will explain everything from its overview to development and practical application examples.
What is ROS?: A framework for accelerating robot development
"ROS" stands for "Robot Operating System". While its name suggests it's a type of operating system, strictly speaking, it's an open-source framework, or middleware, for developing robotic systems.

Middleware is software that sits between the operating system (OS) and applications, providing various functions that are insufficient with the OS alone. ROS specifically improves the efficiency of robot development by providing the following functions:
Because it is open source, a major feature is that not only official extensions but also various individuals and organizations develop extensions, forming an active community.
- Communications functions: Facilitates the sending and receiving of data between the various components within a robot.
- Development tools: Provides a wide range of tools to assist development, including debugging, simulation, data visualization, and logging.
Because it is open source, a major feature is that not only official extensions but also various individuals and organizations develop extensions, forming an active community.
Why ROS2?: Evolution from ROS1 to ROS2
Currently, there are two versions of ROS in use: "ROS1" and "ROS2." ROS2 is an updated version developed to address ROS1's issues and is generally incompatible. Official support for ROS1 ended in May 2025, so ROS2 is now the primary version.
Key improvements in ROS2 include:
Key improvements in ROS2 include:
- Changes in communication method: While ROS1 used a proprietary protocol, ROS2 adopts the standard DDS (Data Distribution Service) protocol.
- Improved real-time performance: Suitable for robot applications requiring real-time control.
- Support for multi-process environments: Collaboration between multiple processes and machines has become easier.
- Improved security: Enables the construction of more secure systems.
ROS2 Applications
ROS2 is used in a wide range of fields.
- Drones
- AMR/AGV (Autonomous Mobile Robots/Automated Guided Vehicles)
- Industrial Robots
- Autonomous Driving
It is also used in Autoware, an open-source software for autonomous driving. - Construction Machinery Construction Management Systems
- Robot Actuators
ROS2 Development Environment and Language Options
ROS2 development supports a variety of platforms, but is most commonly conducted on Ubuntu (Linux).
The main programming languages used are C++ and Python.
There are clear differences between these two languages, and it's common to use both within a single system.
The main programming languages used are C++ and Python.
There are clear differences between these two languages, and it's common to use both within a single system.
C++ | Recommended when real-time performance and performance are a priority. In addition to its language characteristics, C++ allows for more detailed performance tuning than Python and is easier to distribute as a built library. Most ROS2 code is written in C++. |
---|---|
Python | Suitable for using Python libraries like PyTorch, simple prototyping, and GUI creation. |
Other ROS2 development projects exist, such as mROS2 and micro-ROS, which build ROS2 on certain microcontrollers, ROS2 for Unity, which builds ROS2 on Unity apps, and even bridges like the rosbridge suite, which allow other languages like Java, JavaScript, and Rust to receive ROS2 messages.
- Unity is a game development platform.
The ROS2 Ecosystem
ROS2 is supported by a powerful ecosystem (a comprehensive system or environment that supports development and operation) consisting of the following four elements.
Community
With many users worldwide, information is readily available and questions can be easily resolved.
Tools and Features
A wide variety of tools and features are available from various organizations, including data visualization tools (such as rviz), logging tools, sensor drivers, and advanced algorithms.

Visualizing LiDAR SLAM results with rviz.
Communication
Communication is at the core of ROS2.
Within the same network ,modules (nodes) can communicate smoothly, even across different machines.
Within the same network ,modules (nodes) can communicate smoothly, even across different machines.

Package
A basic unit of a ROS2 program that groups related functions.
It consists of source code and configuration files and is used when sharing with other developers.
It consists of source code and configuration files and is used when sharing with other developers.
ROS2 Package Structure and Coding Overview
ROS2 programs are managed in units called "packages." A typical C++ ROS2 package has the following structure:

- The basic unit of a ROS2 program, grouping related functions.
- Consists of source code and configuration files.
- You use packages when sharing with others.
src | Contains source code (e.g., .cpp files). |
---|---|
include/[package name] | Contains header files (e.g., .hpp files). |
package.xml | Contains package meta information (name, version, dependencies, etc.). The ROS2 build system references this file to resolve dependencies between packages. |
CMakeLists.txt | This file describes how to build the package. This file automates the build process in conjunction with the ament_cmake CMake extension. |
Let's take a look at what actual C++ code looks like.
In ROS2, nodes are implemented using a library called rclcpp.
In ROS2, nodes are implemented using a library called rclcpp.
// my_node.hpp -------------------------------------------------------------
// ROS2 library inclusions
#include "rclcpp/rclcpp.hpp“
// Message type inclusions
// Standard ROS2 message types as well as custom message types can be used
#include “std_msgs/msg/float32.hpp" // Standard ROS2 message type
#include “my_msgs/msg/route.hpp" // Custom message type
// Define a unique node by inheriting the Node class
class MyNode : public rclcpp::Node
{
public:
MyNode(const rclcpp::NodeOptions& options = rclcpp::NodeOptions());
private:
// Subscriber definition
rclcpp::Subscription<my_msgs::msg::Route>::SharedPtr _sub;
// Publisher definition
rclcpp::Publisher<std_msgs::msg::Float32>::SharedPtr _pub;
// Callback function definition
void _callback(const my_msgs::msg::Route::SharedPtr msg);
};
// ROS2 library inclusions
#include "rclcpp/rclcpp.hpp“
// Message type inclusions
// Standard ROS2 message types as well as custom message types can be used
#include “std_msgs/msg/float32.hpp" // Standard ROS2 message type
#include “my_msgs/msg/route.hpp" // Custom message type
// Define a unique node by inheriting the Node class
class MyNode : public rclcpp::Node
{
public:
MyNode(const rclcpp::NodeOptions& options = rclcpp::NodeOptions());
private:
// Subscriber definition
rclcpp::Subscription<my_msgs::msg::Route>::SharedPtr _sub;
// Publisher definition
rclcpp::Publisher<std_msgs::msg::Float32>::SharedPtr _pub;
// Callback function definition
void _callback(const my_msgs::msg::Route::SharedPtr msg);
};
// my_node.cpp -------------------------------------------------------------
#include “my_node.hpp“
// The constructor sets up the publisher and subscriber.
// Communication is configured in just a few lines of code.
MyNode::MyNode(const rclcpp::NodeOptions& options):
rclcpp::Node(“my_node", options)
{
// Subscriber setup
_sub = this->create_subscription<my_msgs::msg::Route>(
“target_route",
rclcpp::QoS(10),
std::bind(&myNode::_callback, this, std::placeholders::_1)
);
// Publisher setup
_pub = this->create_publisher<std_msgs::msg::Float32>(
“target_velocity”,
rclcpp::QoS(10),
);
}
// The callback function: This is the main processing loop of the node.
void MyNode::_callback(const my_msgs::msg::Route::SharedPtr msg)
{
// Main processing logic, such as calculating the target velocity for a robot's travel control.
float target_velocity = calculate_target_velocity(msg);
// Convert the calculation result into a message.
auto pub_msg = std_msgs::msg::Float32();
pub_msg.data = target_velocity;
// Publish the message.
_pub->publish(pub_msg);
}
#include “my_node.hpp“
// The constructor sets up the publisher and subscriber.
// Communication is configured in just a few lines of code.
MyNode::MyNode(const rclcpp::NodeOptions& options):
rclcpp::Node(“my_node", options)
{
// Subscriber setup
_sub = this->create_subscription<my_msgs::msg::Route>(
“target_route",
rclcpp::QoS(10),
std::bind(&myNode::_callback, this, std::placeholders::_1)
);
// Publisher setup
_pub = this->create_publisher<std_msgs::msg::Float32>(
“target_velocity”,
rclcpp::QoS(10),
);
}
// The callback function: This is the main processing loop of the node.
void MyNode::_callback(const my_msgs::msg::Route::SharedPtr msg)
{
// Main processing logic, such as calculating the target velocity for a robot's travel control.
float target_velocity = calculate_target_velocity(msg);
// Convert the calculation result into a message.
auto pub_msg = std_msgs::msg::Float32();
pub_msg.data = target_velocity;
// Publish the message.
_pub->publish(pub_msg);
}
// main.cpp -------------------------------------------------------------
// main function: Initializes ROS2 and executes the node.
int main(int argc, char * argv[]) {
// ROS2 initialization
rclcpp::init(argc, argv);
// Node execution
rclcpp::spin(std::make_shared<MyNode>());
// ROS2 shutdown
rclcpp::shutdown();
return 0;
}
// main function: Initializes ROS2 and executes the node.
int main(int argc, char * argv[]) {
// ROS2 initialization
rclcpp::init(argc, argv);
// Node execution
rclcpp::spin(std::make_shared<MyNode>());
// ROS2 shutdown
rclcpp::shutdown();
return 0;
}
As this example shows, basic communication settings in ROS2 can be configured with just a few lines of code, and callback functions form the core of the node's processing. Actual product code such as Dynamixel SDK also provides a ROS2 package that acts as an interface between ROS2 and the motor driver. This is a structure commonly seen in ROS2 packages that connect to hardware.
This article has explained "ROS", an open source framework for robot development, focusing particularly on the currently mainstream "ROS2".
With its rich functionality and flexibility, ROS2 provides powerful support for the development of a wide range of robot systems.
As robot technology continues to evolve, ROS2's applications will likely continue to expand.
- ROS is middleware for developing robot systems, providing communication functions, development tools, algorithms, and more.
- There is a steady transition from ROS1 to ROS2, which offers improved communication methods, real-time performance, and security.
- Development is typically done in an Ubuntu environment, with C++ and Python typically used depending on the application.
- ROS2 is characterized by an ecosystem consisting of an active community, a rich set of tools, and powerful communication functions.
- When coding for ROS2, basic communication settings are easy, and the main focus is on implementing callback functions.
With its rich functionality and flexibility, ROS2 provides powerful support for the development of a wide range of robot systems.
As robot technology continues to evolve, ROS2's applications will likely continue to expand.