1.launch文件实例:
from launch import LaunchDescription
from launch_ros.actions import Node
def generate_launch_description():
return LaunchDescription([
Node(
package='turtlesim',
namespace='turtlesim1',
executable='turtlesim_node',
name='sim'
),
Node(
package='turtlesim',
namespace='turtlesim2',
executable='turtlesim_node',
name='sim'
),
Node(
package='turtlesim',
executable='mimic',
name='mimic',
remappings=[
('/input/pose', '/turtlesim1/turtle1/pose'),
('/output/cmd_vel', '/turtlesim2/turtle1/cmd_vel'),
]
)
])
首先:固定部分,不必多言
from launch import LaunchDescription
from launch_ros.actions import Node
接下来是launch文件起始的描述:
def generate_launch_description():
return LaunchDescription([
])
某一个节点node:
Node(
package='turtlesim',
namespace='turtlesim1',
executable='turtlesim_node',
name='sim'
),
namespace:命名空间,只要命名空间不同,就不存在节点名或话题的冲突。
package:节点所在的功能包
executable:功能包内要运行的可执行文件名
name:启动后的节点名
最后一个节点:
Node(
package='turtlesim',
node_executable='mimic',
name='mimic',
remappings=[
('/input/pose', '/turtlesim1/turtle1/pose'),
('/output/cmd_vel', '/turtlesim2/turtle1/cmd_vel'),
]
)
remapping:重映射,mimic的输入话题从/input/pose重映射为/turtlesim1/turtle1/pose,输出话题从/output/cmd_vel重映射为/turtlesim2/turtle1/cmd_vel。我们基本可以猜到,mimic节点通过订阅turtle1的位置(重映射为/turtlesim1/turtle1/pose),转换成对turtle2的速度指令(充盈设为/turtlesim2/turtle1/cmd_vel)发布出去,最后应该可以达到让turtle2模仿turtle1完成同样的运动。
可考虑用于加载多个机器人。