- お役立ち記事
- Basics of “ROS” and ROS2 programming practice
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.
資料ダウンロード
QCD管理受発注クラウド「newji」は、受発注部門で必要なQCD管理全てを備えた、現場特化型兼クラウド型の今世紀最高の受発注管理システムとなります。
NEWJI DX
製造業に特化したデジタルトランスフォーメーション(DX)の実現を目指す請負開発型のコンサルティングサービスです。AI、iPaaS、および先端の技術を駆使して、製造プロセスの効率化、業務効率化、チームワーク強化、コスト削減、品質向上を実現します。このサービスは、製造業の課題を深く理解し、それに対する最適なデジタルソリューションを提供することで、企業が持続的な成長とイノベーションを達成できるようサポートします。
製造業ニュース解説
製造業、主に購買・調達部門にお勤めの方々に向けた情報を配信しております。
新任の方やベテランの方、管理職を対象とした幅広いコンテンツをご用意しております。
お問い合わせ
コストダウンが利益に直結する術だと理解していても、なかなか前に進めることができない状況。そんな時は、newjiのコストダウン自動化機能で大きく利益貢献しよう!
(β版非公開)