ROS进二阶学习笔记- SMACH:用状态机来管理机器人任务
Posted Sonictl
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ROS进二阶学习笔记- SMACH:用状态机来管理机器人任务相关的知识,希望对你有一定的参考价值。
ROS进二阶学习笔记(2) - SMACH:用状态机来管理机器人任务
http://wiki.ros.org/smach/Tutorials/Getting Started
http://wiki.ros.org/smach/Tutorials好久没有更新关于ROS的笔记,这里进入SMACH的学习和应用,参照rbx2(ros by example volume 2),和ROS官方wiki,进行学习。
====
关于概念
SMACH states是Python类,通过重写execute()方法来返回一个或多个可能的outcomes, 从而扩展smach.State类。 excute() 方法也可以通过可选的参数来来定义一个userdata集合,这个集合可以被用来传递状态之间的信息。本质上讲,状态执行的实际计算基本上可以是任何你想要的。并且,有很多预先定义好的state types ,这可以节省大量的非必须的代码。
- A SMACH state machine is another Python class (smach.StateMachine) that can contain a number of states.
- A state is added to a state machine by defining a set of transitions from the state's outcomes to other states in the machine.
When a state machine is run, these transitions determine the flow of execution from state to state:
input → STATE_1 → outcome, transition → STATE_2
input → STATE_2 → outcome, transition → STATE_3
etc.
预先实现的状态库
Smach comes with a whole library of pre-implemented states that cover many common usecases:
- 特别是SimpleActionState 类,把一个普通的ROS action 变成了一个SMACH 状态。
- 类似的,MonitorState 类封装了ROS topic;
- ServiceState类处理ROS Services;
- CBState 使用 @smach.cb_interface 装饰器使得你可以将几乎任何函数都变成一个SMACH 状态。
Container
To create a Smach state machine, you first create a number of states, and then add those states to a State Machine container.
There are a number of predefined SMACH containers that can also save you a lot of programming.
- The Concurrence 协作 container returns an outcome that depends on more than one state and allows one state to preempt抢占 another.
- The Sequence 序列 container automatically generates sequential transitions among the states that are added to it.
- The Iterator 迭代 container allows you to loop through one or more states until some condition is met.
We will learn more about these containers as we need them.
以上是关于ROS进二阶学习笔记- SMACH:用状态机来管理机器人任务的主要内容,如果未能解决你的问题,请参考以下文章