Skip to content

Commit

Permalink
feat: add validation for scene objects and agents in various functions
Browse files Browse the repository at this point in the history
  • Loading branch information
felixocker committed Sep 12, 2024
1 parent 0212e6c commit 1365bc2
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions src/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ def is_person_busy_or_idle(person_name: str) -> str:
:param person_name: The name of the person to check. The person must be available in the scene.
:return: Result message.
"""
agents = SIMULATION.get_agents()["agents"]
if person_name not in agents:
return f"There is no agent with the name {person_name} in the scene. Did you mean one of these: {agents}?"

busy = SIMULATION.isBusy(person_name)
if busy is None:
return f"It could not be determined if {person_name} is busy. There were technical problems."
Expand All @@ -127,6 +131,13 @@ def check_hindering_reasons(person_name: str, object_name: str) -> str:
:param object_name: The name of the object to check. The object must be available in the scene.
:return: Result message.
"""
objects = SIMULATION.get_objects()["objects"]
if object_name not in objects:
return f"There is no object with the name {object_name} in the scene. Did you mean one of these: {objects}?"
agents = SIMULATION.get_agents()["agents"]
if person_name not in agents:
return f"There is no agent with the name {person_name} in the scene. Did you mean one of these: {agents}?"

# visibility
occluded_by_ = SIMULATION.isOccludedBy(person_name, object_name)["occluded_by"]
occluded_by = [e["name"] for e in occluded_by_]
Expand Down Expand Up @@ -154,6 +165,10 @@ def check_reach_object_for_robot(object_name: str) -> str:
:param object_name: The name of the object to check. The object must be available in the scene.
:return: Result message.
"""
objects = SIMULATION.get_objects()["objects"]
if object_name not in objects:
return f"There is no object with the name {object_name} in the scene. Did you mean one of these: {objects}?"

reachable = SIMULATION.isReachable("robot", object_name)
if reachable:
return f"You can get {object_name}."
Expand All @@ -168,6 +183,12 @@ def pour_into(source_container_name: str, target_container_name: str) -> str:
:param target_container_name: The name of the container to pour into.
:return: Result message.
"""
objects = SIMULATION.get_objects()["objects"]
if source_container_name not in objects:
return f"There is no object with the name {source_container_name} in the scene. Did you mean one of these: {objects}?"
if target_container_name not in objects:
return f"There is no object with the name {target_container_name} in the scene. Did you mean one of these: {objects}?"

res = SIMULATION.plan_fb(
(
f"get {source_container_name} duration 8;"
Expand All @@ -189,6 +210,10 @@ def speak(person_name: str, text: str) -> str:
:param text: The text to speak.
:return: Result message.
"""
agents = SIMULATION.get_agents()["agents"]
if person_name not in agents:
return f"There is no agent with the name {person_name} in the scene. Did you mean one of these: {agents}?"

SIMULATION.execute(f"speak {text}")
return f"You said to {person_name}: {text}"

Expand All @@ -201,6 +226,13 @@ def hand_object_over_to_person(object_name: str, person_name: str) -> str:
:param person_name: The name of the person to hand over the object to. The person must be available in the scene.
:return: Result message.
"""
objects = SIMULATION.get_objects()["objects"]
if object_name not in objects:
return f"There is no object with the name {object_name} in the scene. Did you mean one of these: {objects}?"
agents = SIMULATION.get_agents()["agents"]
if person_name not in agents:
return f"There is no agent with the name {person_name} in the scene. Did you mean one of these: {agents}?"

res = SIMULATION.plan_fb(
(
f"get {object_name} duration 8;"
Expand Down Expand Up @@ -233,6 +265,13 @@ def move_object_to_person(object_name: str, person_name: str) -> str:
:param person_name: The name of the person to move the object to. The person must be available in the scene.
:return: Result message.
"""
objects = SIMULATION.get_objects()["objects"]
if object_name not in objects:
return f"There is no object with the name {object_name} in the scene. Did you mean one of these: {objects}?"
agents = SIMULATION.get_agents()["agents"]
if person_name not in agents:
return f"There is no agent with the name {person_name} in the scene. Did you mean one of these: {agents}?"

res = SIMULATION.plan_fb(
(
f"get {object_name};"
Expand Down Expand Up @@ -265,6 +304,16 @@ def move_object_away_from_person(object_name: str, away_from: str) -> str:
:param away_from: The name of the person or object to move the object away from. It must be available in the scene.
:return: Result message.
"""
objects = SIMULATION.get_objects()["objects"]
if object_name not in objects:
return f"There is no object with the name {object_name} in the scene. Did you mean one of these: {objects}?"
agents = SIMULATION.get_agents()["agents"]
if away_from not in agents and away_from not in objects:
return (
f"There is no agent or object with the name {away_from} in the scene. "
f"Did you mean one of these: {agents} or {objects}?"
)

holdingHand = SIMULATION.is_held_by(
(
f"{object_name}"
Expand Down Expand Up @@ -294,6 +343,14 @@ def point_at_object_or_agent(name: str) -> str:
:param name: The name of the object or person you want to point at.
:return: Result message.
"""
objects = SIMULATION.get_objects()["objects"]
agents = SIMULATION.get_agents()["agents"]
if name not in agents and name not in objects:
return (
f"There is no agent or object with the name {name} in the scene. "
f"Did you mean one of these: {agents} or {objects}?"
)

res = SIMULATION.plan_fb(
(
f"point {name};"
Expand Down

0 comments on commit 1365bc2

Please sign in to comment.