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

World sync ci bug fix #207

Merged
merged 4 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/pycram/datastructures/dataclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ def get_objects_that_have_points(self) -> List[Object]:
return list({point.link_b.object for point in self})

def __str__(self):
return f"ContactPointsList: {', '.join(self.get_names_of_objects_that_have_points())}"
return f"ContactPointsList: {', '.join([point.__str__() for point in self])}"

def __repr__(self):
return self.__str__()
Expand Down
14 changes: 6 additions & 8 deletions src/pycram/datastructures/world.py
Original file line number Diff line number Diff line change
Expand Up @@ -1535,10 +1535,7 @@ class UseProspectionWorld:
with UseProspectionWorld():
NavigateAction.Action([[1, 0, 0], [0, 0, 0, 1]]).perform()
"""
WAIT_TIME_AS_N_SIMULATION_STEPS: int = 20
"""
The time in simulation steps to wait before switching to the prospection world
"""


def __init__(self):
self.prev_world: Optional[World] = None
Expand All @@ -1548,12 +1545,12 @@ def __enter__(self):
"""
This method is called when entering the with block, it will set the current world to the prospection world
"""
# Please do not edit this function, it works as it is now!
if not World.current_world.is_prospection_world:
self.prev_world = World.current_world
World.current_world = World.current_world.prospection_world
World.current_world.resume_world_sync()
time.sleep(self.WAIT_TIME_AS_N_SIMULATION_STEPS * World.current_world.simulation_time_step)
World.current_world.pause_world_sync()
# This is also a join statement since it is called from the main thread.
World.current_world.world_sync.sync_worlds()

def __exit__(self, *args):
"""
Expand Down Expand Up @@ -1655,7 +1652,8 @@ def add_objects_not_in_prospection_world(self):
"""
Adds all objects that are in the main world but not in the prospection world to the prospection world.
"""
[self.add_object(obj) for obj in self.world.objects if obj not in self.object_to_prospection_object_map]
obj_map_copy = copy(self.object_to_prospection_object_map)
[self.add_object(obj) for obj in self.world.objects if obj not in obj_map_copy.keys()]

def add_object(self, obj: Object) -> None:
"""
Expand Down
7 changes: 4 additions & 3 deletions src/pycram/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ def find_multiverse_path() -> Optional[str]:
"""
# Get the value of PYTHONPATH environment variable
pythonpath = os.getenv('PYTHONPATH')
multiverse_relative_path = "Multiverse/multiverse"

# Check if PYTHONPATH is set
if pythonpath:
Expand All @@ -108,8 +109,8 @@ def find_multiverse_path() -> Optional[str]:

# Iterate through each path and check if 'Multiverse' is in it
for path in paths:
if 'multiverse' in path:
multiverse_path = path.split('multiverse')[0]
return multiverse_path + 'multiverse'
if multiverse_relative_path in path:
multiverse_path = path.split(multiverse_relative_path)[0]
return multiverse_path + multiverse_relative_path


15 changes: 7 additions & 8 deletions test/test_attachment.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ def test_detach_sync_in_prospection_world(self):
pass
self.milk.detach(self.robot)
with UseProspectionWorld():
self.assertTrue(self.milk not in self.robot.attachments)
self.assertTrue(self.robot not in self.milk.attachments)
prospection_milk = self.world.get_prospection_object_for_object(self.milk)
prospection_robot = self.world.get_prospection_object_for_object(self.robot)
self.assertTrue(prospection_milk not in prospection_robot.attachments)
self.assertTrue(prospection_robot not in prospection_milk.attachments)
pass
self.assertTrue(self.milk not in self.robot.attachments)
self.assertTrue(self.robot not in self.milk.attachments)
prospection_milk = self.world.get_prospection_object_for_object(self.milk)
prospection_robot = self.world.get_prospection_object_for_object(self.robot)
self.assertTrue(prospection_milk not in prospection_robot.attachments)
self.assertTrue(prospection_robot not in prospection_milk.attachments)

def test_attachment_behavior(self):
self.robot.attach(self.milk)
Expand Down Expand Up @@ -104,5 +105,3 @@ def test_attaching_to_robot_and_moving(self):

new_milk_pos = self.milk.get_position()
self.assertEqual(new_milk_pos.x, milk_pos.x + 1)


Loading