4
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

ROS2 launchファイルの作成

Last updated at Posted at 2020-05-01

ROS2でプログラミングするために勉強したメモです.
ここでは,launchファイルの作成方法を書きます.

A. 準備

1. 起動するフォルダを作成

mkdir launch

2. 起動ファイルを作成

touch launch/<〜launch.py>
  • <〜launch.py>には好きな名前を書く.

B. launchファイルを記述

まず最初に,完成形を示す.つぎにテンプレートを示す.

3. フレームの記述

例) 公式TutorialのLaunchファイル
from launch import LaunchDescription
from launch_ros.actions import Node

def generate_launch_description():
    return LaunchDescription([
        Node(
            package='turtlesim',
            node_namespace='turtlesim1',
            node_executable='turtlesim_node',
            node_name='sim'
        ),
        Node(
            package='turtlesim',
            node_namespace='turtlesim2',
            node_executable='turtlesim_node',
            node_name='sim'
        ),
        Node(
            package='turtlesim',
            node_executable='mimic',
            node_name='mimic',
            remappings=[
                ('/input/pose', '/turtlesim1/turtle1/pose'),
                ('/output/cmd_vel', '/turtlesim2/turtle1/cmd_vel'),
            ]
        )
    ])
参考サイト
テンプレート
# 必要なpythonモジュールをインポート
from launch import LaunchDescription
from launch_ros.actions import Node
# 以下に起動に関する詳細を記述
def generate_launch_description():
   return LaunchDescription([

   ])

4. nodeの記述

例) 公式TutorialのLaunchファイル
Node(
    package='turtlesim',
    node_namespace='turtlesim1',
    node_executable='turtlesim_node',
    node_name='sim'
),
Node(
    package='turtlesim',
    node_namespace='turtlesim2',
    node_executable='turtlesim_node',
    node_name='sim'
),
Node(
    package='turtlesim',
    node_executable='mimic',
    node_name='mimic',
    remappings=[
      ('/input/pose', '/turtlesim1/turtle1/pose'),
      ('/output/cmd_vel', '/turtlesim2/turtle1/cmd_vel'),
    ]
)
  • 名前空間を分けることで,node_nameやtopic_nameの競合を回避できる.
  • topicを再マッピングできる.
テンプレート
Node(
    package='',
    node_namespace='',
    node_executable='',
    node_name=''
    remappings=[
        ('', ''),
        ('', ''),
    ]
)

参考サイト

4
5
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
4
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?