Skip to content

Retry gain and exposure until the left image sensor answers - #51

Merged
adujardin merged 1 commit into
stereolabs:masterfrom
tristanleduc:fix/zed2-left-sensor-retry
Nov 18, 2026
Merged

adujardin merged 1 commit into
stereolabs:masterfrom
tristanleduc:fix/zed2-left-sensor-retry

Conversation

@tristanleduc

@tristanleduc tristanleduc commented Nov 17, 2026 •

Copy link
Copy Markdown

Problem

On the ZED 2 and ZED 2i, while the sensors module (SensorCapture) streams, the left image sensor stops answering for 0.5 s to several seconds at a time. Register reads then return 0xff or 0x00 and writes are lost, while the library reports success: gain and exposure can be silently not applied, and getGain() / getExposure() return values such as 0 or 95325. The right sensor is not affected.

Change

Gain and exposure are accessed through one helper that only accepts the access when the sensor provably answered:

  • the chip ID is read before and after the group of 3 registers;
  • every register is read twice and both reads must agree; a written value must be read back;
  • if any check fails, the whole group is repeated every 10 ms, for up to 6 s;
  • no retry when the camera cannot be reached.

setGain() / setExposure() keep their signature and log an error if the value could not be applied. getGain() / getExposure() return a negative value instead of a wrong one. The public API is unchanged.

The logic is taken from #49 (commit 1cd8f6c by @Myzhar), applied alone on top of master.

Tests

ZED 2i (camera firmware 1523), Ubuntu 22.04, kernel 6.8, USB 3. Cycle: brightness, gain and exposure on both sensors, each read back (up to 5 tries), with a thread reading the IMU and a thread timing every frame. Overnight soak, both columns run the same night, alternating.

Test before (v0.6.0) this PR
Cycles with a setting still wrong after 5 tries 207 / 3,450 (6.0 %) 0 / 15,200, apart from the case below
Retries needed 1,220 14
Cycles slower than 4 s (the call waited for the left sensor) 0 180 (longest 17.6 s)
Longest interval between two frames during those cycles 167 ms at HD720@30, 101 ms at HD1080@30 (normal 33-67 ms)

The PR column is 13,800 cycles at HD720@30, 700 at HD1080@30 and 700 at HD2K@15; the v0.6.0 column is HD720@30. Master has the same gain and exposure code as v0.6.0 (#48 only changed the open). Separately, 100 opens with gain and exposure written right after initializeVideo() gave 0 wrong values, and 200 cycles without the sensors module gave 0 failures.

Cost: when the left sensor stays unreachable, the setting call waits for it, up to 6 s per call. Frames keep arriving while it waits. One of the seven HD2K@15 runs had frame gaps of up to 1.9 s, both during and outside these waits; the cause is not known.

Not fixed by this PR: 7 times during the night, the left sensor stopped answering for good (about once per hour of streaming). The calls then returned an error after 6 s. Closing the camera, calling SensorCapture::resetSensorModule() and opening it again recovered it each time (7 out of 7, 10 to 15 s).

Not tested: ZED 2; Ubuntu 24.04.

@tristanleduc
tristanleduc marked this pull request as ready for review November 17, 2026 17:36
@adujardin
adujardin merged commit dde69ee into stereolabs:master Nov 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants