Skip to content

feat(cameras): Software auto exposure for synchronized stellarHD streams - #639

Open
brandonhs wants to merge 2 commits into
636-switch-to-new-sensor-controls-via-i2c-instead-of-asic-interfacefrom
software-auto-exposure
Open

brandonhs wants to merge 2 commits into
636-switch-to-new-sensor-controls-via-i2c-instead-of-asic-interfacefrom
software-auto-exposure

Conversation

@brandonhs

Copy link
Copy Markdown
Member

Summary

Adds a software auto exposure that sets strobe width and exposure time for synchronized stellarHD streams, with the same values on every camera in the group. ISO stays at the user's value. Also fixes sensor settings (and the firmware AE setting) being lost when a stream starts.

Stacked on #638, which this needs for the firmware I2C sensor writes.

Software auto exposure

  • The synchronized capture loop hands each frame set to the controller, which keeps only the newest, so capture never waits on AE.
  • The controller runs on its own thread at up to 10 Hz (once per frame below 10 fps). It decodes both JPEGs at 1/8 scale in grayscale with Pillow and meters the combined histogram.
  • It steps one light level in EV. The strobe width follows it, and the exposure is the shortest that contains the strobe. Without a strobe, the exposure alone carries it.
  • A highlight limit (98th percentile ≤ 235) wins over the mean target when it asks for less light, so it settles at the limit instead of bouncing across it.
  • Writes go to every camera's ASICInterface worker under one queue key (newest value wins), in a single OmniVision group hold (0x3208).
  • Adds Auto Exposure (Software) and AE Target Brightness controls on the leader. Software and firmware AE are mutually exclusive: turning one on turns the other off, for the whole group. Either one locks the Exposure Time and Strobe Width sliders, which update about once a second.

Fix: settings lost at stream start

The sensor only answers I2C a second or two after the stream starts, so the exposure, ISO and strobe writes made right after starting it were dropped. The firmware also turns its AE on while starting the sensor, so the camera ran firmware AE while the UI said off (it took two clicks to really turn it off). After a stream starts, a background thread now waits for every sensor to answer, reapplies the settings, and checks that the firmware AE matches the setting (3 checks, 0.5 s apart).

Tuning (measured on stellarHD + explore3D)

Measured Setting
Write → visible latency 2 frames, every step SETTLE_FRAMES = 3 (1 oscillates)
Luma vs light exponent 0.43–0.51 RESPONSE_EXPONENT = 0.5
Loop gain settles in 4–6 updates, no overshoot LOOP_GAIN = 0.8
Longest useful exposure VTS − 13 (1461 at VTS 1474; the 30 fps table says 2942) read from the sensor's VTS
Group hold latches exposure and strobe together on

Note: the frontend's FPS_TO_MAX_EXPOSURE has the same 30 fps value (2942), so the manual Exposure Time slider allows values that do nothing on this firmware. Not changed here.

Type of change

  • Bug fix
  • Feature / Refactor
  • Breaking change
  • Misc.

Quick Checklist

  • I have reviewed my own code.
  • I have tested these changes locally: AE loop tuned on two cameras through scripts and run in the dweOS UI; the stream-start reapply fix is not tested on hardware yet. The strobe path is untested (no strobe connected).
  • I have tested these changes on the following platforms (optional):
    • SVC
    • microSVC (optional)
    • SVC Pro

Meter the synchronized frames and set the same exposure time and strobe
width on every camera in the group. ISO stays at the user's value.

The capture loop hands each frame set to the controller, which keeps
only the newest so capture never waits. The controller runs on its own
thread at up to 10 Hz, decodes both JPEGs at 1/8 scale in grayscale and
steps a single light level in EV. The strobe follows the light level and
the exposure is the shortest that contains it. A 98th percentile
highlight limit wins over the mean target when it asks for less light,
so the loop settles at the limit instead of bouncing across it.

Tuned on two cameras: writes use group hold and show 2 frames later,
luma grows like light^0.5, and exposure stops adding light at VTS - 13,
so the longest exposure comes from the sensor's VTS instead of the
table. Settles in 4-6 updates without overshoot.

Adds "Auto Exposure (Software)" and "AE Target Brightness" controls.
Software and firmware auto exposure are mutually exclusive, and both
lock the Exposure Time and Strobe Width sliders. Adds Pillow.
The sensor only answers I2C a second or two after the stream starts, so
the exposure, ISO and strobe writes made right after starting it were
lost. The firmware also turns its auto exposure on while starting the
sensor, so the camera ran firmware AE while the setting said off.

After a stream starts, wait until every sensor in the group answers,
reapply the settings, and check that the firmware AE matches the
setting, writing it again if not (3 checks, 0.5 s apart). Waiting is
cancelled if the stream stops or restarts.
@brandonhs

Copy link
Copy Markdown
Member Author

Slop pr but good for testing!

@github-actions

Copy link
Copy Markdown

Preview build: preview-pr-639 (v0.9.0-pr639.06b8ca4, built from 06b8ca4)

curl -s https://raw.githubusercontent.com/DeepWaterExploration/dweOS/main/install.sh | sudo bash -s preview-pr-639

Rebuilt on every push. Closing this pull request deletes the preview.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant