Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error when resolving possible objects to pick while some are carried by other robots #313

Merged

Conversation

robin-mueller
Copy link
Contributor

When picking objects with multiple robots in a world, it is likely, that some are currently carried and do not reside on locations anymore. Since Robot doesn't have a parent attribute, an error is raised when checking each object's location.

[world.py-1] [ERROR] [1734861471.897019297] [pyrobosim]: Error raised in execute callback: 'Robot' object has no attribute 'parent'
[world.py-1] Traceback (most recent call last):
[world.py-1]   File "/opt/ros/humble/local/lib/python3.10/dist-packages/rclpy/action/server.py", line 333, in _execute_goal
[world.py-1]     execute_result = await await_or_execute(execute_callback, goal_handle)
[world.py-1]   File "/opt/ros/humble/local/lib/python3.10/dist-packages/rclpy/executors.py", line 107, in await_or_execute
[world.py-1]     return callback(*args)
[world.py-1]   File "/home/robin/Desktop/px4-ros2-env/install/auto_apms_simulation/local/lib/python3.10/dist-packages/pyrobosim_ros/ros_interface.py", line 418, in action_callback
[world.py-1]     execution_result = robot.execute_action(robot_action)
[world.py-1]   File "/home/robin/Desktop/px4-ros2-env/install/auto_apms_simulation/local/lib/python3.10/dist-packages/pyrobosim/core/robot.py", line 917, in execute_action
[world.py-1]     result = self.pick_object(action.object, action.pose)
[world.py-1]   File "/home/robin/Desktop/px4-ros2-env/install/auto_apms_simulation/local/lib/python3.10/dist-packages/pyrobosim/core/robot.py", line 494, in pick_object
[world.py-1]     obj = query_to_entity(
[world.py-1]   File "/home/robin/Desktop/px4-ros2-env/install/auto_apms_simulation/local/lib/python3.10/dist-packages/pyrobosim/utils/knowledge.py", line 185, in query_to_entity
[world.py-1]     obj_candidate = resolve_to_object(
[world.py-1]   File "/home/robin/Desktop/px4-ros2-env/install/auto_apms_simulation/local/lib/python3.10/dist-packages/pyrobosim/utils/knowledge.py", line 339, in resolve_to_object
[world.py-1]     possible_objects = [
[world.py-1]   File "/home/robin/Desktop/px4-ros2-env/install/auto_apms_simulation/local/lib/python3.10/dist-packages/pyrobosim/utils/knowledge.py", line 345, in <listcomp>
[world.py-1]     or obj.parent.parent == location
[world.py-1] AttributeError: 'Robot' object has no attribute 'parent'

This PR fixes this issue by checking if the parent has an attribute called parent effectively verifying that it's not a robot. Consequently, objects can not be picked when they are carried by robots.

Note

I've also tried to verify using isinstance(obj.parent, Robot) but this requires to import Robot and causes a circular import error when done on top. It's also possible to import it inside the resolve_to_object method, but I guess this solution is sufficient.

Copy link
Owner

@sea-bass sea-bass left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This certainly works!

I also think this similar check would be good to add in the "room" case right above this block of code?

Copy link
Owner

@sea-bass sea-bass left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I do agree there are better longer term solutions, but this definitely fixes the edge case for now.

@sea-bass sea-bass merged commit c36d198 into sea-bass:main Dec 22, 2024
6 checks passed
@robin-mueller robin-mueller deleted the fix-ignore-currently-carried-objects branch December 22, 2024 11:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants