challenge_hand_me_that
hand_me_that.py
Go to the documentation of this file.
1 #
2 # Copyright (c) 2019, TU/e Robotics, Netherlands
3 # All rights reserved.
4 #
5 # \author Rein Appeldoorn
6 
7 import smach
8 
9 from ed.entity import Entity
10 
11 import robot_smach_states.util.designators as ds
12 from robot_smach_states.navigation import NavigateToWaypoint
13 from robot_smach_states.startup import StartChallengeRobust
14 from robot_smach_states.human_interaction import Say, FindPerson
15 from robot_smach_states.perception import RotateToEntity
16 from robot_smach_states.utility import WaitTime
17 from robocup_knowledge import load_knowledge
18 
19 from .get_furniture_from_operator_pose import GetFurnitureFromOperatorPose
20 from .identify_object import IdentifyObject
21 from .inspect_furniture_entity import InspectFurniture
22 
23 challenge_knowledge = load_knowledge('challenge_hand_me_that')
24 
25 STARTING_POINT = challenge_knowledge.starting_point # Location where the challenge starts
26 HOME_LOCATION = challenge_knowledge.home_location # Location where the robot will go and look at the operator
27 POSSIBLE_FURNITURE = challenge_knowledge.all_possible_furniture
28 ROOM = challenge_knowledge.room
29 
30 
31 class HandMeThat(smach.StateMachine):
32  """ Main StateMachine for the challenge """
33 
34  def __init__(self, robot):
35  smach.StateMachine.__init__(self, outcomes=['done'])
36 
37  furniture_designator = ds.VariableDesignator(resolve_type=Entity)
38  entity_designator = ds.VariableDesignator(resolve_type=[Entity])
39  operator_designator = ds.VariableDesignator(resolve_type=Entity).writeable
40  arm_designator = ds.UnoccupiedArmDesignator(robot).lockable()
41  room_designator = ds.EntityByIdDesignator(robot, uuid=ROOM)
42 
43  TESTING = False
44 
45  with self:
46  if not TESTING:
47  # Intro
48  smach.StateMachine.add('START_CHALLENGE_ROBUST', StartChallengeRobust(robot, STARTING_POINT),
49  transitions={'Done': 'SAY_START',
50  'Aborted': 'done',
51  'Failed': 'SAY_START'})
52 
53  # Say we're gonna start
54  smach.StateMachine.add('SAY_START', Say(robot, "Hand me that it is!", block=False),
55  transitions={'spoken': 'NAVIGATE_TO_START'})
56 
57  # Drive to the start location
58  smach.StateMachine.add('NAVIGATE_TO_START',
59  NavigateToWaypoint(robot, ds.EdEntityDesignator(robot, uuid=HOME_LOCATION)),
60  transitions={'arrived': 'FIND_OPERATOR_IN_ROOM',
61  'unreachable': 'NAVIGATE_TO_START', # ToDo: other fallback
62  'goal_not_defined': 'done'}) # I'm not even going to fill this in
63 
64  # The pre-work
65  smach.StateMachine.add('FIND_OPERATOR_IN_ROOM',
66  FindPerson(robot=robot,
67  found_entity_designator=operator_designator,
68  discard_other_labels=False,
69  room=ROOM,
70  search_timeout=20),
71  transitions={'found': 'LOOK_AT_PERSON',
72  'failed': 'LOOK_AT_CENTER_OF_ROOM'})
73 
74  smach.StateMachine.add('LOOK_AT_PERSON',
75  RotateToEntity(robot=robot, entity=operator_designator),
76  transitions={'succeeded': 'ASK_TO_POINT',
77  'failed': 'LOOK_AT_CENTER_OF_ROOM'})
78 
79  # Ask what operator needs
80  smach.StateMachine.add('ASK_TO_POINT', Say(robot, "What do you need?", block=True),
81  transitions={'spoken': 'GET_FURNITURE_FROM_OPERATOR_POSE'})
82 
83  smach.StateMachine.add('LOOK_AT_CENTER_OF_ROOM',
84  RotateToEntity(robot=robot, entity=room_designator),
85  transitions={'succeeded': 'SAY_CANT_FIND_PERSON',
86  'failed': 'SAY_CANT_FIND_PERSON'})
87 
88  smach.StateMachine.add('SAY_CANT_FIND_PERSON',
89  Say(robot, 'I did not find you, please stand in my view'),
90  transitions={'spoken': 'WAIT_FOR_OPERATOR'})
91 
92  smach.StateMachine.add('WAIT_FOR_OPERATOR', WaitTime(robot, 3),
93  transitions={'waited': 'ASK_TO_POINT',
94  'preempted': 'ASK_TO_POINT'})
95 
96  smach.StateMachine.add('GET_FURNITURE_FROM_OPERATOR_POSE',
97  GetFurnitureFromOperatorPose(robot, furniture_designator.writeable,
98  POSSIBLE_FURNITURE),
99  transitions={'done': 'INSPECT_FURNITURE',
100  'failed': 'SAY_TRY_NEXT'})
101 
102  # Go to the furniture object that was pointing to see what's there
103  smach.StateMachine.add('INSPECT_FURNITURE',
104  InspectFurniture(robot, furniture_designator, entity_designator.writeable),
105  transitions={"succeeded": "IDENTIFY_OBJECT",
106  "failed": "SAY_NO_OBJECT"}) # If no entities, try again
107 
108  # Tell when you failed to
109  smach.StateMachine.add('SAY_NO_OBJECT', Say(robot, ['I did not find any object object there']),
110  transitions={'spoken': 'NAVIGATE_TO_START'})
111 
112  # Point at the object
113  smach.StateMachine.add('IDENTIFY_OBJECT',
114  IdentifyObject(robot, entity_designator, arm_designator),
115  transitions={'done': 'NAVIGATE_TO_START', # Just keep on going
116  'failed': 'SAY_TRY_NEXT'}) # Just keep on going
117 
118  smach.StateMachine.add('SAY_TRY_NEXT', Say(robot, ['I am sorry, lets skip this one and'
119  ' let me try another one',
120  'I will go for the next item']),
121  transitions={'spoken': 'NAVIGATE_TO_START'})
challenge_hand_me_that.identify_object.IdentifyObject
Definition: identify_object.py:157
challenge_hand_me_that.hand_me_that.HandMeThat.__init__
def __init__(self, robot)
Definition: hand_me_that.py:34
challenge_hand_me_that.get_furniture_from_operator_pose.GetFurnitureFromOperatorPose
Definition: get_furniture_from_operator_pose.py:48
challenge_hand_me_that.inspect_furniture_entity.InspectFurniture
Definition: inspect_furniture_entity.py:42
challenge_hand_me_that.hand_me_that.HandMeThat
Definition: hand_me_that.py:31