first_package에서 launch 디렉토리를 생성합니다.
launch 디렉토리 안에서 first.launch.py 파일을 생성합니다.
from launch import LaunchDescription
from launch_ros.actions import Node
def generate_launch_description():
return LaunchDescription(
[
Node(namespace= "turtlesim", package='turtlesim',
xecutable='turtlesim_node', output='screen'),
Node(namespace= "pub_cmd_vel", package='first_package',
executable='my_publisher', output='screen'),
]
)
from setuptools import setup
import os # 추가
import glob # 추가
package_name = 'first_package'
setup(
name=package_name,
version='0.0.0',
packages=[package_name],
data_files=[
('share/ament_index/resource_index/packages',
['resource/' + package_name]),
('share/' + package_name, ['package.xml']),
#추가
('share/' + package_name + '/launch', glob.glob(os.path.join('launch','*.launch.py')))
],
colcon build --packages-select first_package
ros2 launch first_package first.launch.py