Chinaunix首页 | 论坛 | 博客
  • 博客访问: 9145885
  • 博文数量: 1725
  • 博客积分: 12961
  • 博客等级: 上将
  • 技术积分: 19840
  • 用 户 组: 普通用户
  • 注册时间: 2009-01-09 11:25
个人简介

偷得浮生半桶水(半日闲), 好记性不如抄下来(烂笔头). 信息爆炸的时代, 学习是一项持续的工作.

文章分类

全部博文(1725)

文章存档

2024年(1)

2023年(26)

2022年(112)

2021年(217)

2020年(157)

2019年(192)

2018年(81)

2017年(78)

2016年(70)

2015年(52)

2014年(40)

2013年(51)

2012年(85)

2011年(45)

2010年(231)

2009年(287)

分类: 其他平台

2020-06-18 10:49:51

用python写的launch文件可以启动和停止不同的节点,以及触发和操作各种事件。提供这个框架的包是launch_ros.   sudo apt install ros-foxy-launch-ros

通过 ros2 pkg create  --dependencies [deps] 会自动建立 launch 目录.

在 Python 中, 需要在 setup.py中加入data_files, 然后colcon 识别到 launch文件.

点击(此处)折叠或打开

  1. import os
  2. from glob import glob
  3. from setuptools import setup

  4. package_name = 'my_package'

  5. setup(
  6.     # Other parameters ...
  7.     data_files=[
  8.         # ... Other data files
  9.         # Include all launch files. This is the most important line
  10.         (os.path.join('share', package_name), glob('launch/*.launch.py'))
  11.     ]
  12. )
然后建立 my_script.launch.py 文件. 这种文件和 launch 文件的规则不同, 

点击(此处)折叠或打开  my_script.launch.py

  1. import launch
  2. import launch.actions
  3. import launch.substitutions
  4. import launch_ros.actions

  5. def generate_launch_description():
  6.     return launch.LaunchDescription([
  7.         launch.actions.DeclareLaunchArgument(
  8.             'node_prefix',
  9.             default_value=[launch.substitutions.EnvironmentVariable('USER'), '_'],
  10.             description='Prefix for node names'),
  11.         launch_ros.actions.Node(
  12.             package='demo_nodes_cpp', executable='talker', output='screen',
  13.             name=[launch.substitutions.LaunchConfiguration('node_prefix'), 'talker']),
  14.     ])
然后使用 
    
ros2 launch my_package script.launch.py
阅读(1838) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~