Skip to content

Commit

Permalink
Merge pull request #265 from tue-robotics/fix/knowledge-for-spr
Browse files Browse the repository at this point in the history
updated and fixed grammar for spr challenge
  • Loading branch information
LoyVanBeek committed May 20, 2017
2 parents c87d704 + 74454ee commit 614f4a1
Show file tree
Hide file tree
Showing 6 changed files with 510 additions and 122 deletions.
8 changes: 4 additions & 4 deletions challenge_spr/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ rosrun challenge_spr bluff_game.py amigo
- send the image to /amigo/face_recognition/recognize
- process the results
- send data for the inspected crowd to the library
- updated library with questions for crowd, arena and objects

## TODO

Riddle / Bluff games:

- update library with questions:
- about the arena
- about the inspected crowd
- about list of official objects
- update library with predefined questions
- remove WaitForPersonInFront state, substitute it with timeout and Say state
- implement the sound localization into Bluff game
- detect.py
- use skybiometry node and service
- use face_recognition node and service
Expand Down
24 changes: 14 additions & 10 deletions challenge_spr/src/challenge_spr_states/detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def recognize(self, tries):
imgs.append(imgmsg)

rospy.loginfo('Calling Skybiometry...')

try:
# face_properties = self._skybiometry.get_face_properties(imgs, timeout)
get_face_properties = rospy.ServiceProxy('/get_face_properties', GetFaceProperties)
Expand All @@ -84,7 +84,7 @@ def recognize(self, tries):
rospy.logerr(str(e))
self.robot.speech.speak('API call failed, is there internet?')
return [None]*number_of_people

face_log = '\n - '.join([''] + [repr(s) for s in face_properties])
rospy.loginfo('face_properties:%s', face_log)
return face_properties
Expand All @@ -100,7 +100,7 @@ def get_shot(self):
return self._bridge.imgmsg_to_cv2(image, 'bgr8')

def get_faces(self, image):

faces = self._face_recognizer.recognize(image)

rospy.loginfo("Faces: %s", faces)
Expand All @@ -109,17 +109,18 @@ def get_faces(self, image):


def describe_crowd(self, detections):

num_males = 0
num_females = 0
num_women = 0
num_girls = 0
num_men = 0
num_boys = 0
num_elders = 0

if not all(detections):
rospy.loginfo('making a random guess for %d people', len(detections))
if len(detections) > 2:
num_males = 1 + random.randrange(len(detections) - 2)
num_males = 1 + random.randrange(len(detections) - 2)
else:
num_males = 1
num_females = len(detections) - num_males
Expand All @@ -139,14 +140,17 @@ def describe_crowd(self, detections):
num_elders +=1
else:
num_women += 1


num_males = num_boys + num_men
num_females = num_girls + num_women

self.robot.speech.speak("There are %d males and %d females in the crowd" % (num_males, num_females))

return {
"males": num_boys + num_men,
"males": num_males,
"men": num_men,
"boys": num_boys,
"females": num_girls + num_women,
"females": num_females,
"women": num_women,
"girls": num_girls,
"children": num_boys + num_girls,
Expand All @@ -173,7 +177,7 @@ def __init__(self, robot):
DetectCrowd(robot),
transitions={'succeeded': 'Done',
'failed': 'Aborted'})

if __name__ == "__main__":
rospy.init_node('speech_person_recognition_exec')

Expand Down
182 changes: 92 additions & 90 deletions challenge_spr/src/challenge_spr_states/riddle_game.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,97 +24,99 @@ def hear(robot, time_out):

def answer(robot, res, crowd_data):
if res:
if 'answer' in res.semantics:
answer = res.semantics['answer']
rospy.loginfo("Question was: '%s'?"%res.sentence)
robot.speech.speak("The answer is %s"%answer)
return 'answered'
elif 'action' in res.semantics:
# Counting people
if res.semantics['action'] == 'count':

if res.semantics['entity'] == 'people':
answer = 'In the crowd are %d people' % crowd_data['crowd_size']

if res.semantics['entity'] == 'children':
answer = 'In the crowd are %d children' % crowd_data['children']

if res.semantics['entity'] == 'adults':
answer = 'In the crowd are %d adults' % crowd_data['adults']

if res.semantics['entity'] == 'elders':
answer = 'In the crowd are %d elders' % crowd_data['elders']

if res.semantics['entity'] == 'males':
answer = 'In the crowd are %d males' % crowd_data['males']

if res.semantics['entity'] == 'females':
answer = 'In the crowd are %d females' % crowd_data['females']

if res.semantics['entity'] == 'men':
answer = 'In the crowd are %d men' % crowd_data['men']

if res.semantics['entity'] == 'women':
answer = 'In the crowd are %d women' % crowd_data['women']

if res.semantics['entity'] == 'boys':
answer = 'In the crowd are %d boys' % crowd_data['boys']

if res.semantics['entity'] == 'girls':
answer = 'In the crowd are %d girls' % crowd_data['girls']

# Location of placements or beacons
if res.semantics['action'] == 'a_find':
entity = res.semantics['entity']
locations = [l for l in common_knowledge.locations if l['name'] == entity]
if len(locations) == 1:
loc = locations[0]['room']
answer = 'The %s can be found in the %s' % (entity, loc)
else:
answer = 'I dont know that object'

# Count placements or beacons in the room
if res.semantics['action'] == 'a_count':
entity = res.semantics['entity']
locations = [l for l in common_knowledge.locations if l['name'] == entity]
if len(locations) == 1:
loc = locations[0]['room']
if loc == res.semantics['location']:
answer = 'There is one %s in the %s' % (entity, loc)
if 'actions' in res.semantics:
for action in res.semantics['actions']:

# Predefined questions
if action['action'] == 'answer':
# if res.semantics['actions'] == 'answer':
answer = action['solution']#res.semantics['solution']

# Counting people
if action['action'] == 'count':

if action['entity'] == 'people':
answer = 'In the crowd are %d people' % crowd_data['crowd_size']

if action['entity'] == 'children':
answer = 'In the crowd are %d children' % crowd_data['children']

if action['entity'] == 'adults':
answer = 'In the crowd are %d adults' % crowd_data['adults']

if action['entity'] == 'elders':
answer = 'In the crowd are %d elders' % crowd_data['elders']

if action['entity'] == 'males':
answer = 'In the crowd are %d males' % crowd_data['males']

if action['entity'] == 'females':
answer = 'In the crowd are %d females' % crowd_data['females']

if action['entity'] == 'men':
answer = 'In the crowd are %d men' % crowd_data['men']

if action['entity'] == 'women':
answer = 'In the crowd are %d women' % crowd_data['women']

if action['entity'] == 'boys':
answer = 'In the crowd are %d boys' % crowd_data['boys']

if action['entity'] == 'girls':
answer = 'In the crowd are %d girls' % crowd_data['girls']

# Location of placements or beacons
if action['action'] == 'a_find':
entity = action['entity']
locations = [l for l in common_knowledge.locations if l['name'] == entity]
if len(locations) == 1:
loc = locations[0]['room']
answer = 'The %s can be found in the %s' % (entity, loc)
else:
answer = 'I dont know that object'

# Count placements or beacons in the room
if action['action'] == 'a_count':
entity = action['entity']
locations = [l for l in common_knowledge.locations if l['name'] == entity]
if len(locations) == 1:
loc = locations[0]['room']
if loc == action['location']:
answer = 'There is one %s in the %s' % (entity, loc)
else:
answer = 'There are no %s in the %s' % (entity, loc)
else:
answer = 'I dont know that object'

# Find objects
if action['action'] == 'o_find':
entity = action['entity']
locations = [l for l in common_knowledge.objects if l['name'] == entity]
if len(locations) == 1:
cat = locations[0]['category']
print cat
loc, area_name = common_knowledge.get_object_category_location(cat)
answer = 'You can find the %s %s %s' % (entity, area_name, loc)

else:
answer = 'I dont know that object'

# Find category
if action['action'] == 'c_find':
entity = action['entity']
loc, area_name = common_knowledge.get_object_category_location(entity)
answer = 'You can find the %s on the %s' % (entity, loc)

# Return objects category
if action['action'] == 'return_category':
entity = action['entity']
locations = [l for l in common_knowledge.objects if l['name'] == entity]
if len(locations) == 1:
cat = locations[0]['category']
answer = 'The %s belongs to %s' % (entity, cat)

else:
answer = 'There are no %s in the %s' % (entity, loc)
else:
answer = 'I dont know that object'

# Find objects
if res.semantics['action'] == 'o_find':
entity = res.semantics['entity']
locations = [l for l in common_knowledge.objects if l['name'] == entity]
if len(locations) == 1:
cat = locations[0]['category']
print cat
loc, area_name = common_knowledge.get_object_category_location(cat)
answer = 'You can find the %s %s %s' % (entity, area_name, loc)

else:
answer = 'I dont know that object'

# Find category
if res.semantics['action'] == 'c_find':
entity = res.semantics['entity']
loc, area_name = common_knowledge.get_object_category_location(entity)
answer = 'You can find the %s on the %s' % (entity, loc)

# Return objects category
if res.semantics['action'] == 'return_category':
entity = res.semantics['entity']
locations = [l for l in common_knowledge.objects if l['name'] == entity]
if len(locations) == 1:
cat = locations[0]['category']
answer = 'The %s belongs to %s' % (entity, cat)

else:
answer = 'I dont know that object'
answer = 'I dont know that object'

rospy.loginfo("Question was: '%s'?"%res.sentence)
robot.speech.speak("The answer is %s"%answer)
Expand Down
Empty file.

0 comments on commit 614f4a1

Please sign in to comment.