launch をYAMLで記述する – ROS Japanese Tutorial

Written by Takumi Okamoto

16/04/2024

This tutorial is created by Robotics Ambassador Takumi

Robotics Ambassador Program https://www.theconstruct.ai/robotics-ambassador/

何を学ぶか

このチュートリアルでは、YAML を使用して起動ファイルを作成および実行する方法を学習します。

環境

ROS2 Humble
rosject link https://app.theconstruct.ai/l/602c1f4b/

パッケージを作る

以下のコマンドでパッケージを作りましょう。

$ ros2 create pkg simple_yaml_launch

CMakeLists.txt と package.xml

CMakeListsを編集して、launchファイルをinstallディレクトリの適切な場所に設置するよう設定します。。

cmake:CMakeLists.txt
cmake_minimum_required(VERSION 3.8)
project(simple_yaml_launch)

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
endif()

find_package(ament_cmake_auto REQUIRED)

ament_auto_package(
INSTALL_TO_SHARE launch
)

package.xmlを編集してament_cmake_autoを使う設定をします。

xml:package.xml
<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
  <name>simple_yaml_launch</name>
  <version>0.0.0</version>
  <description>TODO: Package description</description>
  <maintainer email="user@todo.todo">user</maintainer>
  <license>TODO: License declaration</license>

  <buildtool_depend>ament_cmake_auto</buildtool_depend>

  <test_depend>ament_lint_auto</test_depend>
  <test_depend>ament_lint_common</test_depend>

  <export>
    <build_type>ament_cmake</build_type>
  </export>
</package>

launch ファイルを記述する

lanchファイルを作成しましょう

bash
cd ~/ros2_ws/src/simple_yaml_launch
mkdir launch
touch launch/turtle_sim_run.launch.yaml

作成したYAMLファイルを以下の様に編集します。
基本的にXMLでlaunchを記述する内容をYAMLに対応させていけば記述できます。

yaml:turtle_sim_run.launch.yaml
launch:
- node:
pkg: "turtlesim"
exec: "turtlesim_node"
name: "sim"
namespace: "turtle1"
コンパイルと実行

以下のコマンドでコンパイルを行います。

bash
cd ~/ros2_ws/
colcon build

無事コンパイルできたら、以下のコマンドで実行してみましょう。
turtle_simの画面が表示できたら成功です。

bash
. install/setup.bash
ros2 launch simple_yaml_launch turtle_sim_run.launch.yaml

別のターミナルを開いて以下のコマンドでturtlesimにトピックを送信してみます。
カメが円を描いて動いたら成功です。

bash
ros2 topic pub -r 1 /turtlesim1/turtle1/cmd_vel geometry_msgs/msg/Twist "{linear: {x: 2.0, y: 0.0, z: 0.0}, angular: {x: 0.0, y: 0.0, z: -1.8}}"

 

Video Tutorial

Topics: ros2 | yaml
Masterclass 2023 batch2 blog banner

Check Out These Related Posts

0 Comments

Pin It on Pinterest

Share This