Skip to content

Commit

Permalink
clean up and update version of neem_pycram_interface, and update text…
Browse files Browse the repository at this point in the history
… annotation.
  • Loading branch information
AbdelrhmanBassiouny committed Aug 25, 2024
1 parent 04d39d5 commit bda59b6
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 19 deletions.
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "episode_segmenter"
version = "1.0.16"
version = "1.0.17"
description = "Annotates activitiy episodes represented by meshes moving in a 3D environment with the corresponding events, actions and activities."
readme = "README.md"
authors = [{ name = "Abdelrhman Bassiouny", email = "[email protected]" }]
Expand All @@ -15,7 +15,7 @@ classifiers = [
"Programming Language :: Python :: 3",
]
keywords = ["robotics", "knowledge", "memories", "episodic", "pycram"]
dependencies = ["neem_pycram_interface",
dependencies = ["neem_pycram_interface==1.0.167",
]
requires-python = ">=3.8"

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
neem_pycram_interface
neem_pycram_interface==1.0.167
trimesh
dm_control
pydub
Expand Down
21 changes: 12 additions & 9 deletions src/episode_segmenter/Events.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def links_in_contact(self) -> List[Link]:
links.extend(self.contact_points.get_links_in_contact_of_object(obj))
return links

def annotate(self, position: Optional[List[float]] = None) -> TextAnnotation:
def annotate(self, position: Optional[List[float]] = None, size: Optional[float] = 2) -> TextAnnotation:
if position is None:
position = [2, 1, 2]
color = Color(0, 0, 1, 1)
Expand All @@ -46,8 +46,9 @@ def annotate(self, position: Optional[List[float]] = None) -> TextAnnotation:
text = f"{main_link.name} in contact with {self.link_names_in_contact()}"
self.text_id = World.current_world.add_text(text,
position,
color=color)
return TextAnnotation(text, position, color, self.text_id)
color=color,
size=size)
return TextAnnotation(text, position, self.text_id, color=color, size=size)

def __str__(self):
return f"Contact {self.contact_points[0].link_a.object.name}: {self.object_names_in_contact()}"
Expand Down Expand Up @@ -80,7 +81,7 @@ def links_lost_contact(self) -> List[Link]:
def objects_lost_contact(self):
return self.contact_points.get_objects_that_got_removed(self.latest_contact_points)

def annotate(self, position: Optional[List[float]] = None) -> TextAnnotation:
def annotate(self, position: Optional[List[float]] = None, size: Optional[float] = 2) -> TextAnnotation:
if position is None:
position = [2, 1, 2]
color = Color(1, 0, 0, 1)
Expand All @@ -92,8 +93,9 @@ def annotate(self, position: Optional[List[float]] = None) -> TextAnnotation:
self.text_id = World.current_world.add_text(
text,
position,
color=color)
return TextAnnotation(text, position, color, self.text_id)
color=color,
size=size)
return TextAnnotation(text, position, self.text_id, color=color, size=size)

def __str__(self):
return f"Loss of contact {self.latest_contact_points[0].link_a.object.name}: {self.object_names_lost_contact()}"
Expand All @@ -118,7 +120,7 @@ def duration(self):
return None
return self.end_timestamp - self.timestamp

def annotate(self, position: Optional[List[float]] = None) -> TextAnnotation:
def annotate(self, position: Optional[List[float]] = None, size: Optional[float] = 2) -> TextAnnotation:
if position is None:
position = [2, 1, 2]
color = Color(0, 1, 0, 1)
Expand All @@ -127,8 +129,9 @@ def annotate(self, position: Optional[List[float]] = None) -> TextAnnotation:
text = f"Picked {self.object.name}"
self.text_id = World.current_world.add_text(text,
position,
color=color)
return TextAnnotation(text, position, color, self.text_id)
color=color,
size=size)
return TextAnnotation(text, position, self.text_id, color=color, size=size)

def __str__(self):
return f"Pick up event: Hand:{self.hand.name}, Object: {self.object.name}, Timestamp: {self.timestamp}"
Expand Down
24 changes: 17 additions & 7 deletions src/episode_segmenter/episode_segmenter.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ def run_event_detectors(self, motion_generator_thread: threading.Thread) -> None

def handle_contact_event(self, event: ContactEvent, hands: List[Object]) -> None:
"""
Handles the contact event by starting the contact threads for the object and the pickup thread for the object.
Handle the contact event by starting the contact threads for the object and the pickup thread for the object.
:param event: The ContactEvent instance that represents the contact event.
:param hands: A list of Object instances that represent the hands.
"""
Expand All @@ -68,12 +69,18 @@ def handle_contact_event(self, event: ContactEvent, hands: List[Object]) -> None
print(f"Creating new thread for object {obj_in_contact.name}")
self.start_contact_threads_for_obj_and_update_tracked_objs(obj_in_contact)

hand_link, obj_link = None, None
if obj_a in hands and obj_in_contact not in hands:
self.start_pick_up_thread_for_obj(link_a, link_b)
hand_link, obj_link = link_a, link_b
elif obj_in_contact in hands and obj_a not in hands:
hand_link, obj_link = link_b, link_a
if hand_link is not None and obj_link is not None:
self.start_pick_up_thread_for_obj(hand_link, obj_link)

def start_contact_threads_for_obj_and_update_tracked_objs(self, obj: Object):
"""
Starts the contact threads for the object and updates the tracked objects.
Start the contact threads for the object and updates the tracked objects.
:param obj: The Object instance for which the contact threads are started.
"""
for detector in (ContactDetector, LossOfContactDetector):
Expand All @@ -84,7 +91,8 @@ def start_contact_threads_for_obj_and_update_tracked_objs(self, obj: Object):

def start_pick_up_thread_for_obj(self, hand_link: Link, obj_link: Link):
"""
Starts the pickup thread for the object.
Start the pickup thread for the object.
:param hand_link: The Link instance that represents the hand.
:param obj_link: The Link instance that represents the object.
"""
Expand All @@ -101,7 +109,8 @@ def start_pick_up_thread_for_obj(self, hand_link: Link, obj_link: Link):

def get_hands_and_track_hand_contacts(self) -> List[Object]:
"""
Gets the hands from the world and starts the contact threads for the hands.
Get the hands from the world and starts the contact threads for the hands.
:return: A list of Object instances that represent the hands.
"""
hands = self.get_hands()
Expand All @@ -112,14 +121,15 @@ def get_hands_and_track_hand_contacts(self) -> List[Object]:
@staticmethod
def get_hands() -> List[Object]:
"""
Gets the hands from the world.
Get the hands from the world.
:return: A list of Object instances that represent the hands.
"""
return [obj for obj in World.current_world.objects if 'hand' in obj.name.lower()]

def join(self):
"""
Joins all the threads.
Join all the threads.
"""
self.motion_generator_thread.join()

Expand Down

0 comments on commit bda59b6

Please sign in to comment.