Read back zoom level after returning to preset (#25118)
CI / AMD64 Build (push) Waiting to run
CI / AMD64 Smoke Test (push) Blocked by required conditions
CI / ARM Build (push) Waiting to run
CI / Jetson Jetpack 6 (push) Waiting to run
CI / AMD64 Extra Build (push) Blocked by required conditions
CI / ARM Extra Build (push) Blocked by required conditions
CI / Synaptics Build (push) Blocked by required conditions
CI / Assemble and push default build (push) Blocked by required conditions

* Read back zoom level after returning to preset

The camera is idle when the track ends, so motor_stopped is still set
after GotoPreset and the status loop meant to update the zoom level
never runs. The next track then starts from the previous track's zoom
level, and in absolute zooming mode its first move zooms back to it.
Clear motor_stopped first, as calibration does after its preset moves.

* Don't block maintenance on the preset status wait

If the camera stops responding when the track ends, get_camera_status
never sets motor_stopped and the wait after the preset move loops
forever. run() waits on camera_maintenance, so every other camera
stalls with it. Drop the wait and let the status check at the top of
maintenance read the zoom level back, once per pass.

* Don't send the stored zoom level on the initial absolute move

A track that starts before maintenance has read the zoom back from the
return preset still sees the previous track's level, and the initial
move sent it as an AbsoluteMove after pan/tilt. Zoom 0 skips the zoom
on the initial move, which is what it was meant to do, and the next
move works from the level read after pan/tilt.

* Drop the motor_stopped clear after returning to preset

The zoom = 0 change on the initial move fixes the stale zoom on its own. Clearing motor_stopped there made a track that starts mid-return have its first move refused and recorded with a start time of 0. The removed wait never polled, as motor_stopped is still set from the wait before the preset move.
This commit is contained in:
Joel Kåberg
2026-11-30 07:29:14 -06:00
committed by GitHub
parent e10551f8e3
commit 55872d73d6
2 changed files with 19 additions and 5 deletions
+3 -5
View File
@@ -1191,9 +1191,10 @@ class PtzAutoTracker(threading.Thread):
# absolute zooming separately from pan/tilt # absolute zooming separately from pan/tilt
if camera_config.onvif.autotracking.zooming == ZoomingModeEnum.absolute: if camera_config.onvif.autotracking.zooming == ZoomingModeEnum.absolute:
# don't zoom on initial move # don't zoom on initial move. the stored zoom level can still be
# the previous track's if this one starts right after a preset return
if "target_box" not in tom: if "target_box" not in tom:
zoom = current_zoom_level zoom = 0
else: else:
if ( if (
result := self._should_zoom_in( result := self._should_zoom_in(
@@ -1421,9 +1422,6 @@ class PtzAutoTracker(threading.Thread):
autotracker_config.return_preset.lower(), autotracker_config.return_preset.lower(),
) )
# update stored zoom level from preset
await self._wait_until_stopped(camera)
self.dispatcher.publish( self.dispatcher.publish(
f"{camera}/ptz_autotracker/active", "OFF", retain=False f"{camera}/ptz_autotracker/active", "OFF", retain=False
) )
+16
View File
@@ -267,6 +267,22 @@ class TestAutotrackerMoveQueue(unittest.IsolatedAsyncioTestCase):
) )
class TestAutotrackerInitialZoom(unittest.TestCase):
def test_initial_absolute_move_does_not_zoom(self) -> None:
tracker = _make_tracker()
tracker.config.cameras[
CAMERA
].onvif.autotracking.zooming = ZoomingModeEnum.absolute
# stale level from the previous track, not yet read back from the preset
tracker.ptz_metrics[CAMERA].zoom_level.value = 0.55
tracker.tracked_object_metrics = {CAMERA: {}}
box = (900, 400, 1000, 600)
obj = MagicMock()
obj.obj_data = {"box": box}
self.assertEqual(tracker._get_zoom_amount(CAMERA, obj, box, 0), 0)
class TestMaxTargetBox(unittest.TestCase): class TestMaxTargetBox(unittest.TestCase):
def test_follows_zoom_factor(self) -> None: def test_follows_zoom_factor(self) -> None:
self.assertAlmostEqual(calculate_max_target_box(0.5), 0.6**2) self.assertAlmostEqual(calculate_max_target_box(0.5), 0.6**2)