Skip to content

[FEATURE] Mira220 (Arducam pivariety) camera support + calibration fixes#206

Draft
AndyJado wants to merge 9 commits into
PiTracLM:mainfrom
AndyJado:mira220_sensor
Draft

[FEATURE] Mira220 (Arducam pivariety) camera support + calibration fixes#206
AndyJado wants to merge 9 commits into
PiTracLM:mainfrom
AndyJado:mira220_sensor

Conversation

@AndyJado
Copy link
Copy Markdown

@AndyJado AndyJado commented May 17, 2026

Description

What does this PR do?

Adds full support for the Mira220 (Arducam pivariety) mono sensor as Camera 2, including camera model detection, external trigger via v4l2, dtoverlay configuration, UI integration, and interactive install prompt. Also fixes calibration failures on this sensor.

Why is this change needed?

The Mira220 is a global-shutter mono sensor used as an alternative to the InnoMaker IMX296 for Camera 2 (flight camera). Without these changes, the sensor is detected but camera2 calibration crashes (SIGABRT/SIGSEGV). Three Mira220-specific issues:

  1. Tuning file: SetLibcameraTuningFileEnvVariable always sets an IMX296 tuning file. No Mira220 tuning file exists — skip for this model, let libcamera auto-detect.
  2. Pipeline config: LIBCAMERA_RPI_CONFIG_FILE points to rpi_apps.yaml. The Arducam-built libcamera segfaults on Mira220 when any pipeline config is loaded — disable the override entirely (IMX296 verified fine without it).
  3. Timeout crash: Device timeout in external trigger mode triggered a camera restart (StopCamera/StartCamera) whose exceptions went uncaught, calling std::terminate.
  4. Overlay prompt: The arducam-pivariety dtoverlay must be present at boot for detection, but on first install it is missing — interactive prompt added.

Related Issue(s)

N/A

Changes Made

  • Add Mira220 (type 6) to CameraModel enum: 1600×1400, 4.464×3.906mm sensor, mono flag
  • External trigger via v4l2-ctl -c trigger_mode=1 on subdev (replaces IMX296 sysfs path)
  • Camera detection: extend regex for hyphenated driver names (arducam-pivariety → type 6)
  • UI config: add type 6 to camera dropdowns, shell detection in detect_pi_cameras.sh
  • Overlay: map type 6 to dtoverlay=arducam-pivariety, preserve on reconfigure, interactive prompt on first install
  • Priming pulse: swap duty cycle for Mira220 external trigger timing
  • Skip IMX296 tuning file for Mira220 (unsetenv LIBCAMERA_RPI_TUNING_FILE)
  • Disable LIBCAMERA_RPI_CONFIG_FILE override (Arducam libcamera incompatibility)
  • Ignore device timeout in cam2 event loop instead of restarting camera

Testing Performed

Test Environment

  • Pi Model: Pi 5 8GB
  • Camera Type: Slot 1: InnoMaker IMX296 Mono, Slot 2: Arducam Mira220 Mono
  • OS Version: Trixie 64-bit
  • Installation Method: Source (./build.sh dev)

Test Results

  • Camera 1 (IMX296) calibration: passes (regression test)
  • Camera 2 (Mira220) calibration: captures frames via external trigger, no crash, GetBall() executes
  • rpicam-still --camera 0 (IMX296): captures without pipeline config — no regression
  • rpicam-still --camera 1 (Mira220): captures without tuning file — 1600×1400 valid image

Test Commands Run

# IMX296 still works without pipeline config
unset LIBCAMERA_RPI_CONFIG_FILE
rpicam-still --camera 0 -o /tmp/test.jpg --timeout 3000 --nopreview
# → Still capture image received, EXIT=0

# Mira220 works without tuning/pipeline config
rpicam-still --camera 1 -o /tmp/test.jpg --timeout 3000 --nopreview
# → Still capture image received, EXIT=0

# Camera1 regression
curl -X POST http://localhost:8080/api/calibration/auto/camera1
# → success, focal length ~6.8mm

# Camera2 calibration
curl -X POST http://localhost:8080/api/calibration/auto/camera2
# → process exit 0, camera captures frames (ball placement needed)

Breaking Changes

  • This PR includes a behavioral change
    • What changes: rpi_apps.yaml is no longer set via LIBCAMERA_RPI_CONFIG_FILE. Both cameras rely on libcamera native timeout.
    • Impact: None. IMX296 tested working without the override.

Dependencies

  • No new dependencies

Hardware Compatibility

  • Tested on Pi 5
  • Tested on Pi 4
  • Tested with single Pi setup
  • Tested with dual Pi setup

Documentation

  • No documentation in this PR (follow-up will cover Mira220 camera docs)

Checklist

Code Quality

  • Code follows existing patterns
  • No unnecessary comments

Build & Test

  • Successfully builds with sudo ./build.sh dev
  • Tested on actual Raspberry Pi hardware

Submission Requirements

  • Commits are logically organized (9 commits)
  • PR title follows format
  • Branch is up-to-date with main

Register Mira220_Mono (type 6) in CameraModel enum with sensor
dimensions 4.464x3.906mm (2.79um pixel), default resolution
1600x1400, mono flag, and ball-radius parameter sharing with
PiGS and InnoMaker IMX296.
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 17, 2026

Thanks for your PR! Before we can review it, please sign our Contributor License Agreement.

How to sign (right here in this PR):

  1. Read the CLA:
  2. Add a new PR comment with exactly this line (copy & paste):
    I have read the CLA Document and I hereby sign the CLA
    
  3. Already signed and not seeing the check pass? Ask me to recheck by commenting:
    recheck
    

    I have read the CLA Document and I hereby sign the CLA
    1 out of 2 committers have signed the CLA.
    ✅ (jamespilgrim)[https://github.com/jamespilgrim]
    @AndyJado
    You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot.

@connorgallopo
Copy link
Copy Markdown
Collaborator

connorgallopo commented May 17, 2026

@AndyJado Please use the original, full PR template.

This has AI patterns so those questions are especially important.

Disregarding that template completely on your first contribution is generally a bad practice.

@AndyJado AndyJado marked this pull request as draft May 17, 2026 13:49
Add v4l2_trigger script that sets trigger_mode control on the
arducam-pivariety v4l-subdev for external trigger (FSIN pin).
Call it from SetExternalTrigger() and extend cam2 quiesce time
for Mira220 just like InnoMaker.
@AndyJado AndyJado force-pushed the mira220_sensor branch 2 times, most recently from fd52c51 to 7d173c9 Compare May 17, 2026 14:25
AndyJado added 2 commits May 17, 2026 22:51
Extend sensor name regex to support hyphenated driver names. Recognise arducam-pivariety sensor as Mira220 (type 6).
Add type 6 to camera dropdowns in configurations.json and\nregister arducam-pivariety in detect_pi_cameras.sh.
…re; prompt on first install

Map camera type 6 to dtoverlay=arducam-pivariety in config.txt.
Preserve the overlay when only one camera is detected to avoid
a circular failure. On first install, if Mira220 is not detected,
interactively ask the user whether one is connected.
@AndyJado AndyJado force-pushed the mira220_sensor branch 2 times, most recently from 891f512 to a8ef621 Compare May 17, 2026 15:46
@AndyJado AndyJado changed the title feat: Mira220 (Arducam pivariety) camera support + calibration fixes [FEATURE] Mira220 (Arducam pivariety) camera support + calibration fixes May 17, 2026
AndyJado added 4 commits May 17, 2026 23:59
The Mira220 external trigger (trigger_mode=1) requires a longer
priming pulse than the InnoMaker to reliably produce frame events
on the FSIN pin.
SetLibcameraTuningFileEnvVariable: for Mira220_Mono, unset
LIBCAMERA_RPI_TUNING_FILE so libcamera auto-detects the best
available fallback. No matching tuning file exists for this sensor.
set_pipeline_configuration: make no-op. The rpi_apps.yaml
causes a segfault with the Arducam-built libcamera on Mira220.
IMX296 verified working without the override.
Do not restart camera on timeout in external trigger mode. The
StopCamera/StartCamera restart path throws uncaught exceptions
that call std::terminate. Instead, just continue waiting for
FSIN pulses — the timeout is expected while the camera waits.
@connorgallopo
Copy link
Copy Markdown
Collaborator

connorgallopo commented May 17, 2026

@AndyJado I also see that every almost single commit is co-authored by AI. We do not accept AI authored contributions in this repository. Not only that - the AI section was again ignored when you updated to use the template. Have you had a chance to look at our AI policy? The lack of transparency on this PR is going to be a blocker for the time being. Until this can be fully end to end and regression tested by a maintainer this should remain on hold.

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.

3 participants