Skip to content

Updates for synchronous and externally triggered cameras (WIP) #4089

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

njhollinghurst
Copy link
Contributor

Update synchronized cameras documentation to:

  • Deprecate the XVS sync method for GS Cam, in favour of XTRIG

  • Recommend "always-on" property instead of using pull-ups

  • Recommend "trigger-mode" for IMX477 be set using the new OF property (better for source and sink on same Pi) while noting that the module parameter still works and that "trigger-mode" means something quite different for IMX296!

  • Document the need to edit the pipeline config file for timeout

  • Some attempt to tidy the structure while covering all the options

  • Remove $ prompts from scripts/commands, so they can be copy-pasted

Update synchronized cameras documentation to:

- Deprecate the XVS sync method for GS Cam, in favour of XTRIG

- Recommend "always-on" property instead of using pull-ups

- Recommend "trigger-mode" for IMX477 be set using the new OF
  property (better for source and sink on same Pi) while noting
  that the module parameter still works and that "trigger-mode"
  means something quite different for IMX296!

- Document the need to edit the pipeline config file for timeout

- Some attempt to tidy the structure while covering all the options

- Remove $ prompts from scripts/commands, so they can be copy-pasted
@lurch lurch requested a review from naushir April 30, 2025 15:20
@lurch
Copy link
Contributor

lurch commented Apr 30, 2025

  • Remove $ prompts from scripts/commands, so they can be copy-pasted

If you use the [source,console] above a code-block, then the $ is automatically non-copyable, see e.g. https://www.raspberrypi.com/documentation/computers/camera_software.html#rpicam-jpeg

@njhollinghurst
Copy link
Contributor Author

It's a bit messy, but hard to make it simpler without omitting required information (indeed it does omit repeating the "timeout-defeat" instructions for GS external trigger, but presumably people will infer that it needs to be done as in the previous section).

I feel this stuff would be better as a separate Application Note rather than part of the generic camera documentation?

Conspicuous by is absence is any mention of the new S/W synchronization method!


This step is only necessary if you have more than one camera with XTR wired in parallel.

As the superuser, edit `/boot/firmware/config.txt`. Change `camera_auto_detect=1` to `camera_auto_detect=0`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We generally don't use phrasing like "As the superuser..." - I think I'd probably just go with "Edit /boot/firmware/config.txt and change..."
You could link to https://www.raspberrypi.com/documentation/computers/config_txt.html#common-hardware-configuration-options if you really want to.

Copy link
Contributor Author

@njhollinghurst njhollinghurst Apr 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll remove it (and the other one below).

I suppose it was a sort of echo of a previous use of that word.

----
dtoverlay=imx296,always-on
----
When using the CAM0 port on a Raspberry Pi 5, CM4 or CM5, append `,cam0` to that line without a space. If both cameras are on the same Raspberry Pi you will need two dtoverlay lines, only one of them with `cam0`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"only one of them with" -> "only one of them ending with" ?


=== Starting the camera

Enable external triggering through superuser mode:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'd shorten this to just "Enable external triggering:"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inherited from the original at L26, but can be shortened.

But now I'm wondering if I strictly need to edit external_trigger.adoc? The original was nice and succinct. The "always-on" parameter is perhaps not essential in this case because the driver is quite low impedance.

Making use of the XVS pin (Vertical Sync) allows one camera to pulse when a frame capture is initiated.
The other camera can then listen for this sync pulse, and capture a frame at the same time as the other camera.
The High Quality (HQ) Camera supports synchronous captures.
Using the XVS pin (Vertical Sync) allows one camera (the "source") to pulse when a frame capture is initiated.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"to pulse" -> "to send a pulse" ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. And I probably should re-check the datasheet and whether or not we're using "fast trigger mode" or whatever it is... to check that the final part of the sentence is accurate too.

=== Using the HQ Camera
[NOTE]
====
Global Shutter (GS) Cameras can also be operated in a synchronous mode. However, the source camera will record one extra frame. Instead, for the GS Camera we recommend using an xref:camera.adoc#external-trigger-on-the-gs-camera[external trigger source]. You cannot synchronise a GS Camera to an HQ Camera.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

People might misinterpret "You cannot synchronise a GS Camera to an HQ Camera." to mean that you can synchronise an HQ Camera to a GS Camera"? 😉 Perhaps changing "to" to "with" is safer?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"and"


Solder the GND and XVS test points of each HQ Camera board to each other.
*For GS Cameras only,* you will also need to connect the XHS (Horizontal Sync) test point of each camera. On any GS Camera that you wish to act as a sink, bridge the two halves of the MAS pad with solder.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"test point of each camera." -> "test point of each camera together." ?


[source,console]
As the superuser, edit `/boot/firmware/config.txt`. Change `camera_auto_detect=1` to `camera_auto_detect=0`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See earlier comment...


Solder the GND of each Camera board to each other. Also solder 2 wires to the XHS test points on each board and connect these. No pullup is needed for XHS pin.
If the cameras are not all started within 1 second, the `rpicam-vid` application can time out. To prevent this, you must edit a configuration file on any Raspberry Pi(s) with sink cameras. On Raspberry Pi 5 or CM5, make a copy of the file `/usr/share/libcamera/pipeline/rpi/pisp/example.yaml`. On other Raspberry Pi models, make a copy of the file `/usr/share/libcamera/pipeline/rpi/vc4/rpi_apps.yaml`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps it's worth suggesting two different commands to copy each of those files to the same filename in the user's home folder, and then using that filename in the export LIBCAMERA_RPI_CONFIG_FILE= line below? 🤷‍♂️

----
$ ffmpeg -i source.h264 -vf select="gte(n\, 1)" source.h264
----
NOTE: When using the GS camera in synchronous mode, the sink will not record exactly the same number of frames as the source. **The source records one extra frame before the sink starts recording**. Because of this, you need to specify that the sink records one less frame with the `--frames` option. You could use `ffmpeg` to delete the first frame from the source camera's video recording.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"You could use" -> "Alternatively you could use"

Copy link
Contributor Author

@njhollinghurst njhollinghurst Apr 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not alternatively, but as well as!

Ben's original doc was somewhat ambiguous about which camera got the extra frame, needed the different command line and needed post-processing.

I need to test this again because getting it wrong leads to a (soft) lockup if the sink doesn't get the right number of syncs.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not alternatively, but as well as!

Ahhh, in which case perhaps the "could" ought to be "should then" ? (and perhaps worth bringing back the example ffmpeg command line)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I was trying to corral the GS-Cam-specific bits into NOTEs, but the ffmpeg command can't really go inside one of those, so might have to re-jig the structure.

It would be nice if we could obliterate GS Camera from this part, but somebody is bound to be using it already...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't the GS-Cam even more suited to synchronised captures, than a rolling-shutter camera? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well it would be nice to steer GS Cam users towards the alternative "external trigger" method (which requires fewer wires, is software-configurable, and doesn't have the asymmetry / off-by-one-frame issues)

Sadly, now that we've documented this method we can't really un-document it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahhh, now I see what you're saying 🙂 Yeah, I guess all we can do is strongly-discourage it.

@lurch lurch self-requested a review April 30, 2025 15:45
@njhollinghurst
Copy link
Contributor Author

njhollinghurst commented Apr 30, 2025

Ah, I've belatedly noticed that we do already document Software Camera Synchronisation, although it's well hidden under rpicam-apps and could maybe do with being bumped a bit up the hierarchy.

I should definitely link there from here.

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

Successfully merging this pull request may close these issues.

2 participants