Skip to content

Commit

Permalink
Make simulation delay in detector configurable (#133)
Browse files Browse the repository at this point in the history
* make simulation delay in detector configurable

* use member variable instead of class variable

* turn detection_delay into a parameter

---------

Co-authored-by: Falko Schindler <falko@zauberzeug.com>
  • Loading branch information
rodja and falkoschindler authored Jun 13, 2024
1 parent b40eb26 commit 1b748da
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions rosys/vision/detector_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,23 @@ class DetectorSimulation(Detector):
Individual camera IDs can be added to a set of `blocked_cameras` to simulate occlusions during pytests.
A list of `simulated_objects` can be filled to define what can be detected.
An optional `noise` parameter controls the spatial accuracy in pixels.
An optional `detection_delay` parameter simulates the time it takes to process an image.
"""

def __init__(self, camera_provider: CalibratableCameraProvider, *, noise: float = 1.0, name: Optional[str] = None) -> None:
def __init__(self,
camera_provider: CalibratableCameraProvider, *,
noise: float = 1.0,
detection_delay: float = 0.4,
name: Optional[str] = None,
) -> None:
super().__init__(name=name)

self.camera_provider = camera_provider
self.noise = noise

self.blocked_cameras: set[str] = set()
self.simulated_objects: list[SimulatedObject] = []
self.detection_delay = detection_delay

rosys.on_repeat(self.step, 0.1)

Expand All @@ -54,7 +61,7 @@ async def detect(self,
tags: list[str] = [],
) -> Detections | None:
is_blocked = image.camera_id in self.blocked_cameras
await rosys.sleep(0.4)
await rosys.sleep(self.detection_delay)
image.set_detections(self.name, Detections())
if not is_blocked:
self.update_simulated_objects(image)
Expand Down

0 comments on commit 1b748da

Please sign in to comment.