image_base_probing_garnics_demo.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 import roslib; 
00004 roslib.load_manifest('zyonz_apps')
00005 import rospy
00006 import smach
00007 import smach_ros
00008 import tf
00009 from pprint import pprint
00010 from std_msgs.msg import String, Int8, Int32
00011 
00012 from iri_common_smach.get_keystroke import GetKeyStroke
00013 from zyonz_apps_base.probing        import SM_ZYONZ_FullProbing
00014 from zyonz_apps_base.move           import SM_ZYONZ_GoHome
00015 
00016 from smach import StateMachine, CBState, Iterator
00017 
00018 class LogResult(smach.State):
00019     def __init__(self):
00020         smach.State.__init__(self, outcomes = ['ok'])
00021 
00022     def execute(self, userdata):
00023         keyserver = GetKeyStroke()
00024         c = -1
00025         print "Press 0 -> fail or 1 -> success"
00026         while ((c < 0) or (c > 1)):
00027             c = keyserver()
00028             try:
00029                 c = int(c)
00030             except ValueError:
00031                 continue
00032 
00033         print "Your value was: " + str(c)
00034         pub = rospy.Publisher('/log/result', Int8, None, False, True)
00035         pub.publish(c)
00036 
00037         return 'ok'
00038 
00039 def construct_main_sm():
00040     # MAIN STATE MACHINE
00041     sm = StateMachine(outcomes = ['continue','aborted','succeeded'])
00042     sm.userdata.rounds = 10
00043 
00044     factory         = SM_ZYONZ_FullProbing()
00045     sm_full_probing = factory.build_sm()
00046 
00047     with sm:
00048         round_iterator = Iterator(outcomes = ['succeeded','aborted'],
00049                                    input_keys = [],
00050                                    it = range(0, sm.userdata.rounds),
00051                                    output_keys = [],
00052                                    it_label = 'index',
00053                                    exhausted_outcome = 'succeeded')
00054         with round_iterator:
00055             container_sm = StateMachine(outcomes = ['succeeded','aborted','continue'])
00056 
00057             with container_sm:
00058                 smach.StateMachine.add('FULL_PROBING_ACTION', sm_full_probing,
00059                          transitions={'succeeded' : 'LOG_RESULT',
00060                                       'aborted'   : 'aborted',
00061                                       'no_kinematic_solution' : 'LOG_RESULT'})
00062                 smach.StateMachine.add('LOG_RESULT', LogResult(),
00063                         transitions={'ok' : 'continue'})
00064 
00065             #close container_sm
00066             Iterator.set_contained_state('CONTAINER_STATE',
00067                                          container_sm,
00068                                          loop_outcomes=['continue'])
00069         #close the round_iterator
00070         StateMachine.add('ROUND_ITERATOR',round_iterator,
00071                      {'succeeded':'succeeded',
00072                       'aborted':'aborted'})
00073     return sm
00074 
00075 def main():
00076     rospy.init_node("base_probing_sm")
00077     sm_main = construct_main_sm()
00078 
00079     # Run state machine introspection server for smach viewer
00080     sis = smach_ros.IntrospectionServer('zyonz_smach_base_probing', sm_main,
00081                                         '/zyonz_image_based_leaf_probing')
00082 
00083     sis.start()
00084 
00085     outcome = sm_main.execute()
00086 
00087     rospy.spin()
00088     sis.stop()
00089 
00090 if __name__ == "__main__":
00091     main()


zyonz_apps
Author(s): sfoix
autogenerated on Fri Dec 6 2013 23:27:41