## For instruction on writing tutorials ## http://www.ros.org/wiki/WritingTutorials #################################### ##FILL ME IN #################################### ## for a custom note with links: ## note = ## for the canned note of "This tutorial assumes that you have completed the previous tutorials:" just add the links ## note.0= ## descriptive title for the tutorial ## title = StateMachine容器 ## multi-line description to be displayed in search ## description = 本教程教会你如何使用!StateMachine容器. ## the next tutorial description (optional) ## next = ## links to next tutorial (optional) ## next.0.link=[[cn/smach/Tutorials/Concurrence container|Concurrence容器]] ## next.1.link= ## what level user is this tutorial for ## level= BeginnerCategory ## keywords = #################################### <<IncludeCSTemplate(TutorialCSHeaderTemplate)>> <<TableOfContents(4)>> == 创建状态机 == 首先加载状态机: {{{#!python from smach import StateMachine }}} SMACH !StateMachine也提供了一个状态接口,它的结果和用户数据交互必须在构造上指定 {{{#!python sm = StateMachine(outcomes = ['outcome1', 'outcome2'], input_keys = ['input1', 'input2'], output_keys = ['output1', 'output2']) }}} 和SMACH状态接口类似,输入键和输出键是可选的。构造函数模板如下: {{{#!python __init__(self, outcomes, input_keys=[], output_keys=[]) }}} == 添加状态 == 当向状态机添加状态时,首先指定要添加状态的状态机。这可以通过使用Python的"with"语句完成。你可以把它想象成"opening"容器来构造。它创建了一个上下文,其中所有后续的add*调用都将应用于打开的容器。 例如,要将两个状态添加到一个名为"sm"的状态机,你可以编写以下内容: {{{#!python with sm: StateMachine.add('FOO', FooState(), {'outcome2':'FOO', 'outcome3':'BAR'}) StateMachine.add('BAR', BarState(), {'outcome3':'FOO', 'outcome4':'outcome2'}) }}} 上面的示例分别添加了"FOO"和"BAR"的两个状态,分别是"FooState"和"BarState"。静态添加方法有可选参数。添加方法的签名如下: {{{#!python add(label, state, transitions=None, remapping=None) }}} 有关转换的详细信息,请查看[[smach/Tutorials/Getting Started|开始指南]] 有关映射的详细信息,请查看[[smach/Tutorials/User Data|用户数据]] ## AUTOGENERATED DO NOT DELETE ## TutorialCategory ## FILL IN THE STACK TUTORIAL CATEGORY HERE ## SMACHContainerCategory