element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Robotics
  • Technologies
  • More
Robotics
Blog ROS2 Learning Series - Blog 3 - Setup
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Robotics to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: crisdeodates
  • Date Created: 9 Apr 2024 10:34 AM Date Created
  • Views 422 views
  • Likes 4 likes
  • Comments 1 comment
  • Robot operating System
  • robotics
  • ROS2
  • ROS
Related
Recommended

ROS2 Learning Series - Blog 3 - Setup

crisdeodates
crisdeodates
9 Apr 2024
ROS2 Learning Series - Blog 3 - Setup

ROS2 – Setup 

Installation 

Unlike ROS1, ROS2 can be installed on all major platforms such as Linux, Windows and MacOS. Here I will focus on installing ROS2 on an Ubuntu 22.04 system. For other platforms, the installation setups are detailed on the official ROS2 documentation page. 

 

Setup the locale settings

$ sudo apt update && sudo apt install locales 
$ sudo locale-gen en_US en_US.UTF-8 
$ sudo update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8

$ export LANG=en_US.UTF-8

Setup the ROS2 sources

$ sudo apt install software-properties-common 
$ sudo add-apt-repository universe 
$ sudo apt update && sudo apt install curl -y 
 
$ sudo curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg 

 

Install the ROS2 packages

$ sudo apt update 
$ sudo apt upgrade 
$ sudo apt install ros-humble-desktop 

 

Setup the ROS2 environment

The following command should be run on every new shell to have access to the ROS2 commands. 

$ source /opt/ros/humble/setup.bash 

However, this command can be added to the shell startup script for it to automatically run every time a new terminal window is created. 

$ echo "source /opt/ros/humble/setup.bash" >> ~/.bashrc 

 

Test the ROS2 installation

To test the ROS2 installation, we will run a simple publisher - subscriber example. 

In a terminal, execute the following: 

$ ros2 run demo_nodes_py listener 

 

In another terminal, execute the following: 

$ source /opt/ros/humble/setup.bash

$ ros2 run demo_nodes_cpp talker 

We should be able to see the talker node saying that it’s Publishing messages and the listener node saying it heard those messages. If this is working, we can be sure that both the C++ and Python ROS2 APIs are working properly. 

 

Packages 

In ROS2, a package can be regarded as an organizational unit, allowing us to install our code or share it with others, allowing them to build and use it easily. To create packages in ROS 2, we can use ament as its build system and colcon as its build tool. We can also create a package using either CMake or Python, which are officially supported, though other build types do exist, but we will focus on amend and colcon. 

 

Workspaces 

In ROS2, a workspace is a directory containing packages. A build system uses a workspace to go through packages to build them for the project. A workspace can contain multiple packages, separated into individual folders. Packages can also belong to different build types in the same workspace (CMake, Python, etc.). However, nesting of packages is not allowed. 

Build system 

A build tool operates on a set of packages. It determines the dependency graph and invokes the specific build system for each package in topological order. The build tool itself should know how to set up the environment for the build system and invoke it. The existing ROS build tools are catkin_make, catkin_make_isolated, catkin_tools, colcon, and ament_tools. It controls the compilation and testing of multiple ROS2 packages together. ROS2 uses ament_tools  and now colcon as the build tool. 

The build system on the other hand operates on a single package. Examples are Make, CMake, ament_cmake, ament_python, Python setuptools, or Autotools. A CMake package is e.g. built by invoking these steps: cmake, make, make install. ROS2 uses ament_cmake and ament_python as the build systems. 

Generally, in ROS, each package contains a manifest file (package.xml). This manifest file contains essential metadata about the package, including its dependencies on other packages. This manifest is required for the meta-build tool to function. 

In the projects that follow, we will use python as our programming language, ament as our build system and colcon as our build tool. 

Reference

  • Sign in to reply
  • DAB
    DAB over 1 year ago

    Looks straight forward.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube