0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

はじめに

  • ROS2のパラメータでネスト化された(入れ子構造)パラメータを利用する方法
  • カテゴリごとに階層化して、パラメータを見やすくする際に便利

動作確認環境

  • ROS2 Dashing/Foxy

方法

YAMLファイルの記述方法と、ノードパラメータ宣言方法を各々示す。

YAMLパラメータファイルの記述

test_node:
    ros__parameters:
        category:
            int_value: 1
            str_value: "test"

ノードパラメータの宣言

.でパラメータをつなぐことでネスト化する。今回の例は2階層なので、.は1つだが、3階層以上の場合は、.を2つつなげることで可能(詳細は参考を参照)。

C++ (rclcpp)

rclcpp::Node

this->declare_parameter<int>("category.int_value", 0)
this->declare_parameter<std::string>("category.str_value", "")

Python (rclpy)

rclpy.Node

declare_parameter('category.int_value', 0).value
declare_parameter('category.str_value', '').value

まとめ

 パラメータをネスト化する方法を紹介した。1つのノード内で、パラメータをカテゴリ分けして視認性をよくするのみ便利。

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?