roslaunch的写法

launch目录里创建launch文件或py文件后,ros2 launch不能直接找到,会报错

1
file 'file.launch' was not found in the share directory of package 'package_name' which is at '/home/user/catkin_ws/install/package_name/share/package_name'

需要在CMakeLists里加一句
1
2
install(DIRECTORY launch
DESTINATION share/${PROJECT_NAME})

再编译后,会把launch文件复制到share目录里。

  • 使用xml
1
2
3
4
5
6
7
8
<launch>
<node pkg="nav2_map_server" exec="map_server" name="map_server">
<param name="yaml_filename" value="/home/zzp/catkin_ws/maps/test.yaml"/>
</node>

<node pkg="nav2_planner" exec="planner_server" name="planner_server" >
</node>
</launch>

args的写法一直查不到,按ROS1的写法是错的,节点会退出: <node pkg ="tf2_ros" exec="static_transform_publisher" name="map_odom_tf" args="1 0 0 0 0 0 map odom 100" />

  • 使用python
1
2
3
cd ~/ros2_ws
mkdir launch
vim launch/both_launch.py

加入下面内容:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
from launch import LaunchDescription
from launch_ros.actions import Node

def generate_launch_description():
return LaunchDescription([
Node(
package='duckiebot',
namespace='duckietown',
executable='duckiebot_node',
name='duckiebot_node1'
),
Node(
package='control',
namespace='duckietown',
executable='control_node',
name='control_node1'
)
])