11 from ed.entity
import Entity
12 from geometry_msgs.msg
import PoseStamped
13 from robot_skills
import get_robot, robot
14 from robot_smach_states.util.designators
import is_writeable, VariableDesignator
15 from robot_smach_states.utility
import CheckTimeOut, WriteDesignator
16 from smach
import StateMachine, cb_interface, CBState
17 from std_msgs.msg
import Header
18 from people_recognition_msgs.msg
import Person3D
49 def __init__(self, robot, furniture_designator, possible_furniture):
51 StateMachine.__init__(self, outcomes=[
'done',
'failed'], output_keys=[
"laser_dot"])
56 is_writeable(furniture_designator)
57 reset_des = VariableDesignator(resolve_type=bool).writeable
59 def _show_view(timeout=5):
60 rgb, depth, depth_info = robot.perception.get_rgb_depth_caminfo()
61 robot.hmi.show_image_from_msg(rgb, timeout)
62 return rgb, depth, depth_info
64 @cb_interface(outcomes=[
'done'])
65 def _prepare_operator(_):
74 robot.speech.speak(
"Let's point, please stand in front of me!", block=
False)
80 robot.speech.speak(
"Please point at the object you want me to hand you", block=
False)
87 robot.speech.speak(
"Three")
89 robot.speech.speak(
"Two")
91 robot.speech.speak(
"One")
95 @cb_interface(outcomes=[
'done',
'failed'])
99 def _is_operator(person):
100 if person.position.z > 3.5:
101 robot.speech.speak(
"Please stand CLOSER to me, so I can see your full body")
104 if person.position.z < 1.5:
105 robot.speech.speak(
"Please stand FURTHER away from me, so I can see your full body")
108 if "is_pointing" not in person.tags:
109 robot.speech.speak(
"Please point with your arm stretched")
129 start = rospy.Time.now()
130 while not rospy.is_shutdown()
and OPERATOR
is None and (rospy.Time.now() - start).to_sec() < 10:
131 persons = robot.perception.detect_person_3d(*_show_view())
133 persons = sorted(persons, key=
lambda x: x.position.z)
135 if _is_operator(person):
139 rospy.logerr(
"Could not find an correct operator. Let him point again")
144 rospy.loginfo(
"I see an operator at %.2f meter in front of me" % OPERATOR.position.z)
148 @cb_interface(outcomes=[
'done',
'failed'], output_keys=[
'laser_dot'])
149 def _get_furniture(user_data):
153 while not rospy.is_shutdown()
and final_result
is None:
156 while not rospy.is_shutdown()
and attempts < 5:
159 map_pose = robot.tf_buffer.transform(PoseStamped(
161 frame_id=OPERATOR.header.frame_id,
162 stamp=rospy.Time.now() - rospy.Duration.from_sec(0.5)
164 pose=OPERATOR.pointing_pose
166 rospy.logwarn(f
"{map_pose=}")
167 result = robot.ed.ray_trace(map_pose)
168 if result
is not None:
177 except Exception
as e:
178 rospy.logerr(
"Could not get ray trace from closest person: {}".format(e))
181 rospy.logerr(
"Could not find an entity with the current operator pose. Let him point again")
188 rospy.loginfo(
"There is a ray intersection with {i} at ({p.x:.4}, {p.y:.4}, {p.z:.4})".format(i=result.entity_id, p=result.intersection_point.point))
190 if result.entity_id
in possible_furniture:
191 final_result = result
193 rospy.loginfo(
"{} is not furniture".format(result.entity_id))
194 robot.speech.speak(
"You pointed at: {}. That's not furniture".format(result.entity_id))
197 robot.get_arm(required_goals=[
"reset"]).send_joint_goal(
"reset")
200 robot.speech.speak(
"You pointed at %s" % final_result.entity_id)
201 robot.get_arm(required_goals=[
"reset"]).send_joint_goal(
"reset")
203 furniture_designator.write(robot.ed.get_entity(final_result.entity_id))
204 user_data[
'laser_dot'] = result.intersection_point
205 rospy.loginfo(f
"{result=}")
209 self.add(
"WRITE_RESET_DES_TRUE", WriteDesignator(reset_des,
True),
210 transitions={
'written':
'PREPARE_OPERATOR'})
211 self.add(
'PREPARE_OPERATOR', CBState(_prepare_operator), transitions={
'done':
'CHECK_TIMEOUT'})
212 self.add(
"CHECK_TIMEOUT", CheckTimeOut(30, reset_des), transitions={
'not_yet':
'GET_OPERATOR',
213 'time_out':
'failed'})
214 self.add(
'GET_OPERATOR', CBState(_get_operator), transitions={
'done':
'GET_FURNITURE',
215 'failed':
'CHECK_TIMEOUT'})
216 self.add(
'GET_FURNITURE', CBState(_get_furniture), transitions={
'done':
'done',
'failed':
'CHECK_TIMEOUT'})
219 if __name__ ==
'__main__':
220 from robocup_knowledge
import load_knowledge
221 rospy.init_node(os.path.splitext(
"test_" + os.path.basename(__file__))[0])
222 furniture_designator_ = VariableDesignator(resolve_type=Entity)
223 robot_instance = get_robot(
"hero")
224 robot_instance.reset()
225 knowledge = load_knowledge(
"challenge_hand_me_that")
227 while not rospy.is_shutdown():