7 import std_msgs.msg
as std_msg
8 import std_srvs.srv
as std_srv
9 import geometry_msgs.msg
as geometry_msg
11 from actionlib
import *
17 '''Check for the object detection result to retry if no objects where detected''' 20 smach.State.__init__(self, outcomes=[
'preempted',
'satisfied',
'fold_arm',
'retry'],
21 input_keys=[
'od_attempt',
'obj_names'],
22 output_keys=[
'od_attempt'])
26 if self.preempt_requested():
27 self.service_preempt()
29 if len(userdata.obj_names) > 0:
30 userdata.od_attempt = 0
32 userdata.od_attempt += 1
33 if userdata.od_attempt == 1:
38 '''Different starts of the SM depending on the command provided when calling 39 the actionlib wrapper. TODO: I think this can be done w/o creating a class...''' 41 smach.State.__init__(self, outcomes=[
'start',
'reset',
'fold',
'quit'],
42 input_keys=[
'user_command'])
45 rospy.loginfo(
"Executing User Command '%s'", ud[
'user_command'].command)
46 return ud[
'user_command'].command
49 rospy.init_node(
'object_manipulation_smach')
53 sm = smach.StateMachine(outcomes=[
'quit',
'error',
'aborted',
'preempted'],
54 input_keys = [
'user_command'], output_keys = [
'ucmd_outcome'])
57 sm.userdata.user_command = UserCommandGoal()
58 sm.userdata.ucmd_outcome = UserCommandResult()
59 sm.userdata.od_attempt = 0
60 sm.userdata.frame = rospy.get_param(
'~arm_link',
'/arm_link')
61 sm.userdata.obj_names = []
62 sm.userdata.obj_name = std_msg.String()
63 sm.userdata.header = std_msg.Header()
64 sm.userdata.pick_pose = geometry_msg.Pose()
65 sm.userdata.place_pose = geometry_msg.Pose()
66 sm.userdata.named_pose_target_type = MoveToTargetGoal.NAMED_TARGET
67 sm.userdata.arm_folded_named_pose =
'resting' 69 smach.StateMachine.add(
'ExecuteUserCommand',
71 transitions={
'start':
'ObjectDetection',
72 'reset':
'ObjectDetection',
74 'quit':
'FoldArmAndQuit'})
78 od_sm = smach.StateMachine(outcomes = [
'succeeded',
'preempted',
'aborted'],
79 input_keys = [
'od_attempt',
'frame',
'obj_names',
80 'named_pose_target_type',
'arm_folded_named_pose'],
81 output_keys = [
'obj_names'])
83 smach.StateMachine.add(
'ObjectDetectionOnce',
84 smach_ros.SimpleActionState(
'object_detection',
85 ObjectDetectionAction,
87 result_slots=[
'obj_names']),
88 remapping={
'frame':
'frame',
89 'obj_names':
'obj_names'},
90 transitions={
'succeeded':
'ObjDetectedCondition',
91 'preempted':
'preempted',
94 smach.StateMachine.add(
'ObjDetectedCondition',
96 remapping={
'obj_names':
'obj_names'},
97 transitions={
'satisfied':
'succeeded',
98 'preempted':
'preempted',
99 'fold_arm':
'ObjDetectionFoldArm',
100 'retry':
'ObjectDetectionOnce'})
102 smach.StateMachine.add(
'ObjDetectionFoldArm',
103 smach_ros.SimpleActionState(
'move_to_target',
105 goal_slots=[
'target_type',
'named_target']),
106 remapping={
'target_type':
'named_pose_target_type',
107 'named_target':
'arm_folded_named_pose'},
108 transitions={
'succeeded':
'ObjectDetectionOnce',
109 'preempted':
'preempted',
110 'aborted':
'ObjectDetectionOnce'})
112 smach.StateMachine.add(
'ObjectDetection', od_sm,
113 remapping={
'frame':
'frame'},
114 transitions={
'succeeded':
'InteractiveManip',
115 'preempted':
'preempted',
118 smach.StateMachine.add(
'InteractiveManip',
119 smach_ros.SimpleActionState(
'interactive_manipulation',
120 InteractiveManipAction,
121 goal_slots=[
'frame'],
122 result_slots=[
'obj_name',
'header',
'pick_pose',
'place_pose']),
123 remapping={
'frame':
'frame',
124 'obj_name':
'obj_name',
126 'pick_pose':
'pick_pose',
127 'place_pose':
'place_pose'},
128 transitions={
'succeeded':
'PickAndPlace',
129 'preempted':
'preempted',
130 'aborted':
'ObjectDetection'})
132 smach.StateMachine.add(
'PickAndPlace',
133 smach_ros.SimpleActionState(
'pick_and_place',
135 goal_slots=[
'frame',
'obj_name',
'header',
'pick_pose',
'place_pose'],
137 remapping={
'frame':
'frame',
139 'pick_pose':
'pick_pose',
140 'place_pose':
'place_pose'},
141 transitions={
'succeeded':
'ObjectDetection',
142 'preempted':
'preempted',
143 'aborted':
'ObjectDetection'})
145 smach.StateMachine.add(
'FoldArm',
146 smach_ros.SimpleActionState(
'move_to_target',
148 goal_slots=[
'target_type',
'named_target']),
149 remapping={
'target_type':
'named_pose_target_type',
150 'named_target':
'arm_folded_named_pose'},
151 transitions={
'succeeded':
'ObjectDetection',
152 'preempted':
'preempted',
153 'aborted':
'ObjectDetection'})
155 smach.StateMachine.add(
'FoldArmAndQuit',
156 smach_ros.SimpleActionState(
'move_to_target',
158 goal_slots=[
'target_type',
'named_target']),
159 remapping={
'target_type':
'named_pose_target_type',
160 'named_target':
'arm_folded_named_pose'},
161 transitions={
'succeeded':
'quit',
167 asw = smach_ros.ActionServerWrapper(
168 'user_commands_action_server', UserCommandAction,
169 wrapped_container = sm,
170 succeeded_outcomes = [
'quit'],
171 aborted_outcomes = [
'aborted'],
172 preempted_outcomes = [
'error'],
173 goal_key =
'user_command',
174 result_key =
'ucmd_outcome')
180 sis = smach_ros.IntrospectionServer(
'object_manipulation', sm,
'/SM_ROOT')
def execute(self, userdata)