1313class ParallaxBinding (BaseBinding ):
1414 """Bindings for Parallax platform."""
1515
16- # Server cache lifetime (60 FPS).
17- CACHE_LIFETIME = 1 / 60
16+ # Server data update rate (30 FPS).
17+ SERVER_DATA_UPDATE_RATE = 1 / 30
1818
1919 # Movement polling preferences.
2020 UNCHANGED_COUNTER_LIMIT = 10
21- UNCHANGED_COUNTER_LIMIT_DEPTH = 50
22- POLL_INTERVAL = 0.1
2321
2422 # Speed preferences (mm/s to use coarse mode).
2523 COARSE_SPEED_THRESHOLD = 0.1
@@ -65,7 +63,8 @@ def get_dimensions(self) -> Vector4:
6563 async def get_position (self , manipulator_id : str ) -> Vector4 :
6664 manipulator_data : dict [str , Any ] = await self ._manipulator_data (manipulator_id )
6765 global_z = float (manipulator_data .get ("global_Z" , 0.0 ) or 0.0 )
68- await sleep (self .POLL_INTERVAL ) # Wait for the stage to stabilize.
66+
67+ await sleep (self .SERVER_DATA_UPDATE_RATE ) # Wait for the stage to stabilize.
6968
7069 global_x = float (manipulator_data .get ("global_X" , 0.0 ) or 0.0 )
7170 global_y = float (manipulator_data .get ("global_Y" , 0.0 ) or 0.0 )
@@ -87,8 +86,9 @@ async def get_shank_count(self, manipulator_id: str) -> int:
8786 manipulator_data : dict [str , Any ] = await self ._manipulator_data (manipulator_id )
8887 return int (manipulator_data .get ("shank_cnt" , 1 ) or 1 )
8988
89+ @staticmethod
9090 @override
91- def get_movement_tolerance (self ) -> float :
91+ def get_movement_tolerance () -> float :
9292 return 0.01
9393
9494 @override
@@ -128,7 +128,7 @@ async def set_position(self, manipulator_id: str, position: Vector4, speed: floa
128128 and unchanged_counter < self .UNCHANGED_COUNTER_LIMIT
129129 ):
130130 # Wait for a short time before checking again.
131- await sleep (self .POLL_INTERVAL )
131+ await sleep (self .SERVER_DATA_UPDATE_RATE )
132132
133133 # Update current position.
134134 current_position = await self .get_position (manipulator_id )
@@ -171,10 +171,10 @@ async def set_depth(self, manipulator_id: str, depth: float, speed: float) -> fl
171171 while (
172172 not self ._movement_stopped
173173 and not abs (current_depth - depth ) <= self .get_movement_tolerance ()
174- and unchanged_counter < self .UNCHANGED_COUNTER_LIMIT_DEPTH
174+ and unchanged_counter < self .UNCHANGED_COUNTER_LIMIT
175175 ):
176176 # Wait for a short time before checking again.
177- await sleep (self .POLL_INTERVAL )
177+ await sleep (self .SERVER_DATA_UPDATE_RATE )
178178
179179 # Get the current depth.
180180 current_depth = (await self .get_position (manipulator_id )).w
@@ -237,7 +237,7 @@ def unified_space_to_platform_space(self, unified_space: Vector4) -> Vector4:
237237 async def _query_data (self ) -> dict [str , Any ]: # pyright: ignore [reportExplicitAny]
238238 try :
239239 # Update cache if it's expired.
240- if get_running_loop ().time () - self .cache_time > self .CACHE_LIFETIME :
240+ if get_running_loop ().time () - self .cache_time > self .SERVER_DATA_UPDATE_RATE :
241241 # noinspection PyTypeChecker
242242 self .cache = (await get_running_loop ().run_in_executor (None , get , self ._url )).json ()
243243 self .cache_time = get_running_loop ().time ()
0 commit comments