sequence.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 """
00003 Description:
00004     Create a simple 3-state state sequence. A Sequence is a StateMachine
00005     that just assumes that states added in some sequence should be
00006     executed in the order in which they were added, but only if they
00007     return the "connector outcome" given in the Sequence constructor.
00008 
00009 Usage:
00010     $> ./sequence.py
00011 
00012 Output:
00013     [INFO] : State machine starting in initial state 'FOO' with userdata: 
00014             []
00015     [INFO] : State machine transitioning 'FOO':'done'-->'BAR'
00016     [INFO] : State machine transitioning 'BAR':'done'-->'BAZ'
00017     [INFO] : State machine terminating 'BAZ':'done':'succeeded'
00018 """
00019 
00020 import roslib; roslib.load_manifest('asmach_tutorials')
00021 import rospy
00022 import asmach as smach
00023 import smach_ros
00024 
00025 class ExampleState(smach.State):
00026     def __init__(self):
00027         smach.State.__init__(self, outcomes = ['done'])
00028     def execute(self, ud):
00029         return 'done'
00030 
00031 def main():
00032     rospy.init_node('smach_example_sequence')
00033 
00034     # Create a SMACH state machine
00035     sq = smach.Sequence(
00036             outcomes = ['succeeded'],
00037             connector_outcome = 'done')
00038 
00039     # Open the container
00040     with sq:
00041         # Add states to the container
00042         smach.Sequence.add('FOO', ExampleState())
00043         smach.Sequence.add('BAR', ExampleState())
00044         smach.Sequence.add('BAZ', ExampleState(), {'done':'succeeded'})
00045 
00046     # Execute SMACH plan
00047     outcome = sq.execute()
00048 
00049 if __name__ == '__main__':
00050     main()


asmach_tutorials
Author(s): Jonathan Bohren
autogenerated on Thu Jan 2 2014 11:27:48