@@ -23,18 +23,32 @@ class CameraEmulator:
2323 __create_key = object ()
2424
2525 @classmethod
26- def create (cls , images_path : str ) -> "tuple[True, CameraEmulator] | tuple[False, None]" :
26+ def create (cls , images_path : str , time_between_images : float = 1.0 ) -> "tuple[True, CameraEmulator] | tuple[False, None]" :
2727 """
2828 Setup camera emulator.
2929
3030 Args:
3131 images_path: Path to the directory containing images for the camera emulator. Cycles through these images to simulate camera input (every 1 second).
32+ time_between_images: Time in seconds between image changes.
3233
3334 Returns:
3435 Success, CameraEmulator instance.
3536 """
3637
3738 if not isinstance (images_path , str ):
39+ print ("Images path is not a string" )
40+ return False , None
41+
42+ if not os .path .isdir (images_path ):
43+ print ("Images path is not a valid directory" )
44+ return False , None
45+
46+ if not isinstance (time_between_images , (int , float )):
47+ print ("Time between images is not a number" )
48+ return False , None
49+
50+ if time_between_images <= 0 :
51+ print ("Time between images must be positive" )
3852 return False , None
3953
4054 try :
@@ -52,10 +66,10 @@ def create(cls, images_path: str) -> "tuple[True, CameraEmulator] | tuple[False,
5266 if virtual_camera_instance is None :
5367 return False , None
5468
55- return True , CameraEmulator (cls .__create_key , images_path , virtual_camera_instance )
69+ return True , CameraEmulator (cls .__create_key , images_path , time_between_images , virtual_camera_instance )
5670
5771 def __init__ (
58- self , class_private_create_key : object , images_path : str , virtual_camera : pyvirtualcam
72+ self , class_private_create_key : object , images_path : str , time_between_images : float , virtual_camera : pyvirtualcam
5973 ) -> None :
6074 """
6175 Private constructor, use create() method.
@@ -67,7 +81,8 @@ def __init__(
6781 self .__image_paths : "list[str]" = []
6882 self .__current_frame = None
6983 self .__image_index = 0
70- self .__next_image_time = time .time () + 1.0
84+ self .__next_image_time = time .time () + time_between_images
85+ self .__time_between_images = time_between_images
7186
7287 self .__get_images ()
7388 self .update_current_image ()
@@ -89,7 +104,7 @@ def periodic(self) -> None:
89104 self .update_current_image ()
90105 except Exception as exc : # pylint: disable=broad-except
91106 print (f"HITL camera image update error: { exc } " )
92- self .__next_image_time = now + 1.0
107+ self .__next_image_time = now + self . __time_between_images
93108 except Exception as exc : # pylint: disable=broad-except
94109 print (f"HITL camera periodic error: { exc } " )
95110
0 commit comments