Please ask about problems and questions regarding this tutorial on answers.ros.org. Don't forget to include in your question the link to this page, the versions of your OS & ROS, and also add appropriate tags. |
通用状态
Description: 本教程将展示如何实现一个通用SMACH状态
Tutorial Level: BEGINNER
Next Tutorial: CB 状态
1 from smach import State
创建状态的最一般(但通常最低效)的方法是从'状态'基类派生出来。在状态的执行方法中,你可以做任何你想做的事情。要知道,SMACH附带了一个有用的状态库,你可以使用它,而不必编写一个完整的自定义状态。
1 class Foo(smach.State):
2 def __init__(self, outcomes=['outcome1', 'outcome2']):
3
4
5 def execute(self, userdata):
6
7 if xxxx:
8 return 'outcome1'
9 else:
10 return 'outcome2'
一些好的代码实践:
- 不要在构造函数中阻塞。如果你的状态需要等待另一个组件出现,请在单独的线程中执行此操作。