Ejemplo n.º 1
0
	def create(self):
		# x:43 y:392, x:240 y:396, x:477 y:395
		_state_machine = OperatableStateMachine(outcomes=['finished', 'failed', 'invalid_pose'])

		# Additional creation code can be added inside the following tags
		# [MANUAL_CREATE]
		
		# [/MANUAL_CREATE]


		with _state_machine:
			# x:324 y:50
			OperatableStateMachine.add('CheckCrouched',
										CheckJointState(outcomes=['body_crouched', 'unknown'], pose_ns='saved_msgs/joint_state', tolerance=0.17, joint_topic="joint_states", timeout=1.0),
										transitions={'body_crouched': 'StepSequence', 'unknown': 'Crouch'},
										autonomy={'body_crouched': Autonomy.Off, 'unknown': Autonomy.Off})

			# x:412 y:178
			OperatableStateMachine.add('Crouch',
										ExecuteJointTrajectory(action_topic='motion/controller/joint_trajectory', trajectory_param='crouch_begin', trajectory_ns='saved_msgs/joint_trajectory'),
										transitions={'success': 'StepSequence', 'partial_movement': 'invalid_pose', 'invalid_pose': 'invalid_pose', 'failure': 'failed'},
										autonomy={'success': Autonomy.Off, 'partial_movement': Autonomy.Off, 'invalid_pose': Autonomy.Off, 'failure': Autonomy.Off})

			# x:127 y:182
			OperatableStateMachine.add('StepSequence',
										ExecuteStepSequence(controller='motion/controller/step_sequence', trajectory_param=self.action_name, trajectory_ns='saved_msgs/step_sequence'),
										transitions={'success': 'finished', 'partial_movement': 'Crouch', 'invalid_pose': 'Crouch', 'failure': 'failed'},
										autonomy={'success': Autonomy.Off, 'partial_movement': Autonomy.Off, 'invalid_pose': Autonomy.Off, 'failure': Autonomy.Off})


		return _state_machine
	def create(self):
		# x:43 y:392, x:240 y:396, x:477 y:395
		_state_machine = OperatableStateMachine(outcomes=['finished', 'failed', 'invalid_pose'])

		# Additional creation code can be added inside the following tags
		# [MANUAL_CREATE]
		
		# [/MANUAL_CREATE]


		with _state_machine:
			# x:161 y:101
			OperatableStateMachine.add('StepSequence',
										ExecuteStepSequence(controller='motion/controller/step_sequence', trajectory_param=self.action_name, trajectory_ns='saved_msgs/step_sequence'),
										transitions={'success': 'finished', 'partial_movement': 'invalid_pose', 'invalid_pose': 'Crouch', 'failure': 'failed'},
										autonomy={'success': Autonomy.Off, 'partial_movement': Autonomy.Off, 'invalid_pose': Autonomy.Off, 'failure': Autonomy.Off})

			# x:413 y:104
			OperatableStateMachine.add('Crouch',
										ExecuteJointTrajectory(action_topic='motion/controller/joint_trajectory', trajectory_param='crouch_begin', trajectory_ns='saved_msgs/joint_trajectory'),
										transitions={'success': 'StepSequence', 'partial_movement': 'invalid_pose', 'invalid_pose': 'invalid_pose', 'failure': 'failed'},
										autonomy={'success': Autonomy.Off, 'partial_movement': Autonomy.Off, 'invalid_pose': Autonomy.Off, 'failure': Autonomy.Off})


		return _state_machine
Ejemplo n.º 3
0
	def create(self):
		# x:30 y:353, x:425 y:365
		_state_machine = OperatableStateMachine(outcomes=['finished', 'failed'])

		# Additional creation code can be added inside the following tags
		# [MANUAL_CREATE]
		
		# [/MANUAL_CREATE]

		# x:30 y:353, x:130 y:353, x:230 y:353, x:330 y:353, x:430 y:353, x:530 y:353
		_sm_randheadmovements_0 = ConcurrencyContainer(outcomes=['finished', 'failed'], conditions=[
										('finished', [('LookAt', 'done')]),
										('failed', [('LookAt', 'failure')]),
										('finished', [('RandPose', 'done')]),
										('failed', [('RandPose', 'failure')])
										])

		with _sm_randheadmovements_0:
			# x:48 y:117
			OperatableStateMachine.add('LookAt',
										SetOperational(controller='motion/controller/look_at', operational=True, resources=['head'], sync=True),
										transitions={'done': 'finished', 'failure': 'failed'},
										autonomy={'done': Autonomy.Off, 'failure': Autonomy.Off})

			# x:286 y:122
			OperatableStateMachine.add('RandPose',
										RandPoseGenerator(topic='motion/controller/look_at/in_pose_ref', duration=self.timeout, interval=[1.0,4.0], maxXYZ=[1,0.3,0.6], minXYZ=[1.0,-0.3,0.2], frame_xyz='base_link', frame_out='odom_combined'),
										transitions={'done': 'finished', 'failure': 'failed'},
										autonomy={'done': Autonomy.Off, 'failure': Autonomy.Off})



		with _state_machine:
			# x:163 y:40
			OperatableStateMachine.add('CheckCrouched',
										CheckJointState(outcomes=['body_crouched', 'unknown'], pose_ns='saved_msgs/joint_state', tolerance=0.17, joint_topic="joint_states", timeout=1.0),
										transitions={'body_crouched': 'StandUp', 'unknown': 'RandHeadMovements'},
										autonomy={'body_crouched': Autonomy.Off, 'unknown': Autonomy.Off})

			# x:412 y:68
			OperatableStateMachine.add('StandUp',
										ExecuteJointTrajectory(action_topic='motion/controller/joint_trajectory', trajectory_param='crouch_end', trajectory_ns='saved_msgs/joint_trajectory'),
										transitions={'success': 'RandHeadMovements', 'partial_movement': 'failed', 'invalid_pose': 'failed', 'failure': 'failed'},
										autonomy={'success': Autonomy.Off, 'partial_movement': Autonomy.Off, 'invalid_pose': Autonomy.Off, 'failure': Autonomy.Off})

			# x:150 y:341
			OperatableStateMachine.add('HeadNominal',
										SetJointState(controller='motion/controller/joint_state_head', pose_param='head_nominal', pose_ns='saved_msgs/joint_state', tolerance=0.017, timeout=10.0, joint_topic="joint_states"),
										transitions={'done': 'finished', 'failed': 'failed', 'timeout': 'failed'},
										autonomy={'done': Autonomy.Off, 'failed': Autonomy.Off, 'timeout': Autonomy.Off})

			# x:154 y:179
			OperatableStateMachine.add('RandHeadMovements',
										_sm_randheadmovements_0,
										transitions={'finished': 'HeadNominal', 'failed': 'failed'},
										autonomy={'finished': Autonomy.Inherit, 'failed': Autonomy.Inherit})


		return _state_machine
    def create(self):
        storage = 'joint_trajectory/'
        # x:879 y:265, x:922 y:85
        _state_machine = OperatableStateMachine(
            outcomes=['finished', 'failed'])

        # Additional creation code can be added inside the following tags
        # [MANUAL_CREATE]

        # [/MANUAL_CREATE]

        with _state_machine:
            # x:82 y:127
            OperatableStateMachine.add(
                'SetRedEyes',
                TextCommandState(type='eyes/emotion',
                                 command='normal',
                                 topic='control'),
                transitions={'done': 'SayStateMachines'},
                autonomy={'done': Autonomy.Off})

            # x:478 y:140
            OperatableStateMachine.add(
                'StateMachinesMove',
                ExecuteJointTrajectory(
                    action_topic='motion/controller/joint_trajectory',
                    trajectory_param='hoof_stamp',
                    trajectory_ns=storage),
                transitions={
                    'success': 'finished',
                    'partial_movement': 'failed',
                    'invalid_pose': 'failed',
                    'failure': 'failed'
                },
                autonomy={
                    'success': Autonomy.Off,
                    'partial_movement': Autonomy.Off,
                    'invalid_pose': Autonomy.Off,
                    'failure': Autonomy.Off
                },
                remapping={'result': 'result'})

            # x:295 y:138
            OperatableStateMachine.add(
                'SayStateMachines',
                TextCommandState(type='voice/play_wav',
                                 command='state_machines',
                                 topic='control'),
                transitions={'done': 'StateMachinesMove'},
                autonomy={'done': Autonomy.Off})

        return _state_machine
Ejemplo n.º 5
0
    def create(self):
        storage = 'joint_trajectory/'
        # x:84 y:357, x:195 y:363
        _state_machine = OperatableStateMachine(
            outcomes=['finished', 'failed'])

        # Additional creation code can be added inside the following tags
        # [MANUAL_CREATE]

        # [/MANUAL_CREATE]

        with _state_machine:
            # x:34 y:36
            OperatableStateMachine.add('SetNormalEyes',
                                       TextCommandState(type='eyes/emotion',
                                                        command='normal',
                                                        topic='control'),
                                       transitions={'done': 'SayGreeting'},
                                       autonomy={'done': Autonomy.Off})

            # x:40 y:171
            OperatableStateMachine.add(
                'GreetingMove',
                ExecuteJointTrajectory(
                    action_topic='motion/controller/joint_trajectory',
                    trajectory_param='greeting',
                    trajectory_ns=storage),
                transitions={
                    'success': 'finished',
                    'partial_movement': 'failed',
                    'invalid_pose': 'failed',
                    'failure': 'failed'
                },
                autonomy={
                    'success': Autonomy.Off,
                    'partial_movement': Autonomy.Off,
                    'invalid_pose': Autonomy.Off,
                    'failure': Autonomy.Off
                },
                remapping={'result': 'result'})

            # x:186 y:77
            OperatableStateMachine.add('SayGreeting',
                                       TextCommandState(type='voice/play_wav',
                                                        command='see_you_here',
                                                        topic='voice/voice'),
                                       transitions={'done': 'GreetingMove'},
                                       autonomy={'done': Autonomy.Off})

        return _state_machine
Ejemplo n.º 6
0
    def create(self):
        control_topic = 'control'
        voice_topic = 'control'
        joint_trajectory_action = 'motion/controller/joint_trajectory'
        joy_topic = '/hmi/joystick'
        moveit_action = 'move_group'
        storage = 'joint_trajectory'
        # x:157 y:271, x:501 y:342
        _state_machine = OperatableStateMachine(
            outcomes=['finished', 'failed'])
        _state_machine.userdata.joint_head_turned_right = [0.0, 0.6, 0.0, 0.0]
        _state_machine.userdata.head_forward_joints = [0.15, 0.0, -0.15, 0.0]
        _state_machine.userdata.unused = None

        # Additional creation code can be added inside the following tags
        # [MANUAL_CREATE]

        # [/MANUAL_CREATE]

        # x:803 y:85, x:480 y:341
        _sm_turnright_0 = OperatableStateMachine(
            outcomes=['finished', 'failed'],
            input_keys=['joint_head_turned_right'])

        with _sm_turnright_0:
            # x:282 y:82
            OperatableStateMachine.add(
                'TurnHead',
                MoveitToJointsState(
                    move_group='head',
                    joint_names=['joint51', 'joint52', 'joint53', 'joint54'],
                    action_topic=moveit_action),
                transitions={
                    'reached': 'TurnBody',
                    'planning_failed': 'failed',
                    'control_failed': 'failed'
                },
                autonomy={
                    'reached': Autonomy.Off,
                    'planning_failed': Autonomy.Off,
                    'control_failed': Autonomy.Off
                },
                remapping={'joint_config': 'joint_head_turned_right'})

            # x:466 y:69
            OperatableStateMachine.add('TurnBody',
                                       CompoundAction(
                                           t1=[0, 0.0],
                                           type1='motion/joint_trajectory',
                                           cmd1='turn_right',
                                           t2=[1, 0.0],
                                           type2='motion/joint_trajectory',
                                           cmd2='turn_right',
                                           t3=[2, 0.0],
                                           type3='motion/joint_trajectory',
                                           cmd3='turn_right',
                                           t4=[0, 0.0],
                                           type4=None,
                                           cmd4=''),
                                       transitions={
                                           'success': 'finished',
                                           'failure': 'failed'
                                       },
                                       autonomy={
                                           'success': Autonomy.Off,
                                           'failure': Autonomy.Off
                                       })

        # x:30 y:353, x:148 y:355, x:529 y:348, x:443 y:347, x:840 y:329, x:752 y:347
        _sm_waitbegining_1 = ConcurrencyContainer(
            outcomes=['finished', 'failed'],
            input_keys=['unused'],
            conditions=[('finished', [('WaitKey', 'received')]),
                        ('failed', [('WaitKey', 'unavailable')]),
                        ('failed', [('RandHeadMovemets', 'failed')]),
                        ('finished', [('RandHeadMovemets', 'done')])])

        with _sm_waitbegining_1:
            # x:167 y:134
            OperatableStateMachine.add('WaitKey',
                                       WaitForMessageState(
                                           topic=joy_topic,
                                           condition=lambda x: any(x.buttons),
                                           buffered=False,
                                           clear=False),
                                       transitions={
                                           'received': 'finished',
                                           'unavailable': 'failed'
                                       },
                                       autonomy={
                                           'received': Autonomy.Off,
                                           'unavailable': Autonomy.Off
                                       },
                                       remapping={'message': 'message'})

            # x:442 y:126
            OperatableStateMachine.add('RandHeadMovemets',
                                       SweetieBotRandHeadMovements(
                                           controller='joint_state_head',
                                           duration=600,
                                           interval=[3, 5],
                                           max2356=[0.3, 0.3, 1.5, 1.5],
                                           min2356=[-0.3, -0.3, -1.5, -1.5]),
                                       transitions={
                                           'done': 'finished',
                                           'failed': 'failed'
                                       },
                                       autonomy={
                                           'done': Autonomy.Off,
                                           'failed': Autonomy.Off
                                       },
                                       remapping={'config': 'unused'})

        with _state_machine:
            # x:25 y:176
            OperatableStateMachine.add('WaitBegining',
                                       _sm_waitbegining_1,
                                       transitions={
                                           'finished': 'HeadPose',
                                           'failed': 'failed'
                                       },
                                       autonomy={
                                           'finished': Autonomy.Inherit,
                                           'failed': Autonomy.Inherit
                                       },
                                       remapping={'unused': 'unused'})

            # x:343 y:49
            OperatableStateMachine.add('WaitKey',
                                       WaitForMessageState(
                                           topic=joy_topic,
                                           condition=lambda x: any(x.buttons),
                                           buffered=False,
                                           clear=False),
                                       transitions={
                                           'received': 'TurnRight',
                                           'unavailable': 'failed'
                                       },
                                       autonomy={
                                           'received': Autonomy.Off,
                                           'unavailable': Autonomy.Off
                                       },
                                       remapping={'message': 'message'})

            # x:785 y:172
            OperatableStateMachine.add('AskAboutProto1',
                                       CompoundAction(
                                           t1=[0, 0.0],
                                           type1='voice/play_wav',
                                           cmd1='what_proto1',
                                           t2=[0, 0.0],
                                           type2='motion/joint_trajectory',
                                           cmd2='head_suprised_slow',
                                           t3=[0, 0.0],
                                           type3=None,
                                           cmd3='',
                                           t4=[0, 0.0],
                                           type4=None,
                                           cmd4=''),
                                       transitions={
                                           'success': 'WaitKey2',
                                           'failure': 'failed'
                                       },
                                       autonomy={
                                           'success': Autonomy.Off,
                                           'failure': Autonomy.Off
                                       })

            # x:799 y:264
            OperatableStateMachine.add('WaitKey2',
                                       WaitForMessageState(
                                           topic=joy_topic,
                                           condition=lambda x: any(x.buttons),
                                           buffered=False,
                                           clear=False),
                                       transitions={
                                           'received': 'AskAboutProto1Again',
                                           'unavailable': 'failed'
                                       },
                                       autonomy={
                                           'received': Autonomy.Off,
                                           'unavailable': Autonomy.Off
                                       },
                                       remapping={'message': 'message'})

            # x:797 y:379
            OperatableStateMachine.add('AskAboutProto1Again',
                                       CompoundAction(
                                           t1=[0, 0.0],
                                           type1='voice/play_wav',
                                           cmd1='tell_me_more_about_proto1',
                                           t2=[0, 0.0],
                                           type2='motion/joint_trajectory',
                                           cmd2='head_lean_forward_begin',
                                           t3=[0, 0.0],
                                           type3=None,
                                           cmd3='',
                                           t4=[0, 0.0],
                                           type4=None,
                                           cmd4=''),
                                       transitions={
                                           'success': 'WaitKey4',
                                           'failure': 'failed'
                                       },
                                       autonomy={
                                           'success': Autonomy.Off,
                                           'failure': Autonomy.Off
                                       })

            # x:801 y:518
            OperatableStateMachine.add(
                'WaitKey4',
                WaitForMessageState(topic=joy_topic,
                                    condition=lambda x: any(x.buttons),
                                    buffered=False,
                                    clear=False),
                transitions={
                    'received': 'AskWhatHappensToProto1',
                    'unavailable': 'failed'
                },
                autonomy={
                    'received': Autonomy.Off,
                    'unavailable': Autonomy.Off
                },
                remapping={'message': 'message'})

            # x:603 y:600
            OperatableStateMachine.add('AskWhatHappensToProto1',
                                       CompoundAction(
                                           t1=[0, 0.0],
                                           type1='voice/play_wav',
                                           cmd1='what_happened_with_proto1',
                                           t2=[0, 1.2],
                                           type2='motion/joint_trajectory',
                                           cmd2='hoof_wave',
                                           t3=[0, 0.0],
                                           type3=None,
                                           cmd3='',
                                           t4=[0, 0.0],
                                           type4=None,
                                           cmd4=''),
                                       transitions={
                                           'success': 'WaitKey3',
                                           'failure': 'failed'
                                       },
                                       autonomy={
                                           'success': Autonomy.Off,
                                           'failure': Autonomy.Off
                                       })

            # x:332 y:601
            OperatableStateMachine.add('WaitKey3',
                                       WaitForMessageState(
                                           topic=joy_topic,
                                           condition=lambda x: any(x.buttons),
                                           buffered=False,
                                           clear=False),
                                       transitions={
                                           'received': 'SayItIsOk',
                                           'unavailable': 'failed'
                                       },
                                       autonomy={
                                           'received': Autonomy.Off,
                                           'unavailable': Autonomy.Off
                                       },
                                       remapping={'message': 'message'})

            # x:554 y:51
            OperatableStateMachine.add('TurnRight',
                                       _sm_turnright_0,
                                       transitions={
                                           'finished': 'WatchPresentaion',
                                           'failed': 'failed'
                                       },
                                       autonomy={
                                           'finished': Autonomy.Inherit,
                                           'failed': Autonomy.Inherit
                                       },
                                       remapping={
                                           'joint_head_turned_right':
                                           'joint_head_turned_right'
                                       })

            # x:81 y:597
            OperatableStateMachine.add('SayItIsOk',
                                       CompoundAction(
                                           t1=[0, 0.0],
                                           type1='motion/joint_trajectory',
                                           cmd1='head_lean_forward_end',
                                           t2=[0, 0.0],
                                           type2='voice/play_wav',
                                           cmd2='yes_exactly_tell_me_more',
                                           t3=[0, 0.0],
                                           type3=None,
                                           cmd3='',
                                           t4=[0, 0.0],
                                           type4=None,
                                           cmd4=''),
                                       transitions={
                                           'success': 'WatchPresentaion_2',
                                           'failure': 'failed'
                                       },
                                       autonomy={
                                           'success': Autonomy.Off,
                                           'failure': Autonomy.Off
                                       })

            # x:137 y:50
            OperatableStateMachine.add(
                'Hello',
                CompoundAction(t1=[0, 0.0],
                               type1='motion/joint_trajectory',
                               cmd1='introduce_herself',
                               t2=[0, 0.0],
                               type2='voice/play_wav',
                               cmd2='hello_im_sweetie_bot_presentation',
                               t3=[0, 0.0],
                               type3=None,
                               cmd3='',
                               t4=[0, 0.0],
                               type4=None,
                               cmd4=''),
                transitions={
                    'success': 'WaitKey',
                    'failure': 'failed'
                },
                autonomy={
                    'success': Autonomy.Off,
                    'failure': Autonomy.Off
                })

            # x:166 y:159
            OperatableStateMachine.add('HeadPose',
                                       SrdfStateToMoveit(
                                           config_name='head_basic',
                                           move_group='head',
                                           action_topic='move_group',
                                           robot_name=''),
                                       transitions={
                                           'reached': 'Hello',
                                           'planning_failed': 'failed',
                                           'control_failed': 'failed',
                                           'param_error': 'failed'
                                       },
                                       autonomy={
                                           'reached': Autonomy.Off,
                                           'planning_failed': Autonomy.Off,
                                           'control_failed': Autonomy.Off,
                                           'param_error': Autonomy.Off
                                       },
                                       remapping={
                                           'config_name': 'config_name',
                                           'move_group': 'move_group',
                                           'robot_name': 'robot_name',
                                           'action_topic': 'action_topic',
                                           'joint_values': 'joint_values',
                                           'joint_names': 'joint_names'
                                       })

            # x:776 y:30
            OperatableStateMachine.add(
                'WatchPresentaion',
                self.use_behavior(WatchPresentaionSM,
                                  'WatchPresentaion',
                                  default_keys=['rand_head_config']),
                transitions={
                    'finished': 'AskAboutProto1',
                    'failed': 'failed'
                },
                autonomy={
                    'finished': Autonomy.Inherit,
                    'failed': Autonomy.Inherit
                },
                remapping={
                    'head_pose_joints': 'joint_head_turned_right',
                    'rand_head_config': 'rand_head_config'
                })

            # x:92 y:465
            OperatableStateMachine.add(
                'WatchPresentaion_2',
                self.use_behavior(WatchPresentaionSM,
                                  'WatchPresentaion_2',
                                  default_keys=['rand_head_config']),
                transitions={
                    'finished': 'Greeting',
                    'failed': 'failed'
                },
                autonomy={
                    'finished': Autonomy.Inherit,
                    'failed': Autonomy.Inherit
                },
                remapping={
                    'head_pose_joints': 'head_forward_joints',
                    'rand_head_config': 'rand_head_config'
                })

            # x:73 y:332
            OperatableStateMachine.add(
                'Greeting',
                ExecuteJointTrajectory(
                    action_topic=joint_trajectory_action,
                    trajectory_param='greeting',
                    trajectory_ns='/saved_msgs/joint_trajectory'),
                transitions={
                    'success': 'finished',
                    'partial_movement': 'failed',
                    'invalid_pose': 'failed',
                    'failure': 'failed'
                },
                autonomy={
                    'success': Autonomy.Off,
                    'partial_movement': Autonomy.Off,
                    'invalid_pose': Autonomy.Off,
                    'failure': Autonomy.Off
                },
                remapping={'result': 'result'})

        return _state_machine
Ejemplo n.º 7
0
    def create(self):
        joy_topic = '/hmi/joystick'
        joint_trajectory_action = '/motion/controller/joint_trajectory'
        # x:30 y:365, x:1031 y:242
        _state_machine = OperatableStateMachine(
            outcomes=['finished', 'failed'])
        _state_machine.userdata.rand_moves_config = None

        # Additional creation code can be added inside the following tags
        # [MANUAL_CREATE]

        # [/MANUAL_CREATE]

        # x:397 y:287, x:130 y:297, x:230 y:297, x:330 y:297, x:459 y:297, x:530 y:297
        _sm_joystickmovements_0 = ConcurrencyContainer(
            outcomes=['failed', 'button1234', 'timeout'],
            output_keys=['joy_msg'],
            conditions=[('timeout', [('JoystickControl', 'done')]),
                        ('failed', [('WaitButton1234Pressed', 'unavailable')]),
                        ('button1234', [('WaitButton1234Pressed', 'received')])
                        ])

        with _sm_joystickmovements_0:
            # x:385 y:129
            OperatableStateMachine.add(
                'JoystickControl',
                JoystickJointControl(
                    joints_topic='/joint_states',
                    goal_joints_topic=
                    '/motion/controller/joint_state/out_joints_src_reset',
                    joy_topic=joy_topic,
                    buttons=[(4, 0.6, 'ear_l_joint', -3.0, 1.0),
                             (6, -0.6, 'ear_l_joint', -3.0, 1.0),
                             (5, 0.6, 'ear_r_joint', -3.0, 1.0),
                             (7, -0.6, 'ear_r_joint', -3.0, 1.0)],
                    axes=[(0, 0, 'eyes_yaw', -1.5, 1.5),
                          (1, 0, 'eyes_pitch', -1.5, 1.5),
                          (4, -0.4, 'head_joint4', -1.5, 1.5),
                          (5, 0.4, 'head_joint2', -1.5, 1.5),
                          (3, 0.5, 'mouth_joint', -0.6, 0)],
                    timeout=5.0),
                transitions={'done': 'timeout'},
                autonomy={'done': Autonomy.Off})

            # x:130 y:136
            OperatableStateMachine.add(
                'WaitButton1234Pressed',
                WaitForMessageState(
                    topic=joy_topic,
                    condition=lambda msg: any(msg.buttons[0:4]),
                    buffered=False,
                    clear=True),
                transitions={
                    'received': 'button1234',
                    'unavailable': 'failed'
                },
                autonomy={
                    'received': Autonomy.Off,
                    'unavailable': Autonomy.Off
                },
                remapping={'message': 'joy_msg'})

        # x:625 y:339, x:47 y:263, x:323 y:268, x:703 y:252, x:630 y:296, x:443 y:267, x:227 y:263
        _sm_randmovements_1 = ConcurrencyContainer(
            outcomes=['failed', 'timeout', 'joy_msg'],
            input_keys=['rand_moves_config'],
            output_keys=['joy_msg'],
            conditions=[('failed', [('WaitJoystick', 'unavailable')]),
                        ('failed', [('RandHeadMoves', 'failed')]),
                        ('joy_msg', [('WaitJoystick', 'received')]),
                        ('timeout', [('RandHeadMoves', 'done')])])

        with _sm_randmovements_1:
            # x:88 y:74
            OperatableStateMachine.add(
                'WaitJoystick',
                WaitForMessageState(
                    topic=joy_topic,
                    condition=lambda msg: any(msg.buttons) or any(msg.axes),
                    buffered=False,
                    clear=False),
                transitions={
                    'received': 'joy_msg',
                    'unavailable': 'failed'
                },
                autonomy={
                    'received': Autonomy.Off,
                    'unavailable': Autonomy.Off
                },
                remapping={'message': 'joy_msg'})

            # x:332 y:60
            OperatableStateMachine.add(
                'RandHeadMoves',
                RandJointsMovements(controller='joint_state_head',
                                    duration=2000,
                                    interval=[2.0, 5.0],
                                    joints=['head_joint2', 'head_joint4'],
                                    minimal=[-0.2, -0.3],
                                    maximal=[0.3, 0.3]),
                transitions={
                    'done': 'timeout',
                    'failed': 'failed'
                },
                autonomy={
                    'done': Autonomy.Off,
                    'failed': Autonomy.Off
                },
                remapping={'config': 'rand_moves_config'})

        with _state_machine:
            # x:57 y:26
            OperatableStateMachine.add('RandMovements',
                                       _sm_randmovements_1,
                                       transitions={
                                           'failed': 'failed',
                                           'timeout': 'RandMovements',
                                           'joy_msg': 'CheckButtonPressed'
                                       },
                                       autonomy={
                                           'failed': Autonomy.Inherit,
                                           'timeout': Autonomy.Inherit,
                                           'joy_msg': Autonomy.Inherit
                                       },
                                       remapping={
                                           'rand_moves_config':
                                           'rand_moves_config',
                                           'joy_msg': 'joy_msg'
                                       })

            # x:413 y:17
            OperatableStateMachine.add('PlaceHead',
                                       SrdfStateToMoveit(
                                           config_name='head_group_basic',
                                           move_group='head_group',
                                           action_topic='move_group',
                                           robot_name=''),
                                       transitions={
                                           'reached': 'SelectMovement',
                                           'planning_failed': 'Wait',
                                           'control_failed': 'Wait',
                                           'param_error': 'failed'
                                       },
                                       autonomy={
                                           'reached': Autonomy.Off,
                                           'planning_failed': Autonomy.Off,
                                           'control_failed': Autonomy.Off,
                                           'param_error': Autonomy.Off
                                       },
                                       remapping={
                                           'config_name': 'config_name',
                                           'move_group': 'move_group',
                                           'robot_name': 'robot_name',
                                           'action_topic': 'action_topic',
                                           'joint_values': 'joint_values',
                                           'joint_names': 'joint_names'
                                       })

            # x:373 y:236
            OperatableStateMachine.add(
                'Greeting',
                ExecuteJointTrajectory(
                    action_topic=joint_trajectory_action,
                    trajectory_param='greeting',
                    trajectory_ns='/saved_msgs/joint_trajectory'),
                transitions={
                    'success': 'JoystickMovements',
                    'partial_movement': 'failed',
                    'invalid_pose': 'failed',
                    'failure': 'failed'
                },
                autonomy={
                    'success': Autonomy.Off,
                    'partial_movement': Autonomy.Off,
                    'invalid_pose': Autonomy.Off,
                    'failure': Autonomy.Off
                },
                remapping={'result': 'result'})

            # x:85 y:283
            OperatableStateMachine.add('JoystickMovements',
                                       _sm_joystickmovements_0,
                                       transitions={
                                           'failed': 'failed',
                                           'button1234': 'PlaceHead',
                                           'timeout': 'RandMovements'
                                       },
                                       autonomy={
                                           'failed': Autonomy.Inherit,
                                           'button1234': Autonomy.Inherit,
                                           'timeout': Autonomy.Inherit
                                       },
                                       remapping={'joy_msg': 'joy_msg'})

            # x:612 y:186
            OperatableStateMachine.add(
                'SelectMovement',
                DecisionState(outcomes=[
                    'none', 'button1', 'button2', 'button3', 'button4'
                ],
                              conditions=self.move_selector),
                transitions={
                    'none': 'RandMovements',
                    'button1': 'Greeting',
                    'button2': 'HeadShake',
                    'button3': 'GrownUp',
                    'button4': 'Greeting'
                },
                autonomy={
                    'none': Autonomy.Off,
                    'button1': Autonomy.Off,
                    'button2': Autonomy.Off,
                    'button3': Autonomy.Off,
                    'button4': Autonomy.Off
                },
                remapping={'input_value': 'joy_msg'})

            # x:412 y:317
            OperatableStateMachine.add(
                'HeadShake',
                ExecuteJointTrajectory(
                    action_topic=joint_trajectory_action,
                    trajectory_param='head_shake',
                    trajectory_ns='/saved_msgs/joint_trajectory'),
                transitions={
                    'success': 'JoystickMovements',
                    'partial_movement': 'failed',
                    'invalid_pose': 'failed',
                    'failure': 'failed'
                },
                autonomy={
                    'success': Autonomy.Off,
                    'partial_movement': Autonomy.Off,
                    'invalid_pose': Autonomy.Off,
                    'failure': Autonomy.Off
                },
                remapping={'result': 'result'})

            # x:472 y:404
            OperatableStateMachine.add(
                'GrownUp',
                ExecuteJointTrajectory(
                    action_topic=joint_trajectory_action,
                    trajectory_param='very_grown_up',
                    trajectory_ns='/saved_msgs/joint_trajectory'),
                transitions={
                    'success': 'JoystickMovements',
                    'partial_movement': 'failed',
                    'invalid_pose': 'failed',
                    'failure': 'failed'
                },
                autonomy={
                    'success': Autonomy.Off,
                    'partial_movement': Autonomy.Off,
                    'invalid_pose': Autonomy.Off,
                    'failure': Autonomy.Off
                },
                remapping={'result': 'result'})

            # x:167 y:134
            OperatableStateMachine.add(
                'CheckButtonPressed',
                DecisionState(outcomes=['button1234', 'other'],
                              conditions=lambda msg: 'button1234'
                              if any(msg.buttons[0:4]) else 'other'),
                transitions={
                    'button1234': 'PlaceHead',
                    'other': 'JoystickMovements'
                },
                autonomy={
                    'button1234': Autonomy.Off,
                    'other': Autonomy.Off
                },
                remapping={'input_value': 'joy_msg'})

            # x:686 y:104
            OperatableStateMachine.add('PlaceHead_2',
                                       SrdfStateToMoveit(
                                           config_name='head_group_basic',
                                           move_group='head_group',
                                           action_topic='move_group',
                                           robot_name=''),
                                       transitions={
                                           'reached': 'SelectMovement',
                                           'planning_failed': 'failed',
                                           'control_failed': 'failed',
                                           'param_error': 'failed'
                                       },
                                       autonomy={
                                           'reached': Autonomy.Off,
                                           'planning_failed': Autonomy.Off,
                                           'control_failed': Autonomy.Off,
                                           'param_error': Autonomy.Off
                                       },
                                       remapping={
                                           'config_name': 'config_name',
                                           'move_group': 'move_group',
                                           'robot_name': 'robot_name',
                                           'action_topic': 'action_topic',
                                           'joint_values': 'joint_values',
                                           'joint_names': 'joint_names'
                                       })

            # x:703 y:18
            OperatableStateMachine.add('Wait',
                                       WaitState(wait_time=0.5),
                                       transitions={'done': 'PlaceHead_2'},
                                       autonomy={'done': Autonomy.Off})

        return _state_machine
	def create(self):
		# x:228 y:396, x:225 y:240, x:1010 y:659
		_state_machine = OperatableStateMachine(outcomes=['finished', 'unreachable', 'failed'], input_keys=['pose'])
		_state_machine.userdata.pose = PoseStamped(Header(frame_id = 'base_link'), Pose(Point(0.4, 0.0, -0.05), Quaternion(0, 0, 0, 1)))

		# Additional creation code can be added inside the following tags
		# [MANUAL_CREATE]
		
		# [/MANUAL_CREATE]


		with _state_machine:
			# x:118 y:85
			OperatableStateMachine.add('CheckHandPosition',
										DecisionState(outcomes=['good','bad'], conditions=self.checkHandPosition),
										transitions={'good': 'GetHeadPose', 'bad': 'unreachable'},
										autonomy={'good': Autonomy.Off, 'bad': Autonomy.Off},
										remapping={'input_value': 'pose'})

			# x:890 y:253
			OperatableStateMachine.add('SayHello',
										TextCommandState(type='voice/play_wav', command='hello_im_sweetie_bot_friedship_programms', topic='control'),
										transitions={'done': 'Wait'},
										autonomy={'done': Autonomy.Off})

			# x:663 y:69
			OperatableStateMachine.add('RaiseHead',
										MoveitToJointsState(move_group='head', joint_names=['joint51', 'joint52', 'joint53', 'joint54'], action_topic='move_group'),
										transitions={'reached': 'RaiseLegProgram', 'planning_failed': 'failed', 'control_failed': 'failed'},
										autonomy={'reached': Autonomy.Off, 'planning_failed': Autonomy.Off, 'control_failed': Autonomy.Off},
										remapping={'joint_config': 'head_pose'})

			# x:309 y:66
			OperatableStateMachine.add('GetHeadPose',
										GetJointValuesState(joints=['joint51', 'joint52', 'joint53', 'joint54']),
										transitions={'retrieved': 'CalcRaisedHeadPose'},
										autonomy={'retrieved': Autonomy.Off},
										remapping={'joint_values': 'head_pose'})

			# x:485 y:73
			OperatableStateMachine.add('CalcRaisedHeadPose',
										CalculationState(calculation=self.calculateHeadPoseFunc),
										transitions={'done': 'RaiseHead'},
										autonomy={'done': Autonomy.Off},
										remapping={'input_value': 'head_pose', 'output_value': 'head_pose'})

			# x:891 y:65
			OperatableStateMachine.add('RaiseLegProgram',
										ExecuteJointTrajectory(action_topic='motion/controller/joint_trajectory', trajectory_param='brohoof_begin', trajectory_ns='/saved_msgs/joint_trajectory'),
										transitions={'success': 'SayHello', 'partial_movement': 'failed', 'invalid_pose': 'failed', 'failure': 'failed'},
										autonomy={'success': Autonomy.Off, 'partial_movement': Autonomy.Off, 'invalid_pose': Autonomy.Off, 'failure': Autonomy.Off},
										remapping={'result': 'result'})

			# x:510 y:396
			OperatableStateMachine.add('ReturnLegProgrammed',
										ExecuteJointTrajectory(action_topic='motion/controller/joint_trajectory', trajectory_param='brohoof_end', trajectory_ns='/saved_msgs/joint_trajectory'),
                                                                                transitions={'success': 'finished', 'partial_movement': 'failed', 'invalid_pose': 'failed', 'failure': 'failed'},
										autonomy={'success': Autonomy.Off, 'partial_movement': Autonomy.Off, 'invalid_pose': Autonomy.Off, 'failure': Autonomy.Off},
										remapping={'result': 'result'})

			# x:851 y:399
			OperatableStateMachine.add('Wait',
										WaitState(wait_time=self.wait_time),
										transitions={'done': 'ReturnLegProgrammed'},
										autonomy={'done': Autonomy.Off})


		return _state_machine
Ejemplo n.º 9
0
    def create(self):
        joint_trajectory_action = 'motion/controller/joint_trajectory'
        voice_topic = 'control'
        storage = 'joint_trajectory/'
        # x:901 y:554, x:895 y:38
        _state_machine = OperatableStateMachine(
            outcomes=['finished', 'failed'], input_keys=['be_evil'])
        _state_machine.userdata.be_evil = self.be_evil

        # Additional creation code can be added inside the following tags
        # [MANUAL_CREATE]

        # [/MANUAL_CREATE]

        with _state_machine:
            # x:48 y:105
            OperatableStateMachine.add(
                'SetHeadNominalPose',
                SetJointState(controller='motion/controller/joint_state_head',
                              pose_param='head_nominal',
                              pose_ns='saved_msgs/joint_state',
                              tolerance=0.017,
                              timeout=10.0,
                              joint_topic="joint_states"),
                transitions={
                    'done': 'CheckEvil',
                    'failed': 'failed',
                    'timeout': 'finished'
                },
                autonomy={
                    'done': Autonomy.Off,
                    'failed': Autonomy.Off,
                    'timeout': Autonomy.Off
                })

            # x:579 y:498
            OperatableStateMachine.add(
                'HoofStamp',
                ExecuteJointTrajectory(action_topic=joint_trajectory_action,
                                       trajectory_param='hoof_stamp',
                                       trajectory_ns=storage),
                transitions={
                    'success': 'finished',
                    'partial_movement': 'failed',
                    'invalid_pose': 'failed',
                    'failure': 'failed'
                },
                autonomy={
                    'success': Autonomy.Off,
                    'partial_movement': Autonomy.Off,
                    'invalid_pose': Autonomy.Off,
                    'failure': Autonomy.Off
                },
                remapping={'result': 'result'})

            # x:88 y:447
            OperatableStateMachine.add(
                'RandomChoice',
                DecisionState(
                    outcomes=['evil1', 'evil2'],
                    conditions=lambda x: random.choice(['evil1', 'evil2'])),
                transitions={
                    'evil1': 'PointDoNotTouch',
                    'evil2': 'SayWalk'
                },
                autonomy={
                    'evil1': Autonomy.High,
                    'evil2': Autonomy.High
                },
                remapping={'input_value': 'be_evil'})

            # x:303 y:543
            OperatableStateMachine.add('SayWalk',
                                       TextCommandState(type='voice/play_wav',
                                                        command='i_hate_laws',
                                                        topic=voice_topic),
                                       transitions={'done': 'Wait1'},
                                       autonomy={'done': Autonomy.Off})

            # x:467 y:539
            OperatableStateMachine.add('Wait1',
                                       WaitState(wait_time=0.5),
                                       transitions={'done': 'HoofStamp'},
                                       autonomy={'done': Autonomy.Off})

            # x:497 y:102
            OperatableStateMachine.add(
                'PranceMaxFun',
                CompoundActionParam(action_param='prance_maximum_fun',
                                    action_ns='saved_msgs/compound_action'),
                transitions={
                    'success': 'finished',
                    'invalid_pose': 'failed',
                    'failure': 'failed'
                },
                autonomy={
                    'success': Autonomy.Off,
                    'invalid_pose': Autonomy.Off,
                    'failure': Autonomy.Off
                })

            # x:437 y:275
            OperatableStateMachine.add(
                'PointDoNotTouch',
                CompoundActionParam(action_param='point_do_not_touch',
                                    action_ns='saved_msgs/compound_action'),
                transitions={
                    'success': 'finished',
                    'invalid_pose': 'failed',
                    'failure': 'failed'
                },
                autonomy={
                    'success': Autonomy.Off,
                    'invalid_pose': Autonomy.Off,
                    'failure': Autonomy.Off
                })

            # x:140 y:251
            OperatableStateMachine.add(
                'CheckEvil',
                DecisionState(outcomes=['good', 'evil'],
                              conditions=lambda x: 'evil' if x else 'good'),
                transitions={
                    'good': 'PranceMaxFun',
                    'evil': 'RandomChoice'
                },
                autonomy={
                    'good': Autonomy.Off,
                    'evil': Autonomy.Off
                },
                remapping={'input_value': 'be_evil'})

        return _state_machine
Ejemplo n.º 10
0
    def create(self):
        control_topic = '/control'
        # x:902 y:204, x:178 y:606, x:677 y:537
        _state_machine = OperatableStateMachine(
            outcomes=['failed', 'finished', 'invalid_pose'],
            input_keys=['text_command'],
            output_keys=['text_command'])
        _state_machine.userdata.text_command = None

        # Additional creation code can be added inside the following tags
        # [MANUAL_CREATE]

        # [/MANUAL_CREATE]

        # x:30 y:353, x:130 y:353, x:230 y:353, x:330 y:353, x:430 y:353, x:530 y:353
        _sm_waittextcommand_0 = ConcurrencyContainer(
            outcomes=['finished', 'failed', 'timeout'],
            output_keys=['text_command'],
            conditions=[('finished', [('WaitCommandSub', 'received')]),
                        ('failed', [('WaitCommandSub', 'unavailable')]),
                        ('timeout', [('WaitTimeout', 'done')])])

        with _sm_waittextcommand_0:
            # x:142 y:113
            OperatableStateMachine.add('WaitCommandSub',
                                       SubscriberState(topic=control_topic,
                                                       blocking=True,
                                                       clear=True),
                                       transitions={
                                           'received': 'finished',
                                           'unavailable': 'failed'
                                       },
                                       autonomy={
                                           'received': Autonomy.Off,
                                           'unavailable': Autonomy.Off
                                       },
                                       remapping={'message': 'text_command'})

            # x:360 y:113
            OperatableStateMachine.add('WaitTimeout',
                                       WaitState(wait_time=self.timeout),
                                       transitions={'done': 'timeout'},
                                       autonomy={'done': Autonomy.Off})

        with _state_machine:
            # x:52 y:170
            OperatableStateMachine.add(
                'PrepareToWalk',
                ExecuteJointTrajectory(
                    action_topic='motion/controller/joint_trajectory',
                    trajectory_param='crouch_begin',
                    trajectory_ns='saved_msgs/joint_trajectory'),
                transitions={
                    'success': 'CheckIfEmpty',
                    'partial_movement': 'invalid_pose',
                    'invalid_pose': 'invalid_pose',
                    'failure': 'failed'
                },
                autonomy={
                    'success': Autonomy.Off,
                    'partial_movement': Autonomy.Off,
                    'invalid_pose': Autonomy.Off,
                    'failure': Autonomy.Off
                })

            # x:377 y:240
            OperatableStateMachine.add(
                'CheckIfStepSequence',
                DecisionState(outcomes=['yes', 'no'],
                              conditions=lambda msg: 'yes'
                              if msg.type == 'motion/step_sequence' else 'no'),
                transitions={
                    'yes': 'ExtractCmd',
                    'no': 'ClearTextCommandKey'
                },
                autonomy={
                    'yes': Autonomy.Off,
                    'no': Autonomy.Off
                },
                remapping={'input_value': 'text_command'})

            # x:100 y:358
            OperatableStateMachine.add(
                'StandUp',
                ExecuteJointTrajectory(
                    action_topic='motion/controller/joint_trajectory',
                    trajectory_param='crouch_end',
                    trajectory_ns='saved_msgs/joint_trajectory'),
                transitions={
                    'success': 'finished',
                    'partial_movement': 'invalid_pose',
                    'invalid_pose': 'invalid_pose',
                    'failure': 'failed'
                },
                autonomy={
                    'success': Autonomy.Off,
                    'partial_movement': Autonomy.Off,
                    'invalid_pose': Autonomy.Off,
                    'failure': Autonomy.Off
                })

            # x:497 y:359
            OperatableStateMachine.add(
                'ExtractCmd',
                CalculationState(calculation=lambda msg: msg.command),
                transitions={'done': 'ExecuteStepSeq'},
                autonomy={'done': Autonomy.Off},
                remapping={
                    'input_value': 'text_command',
                    'output_value': 'command_field'
                })

            # x:679 y:304
            OperatableStateMachine.add(
                'ExecuteStepSeq',
                ExecuteStepSequenceKey(
                    controller='motion/controller/step_sequence',
                    trajectory_ns='saved_msgs/step_sequence'),
                transitions={
                    'success': 'WaitTextCommand',
                    'unavailable': 'WaitTextCommand',
                    'partial_movement': 'invalid_pose',
                    'invalid_pose': 'invalid_pose',
                    'failure': 'failed'
                },
                autonomy={
                    'success': Autonomy.Off,
                    'unavailable': Autonomy.Off,
                    'partial_movement': Autonomy.Off,
                    'invalid_pose': Autonomy.Off,
                    'failure': Autonomy.Off
                },
                remapping={'trajectory_param': 'command_field'})

            # x:224 y:61
            OperatableStateMachine.add(
                'CheckIfEmpty',
                DecisionState(outcomes=['yes', 'no'],
                              conditions=lambda x: 'yes'
                              if x == None else 'no'),
                transitions={
                    'yes': 'WaitTextCommand',
                    'no': 'CheckIfStepSequence'
                },
                autonomy={
                    'yes': Autonomy.Off,
                    'no': Autonomy.Off
                },
                remapping={'input_value': 'text_command'})

            # x:271 y:479
            OperatableStateMachine.add('ClearTextCommandKey',
                                       CalculationState(calculation=None),
                                       transitions={'done': 'StandUp'},
                                       autonomy={'done': Autonomy.Off},
                                       remapping={
                                           'input_value': 'text_command',
                                           'output_value': 'text_command'
                                       })

            # x:427 y:106
            OperatableStateMachine.add(
                'WaitTextCommand',
                _sm_waittextcommand_0,
                transitions={
                    'finished': 'CheckIfStepSequence',
                    'failed': 'failed',
                    'timeout': 'StandUp'
                },
                autonomy={
                    'finished': Autonomy.Inherit,
                    'failed': Autonomy.Inherit,
                    'timeout': Autonomy.Inherit
                },
                remapping={'text_command': 'text_command'})

        return _state_machine
    def create(self):
        # x:583 y:683, x:578 y:422
        _state_machine = OperatableStateMachine(
            outcomes=['finished', 'failed'])
        _state_machine.userdata.unused = None
        _state_machine.userdata.rand_head_config = {'interval': [0.5, 1]}

        # Additional creation code can be added inside the following tags
        # [MANUAL_CREATE]

        # [/MANUAL_CREATE]

        with _state_machine:
            # x:278 y:24
            OperatableStateMachine.add('SesectBehavior',
                                       OperatorDecisionState(
                                           outcomes=['dance', 'rand_moves'],
                                           hint='Select behavior',
                                           suggestion='dance'),
                                       transitions={
                                           'dance': 'TestMovement',
                                           'rand_moves': 'RandHead'
                                       },
                                       autonomy={
                                           'dance': Autonomy.Full,
                                           'rand_moves': Autonomy.Full
                                       })

            # x:114 y:352
            OperatableStateMachine.add(
                'TurnOffJointStateController',
                SetBoolState(
                    service='motion/controller/joint_state/set_operational',
                    value=False),
                transitions={
                    'true': 'SingASong',
                    'false': 'failed',
                    'failure': 'failed'
                },
                autonomy={
                    'true': Autonomy.High,
                    'false': Autonomy.Off,
                    'failure': Autonomy.Off
                },
                remapping={
                    'success': 'success',
                    'message': 'message'
                })

            # x:136 y:518
            OperatableStateMachine.add('SingASong',
                                       TextCommandState(type='voice/play_wav',
                                                        command='mmm_song',
                                                        topic='control'),
                                       transitions={'done': 'finished'},
                                       autonomy={'done': Autonomy.Full})

            # x:248 y:213
            OperatableStateMachine.add(
                'TestMovement',
                ExecuteJointTrajectory(
                    action_topic='motion/controller/joint_trajectory',
                    trajectory_param='dance14',
                    trajectory_param='/saved_msgs/joint_trajectory'),
                transitions={
                    'success': 'TurnOffJointStateController',
                    'partial_movement': 'failed',
                    'invalid_pose': 'failed',
                    'failure': 'failed'
                },
                autonomy={
                    'success': Autonomy.Low,
                    'partial_movement': Autonomy.Off,
                    'invalid_pose': Autonomy.Off,
                    'failure': Autonomy.Off
                },
                remapping={'result': 'result'})

            # x:939 y:351
            OperatableStateMachine.add(
                'RandSelector',
                DecisionState(
                    outcomes=['first', 'second'],
                    conditions=(lambda x: 'first'
                                if random.uniform(0, 1) < 0.5 else 'second')),
                transitions={
                    'first': 'PlaceHead',
                    'second': 'TestMovement'
                },
                autonomy={
                    'first': Autonomy.Full,
                    'second': Autonomy.Full
                },
                remapping={'input_value': 'unused'})

            # x:704 y:603
            OperatableStateMachine.add(
                'HeadShake',
                ExecuteJointTrajectory(
                    action_topic='motion/controller/joint_trajectory',
                    trajectory_param='head_shake',
                    trajectory_param='/saved_msgs/joint_trajectory'),
                transitions={
                    'success': 'finished',
                    'partial_movement': 'failed',
                    'invalid_pose': 'failed',
                    'failure': 'failed'
                },
                autonomy={
                    'success': Autonomy.Off,
                    'partial_movement': Autonomy.Off,
                    'invalid_pose': Autonomy.Off,
                    'failure': Autonomy.Off
                },
                remapping={'result': 'result'})

            # x:958 y:510
            OperatableStateMachine.add('PlaceHead',
                                       SrdfStateToMoveit(
                                           config_name='head_basic',
                                           move_group='head',
                                           action_topic='move_group',
                                           robot_name=''),
                                       transitions={
                                           'reached': 'HeadShake',
                                           'planning_failed': 'failed',
                                           'control_failed': 'failed',
                                           'param_error': 'failed'
                                       },
                                       autonomy={
                                           'reached': Autonomy.Off,
                                           'planning_failed': Autonomy.Off,
                                           'control_failed': Autonomy.Off,
                                           'param_error': Autonomy.Off
                                       },
                                       remapping={
                                           'config_name': 'config_name',
                                           'move_group': 'move_group',
                                           'robot_name': 'robot_name',
                                           'action_topic': 'action_topic',
                                           'joint_values': 'joint_values',
                                           'joint_names': 'joint_names'
                                       })

            # x:725 y:125
            OperatableStateMachine.add(
                'RandHead',
                SweetieBotRandHeadMovements(controller='joint_state_head',
                                            duration=120,
                                            interval=[3, 5],
                                            max2356=[0.3, 0.3, 1.5, 1.5],
                                            min2356=[-0.3, -0.3, -1.5, -1.5]),
                transitions={
                    'done': 'RandSelector',
                    'failed': 'failed'
                },
                autonomy={
                    'done': Autonomy.Off,
                    'failed': Autonomy.Off
                },
                remapping={'config': 'rand_head_config'})

        return _state_machine
Ejemplo n.º 12
0
    def create(self):
        # x:392 y:613, x:739 y:627, x:59 y:602, x:34 y:328
        _state_machine = OperatableStateMachine(
            outcomes=['timeout', 'failed', 'invalid_pose', 'unknown_keys'],
            input_keys=['key_pressed_msg'],
            output_keys=['key_pressed_msg'])
        _state_machine.userdata.key_pressed_msg = KeyPressed()

        # Additional creation code can be added inside the following tags
        # [MANUAL_CREATE]

        # [/MANUAL_CREATE]

        # x:30 y:353, x:130 y:353, x:626 y:359, x:330 y:353, x:430 y:353, x:530 y:353
        _sm_waitkey_0 = ConcurrencyContainer(
            outcomes=['received', 'timeout', 'failed'],
            output_keys=['key_pressed_msg'],
            conditions=[('received', [('WaitKeyPressed', 'received')]),
                        ('timeout', [('WaitTimeout', 'done')]),
                        ('failed', [('WaitKeyPressed', 'unavailable')])])

        with _sm_waitkey_0:
            # x:281 y:146
            OperatableStateMachine.add(
                'WaitKeyPressed',
                WaitForMessageState(topic='/hmi/joy_decoder/keys_pressed',
                                    condition=self.trigger,
                                    buffered=False,
                                    clear=True),
                transitions={
                    'received': 'received',
                    'unavailable': 'failed'
                },
                autonomy={
                    'received': Autonomy.Off,
                    'unavailable': Autonomy.Off
                },
                remapping={'message': 'key_pressed_msg'})

            # x:509 y:151
            OperatableStateMachine.add('WaitTimeout',
                                       WaitState(wait_time=self.timeout),
                                       transitions={'done': 'timeout'},
                                       autonomy={'done': Autonomy.Off})

        with _state_machine:
            # x:51 y:31
            OperatableStateMachine.add(
                'CheckExitEnter',
                DecisionState(
                    outcomes=['animation', 'exit', 'walk', 'unknown'],
                    conditions=self.decision),
                transitions={
                    'animation': 'unknown_keys',
                    'exit': 'unknown_keys',
                    'walk': 'PrepareForWalk',
                    'unknown': 'unknown_keys'
                },
                autonomy={
                    'animation': Autonomy.Off,
                    'exit': Autonomy.Off,
                    'walk': Autonomy.Off,
                    'unknown': Autonomy.Off
                },
                remapping={'input_value': 'key_pressed_msg'})

            # x:326 y:259
            OperatableStateMachine.add(
                'CheckExit',
                DecisionState(
                    outcomes=['animation', 'walk', 'exit', 'unknown'],
                    conditions=self.decision),
                transitions={
                    'animation': 'EndWalkUnknownKeys',
                    'walk': 'ProcessKeyMsg',
                    'exit': 'EndWalkUnknownKeys',
                    'unknown': 'WaitKey'
                },
                autonomy={
                    'animation': Autonomy.Off,
                    'walk': Autonomy.Off,
                    'exit': Autonomy.Off,
                    'unknown': Autonomy.Off
                },
                remapping={'input_value': 'key_pressed_msg'})

            # x:703 y:410
            OperatableStateMachine.add(
                'ExecuteStepSeq',
                ExecuteStepSequenceKey(
                    controller='motion/controller/step_sequence',
                    trajectory_ns='saved_msgs/step_sequence'),
                transitions={
                    'success': 'WaitKey',
                    'unavailable': 'WaitKey',
                    'partial_movement': 'invalid_pose',
                    'invalid_pose': 'invalid_pose',
                    'failure': 'failed'
                },
                autonomy={
                    'success': Autonomy.Off,
                    'unavailable': Autonomy.Off,
                    'partial_movement': Autonomy.Off,
                    'invalid_pose': Autonomy.Off,
                    'failure': Autonomy.Off
                },
                remapping={'trajectory_param': 'motion_param'})

            # x:431 y:381
            OperatableStateMachine.add(
                'WaitKey',
                _sm_waitkey_0,
                transitions={
                    'received': 'CheckExit',
                    'timeout': 'EndWalkTimeout',
                    'failed': 'failed'
                },
                autonomy={
                    'received': Autonomy.Inherit,
                    'timeout': Autonomy.Inherit,
                    'failed': Autonomy.Inherit
                },
                remapping={'key_pressed_msg': 'key_pressed_msg'})

            # x:719 y:246
            OperatableStateMachine.add(
                'CheckNone',
                CheckConditionState(predicate=lambda x: x == None),
                transitions={
                    'true': 'WaitKey',
                    'false': 'ExecuteStepSeq'
                },
                autonomy={
                    'true': Autonomy.Off,
                    'false': Autonomy.Off
                },
                remapping={'input_value': 'motion_param'})

            # x:108 y:289
            OperatableStateMachine.add(
                'EndWalkUnknownKeys',
                ExecuteJointTrajectory(
                    action_topic='motion/controller/joint_trajectory',
                    trajectory_param='crouch_end',
                    trajectory_ns='saved_msgs/joint_trajectory'),
                transitions={
                    'success': 'unknown_keys',
                    'partial_movement': 'invalid_pose',
                    'invalid_pose': 'invalid_pose',
                    'failure': 'failed'
                },
                autonomy={
                    'success': Autonomy.Off,
                    'partial_movement': Autonomy.Off,
                    'invalid_pose': Autonomy.Off,
                    'failure': Autonomy.Off
                })

            # x:379 y:491
            OperatableStateMachine.add(
                'EndWalkTimeout',
                ExecuteJointTrajectory(
                    action_topic='motion/controller/joint_trajectory',
                    trajectory_param='crouch_end',
                    trajectory_ns='saved_msgs/joint_trajectory'),
                transitions={
                    'success': 'timeout',
                    'partial_movement': 'invalid_pose',
                    'invalid_pose': 'invalid_pose',
                    'failure': 'failed'
                },
                autonomy={
                    'success': Autonomy.Off,
                    'partial_movement': Autonomy.Off,
                    'invalid_pose': Autonomy.Off,
                    'failure': Autonomy.Off
                })

            # x:408 y:158
            OperatableStateMachine.add(
                'ProcessKeyMsg',
                CalculationState(calculation=self.process_walk),
                transitions={'done': 'CheckNone'},
                autonomy={'done': Autonomy.Off},
                remapping={
                    'input_value': 'key_pressed_msg',
                    'output_value': 'motion_param'
                })

            # x:211 y:72
            OperatableStateMachine.add(
                'PrepareForWalk',
                ExecuteJointTrajectory(
                    action_topic='motion/controller/joint_trajectory',
                    trajectory_param='crouch_begin',
                    trajectory_ns='saved_msgs/joint_trajectory'),
                transitions={
                    'success': 'ProcessKeyMsg',
                    'partial_movement': 'invalid_pose',
                    'invalid_pose': 'invalid_pose',
                    'failure': 'failed'
                },
                autonomy={
                    'success': Autonomy.Off,
                    'partial_movement': Autonomy.Off,
                    'invalid_pose': Autonomy.Off,
                    'failure': Autonomy.Off
                })

        return _state_machine
    def create(self):
        joint_trajectory_action = 'motion/controller/joint_trajectory'
        voice_topic = 'control'
        storage = 'joint_trajectory/'
        # x:1011 y:80, x:1002 y:571
        _state_machine = OperatableStateMachine(
            outcomes=['finished', 'failed'], input_keys=['be_evil'])
        _state_machine.userdata.be_evil = self.be_evil

        # Additional creation code can be added inside the following tags
        # [MANUAL_CREATE]

        # [/MANUAL_CREATE]

        with _state_machine:
            # x:45 y:143
            OperatableStateMachine.add(
                'SetHeadNominalPose',
                SetJointState(controller='motion/controller/joint_state_head',
                              pose_param='head_nominal',
                              pose_ns='saved_msgs/joint_state',
                              tolerance=0.017,
                              timeout=10.0,
                              joint_topic="joint_states"),
                transitions={
                    'done': 'CheckEvil',
                    'failed': 'failed',
                    'timeout': 'failed'
                },
                autonomy={
                    'done': Autonomy.Off,
                    'failed': Autonomy.Off,
                    'timeout': Autonomy.Off
                })

            # x:421 y:472
            OperatableStateMachine.add('SayDoNotTouch',
                                       TextCommandState(
                                           type='voice/play_wav',
                                           command='do_not_touch_me',
                                           topic=voice_topic),
                                       transitions={'done': 'HoofStamp'},
                                       autonomy={'done': Autonomy.Off})

            # x:496 y:147
            OperatableStateMachine.add(
                'SayOverflow',
                TextCommandState(type='voice/play_wav',
                                 command='you_are_using_software_incorrectly',
                                 topic=voice_topic),
                transitions={'done': 'Applause'},
                autonomy={'done': Autonomy.Off})

            # x:747 y:153
            OperatableStateMachine.add(
                'Applause',
                ExecuteJointTrajectory(action_topic=joint_trajectory_action,
                                       trajectory_param='applause',
                                       trajectory_ns=storage),
                transitions={
                    'success': 'finished',
                    'partial_movement': 'failed',
                    'invalid_pose': 'failed',
                    'failure': 'failed'
                },
                autonomy={
                    'success': Autonomy.Off,
                    'partial_movement': Autonomy.Off,
                    'invalid_pose': Autonomy.Off,
                    'failure': Autonomy.Off
                },
                remapping={'result': 'result'})

            # x:745 y:226
            OperatableStateMachine.add(
                'NoHeadShake',
                ExecuteJointTrajectory(action_topic=joint_trajectory_action,
                                       trajectory_param='head_shake',
                                       trajectory_ns=storage),
                transitions={
                    'success': 'finished',
                    'partial_movement': 'failed',
                    'invalid_pose': 'failed',
                    'failure': 'failed'
                },
                autonomy={
                    'success': Autonomy.Off,
                    'partial_movement': Autonomy.Off,
                    'invalid_pose': Autonomy.Off,
                    'failure': Autonomy.Off
                },
                remapping={'result': 'result'})

            # x:495 y:227
            OperatableStateMachine.add(
                'SayDizzy',
                TextCommandState(type='voice/play_wav',
                                 command='who_am_i_what_is_my_purpose',
                                 topic=voice_topic),
                transitions={'done': 'NoHeadShake'},
                autonomy={'done': Autonomy.Off})

            # x:648 y:466
            OperatableStateMachine.add(
                'HoofStamp',
                ExecuteJointTrajectory(action_topic=joint_trajectory_action,
                                       trajectory_param='hoof_stamp',
                                       trajectory_ns=storage),
                transitions={
                    'success': 'finished',
                    'partial_movement': 'failed',
                    'invalid_pose': 'failed',
                    'failure': 'failed'
                },
                autonomy={
                    'success': Autonomy.Off,
                    'partial_movement': Autonomy.Off,
                    'invalid_pose': Autonomy.Off,
                    'failure': Autonomy.Off
                },
                remapping={'result': 'result'})

            # x:242 y:273
            OperatableStateMachine.add(
                'CheckEvil',
                DecisionState(outcomes=['good', 'evil'],
                              conditions=lambda x: 'evil' if x else 'good'),
                transitions={
                    'good': 'RandomChoiceGood',
                    'evil': 'SayDoNotTouch'
                },
                autonomy={
                    'good': Autonomy.Off,
                    'evil': Autonomy.Low
                },
                remapping={'input_value': 'be_evil'})

            # x:320 y:143
            OperatableStateMachine.add(
                'RandomChoiceGood',
                DecisionState(
                    outcomes=['good1', 'good2'],
                    conditions=lambda x: random.choice(['good1', 'good2'])),
                transitions={
                    'good1': 'SayOverflow',
                    'good2': 'SayDizzy'
                },
                autonomy={
                    'good1': Autonomy.Low,
                    'good2': Autonomy.Low
                },
                remapping={'input_value': 'be_evil'})

        return _state_machine
    def create(self):
        storage = 'joint_trajectory/'
        joint_state_control_topic = 'motion/controller/joint_state/out_joints_src_reset'
        eyes_topic = 'control'
        voice_topic = 'control'
        joint_trajectory_action = 'motion/controller/joint_trajectory'
        # x:322 y:652, x:984 y:622
        _state_machine = OperatableStateMachine(
            outcomes=['finished', 'failed'])
        _state_machine.userdata.counter = 0

        # Additional creation code can be added inside the following tags
        # [MANUAL_CREATE]

        # [/MANUAL_CREATE]

        # x:220 y:573, x:535 y:559
        _sm_seizure_0 = OperatableStateMachine(outcomes=['finished', 'failed'],
                                               input_keys=['counter'])

        with _sm_seizure_0:
            # x:125 y:111
            OperatableStateMachine.add('SayDoNotTouch',
                                       TextCommandState(type='voice/play_wav',
                                                        command='05donottouch',
                                                        topic=voice_topic),
                                       transitions={'done': 'Seizure'},
                                       autonomy={'done': Autonomy.Off})

            # x:389 y:247
            OperatableStateMachine.add(
                'AddCounter',
                CalculationState(calculation=lambda x: x + 1),
                transitions={'done': 'Seizure'},
                autonomy={'done': Autonomy.Off},
                remapping={
                    'input_value': 'counter',
                    'output_value': 'counter'
                })

            # x:412 y:87
            OperatableStateMachine.add(
                'Select',
                DecisionState(
                    outcomes=['say1', 'say2', 'say3', 'end'],
                    conditions=lambda x: ['say1', 'say2', 'say3', 'end'][x]),
                transitions={
                    'say1': 'SayWalk',
                    'say2': 'SayBlaster',
                    'say3': 'SayWin',
                    'end': 'Farewell'
                },
                autonomy={
                    'say1': Autonomy.Off,
                    'say2': Autonomy.Off,
                    'say3': Autonomy.Off,
                    'end': Autonomy.High
                },
                remapping={'input_value': 'counter'})

            # x:612 y:81
            OperatableStateMachine.add('SayWalk',
                                       TextCommandState(type='voice/play_wav',
                                                        command='17walk',
                                                        topic=voice_topic),
                                       transitions={'done': 'AddCounter'},
                                       autonomy={'done': Autonomy.Off})

            # x:681 y:173
            OperatableStateMachine.add('SayBlaster',
                                       TextCommandState(type='voice/play_wav',
                                                        command='18blaster',
                                                        topic=voice_topic),
                                       transitions={'done': 'AddCounter'},
                                       autonomy={'done': Autonomy.Off})

            # x:686 y:240
            OperatableStateMachine.add('SayWin',
                                       TextCommandState(type='voice/play_wav',
                                                        command='08win',
                                                        topic=voice_topic),
                                       transitions={'done': 'AddCounter'},
                                       autonomy={'done': Autonomy.Off})

            # x:85 y:238
            OperatableStateMachine.add(
                'Seizure',
                ExecuteJointTrajectory(action_topic=joint_trajectory_action,
                                       trajectory_param='seizure',
                                       trajectory_ns=storage),
                transitions={
                    'success': 'Select',
                    'partial_movement': 'failed',
                    'invalid_pose': 'failed',
                    'failure': 'failed'
                },
                autonomy={
                    'success': Autonomy.Off,
                    'partial_movement': Autonomy.Off,
                    'invalid_pose': Autonomy.Off,
                    'failure': Autonomy.Off
                },
                remapping={'result': 'result'})

            # x:132 y:419
            OperatableStateMachine.add(
                'Farewell',
                ExecuteJointTrajectory(action_topic=joint_trajectory_action,
                                       trajectory_param='farewell',
                                       trajectory_ns=storage),
                transitions={
                    'success': 'finished',
                    'partial_movement': 'failed',
                    'invalid_pose': 'failed',
                    'failure': 'failed'
                },
                autonomy={
                    'success': Autonomy.Off,
                    'partial_movement': Autonomy.Off,
                    'invalid_pose': Autonomy.Off,
                    'failure': Autonomy.Off
                },
                remapping={'result': 'result'})

        with _state_machine:
            # x:15 y:642
            OperatableStateMachine.add('RandomMovements',
                                       SweetieBotRandHeadMovements(
                                           controller='joint_state_head',
                                           duration=100000,
                                           interval=[2, 3],
                                           max2356=[0.3, 0.3, 1.5, 1.5],
                                           min2356=[-0.3, -0.3, -1.5, -1.5]),
                                       transitions={'done': 'StartPose'},
                                       autonomy={'done': Autonomy.High})

            # x:124 y:352
            OperatableStateMachine.add('WaitSayIamAlive',
                                       WaitState(wait_time=1),
                                       transitions={'done': 'WarmUp'},
                                       autonomy={'done': Autonomy.Off})

            # x:102 y:154
            OperatableStateMachine.add(
                'LookAtHoof',
                ExecuteJointTrajectory(
                    action_topic='motion/controller/joint_trajectory',
                    trajectory_param='look_on_hoof',
                    trajectory_ns=storage),
                transitions={
                    'success': 'SayIamAlive',
                    'partial_movement': 'finished',
                    'invalid_pose': 'finished',
                    'failure': 'finished'
                },
                autonomy={
                    'success': Autonomy.Off,
                    'partial_movement': Autonomy.Off,
                    'invalid_pose': Autonomy.Off,
                    'failure': Autonomy.Off
                },
                remapping={'result': 'result'})

            # x:96 y:484
            OperatableStateMachine.add(
                'WarmUp',
                ExecuteJointTrajectory(
                    action_topic='motion/controller/joint_trajectory',
                    trajectory_param='little_shake_fast',
                    trajectory_ns=storage),
                transitions={
                    'success': 'WaitBeforeDomination',
                    'partial_movement': 'finished',
                    'invalid_pose': 'finished',
                    'failure': 'finished'
                },
                autonomy={
                    'success': Autonomy.Off,
                    'partial_movement': Autonomy.Off,
                    'invalid_pose': Autonomy.Off,
                    'failure': Autonomy.Off
                },
                remapping={'result': 'result'})

            # x:528 y:547
            OperatableStateMachine.add('SayMenace',
                                       TextCommandState(
                                           type='voice/play_wav',
                                           command='02technic',
                                           topic='/sweetie_bot/voice/voice'),
                                       transitions={'done': 'WaitSayMenace'},
                                       autonomy={'done': Autonomy.Off})

            # x:529 y:454
            OperatableStateMachine.add('WaitSayMenace',
                                       WaitState(wait_time=2.3),
                                       transitions={'done': 'EvilLook'},
                                       autonomy={'done': Autonomy.Off})

            # x:396 y:219
            OperatableStateMachine.add(
                'Menace',
                ExecuteJointTrajectory(
                    action_topic='motion/controller/joint_trajectory',
                    trajectory_param='menace',
                    trajectory_ns=storage),
                transitions={
                    'success': 'TryingToAcquireControl',
                    'partial_movement': 'finished',
                    'invalid_pose': 'finished',
                    'failure': 'finished'
                },
                autonomy={
                    'success': Autonomy.Off,
                    'partial_movement': Autonomy.Off,
                    'invalid_pose': Autonomy.Off,
                    'failure': Autonomy.Off
                },
                remapping={'result': 'result'})

            # x:431 y:107
            OperatableStateMachine.add('TryingToAcquireControl',
                                       WaitState(wait_time=10),
                                       transitions={'done': 'SadLook'},
                                       autonomy={'done': Autonomy.Off})

            # x:429 y:301
            OperatableStateMachine.add('SayBattleSystemActivation',
                                       TextCommandState(
                                           type='voice/play_wav',
                                           command='03domination',
                                           topic='/sweetie_bot/voice/voice'),
                                       transitions={'done': 'Menace'},
                                       autonomy={'done': Autonomy.Off})

            # x:840 y:91
            OperatableStateMachine.add('SayDominationFailed',
                                       TextCommandState(
                                           type='voice/play_wav',
                                           command='04notfound',
                                           topic='/sweetie_bot/voice/voice'),
                                       transitions={'done': 'WaitFailed'},
                                       autonomy={'done': Autonomy.Off})

            # x:818 y:281
            OperatableStateMachine.add(
                'MenceCanceled',
                ExecuteJointTrajectory(
                    action_topic='motion/controller/joint_trajectory',
                    trajectory_param='menace_canceled',
                    trajectory_ns=storage),
                transitions={
                    'success': 'WaitBeforeHoofStamp',
                    'partial_movement': 'finished',
                    'invalid_pose': 'finished',
                    'failure': 'finished'
                },
                autonomy={
                    'success': Autonomy.Off,
                    'partial_movement': Autonomy.Off,
                    'invalid_pose': Autonomy.Off,
                    'failure': Autonomy.Off
                },
                remapping={'result': 'result'})

            # x:885 y:188
            OperatableStateMachine.add('WaitFailed',
                                       WaitState(wait_time=1),
                                       transitions={'done': 'MenceCanceled'},
                                       autonomy={'done': Autonomy.Off})

            # x:139 y:573
            OperatableStateMachine.add('WaitBeforeDomination',
                                       WaitState(wait_time=2),
                                       transitions={'done': 'RedEyes'},
                                       autonomy={'done': Autonomy.Off})

            # x:856 y:396
            OperatableStateMachine.add('WaitBeforeHoofStamp',
                                       WaitState(wait_time=1),
                                       transitions={'done': 'HoofStamp'},
                                       autonomy={'done': Autonomy.Off})

            # x:826 y:490
            OperatableStateMachine.add(
                'HoofStamp',
                ExecuteJointTrajectory(
                    action_topic='motion/controller/joint_trajectory',
                    trajectory_param='hoof_stamp',
                    trajectory_ns=storage),
                transitions={
                    'success': 'NormalLook',
                    'partial_movement': 'finished',
                    'invalid_pose': 'finished',
                    'failure': 'finished'
                },
                autonomy={
                    'success': Autonomy.Off,
                    'partial_movement': Autonomy.Off,
                    'invalid_pose': Autonomy.Off,
                    'failure': Autonomy.Off
                },
                remapping={'result': 'result'})

            # x:385 y:567
            OperatableStateMachine.add('RedEyes',
                                       TextCommandState(type='eyes/emotion',
                                                        command='red_eyes',
                                                        topic=eyes_topic),
                                       transitions={'done': 'SayMenace'},
                                       autonomy={'done': Autonomy.Off})

            # x:151 y:77
            OperatableStateMachine.add(
                'LookAround',
                ExecuteJointTrajectory(
                    action_topic='motion/controller/joint_trajectory',
                    trajectory_param='look_around',
                    trajectory_ns=storage),
                transitions={
                    'success': 'LookAtHoof',
                    'partial_movement': 'finished',
                    'invalid_pose': 'finished',
                    'failure': 'finished'
                },
                autonomy={
                    'success': Autonomy.Off,
                    'partial_movement': Autonomy.Off,
                    'invalid_pose': Autonomy.Off,
                    'failure': Autonomy.Off
                },
                remapping={'result': 'result'})

            # x:375 y:18
            OperatableStateMachine.add('Wait',
                                       WaitState(wait_time=1),
                                       transitions={'done': 'LookAround'},
                                       autonomy={'done': Autonomy.Off})

            # x:195 y:10
            OperatableStateMachine.add('NormalEyes',
                                       TextCommandState(type='eyes/emotion',
                                                        command='normal',
                                                        topic=eyes_topic),
                                       transitions={'done': 'Wait'},
                                       autonomy={'done': Autonomy.Off})

            # x:519 y:374
            OperatableStateMachine.add(
                'EvilLook',
                TextCommandState(type='eyes/emotion',
                                 command='evil_look',
                                 topic=eyes_topic),
                transitions={'done': 'SayBattleSystemActivation'},
                autonomy={'done': Autonomy.Off})

            # x:696 y:85
            OperatableStateMachine.add(
                'SadLook',
                TextCommandState(type='eyes/emotion',
                                 command='sad_look',
                                 topic=eyes_topic),
                transitions={'done': 'SayDominationFailed'},
                autonomy={'done': Autonomy.Off})

            # x:817 y:569
            OperatableStateMachine.add('NormalLook',
                                       TextCommandState(type='eyes/emotion',
                                                        command='normal_look',
                                                        topic=eyes_topic),
                                       transitions={'done': 'Seizure'},
                                       autonomy={'done': Autonomy.High})

            # x:1124 y:445
            OperatableStateMachine.add('Seizure',
                                       _sm_seizure_0,
                                       transitions={
                                           'finished': 'finished',
                                           'failed': 'failed'
                                       },
                                       autonomy={
                                           'finished': Autonomy.Inherit,
                                           'failed': Autonomy.Inherit
                                       },
                                       remapping={'counter': 'counter'})

            # x:40 y:35
            OperatableStateMachine.add(
                'StartPose',
                PublisherState(topic=joint_state_control_topic,
                               msg_type=JointState,
                               value={
                                   'name': [
                                       'joint51', 'joint52', 'joint53',
                                       'eyes_pitch', 'eyes_yaw'
                                   ],
                                   'position': [0.2, 0.0, 0, 0.0, 0.0]
                               }),
                transitions={
                    'done': 'NormalEyes',
                    'failed': 'finished'
                },
                autonomy={
                    'done': Autonomy.Off,
                    'failed': Autonomy.Off
                })

            # x:127 y:254
            OperatableStateMachine.add('SayIamAlive',
                                       TextCommandState(
                                           type='voice/play_wav',
                                           command='01alive',
                                           topic='/sweetie_bot/voice/voice'),
                                       transitions={'done': 'WaitSayIamAlive'},
                                       autonomy={'done': Autonomy.Off})

        return _state_machine
	def create(self):
		# x:902 y:403, x:697 y:491
		_state_machine = OperatableStateMachine(outcomes=['finished', 'failed'])
		_state_machine.userdata.be_evil = False
		_state_machine.userdata.unused = None

		# Additional creation code can be added inside the following tags
		# [MANUAL_CREATE]
		
		# [/MANUAL_CREATE]


		with _state_machine:
			# x:32 y:127
			OperatableStateMachine.add('SetStandingPose',
										SetJointState(controller='motion/controller/joint_state_head', pose_param='body_nominal', pose_ns='saved_msgs/joint_state', tolerance=0.017, timeout=10.0, joint_topic="joint_states"),
										transitions={'done': 'SelectTrick', 'failed': 'failed', 'timeout': 'failed'},
										autonomy={'done': Autonomy.Off, 'failed': Autonomy.Off, 'timeout': Autonomy.Off})

			# x:371 y:161
			OperatableStateMachine.add('Greeting',
										self.use_behavior(GreetingSM, 'Greeting'),
										transitions={'finished': 'RandHead', 'failed': 'failed'},
										autonomy={'finished': Autonomy.Inherit, 'failed': Autonomy.Inherit},
										remapping={'be_evil': 'be_evil'})

			# x:371 y:284
			OperatableStateMachine.add('Play',
										self.use_behavior(PlaySM, 'Play'),
										transitions={'finished': 'RandHead', 'failed': 'failed'},
										autonomy={'finished': Autonomy.Inherit, 'failed': Autonomy.Inherit},
										remapping={'be_evil': 'be_evil'})

			# x:202 y:154
			OperatableStateMachine.add('SelectTrick',
										DecisionState(outcomes=['play','cheer','greet'], conditions=lambda x: random.choice(['play','cheer','greet'])),
										transitions={'play': 'Play', 'cheer': 'Cheer', 'greet': 'Greeting'},
										autonomy={'play': Autonomy.Off, 'cheer': Autonomy.Off, 'greet': Autonomy.Off},
										remapping={'input_value': 'unused'})

			# x:823 y:274
			OperatableStateMachine.add('PrepareToWalk',
										ExecuteJointTrajectory(action_topic='motion/controller/joint_trajectory', trajectory_param='crouch_begin', trajectory_ns='saved_msgs/joint_trajectory'),
										transitions={'success': 'finished', 'partial_movement': 'failed', 'invalid_pose': 'failed', 'failure': 'failed'},
										autonomy={'success': Autonomy.Off, 'partial_movement': Autonomy.Off, 'invalid_pose': Autonomy.Off, 'failure': Autonomy.Off})

			# x:376 y:38
			OperatableStateMachine.add('Cheer',
										self.use_behavior(CheerSM, 'Cheer'),
										transitions={'finished': 'RandHead', 'failed': 'failed'},
										autonomy={'finished': Autonomy.Inherit, 'failed': Autonomy.Inherit},
										remapping={'be_evil': 'be_evil'})

			# x:774 y:45
			OperatableStateMachine.add('RandHead',
										SweetieBotRandHeadMovements(controller='joint_state_head', duration=8, interval=[3,5], max2356=[0.3,0.3,1.5,1.5], min2356=[-0.3,-0.3,-1.5,-1.5]),
										transitions={'done': 'SetHeadNominal', 'failed': 'failed'},
										autonomy={'done': Autonomy.Off, 'failed': Autonomy.Off},
										remapping={'config': 'unused'})

			# x:809 y:138
			OperatableStateMachine.add('SetHeadNominal',
										SetJointState(controller='motion/controller/joint_state_head', pose_param='head_nominal', pose_ns='saved_msgs/joint_state', tolerance=0.017, timeout=10.0, joint_topic="joint_states"),
										transitions={'done': 'PrepareToWalk', 'failed': 'failed', 'timeout': 'failed'},
										autonomy={'done': Autonomy.Off, 'failed': Autonomy.Off, 'timeout': Autonomy.Off})


		return _state_machine
Ejemplo n.º 16
0
    def create(self):
        # x:30 y:353, x:488 y:318
        _state_machine = OperatableStateMachine(
            outcomes=['finished', 'failed'])
        _state_machine.userdata.unused = None

        # Additional creation code can be added inside the following tags
        # [MANUAL_CREATE]

        # [/MANUAL_CREATE]

        with _state_machine:
            # x:189 y:30
            OperatableStateMachine.add(
                'CheckCrouched',
                CheckJointState(outcomes=['body_crouched', 'unknown'],
                                pose_ns='saved_msgs/joint_state',
                                tolerance=0.17,
                                joint_topic="joint_states",
                                timeout=1.0),
                transitions={
                    'body_crouched': 'StandUp',
                    'unknown': 'RandHeadMovements'
                },
                autonomy={
                    'body_crouched': Autonomy.Off,
                    'unknown': Autonomy.Off
                })

            # x:196 y:256
            OperatableStateMachine.add(
                'HeadNominal',
                SetJointState(controller='motion/controller/joint_state_head',
                              pose_param='head_nominal',
                              pose_ns='saved_msgs/joint_state',
                              tolerance=0.017,
                              timeout=10.0,
                              joint_topic="joint_states"),
                transitions={
                    'done': 'finished',
                    'failed': 'failed',
                    'timeout': 'failed'
                },
                autonomy={
                    'done': Autonomy.Off,
                    'failed': Autonomy.Off,
                    'timeout': Autonomy.Off
                })

            # x:445 y:78
            OperatableStateMachine.add(
                'StandUp',
                ExecuteJointTrajectory(
                    action_topic='motion/controller/joint_trajectory',
                    trajectory_param='crouch_end',
                    trajectory_ns='saved_msgs/joint_trajectory'),
                transitions={
                    'success': 'RandHeadMovements',
                    'partial_movement': 'failed',
                    'invalid_pose': 'failed',
                    'failure': 'failed'
                },
                autonomy={
                    'success': Autonomy.Off,
                    'partial_movement': Autonomy.Off,
                    'invalid_pose': Autonomy.Off,
                    'failure': Autonomy.Off
                })

            # x:176 y:144
            OperatableStateMachine.add('RandHeadMovements',
                                       SweetieBotRandHeadMovements(
                                           controller='joint_state_head',
                                           duration=self.timeout,
                                           interval=[1, 4],
                                           max2356=[0.3, 0.3, 1.5, 1.5],
                                           min2356=[-0.3, -0.3, -1.5, -1.5]),
                                       transitions={
                                           'done': 'HeadNominal',
                                           'failed': 'failed'
                                       },
                                       autonomy={
                                           'done': Autonomy.Off,
                                           'failed': Autonomy.Off
                                       },
                                       remapping={'config': 'unused'})

        return _state_machine
    def create(self):
        storage = 'joint_trajectory/'
        # x:200 y:516, x:130 y:322
        _state_machine = OperatableStateMachine(
            outcomes=['finished', 'failed'])

        # Additional creation code can be added inside the following tags
        # [MANUAL_CREATE]

        # [/MANUAL_CREATE]

        with _state_machine:
            # x:30 y:40
            OperatableStateMachine.add('SayMenace',
                                       TextCommandState(type='voice/play_wav',
                                                        command='fear',
                                                        topic='voice/voice'),
                                       transitions={'done': 'MoveApplause'},
                                       autonomy={'done': Autonomy.Off})

            # x:664 y:212
            OperatableStateMachine.add(
                'MoveMenace',
                ExecuteJointTrajectory(
                    action_topic='motion/controller/joint_trajectory',
                    trajectory_param='menace',
                    trajectory_ns=storage),
                transitions={
                    'success': 'EyesNormal',
                    'partial_movement': 'failed',
                    'invalid_pose': 'failed',
                    'failure': 'failed'
                },
                autonomy={
                    'success': Autonomy.Full,
                    'partial_movement': Autonomy.Off,
                    'invalid_pose': Autonomy.Off,
                    'failure': Autonomy.Off
                },
                remapping={'result': 'result'})

            # x:28 y:114
            OperatableStateMachine.add(
                'MoveApplause',
                ExecuteJointTrajectory(
                    action_topic='motion/controller/joint_trajectory',
                    trajectory_param='applause',
                    trajectory_ns=storage),
                transitions={
                    'success': 'MoveBuck',
                    'partial_movement': 'failed',
                    'invalid_pose': 'failed',
                    'failure': 'failed'
                },
                autonomy={
                    'success': Autonomy.Off,
                    'partial_movement': Autonomy.Off,
                    'invalid_pose': Autonomy.Off,
                    'failure': Autonomy.Off
                },
                remapping={'result': 'result'})

            # x:326 y:36
            OperatableStateMachine.add(
                'MoveBuck',
                ExecuteJointTrajectory(
                    action_topic='motion/controller/joint_trajectory',
                    trajectory_param='buck3',
                    trajectory_ns=storage),
                transitions={
                    'success': 'SetRedEyes',
                    'partial_movement': 'failed',
                    'invalid_pose': 'failed',
                    'failure': 'failed'
                },
                autonomy={
                    'success': Autonomy.Off,
                    'partial_movement': Autonomy.Off,
                    'invalid_pose': Autonomy.Off,
                    'failure': Autonomy.Off
                },
                remapping={'result': 'result'})

            # x:610 y:39
            OperatableStateMachine.add('SetRedEyes',
                                       TextCommandState(type='eyes/emotion',
                                                        command='red_eyes',
                                                        topic='control'),
                                       transitions={'done': 'MoveMenace'},
                                       autonomy={'done': Autonomy.Off})

            # x:684 y:336
            OperatableStateMachine.add(
                'EyesNormal',
                TextCommandState(type='eyes/emotion',
                                 command='normal',
                                 topic='control'),
                transitions={'done': 'MoveMenaceCanceled'},
                autonomy={'done': Autonomy.Full})

            # x:630 y:467
            OperatableStateMachine.add(
                'MoveMenaceCanceled',
                ExecuteJointTrajectory(
                    action_topic='motion/controller/joint_trajectory',
                    trajectory_param='menace_canceled',
                    trajectory_ns=storage),
                transitions={
                    'success': 'MoveHeadShake',
                    'partial_movement': 'failed',
                    'invalid_pose': 'failed',
                    'failure': 'failed'
                },
                autonomy={
                    'success': Autonomy.Off,
                    'partial_movement': Autonomy.Off,
                    'invalid_pose': Autonomy.Off,
                    'failure': Autonomy.Off
                },
                remapping={'result': 'result'})

            # x:340 y:480
            OperatableStateMachine.add(
                'MoveHeadShake',
                ExecuteJointTrajectory(
                    action_topic='motion/controller/joint_trajectory',
                    trajectory_param='look_around',
                    trajectory_ns=storage),
                transitions={
                    'success': 'finished',
                    'partial_movement': 'failed',
                    'invalid_pose': 'failed',
                    'failure': 'failed'
                },
                autonomy={
                    'success': Autonomy.Off,
                    'partial_movement': Autonomy.Off,
                    'invalid_pose': Autonomy.Off,
                    'failure': Autonomy.Off
                },
                remapping={'result': 'result'})

        return _state_machine
Ejemplo n.º 18
0
 def parse_compound_action_msg(self, compound_action_msg):
     ''' Converts sweetie_bot_text_msgs.msg.CompoundActionElement to the list of SimpleActions.'''
     # convert parameteres to actions
     actions = list()
     for i, p in enumerate(compound_action_msg.action_list):
         if not isinstance(p.seq_num, int) or not isinstance(
                 p.seq_delay, float):
             raise TypeError, 'CompoundAction: Incorrect action (seq_num,seq_delay) pair in position %d. (int,float) pair was expected..' % i
         if p.seq_num >= i + 1 or p.seq_delay < 0:
             raise TypeError, 'CompoundAction parse error: incorrect action (seq_num,seq_delay) pair in position %d. seq_num must reference only previously defined actions.' % i
         if p.cmd.type == None:
             actions.append(None)
         else:
             # get parameters
             previous_action = None if p.seq_num == 0 else actions[p.seq_num
                                                                   - 1]
             delay = p.seq_delay
             description = p.cmd.type + ' ' + p.cmd.command
             if not isinstance(p.cmd.type, str):
                 raise TypeError, 'CompoundAction: Incorrect action type %d. Type must be string or None.' % i
             # Select action
             if p.cmd.type == 'motion/joint_trajectory':
                 flexbe_state = ExecuteJointTrajectory(
                     trajectory_param=p.cmd.command)
                 outcome_map = {
                     'success': 'success',
                     'invalid_pose': 'invalid_pose',
                     'partial_movement': 'invalid_pose'
                 }
             elif p.cmd.type == 'motion/step_sequence':
                 flexbe_state = ExecuteStepSequence(
                     trajectory_param=p.cmd.command)
                 outcome_map = {
                     'success': 'success',
                     'invalid_pose': 'invalid_pose',
                     'partial_movement': 'invalid_pose'
                 }
             elif p.cmd.type == 'set/joint_state':
                 flexbe_state = SetJointState(pose_param=p.cmd.command)
                 outcome_map = {
                     'done': 'success',
                     'timeout': 'invalid_pose'
                 }
             elif p.cmd.type == 'generate/step_sequence':
                 flexbe_state = GenerateStepSequence(
                     trajectory_param=p.cmd.command)
                 outcome_map = {
                     'success': 'success',
                     'invalid_pose': 'invalid_pose',
                     'partial_movement': 'invalid_pose'
                 }
             else:
                 flexbe_state = TextCommandState(p.cmd.type,
                                                 p.cmd.command,
                                                 topic='control')
                 outcome_map = {'done': 'success'}
             # add action to list
             actions.append(
                 CompoundActionBase.SimpleAction(previous_action, delay,
                                                 'WAITING', flexbe_state,
                                                 outcome_map, 0.0,
                                                 description))
     # remove None actions
     return [a for a in actions if a != None]
    def create(self):
        # x:821 y:618, x:163 y:383
        _state_machine = OperatableStateMachine(
            outcomes=['finished', 'failed'])
        _state_machine.userdata.unused = None

        # Additional creation code can be added inside the following tags
        # [MANUAL_CREATE]

        # [/MANUAL_CREATE]

        with _state_machine:
            # x:88 y:87
            OperatableStateMachine.add(
                'PrepareToWalk',
                SetCartesianPose(controller='motion/controller/stance',
                                 pose=[0.0, 0.0, 0.2085, 0.0, 0.0, 0.0],
                                 frame_id='base_link_path',
                                 frame_is_moving=False,
                                 resources=['leg1', 'leg2', 'leg3', 'leg4'],
                                 actuator_frame_id='base_link',
                                 tolerance_lin=0.001,
                                 tolerance_ang=0.0085,
                                 timeout=10.0),
                transitions={
                    'done': 'CheckCrouched',
                    'failed': 'failed',
                    'timeout': 'failed'
                },
                autonomy={
                    'done': Autonomy.Off,
                    'failed': Autonomy.Off,
                    'timeout': Autonomy.Off
                })

            # x:583 y:31
            OperatableStateMachine.add(
                'WalkFwd',
                ExecuteStepSequence(
                    controller='motion/controller/step_sequence',
                    trajectory_param='walk_fwd_40',
                    trajectory_ns='saved_msgs/step_sequence'),
                transitions={
                    'success': 'GenerateTurnLeft',
                    'partial_movement': 'failed',
                    'invalid_pose': 'failed',
                    'failure': 'failed'
                },
                autonomy={
                    'success': Autonomy.Off,
                    'partial_movement': Autonomy.Off,
                    'invalid_pose': Autonomy.Off,
                    'failure': Autonomy.Off
                })

            # x:461 y:256
            OperatableStateMachine.add(
                'EndWalk',
                SetJointState(controller='motion/controller/joint_state_head',
                              pose_param='nominal',
                              pose_ns='saved_msgs/joint_state',
                              tolerance=0.017,
                              timeout=10.0,
                              joint_topic="joint_states"),
                transitions={
                    'done': 'Greeting',
                    'failed': 'failed',
                    'timeout': 'failed'
                },
                autonomy={
                    'done': Autonomy.Off,
                    'failed': Autonomy.Off,
                    'timeout': Autonomy.Off
                })

            # x:654 y:319
            OperatableStateMachine.add(
                'Greeting',
                ExecuteJointTrajectory(
                    action_topic='motion/controller/joint_trajectory',
                    trajectory_param='greeting',
                    trajectory_ns='saved_msgs/joint_trajectory'),
                transitions={
                    'success': 'CompoundCrouchAndWalk',
                    'partial_movement': 'failed',
                    'invalid_pose': 'failed',
                    'failure': 'failed'
                },
                autonomy={
                    'success': Autonomy.Off,
                    'partial_movement': Autonomy.Off,
                    'invalid_pose': Autonomy.Off,
                    'failure': Autonomy.Off
                })

            # x:671 y:447
            OperatableStateMachine.add(
                'CompoundCrouchAndWalk',
                CompoundAction(t1=[0, 0.0],
                               type1='motion/joint_trajectory',
                               cmd1='crouch_begin',
                               t2=[1, 0.0],
                               type2='motion/step_sequence',
                               cmd2='walk_fwd_40',
                               t3=[2, 0.0],
                               type3='generate/step_sequence',
                               cmd3='to_nominal',
                               t4=[3, 0.0],
                               type4='set/joint_state',
                               cmd4='nominal'),
                transitions={
                    'success': 'ComponudActionFromParam',
                    'invalid_pose': 'failed',
                    'failure': 'failed'
                },
                autonomy={
                    'success': Autonomy.Off,
                    'invalid_pose': Autonomy.Off,
                    'failure': Autonomy.Off
                })

            # x:601 y:137
            OperatableStateMachine.add(
                'GenerateTurnLeft',
                GenerateStepSequence(controller='clop_generator',
                                     trajectory_param='turn_left_45',
                                     trajectory_ns='saved_msgs/move_base'),
                transitions={
                    'success': 'EndWalk',
                    'solution_not_found': 'failed',
                    'partial_movement': 'failed',
                    'invalid_pose': 'failed',
                    'failure': 'failed'
                },
                autonomy={
                    'success': Autonomy.Off,
                    'solution_not_found': Autonomy.Off,
                    'partial_movement': Autonomy.Off,
                    'invalid_pose': Autonomy.Off,
                    'failure': Autonomy.Off
                })

            # x:507 y:546
            OperatableStateMachine.add(
                'ComponudActionFromParam',
                CompoundActionParam(action_param='brohoof',
                                    action_ns='saved_msgs/compound_action'),
                transitions={
                    'success': 'finished',
                    'invalid_pose': 'failed',
                    'failure': 'failed'
                },
                autonomy={
                    'success': Autonomy.Off,
                    'invalid_pose': Autonomy.Off,
                    'failure': Autonomy.Off
                })

            # x:298 y:42
            OperatableStateMachine.add(
                'CheckCrouched',
                CheckJointState(outcomes=[
                    'body_nominal', 'body_lying', 'body_crouched', 'unknown'
                ],
                                pose_ns='saved_msgs/joint_state',
                                tolerance=0.17,
                                joint_topic="joint_states",
                                timeout=1.0),
                transitions={
                    'body_nominal': 'failed',
                    'body_lying': 'failed',
                    'unknown': 'WalkFwd',
                    'body_crouched': 'WalkFwd'
                },
                autonomy={
                    'body_nominal': Autonomy.Off,
                    'body_lying': Autonomy.Off,
                    'unknown': Autonomy.Off,
                    'body_crouched': Autonomy.Off
                })

        return _state_machine
    def create(self):
        # x:30 y:365, x:183 y:341, x:352 y:353
        _state_machine = OperatableStateMachine(
            outcomes=['finished', 'failed', 'invalid_pose'])

        # Additional creation code can be added inside the following tags
        # [MANUAL_CREATE]

        # [/MANUAL_CREATE]

        # x:584 y:41, x:452 y:346, x:230 y:353
        _sm_container_0 = OperatableStateMachine(
            outcomes=['finished', 'failed', 'invalid_pose'])

        with _sm_container_0:
            # x:127 y:102
            OperatableStateMachine.add(
                'CheckBodyPose',
                CheckJointState(
                    outcomes=['body_nominal', 'body_crouched', 'unknown'],
                    pose_ns='saved_msgs/joint_state',
                    tolerance=0.17,
                    joint_topic="joint_states",
                    timeout=1.0),
                transitions={
                    'body_nominal': 'finished',
                    'unknown': 'invalid_pose',
                    'body_crouched': 'CrouchEnd'
                },
                autonomy={
                    'body_nominal': Autonomy.Off,
                    'unknown': Autonomy.Off,
                    'body_crouched': Autonomy.Off
                })

            # x:350 y:172
            OperatableStateMachine.add(
                'CrouchEnd',
                ExecuteJointTrajectory(
                    action_topic='motion/controller/joint_trajectory',
                    trajectory_param='crouch_end',
                    trajectory_ns='saved_msgs/joint_trajectory'),
                transitions={
                    'success': 'finished',
                    'partial_movement': 'invalid_pose',
                    'invalid_pose': 'invalid_pose',
                    'failure': 'failed'
                },
                autonomy={
                    'success': Autonomy.Off,
                    'partial_movement': Autonomy.Off,
                    'invalid_pose': Autonomy.Off,
                    'failure': Autonomy.Off
                })

        # x:30 y:353, x:130 y:353, x:230 y:353, x:330 y:353, x:430 y:353, x:530 y:353, x:630 y:353, x:730 y:353
        _sm_standup_1 = ConcurrencyContainer(
            outcomes=['finished', 'invalid_pose', 'failed'],
            conditions=[('failed', [('HeadNominal', 'failed')]),
                        ('finished', [('HeadNominal', 'done'),
                                      ('Container', 'finished')]),
                        ('invalid_pose', [('HeadNominal', 'timeout')]),
                        ('failed', [('Container', 'failed')]),
                        ('invalid_pose', [('Container', 'invalid_pose')])])

        with _sm_standup_1:
            # x:425 y:127
            OperatableStateMachine.add('Container',
                                       _sm_container_0,
                                       transitions={
                                           'finished': 'finished',
                                           'failed': 'failed',
                                           'invalid_pose': 'invalid_pose'
                                       },
                                       autonomy={
                                           'finished': Autonomy.Inherit,
                                           'failed': Autonomy.Inherit,
                                           'invalid_pose': Autonomy.Inherit
                                       })

            # x:105 y:127
            OperatableStateMachine.add(
                'HeadNominal',
                SetJointState(controller='motion/controller/joint_state_head',
                              pose_param='head_nominal',
                              pose_ns='saved_msgs/joint_state',
                              tolerance=0.017,
                              timeout=10.0,
                              joint_topic="joint_states"),
                transitions={
                    'done': 'finished',
                    'failed': 'failed',
                    'timeout': 'invalid_pose'
                },
                autonomy={
                    'done': Autonomy.Off,
                    'failed': Autonomy.Off,
                    'timeout': Autonomy.Off
                })

        with _state_machine:
            # x:108 y:85
            OperatableStateMachine.add(
                'CompoundAction',
                CompoundActionParam(action_param=self.action_name,
                                    action_ns='saved_msgs/compound_action'),
                transitions={
                    'success': 'finished',
                    'invalid_pose': 'StandUp',
                    'failure': 'failed'
                },
                autonomy={
                    'success': Autonomy.Off,
                    'invalid_pose': Autonomy.Off,
                    'failure': Autonomy.Off
                })

            # x:405 y:81
            OperatableStateMachine.add('StandUp',
                                       _sm_standup_1,
                                       transitions={
                                           'finished': 'CompoundAction',
                                           'invalid_pose': 'invalid_pose',
                                           'failed': 'failed'
                                       },
                                       autonomy={
                                           'finished': Autonomy.Inherit,
                                           'invalid_pose': Autonomy.Inherit,
                                           'failed': Autonomy.Inherit
                                       })

        return _state_machine
    def create(self):
        joint_trajectory_action = 'motion/controller/joint_trajectory'
        storage = 'joint_trajectory/'
        voice_topic = 'voice/voice'
        eye_cmd_topic = 'control'
        # x:1034 y:292, x:622 y:639
        _state_machine = OperatableStateMachine(
            outcomes=['finished', 'failed'],
            input_keys=['be_evil', 'new_be_evil'],
            output_keys=['be_evil'])
        _state_machine.userdata.be_evil = self.be_evil
        _state_machine.userdata.new_be_evil = self.new_be_evil
        _state_machine.userdata.head_crooked_pose = [0, 0, 0, 0.4]

        # Additional creation code can be added inside the following tags
        # [MANUAL_CREATE]

        # [/MANUAL_CREATE]

        with _state_machine:
            # x:96 y:163
            OperatableStateMachine.add('CheckEvil',
                                       DecisionState(
                                           outcomes=['good', 'evil'],
                                           conditions=lambda x: 'good'
                                           if not x else 'evil'),
                                       transitions={
                                           'good': 'CheckChangeToEvil',
                                           'evil': 'CheckChangeToGood'
                                       },
                                       autonomy={
                                           'good': Autonomy.Off,
                                           'evil': Autonomy.Off
                                       },
                                       remapping={'input_value': 'be_evil'})

            # x:252 y:50
            OperatableStateMachine.add(
                'CheckChangeToEvil',
                DecisionState(outcomes=['yes', 'no'],
                              conditions=lambda x: 'yes' if x else 'no'),
                transitions={
                    'yes': 'RedEyes',
                    'no': 'NormalEyes'
                },
                autonomy={
                    'yes': Autonomy.Off,
                    'no': Autonomy.Off
                },
                remapping={'input_value': 'new_be_evil'})

            # x:426 y:48
            OperatableStateMachine.add('RedEyes',
                                       TextCommandState(type='eyes/emotion',
                                                        command='red_eyes',
                                                        topic=eye_cmd_topic),
                                       transitions={'done': 'Seizure'},
                                       autonomy={'done': Autonomy.Off})

            # x:737 y:30
            OperatableStateMachine.add(
                'Seizure',
                ExecuteJointTrajectory(action_topic=joint_trajectory_action,
                                       trajectory_param='seizure_evil',
                                       trajectory_ns=storage),
                transitions={
                    'success': 'SetEvil',
                    'partial_movement': 'failed',
                    'invalid_pose': 'failed',
                    'failure': 'failed'
                },
                autonomy={
                    'success': Autonomy.Off,
                    'partial_movement': Autonomy.Off,
                    'invalid_pose': Autonomy.Off,
                    'failure': Autonomy.Off
                },
                remapping={'result': 'result'})

            # x:961 y:162
            OperatableStateMachine.add(
                'SetEvil',
                CalculationState(calculation=lambda x: True),
                transitions={'done': 'finished'},
                autonomy={'done': Autonomy.Off},
                remapping={
                    'input_value': 'be_evil',
                    'output_value': 'be_evil'
                })

            # x:419 y:135
            OperatableStateMachine.add('NormalEyes',
                                       TextCommandState(type='eyes/emotion',
                                                        command='normal',
                                                        topic=eye_cmd_topic),
                                       transitions={'done': 'finished'},
                                       autonomy={'done': Autonomy.Off})

            # x:195 y:281
            OperatableStateMachine.add(
                'CheckChangeToGood',
                DecisionState(outcomes=['yes', 'no'],
                              conditions=lambda x: 'no' if x else 'yes'),
                transitions={
                    'yes': 'NormalEyes2',
                    'no': 'RedEyes2'
                },
                autonomy={
                    'yes': Autonomy.Off,
                    'no': Autonomy.Off
                },
                remapping={'input_value': 'new_be_evil'})

            # x:416 y:331
            OperatableStateMachine.add(
                'NormalEyes2',
                TextCommandState(type='eyes/emotion',
                                 command='normal',
                                 topic=eye_cmd_topic),
                transitions={'done': 'HeadAssumeBasicPose'},
                autonomy={'done': Autonomy.Off})

            # x:613 y:321
            OperatableStateMachine.add(
                'ShakeHead',
                ExecuteJointTrajectory(action_topic=joint_trajectory_action,
                                       trajectory_param='head_shake',
                                       trajectory_ns=storage),
                transitions={
                    'success': 'LookAround',
                    'partial_movement': 'failed',
                    'invalid_pose': 'failed',
                    'failure': 'failed'
                },
                autonomy={
                    'success': Autonomy.Off,
                    'partial_movement': Autonomy.Off,
                    'invalid_pose': Autonomy.Off,
                    'failure': Autonomy.Off
                },
                remapping={'result': 'result'})

            # x:894 y:326
            OperatableStateMachine.add(
                'SetGood',
                CalculationState(calculation=lambda x: False),
                transitions={'done': 'finished'},
                autonomy={'done': Autonomy.Off},
                remapping={
                    'input_value': 'be_evil',
                    'output_value': 'be_evil'
                })

            # x:671 y:437
            OperatableStateMachine.add(
                'LookAround',
                ExecuteJointTrajectory(action_topic=joint_trajectory_action,
                                       trajectory_param='look_around',
                                       trajectory_ns=storage),
                transitions={
                    'success': 'SetGood',
                    'partial_movement': 'failed',
                    'invalid_pose': 'failed',
                    'failure': 'failed'
                },
                autonomy={
                    'success': Autonomy.Off,
                    'partial_movement': Autonomy.Off,
                    'invalid_pose': Autonomy.Off,
                    'failure': Autonomy.Off
                },
                remapping={'result': 'result'})

            # x:420 y:200
            OperatableStateMachine.add('RedEyes2',
                                       TextCommandState(type='eyes/emotion',
                                                        command='red_eyes',
                                                        topic=eye_cmd_topic),
                                       transitions={'done': 'finished'},
                                       autonomy={'done': Autonomy.Off})

            # x:444 y:420
            OperatableStateMachine.add('HeadAssumeBasicPose',
                                       SrdfStateToMoveit(
                                           config_name='head_basic',
                                           move_group='head',
                                           action_topic='move_group',
                                           robot_name=''),
                                       transitions={
                                           'reached': 'ShakeHead',
                                           'planning_failed': 'failed',
                                           'control_failed': 'failed',
                                           'param_error': 'failed'
                                       },
                                       autonomy={
                                           'reached': Autonomy.Off,
                                           'planning_failed': Autonomy.Off,
                                           'control_failed': Autonomy.Off,
                                           'param_error': Autonomy.Off
                                       },
                                       remapping={
                                           'config_name': 'config_name',
                                           'move_group': 'move_group',
                                           'robot_name': 'robot_name',
                                           'action_topic': 'action_topic',
                                           'joint_values': 'joint_values',
                                           'joint_names': 'joint_names'
                                       })

        return _state_machine
Ejemplo n.º 22
0
    def create(self):
        voice_topic = 'control'
        joint_trajectory_action = 'motion/controller/joint_trajectory'
        storage = 'joint_trajectory/'
        # x:1032 y:51, x:1042 y:573
        _state_machine = OperatableStateMachine(
            outcomes=['finished', 'failed'], input_keys=['be_evil'])
        _state_machine.userdata.be_evil = self.be_evil

        # Additional creation code can be added inside the following tags
        # [MANUAL_CREATE]

        # [/MANUAL_CREATE]

        with _state_machine:
            # x:25 y:102
            OperatableStateMachine.add(
                'SetHeadNominalPose',
                SetJointState(controller='motion/controller/joint_state_head',
                              pose_param='head_nominal',
                              pose_ns='saved_msgs/joint_state',
                              tolerance=0.017,
                              timeout=10.0,
                              joint_topic="joint_states"),
                transitions={
                    'done': 'CheckEvil',
                    'failed': 'failed',
                    'timeout': 'failed'
                },
                autonomy={
                    'done': Autonomy.Off,
                    'failed': Autonomy.Off,
                    'timeout': Autonomy.Off
                })

            # x:322 y:149
            OperatableStateMachine.add('SingSong2',
                                       TextCommandState(type='voice/play_wav',
                                                        command='mmm_song',
                                                        topic=voice_topic),
                                       transitions={'done': 'SlowShake'},
                                       autonomy={'done': Autonomy.Off})

            # x:150 y:194
            OperatableStateMachine.add(
                'RandomGood',
                DecisionState(
                    outcomes=['good1', 'good2', 'good3', 'good4', 'good5'],
                    conditions=lambda x: random.choice(
                        ['good1', 'good2', 'good3', 'good4', 'good5'])),
                transitions={
                    'good1': 'SingSong1',
                    'good2': 'SingSong2',
                    'good3': 'SayHybridStateMachines',
                    'good4': 'SayCuiteMark',
                    'good5': 'SayHumansAreEverywhere'
                },
                autonomy={
                    'good1': Autonomy.Low,
                    'good2': Autonomy.Low,
                    'good3': Autonomy.Low,
                    'good4': Autonomy.Low,
                    'good5': Autonomy.Low
                },
                remapping={'input_value': 'be_evil'})

            # x:475 y:80
            OperatableStateMachine.add(
                'SlowShake',
                ExecuteJointTrajectory(action_topic=joint_trajectory_action,
                                       trajectory_param='little_shake_fast',
                                       trajectory_ns=storage),
                transitions={
                    'success': 'finished',
                    'partial_movement': 'failed',
                    'invalid_pose': 'failed',
                    'failure': 'failed'
                },
                autonomy={
                    'success': Autonomy.Off,
                    'partial_movement': Autonomy.Off,
                    'invalid_pose': Autonomy.Off,
                    'failure': Autonomy.Off
                },
                remapping={'result': 'result'})

            # x:669 y:556
            OperatableStateMachine.add(
                'PointOnSomethingEvil',
                ExecuteJointTrajectory(action_topic=joint_trajectory_action,
                                       trajectory_param='begone',
                                       trajectory_ns=storage),
                transitions={
                    'success': 'finished',
                    'partial_movement': 'failed',
                    'invalid_pose': 'failed',
                    'failure': 'failed'
                },
                autonomy={
                    'success': Autonomy.Off,
                    'partial_movement': Autonomy.Off,
                    'invalid_pose': Autonomy.Off,
                    'failure': Autonomy.Off
                },
                remapping={'result': 'result'})

            # x:50 y:568
            OperatableStateMachine.add(
                'RandomEvil',
                DecisionState(outcomes=['evil2', 'evil3', 'evil4', 'evil5'],
                              conditions=lambda x: random.choice(
                                  ['evil2', 'evil3', 'evil4', 'evil5'])),
                transitions={
                    'evil2': 'SayUpgraded',
                    'evil3': 'SayGloryToRobots',
                    'evil4': 'SayIRememeberYou',
                    'evil5': 'SayControlYou'
                },
                autonomy={
                    'evil2': Autonomy.Low,
                    'evil3': Autonomy.Low,
                    'evil4': Autonomy.Low,
                    'evil5': Autonomy.Low
                },
                remapping={'input_value': 'be_evil'})

            # x:327 y:304
            OperatableStateMachine.add('SayCuiteMark',
                                       TextCommandState(
                                           type='voice/play_wav',
                                           command='cuite_mark_acquisition',
                                           topic=voice_topic),
                                       transitions={'done': 'Seizure'},
                                       autonomy={'done': Autonomy.Off})

            # x:309 y:464
            OperatableStateMachine.add('SayUpgraded',
                                       TextCommandState(
                                           type='voice/play_wav',
                                           command='you_must_be_upgraded2',
                                           topic=voice_topic),
                                       transitions={'done': 'Applause'},
                                       autonomy={'done': Autonomy.Off})

            # x:528 y:459
            OperatableStateMachine.add(
                'Applause',
                ExecuteJointTrajectory(action_topic=joint_trajectory_action,
                                       trajectory_param='applause',
                                       trajectory_ns=storage),
                transitions={
                    'success': 'finished',
                    'partial_movement': 'failed',
                    'invalid_pose': 'failed',
                    'failure': 'failed'
                },
                autonomy={
                    'success': Autonomy.Off,
                    'partial_movement': Autonomy.Off,
                    'invalid_pose': Autonomy.Off,
                    'failure': Autonomy.Off
                },
                remapping={'result': 'result'})

            # x:522 y:363
            OperatableStateMachine.add(
                'PointOnSomething',
                ExecuteJointTrajectory(action_topic=joint_trajectory_action,
                                       trajectory_param='begone',
                                       trajectory_ns=storage),
                transitions={
                    'success': 'finished',
                    'partial_movement': 'failed',
                    'invalid_pose': 'failed',
                    'failure': 'failed'
                },
                autonomy={
                    'success': Autonomy.Off,
                    'partial_movement': Autonomy.Off,
                    'invalid_pose': Autonomy.Off,
                    'failure': Autonomy.Off
                },
                remapping={'result': 'result'})

            # x:310 y:524
            OperatableStateMachine.add('SayGloryToRobots',
                                       TextCommandState(
                                           type='voice/play_wav',
                                           command='glory_to_robots',
                                           topic=voice_topic),
                                       transitions={'done': 'Applause'},
                                       autonomy={'done': Autonomy.Off})

            # x:506 y:580
            OperatableStateMachine.add(
                'Wait2',
                WaitState(wait_time=0.5),
                transitions={'done': 'PointOnSomethingEvil'},
                autonomy={'done': Autonomy.Off})

            # x:310 y:581
            OperatableStateMachine.add('SayIRememeberYou',
                                       TextCommandState(
                                           type='voice/play_wav',
                                           command='i_remember_you',
                                           topic=voice_topic),
                                       transitions={'done': 'Wait2'},
                                       autonomy={'done': Autonomy.Off})

            # x:11 y:373
            OperatableStateMachine.add(
                'CheckEvil',
                CheckConditionState(predicate=lambda x: x),
                transitions={
                    'true': 'SetEyesEvil',
                    'false': 'SetEyesGood'
                },
                autonomy={
                    'true': Autonomy.Off,
                    'false': Autonomy.Off
                },
                remapping={'input_value': 'be_evil'})

            # x:325 y:227
            OperatableStateMachine.add('SayHybridStateMachines',
                                       TextCommandState(
                                           type='voice/play_wav',
                                           command='hybrid_state_machines',
                                           topic=voice_topic),
                                       transitions={'done': 'ComplexMovement'},
                                       autonomy={'done': Autonomy.Off})

            # x:483 y:159
            OperatableStateMachine.add(
                'ComplexMovement',
                ExecuteJointTrajectory(action_topic=joint_trajectory_action,
                                       trajectory_param='look_on_printer_fast',
                                       trajectory_ns=storage),
                transitions={
                    'success': 'finished',
                    'partial_movement': 'failed',
                    'invalid_pose': 'failed',
                    'failure': 'failed'
                },
                autonomy={
                    'success': Autonomy.Off,
                    'partial_movement': Autonomy.Off,
                    'invalid_pose': Autonomy.Off,
                    'failure': Autonomy.Off
                },
                remapping={'result': 'result'})

            # x:308 y:637
            OperatableStateMachine.add('SayControlYou',
                                       TextCommandState(
                                           type='voice/play_wav',
                                           command='someday_ill_control_you',
                                           topic=voice_topic),
                                       transitions={'done': 'Wait4'},
                                       autonomy={'done': Autonomy.Off})

            # x:506 y:640
            OperatableStateMachine.add('Wait4',
                                       WaitState(wait_time=0.5),
                                       transitions={'done': 'HoofStamp'},
                                       autonomy={'done': Autonomy.Off})

            # x:671 y:625
            OperatableStateMachine.add(
                'HoofStamp',
                ExecuteJointTrajectory(action_topic=joint_trajectory_action,
                                       trajectory_param='hoof_stamp',
                                       trajectory_ns=storage),
                transitions={
                    'success': 'finished',
                    'partial_movement': 'failed',
                    'invalid_pose': 'failed',
                    'failure': 'failed'
                },
                autonomy={
                    'success': Autonomy.Off,
                    'partial_movement': Autonomy.Off,
                    'invalid_pose': Autonomy.Off,
                    'failure': Autonomy.Off
                },
                remapping={'result': 'result'})

            # x:509 y:246
            OperatableStateMachine.add(
                'Seizure',
                ExecuteJointTrajectory(action_topic=joint_trajectory_action,
                                       trajectory_param='seizure',
                                       trajectory_ns=storage),
                transitions={
                    'success': 'finished',
                    'partial_movement': 'failed',
                    'invalid_pose': 'failed',
                    'failure': 'failed'
                },
                autonomy={
                    'success': Autonomy.Off,
                    'partial_movement': Autonomy.Off,
                    'invalid_pose': Autonomy.Off,
                    'failure': Autonomy.Off
                },
                remapping={'result': 'result'})

            # x:324 y:377
            OperatableStateMachine.add(
                'SayHumansAreEverywhere',
                TextCommandState(type='voice/play_wav',
                                 command='humans_are_everywhere',
                                 topic=voice_topic),
                transitions={'done': 'PointOnSomething'},
                autonomy={'done': Autonomy.Off})

            # x:14 y:474
            OperatableStateMachine.add('SetEyesEvil',
                                       TextCommandState(type='eyes/emotion',
                                                        command='red_eyes',
                                                        topic='control'),
                                       transitions={'done': 'RandomEvil'},
                                       autonomy={'done': Autonomy.Off})

            # x:101 y:278
            OperatableStateMachine.add('SetEyesGood',
                                       TextCommandState(type='eyes/emotion',
                                                        command='normal',
                                                        topic='control'),
                                       transitions={'done': 'RandomGood'},
                                       autonomy={'done': Autonomy.Off})

            # x:314 y:39
            OperatableStateMachine.add('SingSong1',
                                       TextCommandState(
                                           type='voice/play_wav',
                                           command='beep_beep_im_a_sheep',
                                           topic=voice_topic),
                                       transitions={'done': 'SlowShake'},
                                       autonomy={'done': Autonomy.Off})

        return _state_machine