ROS2轻松学2-工具篇15-lifecycle演示讲义
ROS2轻松学2-工具篇15-lifecycle演示讲义
说明:
- 介绍如何认识lifecycle
- lifecycle在于给节点增加一个生命周期管理,通过状态来更好控制节点处理流程
参考:
lifecycle
- lifecycle帮助
ros2 lifecycle -h
一步演示示例:
- 启动一步演示,完成生命周期管理
ros2 launch lifecycle lifecycle_demo.launch.py
分布步演示示例:
- 启动talker
ros2 run lifecycle lifecycle_talker
- 启动listener
ros2 run lifecycle lifecycle_listener
- 查看节点
ros2 lifecycle node
- 查看节点状态
ros2 lifecycle get /lc_talker
- 查看可用状态
ros2 lifecycle list lc_talker #查看可用状态机
ros2 lifecycle list lc_talker -a #查看完整状态机
- 按顺序设置状态
ros2 lifecycle set /lc_talker configure
ros2 lifecycle set /lc_talker activate
ros2 lifecycle set /lc_talker deactivate
ros2 lifecycle set /lc_talker cleanup
ros2 lifecycle set /lc_talker shutdown
- 按顺序执行,控制节点运行流程
- 通过服务调用来获取状态
ros2 service call /lc_talker/get_state lifecycle_msgs/srv/GetState
- 通过服务调用来设置状态
ros2 service call /lc_talker/change_state lifecycle_msgs/ChangeState "{transition: {id: 1}}"
ros2 service call /lc_talker/change_state lifecycle_msgs/ChangeState "{transition: {id: 3}}"
ros2 service call /lc_talker/change_state lifecycle_msgs/ChangeState "{transition: {id: 4}}"
ros2 service call /lc_talker/change_state lifecycle_msgs/ChangeState "{transition: {id: 2}}"
ros2 service call /lc_talker/change_state lifecycle_msgs/ChangeState "{transition: {id: 5}}"
- ID: 1-configure 3-activate 4-deactivate 2-cleanup 5-6-7-shutdown
- 找到对应的变换id
ros2 interface show lifecycle_msgs/msg/Transition
ros2 lifecycle list lc_talker -a
获取最新文章: 扫一扫右上角的二维码加入“创客智造”公众号