Skip to content

Commit

Permalink
Merge pull request #207 from AbdelrhmanBassiouny/world_sync_ci_bug_fix
Browse files Browse the repository at this point in the history
World sync ci bug fix
  • Loading branch information
Tigul authored Oct 11, 2024
2 parents 17c7025 + f229ac4 commit 2ef6f03
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 20 deletions.
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 @@ -1536,10 +1536,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 @@ -1549,12 +1546,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 @@ -1656,7 +1653,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)


0 comments on commit 2ef6f03

Please sign in to comment.