pionner_probing.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 import roslib; roslib.load_manifest('zyonz_apps')
00003 import rospy
00004 import smach
00005 import smach_ros
00006 import copy
00007 
00008 from smach import Iterator
00009 from smach_ros import ServiceState
00010 from iri_wam_smach.sm_wam_move_from_pose import SM_WAM_MoveFromPose
00011 from geometry_msgs.msg import PoseStamped
00012 from iri_common_smach.st_sleep import WaitSeconds
00013 
00014 class SM_ESTIRABOT_ApproachAndCatch():
00015     def __init_(self):
00016         pass
00017 
00018     def build_internal_sm(self):
00019         sm_move_factory = SM_WAM_MoveFromPose('/estirabot/wam_wrapper/joints_move',
00020                                               '/estirabot/wam_ik/pose_move')
00021         sm_move         = sm_move_factory.build_sm()
00022 
00023         sm = smach.StateMachine(outcomes   = ['aborted','continue'],
00024                                 input_keys = ['approach_pose_st','catch_pose_st','lift_pose_st'])
00025 
00026         with sm:
00027              smach.StateMachine.add('GO_TO_APPROACH', sm_move,
00028                      transitions = {'success' : 'WAIT_AFTER_APPROACH',
00029                                     'aborted': 'aborted'},
00030                      remapping   = {'pose_st': 'approach_pose_st'})
00031 
00032              smach.StateMachine.add('WAIT_AFTER_APPROACH', WaitSeconds(1),
00033                      transitions = {'finish' : 'GO_TO_CATCH'})
00034 
00035              smach.StateMachine.add('GO_TO_CATCH', sm_move,
00036                      transitions = {'success' : 'WAIT_AFTER_CATCH',
00037                                     'aborted'   : 'aborted'},
00038                      remapping   = {'pose_st': 'catch_pose_st'})
00039 
00040              smach.StateMachine.add('WAIT_AFTER_CATCH', WaitSeconds(1),
00041                      transitions = {'finish' : 'GO_TO_LIFT'})
00042 
00043              smach.StateMachine.add('GO_TO_LIFT', sm_move,
00044                      transitions = {'success' : 'WAIT_AFTER_LIFT',
00045                                     'aborted'   : 'aborted'},
00046                      remapping   = {'pose_st': 'lift_pose_st'})
00047 
00048              smach.StateMachine.add('WAIT_AFTER_LIFT', WaitSeconds(1),
00049                      transitions = {'finish' : 'GO_TO_CATCH_RETURN'})
00050 
00051              smach.StateMachine.add('GO_TO_CATCH_RETURN', sm_move,
00052                      transitions = {'success' : 'WAIT_AFTER_CATCH_RETURN',
00053                                     'aborted'   : 'aborted'},
00054                      remapping   = {'pose_st': 'catch_pose_st'})
00055 
00056              smach.StateMachine.add('WAIT_AFTER_CATCH_RETURN', WaitSeconds(1),
00057                      transitions = {'finish' : 'FINAL_POSITION'})
00058 
00059              smach.StateMachine.add('FINAL_POSITION', sm_move,
00060                      transitions = {'success' : 'continue',
00061                                     'aborted': 'aborted'},
00062                      remapping   = {'pose_st': 'approach_pose_st'})
00063 
00064         return sm
00065 
00066     def build_iterator(self):
00067         iterator = Iterator(outcomes = ['success','aborted'],
00068                          input_keys = ['approach_pose_st','catch_pose_st','lift_pose_st'],
00069                          it = range(0, 3),
00070                          output_keys = [],
00071                          it_label = 'index',
00072                          exhausted_outcome = 'success')
00073         with iterator:
00074             iterator.set_contained_state('RUN_STEPS',
00075                                         self.build_internal_sm(),
00076                                         loop_outcomes=['continue'])
00077         return iterator
00078 
00079     def build_sm(self):
00080         sm = smach.StateMachine(outcomes = ['succeeded','aborted'],
00081                                 input_keys = [])
00082 
00083         catch = PoseStamped()
00084         catch.header.frame_id = 'wam_link0'
00085         catch.pose.position.x = 0.825
00086         catch.pose.position.y = 0.052
00087         catch.pose.position.z = -0.210
00088         catch.pose.orientation.x = 0.680
00089         catch.pose.orientation.y = -0.014
00090         catch.pose.orientation.z = 0.731
00091         catch.pose.orientation.w = -0.024
00092 
00093         app = copy.deepcopy(catch)
00094         app.pose.position.x = catch.pose.position.x - 0.07
00095 
00096         lift = copy.deepcopy(catch)
00097         lift.pose.position.z = catch.pose.position.z + 0.05
00098 
00099         sm.userdata.approach_pose_st = app
00100         sm.userdata.catch_pose_st    = catch
00101         sm.userdata.lift_pose_st     = lift
00102 
00103         sm_iterator = self.build_iterator()
00104 
00105         with sm:
00106             smach.StateMachine.add('APP_CONTAINER', sm_iterator,
00107                 transitions = { 'success' : 'succeeded' })
00108 
00109         return sm
00110 
00111 def main():
00112     rospy.init_node("base_probing_sm")
00113     sm_grab_factory = SM_ESTIRABOT_ApproachAndCatch()
00114     sm_main = sm_grab_factory.build_sm()
00115 
00116     sis = smach_ros.IntrospectionServer('estirabot_smach_probing', sm_main,
00117                                       '/estirabot_smach_probing')
00118     sis.start()
00119 
00120     outcome = sm_main.execute()
00121 
00122     rospy.spin()
00123     sis.stop()
00124 
00125 if __name__ == "__main__":
00126     main()


estirabot_apps
Author(s): Jose Luis Rivero
autogenerated on Fri Dec 6 2013 23:20:59