Artefacts ツールキットの設定ヘルパー
Artefacts ツールキットの設定ヘルパーは、 artefacts.yaml
Artefacts ツールキットの設定ヘルパーは、
インポート方法:
from artefacts_toolkit.config import get_artefacts_param
関数
関数リファレンス
get_artefacts_param
artefacts.yaml
ファイルで設定されたパラメータを返します。 param_type
が launch
に設定されている場合、ROS の起動引数として使用できるように string
型で返されます。
この関数はパラメトリックテストに特に役立ちます。 artefacts.yaml
ファイルでパラメータ値のリストを定義すると(例:launch/world: ["empty.sdf", "bookstore.sdf", "restaurant.sdf"]
)、 artefacts run
コマンドはリスト内の各値に対して1回ずつ、テストを複数回実行します。各テスト実行中、 get_artefacts_param("launch", "world")
は自動的にその特定のテスト実行に対する現在のパラメータ値を返します。
これはグリッドベースのテストに特に強力です!それぞれ3つの可能な値を持つ3つのパラメータがある場合、Artefacts は自動的にテストを27回(3 × 3 × 3)実行しますが、起動ファイルのコードは変更されません。
get_artefacts_param(
param_type,
param_name,
default=None,
is_ros=True
)
パラメータ
パラメータ | 型 | 説明 | デフォルト |
---|---|---|---|
param_type |
str |
パラメータの名前空間/カテゴリ(例:「launch/world」の「launch」) | 必須 |
param_name |
str |
T特定のパラメータ名(例:「launch/world」の「world」) | 必須 |
default |
any |
artefacts.yamlでパラメータが見つからない場合に返す値 | None |
is_ros |
bool |
パラメータをROS パラメータ形式に変換するかどうか | True |
戻り値
この関数は次の動作でパラメータ値を返します:
param_type
が"launch"
でis_ros
がTrue
の場合:artefacts.yaml
ファイルの元の型に関係なく、値をstr
として返します。これはROS起動引数として使用できるようにするためです。default
がNone
以外に設定されている場合、artefacts が要求されたパラメータを見つけられない場合に値が返されます。これは(例えば)artefacts run
の代わりにlaunch_test
を使用しているがコード変更を行いたくない場合に便利です。また、KeyError
例外を防ぎます。- その他のすべての場合:YAMLファイルの元の型(例:
list
、dict
、int
、float
、str
など)で値を返します。
Note
- 現在はROS パラメータ / ROS起動引数のみをサポートしています。
- パラメトリックテストは、artefactsをローカルで実行する場合、順次実行されます。プラットフォーム上で実行する場合、並行して実行されます(同時実行テストの最大数はサブスクリプションプランによって決まります)。
例
以下の設定が設定された artefacts.yaml
ファイルがある場合:
scenarios:
defaults:
output_dirs: ["output"]
metrics:
- /odometry_error
params:
launch/world: ["bookstore.sdf", "empty.sdf"]
テスト起動ファイルでパラメータを次のように取得します:
def generate_test_description():
try:
world = get_artefacts_param("launch", "world")
except FileNotFoundError:
world = "empty.world"
run_headless = LaunchConfiguration("run_headless")
launch_navigation_stack = IncludeLaunchDescription(
PythonLaunchDescriptionSource(
[
os.path.join(
get_package_share_directory("sam_bot_nav2_gz"),
"launch",
"complete_navigation.launch.py"
),
]
),
launch_arguments=[("run_headless", run_headless), ("world_file", world)],
)
...# Rest of launch test file
This will run the same test twice - once in an empty world and once in a bookstore world - without any changes to your launch file code between runs.