## 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 = 通用状态 ## multi-line description to be displayed in search ## description = 本教程将展示如何实现一个通用SMACH状态 ## the next tutorial description (optional) ## next = ## links to next tutorial (optional) ## next.0.link=[[cn/smach/Tutorials/CBState|CB 状态]] ## next.1.link= ## what level user is this tutorial for ## level= BeginnerCategory ## keywords = #################################### <<IncludeCSTemplate(TutorialCSHeaderTemplate)>> {{{#!python from smach import State }}} 创建状态的最一般(但通常最低效)的方法是从'状态'基类派生出来。在状态的执行方法中,你可以做任何你想做的事情。要知道,SMACH附带了一个有用的状态库,你可以使用它,而不必编写一个完整的自定义状态。 {{{ #!python class Foo(smach.State): def __init__(self, outcomes=['outcome1', 'outcome2']): # Your state initialization goes here def execute(self, userdata): # Your state execution goes here if xxxx: return 'outcome1' else: return 'outcome2' }}} 一些好的代码实践: * 不要在构造函数中阻塞。如果你的状态需要等待另一个组件出现,请在单独的线程中执行此操作。 ## AUTOGENERATED DO NOT DELETE ## TutorialCategory ## FILL IN THE STACK TUTORIAL CATEGORY HERE ## SMACHStatesCategory