Skip to main content
Version: 1.1.0

GMSL2 Camera

Hardware​

AutomatePro can be ordered with 0, 2, or 4 GMSL2 (Gigabit Multimedia Serial Link) camera inputs. GMSL2 is a high-speed, low-latency camera link commonly used in automotive applications. It supports cable lengths up to 15 m and Power over Coax (PoC). AutomatePro can supply up to 12 W total to downstream GMSL2 cameras.

Recommended cameras are listed in the camera accessories. The number of populated FAKRA Z connectors depends on the ordered device configuration. The AutomatePro software supports up to four cameras, cam1 to cam4. A two-camera board has cam1 and cam2; cam3 and cam4 exist only on a four-camera board.

GMSL2 camera connectors

Onboard GMSL2 Specifications​

ParameterValue
Onboard ICMAX9296AGT (two-camera board)
MAX96712 (four-camera board)
StandardGMSL2
Max cable length15 m
Max data rate4.5 Gbps
PoC voltage12 VDC
FAKRA typeType Z (Water Blue)
Max power12 W total

ROS API​

Nodes: automatepro_cam1_node, automatepro_cam2_node, automatepro_cam3_node, automatepro_cam4_node​

Publishers​

Replace <camera_name> with the configured camera name, usually cam1 to cam4.

TopicTypeDescription
/camera/<camera_name>/image_rawsensor_msgs/msg/ImageRaw camera frames in the encoding set by raw.encoding. Published only when raw.enable is true; the packaged file sets false.
/camera/<camera_name>/camera_infosensor_msgs/msg/CameraInfoCamera calibration and projection information.
/camera/<camera_name>/h264/videofoxglove_msgs/msg/CompressedVideoH.264 compressed video frames. Published when compression.enable and compression.publish are true.
/camera/<camera_name>/h264/calibfoxglove_msgs/msg/CameraCalibrationCalibration metadata for the compressed stream.
/camera/<camera_name>/ipc/camera_infosensor_msgs/msg/CameraInfoCalibration of the frames sent over IPC. Published only when ipc.enable is true.
/diagnosticsdiagnostic_msgs/msg/DiagnosticArrayCamera state and reason, recovery attempts, and the rate of each output.

Verify Cameras​

Run these checks from AutomatePro over SSH:

. /opt/automatepro/scripts/ros-env.sh && automatepro_source_ros
ros2 node list | grep automatepro_cam
ros2 topic list | grep '/camera/'

For a single-frame check:

ros2 topic echo /camera/cam1/camera_info --once

If camera compression is enabled, verify the H.264 stream:

ros2 topic hz /camera/cam1/h264/video

Configuration​

Each camera is exposed as a V4L2 device with a stable path, /dev/automatepro/gmsl2-cam1 to /dev/automatepro/gmsl2-cam4, that follows the camera's port. The AutomatePro camera driver uses these devices through GStreamer and publishes ROS 2 image and compressed-video topics.

Driver: automatepro_camera_driver
Container: automatepro-core-driver

info

Runtime ROS configuration is stored in /etc/opt/automatepro/ros. Packaged defaults are stored in /opt/automatepro/defconfig/ros.

Edit the camera parameter file:

sudo nano /etc/opt/automatepro/ros/camera_params.yaml

Important parameter groups:

ParameterDefaultDescription
enabletrueNot used by the AutomatePro services; ROS_DRIVER_CAM_1 to ROS_DRIVER_CAM_4 in /etc/opt/automatepro/automatepro.conf select the camera nodes.
camera_namecam1 to cam4Name used in camera topic namespaces.
frame_idautomatepro_cam1 to automatepro_cam4Frame ID stamped on camera messages.
resolution[640, 512]ROS output resolution.
scaling_filter5-tapFilter used wherever a frame is resized: nearest, bilinear, 5-tap, 10-tap, smart, or nicest.
rotation.angle_rad0.0Turns the picture by this angle in radians, counter-clockwise on screen when positive. Whole quarter turns turn every output; other angles, within 45°, turn only the frames for H.264 and IPC.
rotation.cornerscropFor angles other than whole quarter turns: crop zooms to fill the frame, black keeps the whole picture.
raw.enablefalsePublishes image_raw. camera_info is published either way.
raw.encodingbgr8Encoding of image_raw: bgr8, rgb8, or mono8.
image.qos_history_depth1Queue depth for the image_raw and camera_info publishers.
image.qos_reliabilityreliableQoS reliability of image_raw and camera_info, either reliable or best_effort.
image.qos_durabilityvolatileQoS durability of image_raw and camera_info, either volatile or transient_local.
camera_info.*Zeros (uncalibrated)Calibration values published on camera_info.
compression.enabletrueEnables H.264 output.
compression.publishtruePublishes h264/video and h264/calib. When false, the stream is sent over RTP alone.
compression.rectifyfalseEncodes rectified frames. image_raw and camera_info stay unrectified.
compression.encoderautoSelects the encoder: auto uses the NVIDIA hardware video encoder (NVENC) when available and falls back to CPU encoding, nvenc forces nvv4l2h264enc and fails to configure without it, and x264 forces x264enc.
compression.bitrate_kbps2000Target bitrate in kbps. Set to 0 for automatic bitrate calculation.
compression.bits_per_pixel0.1Used for automatic bitrate calculation when bitrate_kbps is 0.
compression.keyframe_interval_frames30Frames between H.264 keyframes.
compression.resolution[640, 512]Compressed stream resolution.
compression.frame_rate_hz30Compressed stream frame rate.
compression.qos_*1, best_effort, volatileQoS settings for the compressed-video publishers.
compression.rtp.enablefalseSends the H.264 stream over RTP/UDP when enabled.
compression.rtp.ip127.0.0.1RTP destination IP address.
compression.rtp.port5000 to 5003RTP destination UDP port, one per camera (5000 for cam1).
ipc.enablefalseSends NV12 frames to a local consumer over nvunixfd.
ipc.rectifyfalseSends rectified frames, made from camera_info, which must be this camera's calibration.
ipc.socket_path/run/automatepro/camera/cam1.sock to cam4.sockUnix socket of the IPC frames. The socket's directory must exist.
supervisor.stall_timeout_s2.0Time in seconds without a filled frame before the camera counts as stalled.
supervisor.cycle_time_s0.5Interval in seconds at which the supervisor checks the camera.
recovery.healthy_reset_s300Seconds of streaming without a stall that restore the recovery attempts.
recovery.max_total_attempts5Recovery attempts before the camera node gives up. 0 means unlimited.
recovery.retry_delay_s5Seconds between recovery attempts; the first attempt is immediate.
logging.throttle_s10.0Throttle period in seconds of repetitive warnings and errors.
logging.gstreamer_debugemptyGStreamer debug thresholds in GST_DEBUG syntax, for example "2". Empty leaves them untouched.
publish_rate_hz0.0Rate limit in Hz of image_raw and camera_info. 0.0 publishes every frame; H.264 output rate is controlled by compression.frame_rate_hz.
sensor.device/dev/automatepro/gmsl2-cam1 to /dev/automatepro/gmsl2-cam4V4L2 device. Normally fixed by hardware.
sensor.resolution[1920, 1536]Sensor capture resolution. Normally fixed by hardware.
sensor.frame_rate_hz30Sensor capture frame rate.
sensor.formatUYVYSensor pixel format. Normally fixed by hardware.
sensor.presence_check.enabletrueOpens the capture device only while the camera's GMSL2 link reports it set up.
sensor.presence_check.timeout_s2.0Time in seconds for which a link that is still coming up is read again before the camera counts as absent.
sensor.presence_check.link_state_fileemptyThe camera's gmsl_link_state file. Empty finds it from sensor.device.

Default Config​

The default file includes one block for each of the four camera nodes, named with the node's full name, such as /automatepro_cam1_node. The most commonly edited values are shown below:

/automatepro_cam1_node:
ros__parameters:
enable: true
camera_name: "cam1"
frame_id: "automatepro_cam1"
resolution: [640, 512]

camera_info:
distortion_model: "plumb_bob"
d: [0.0, 0.0, 0.0, 0.0, 0.0]
k: [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
r: [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
p: [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]

raw:
enable: false
encoding: "bgr8"

compression:
enable: true
encoder: "auto"
bitrate_kbps: 2000
bits_per_pixel: 0.1
keyframe_interval_frames: 30
resolution: [640, 512]
frame_rate_hz: 30

rtp:
enable: false
ip: "127.0.0.1"
port: 5000

supervisor:
stall_timeout_s: 2.0
cycle_time_s: 0.5

recovery:
healthy_reset_s: 300
max_total_attempts: 5
retry_delay_s: 5

publish_rate_hz: 0.0

# Do not change the sensor block unless Lemvos support instructs you to.
sensor:
device: "/dev/automatepro/gmsl2-cam1"
resolution: [1920, 1536]
frame_rate_hz: 30
format: "UYVY"

/automatepro_cam2_node:
ros__parameters:
enable: true
camera_name: "cam2"
frame_id: "automatepro_cam2"
resolution: [640, 512]

# Same structure as cam1. Defaults use /dev/automatepro/gmsl2-cam2 and RTP port 5001.
sensor:
device: "/dev/automatepro/gmsl2-cam2"
resolution: [1920, 1536]
frame_rate_hz: 30
format: "UYVY"
Important

Restart automatepro-core-driver after changing the configuration. Configuration values are loaded when the driver container starts and are only applied after the service restarts.

sudo systemctl restart automatepro-core-driver

Frame Sync on the Four-Camera Board​

The four-camera board can start every camera's frames from one 30 Hz frame-sync pulse. The boot setting is the frame_sync value on the options max96712 line of /etc/modprobe.d/automatepro-gmsl2.conf: 0, the default, leaves each camera on its own timing, and 1 runs the deserializer's frame-sync generator and passes the pulse to every camera. The two-camera board ignores the setting. Edit the value, then reboot:

sudo nano /etc/modprobe.d/automatepro-gmsl2.conf
sudo reboot

To switch frame sync without a reboot, write 1 (on) or 0 (off) to /sys/bus/i2c/devices/2-0029/frame_sync, the deserializer's frame-sync file, which only the four-camera board has. Any user can read the file, and only root can write it:

cat /sys/bus/i2c/devices/2-0029/frame_sync
echo 1 | sudo tee /sys/bus/i2c/devices/2-0029/frame_sync

The file reads 1 while frame sync is on and 0 while it is off. After a change, the kernel log (sudo journalctl -k) shows frame sync on by request or frame sync off by request. The switch lasts until the next boot, which takes the value of /etc/modprobe.d/automatepro-gmsl2.conf again.

A switch never interrupts a stream. A camera that is not streaming follows it at once. A streaming camera keeps its timing until its stream stops and follows the new setting from its next stream start. To move a streaming camera over at once, reset it, for example with sudo gmsl2-reset cam2; its camera node then restarts its pipeline. After a switch to 0, the pulse keeps running until the last camera streaming on it has stopped. A camera set up later, after it is plugged in again or reset, follows the setting in force. If the write fails with Input/output error, the deserializer or a camera did not take the setting; the file keeps the new value, and writing the same value again retries the change.

Important

On a unit that switches frame sync without a reboot, leave the V4L2 control trig_mode of every camera at its default. A camera set to trigger mode 2 (external trigger) follows the pulse from each of its stream starts, whatever the setting, and a switch to 0 while it streams can stop the pulse under it and freeze its stream.

Enable or Disable Camera Drivers​

To disable the AutomatePro camera driver and use a different V4L2, OpenCV, GStreamer, or custom camera stack, edit /etc/opt/automatepro/automatepro.conf:

sudo nano /etc/opt/automatepro/automatepro.conf

Set the relevant flags to 0:

ROS_DRIVER_CAM_1=0
ROS_DRIVER_CAM_2=0

ROS_DRIVER_CAM_3 and ROS_DRIVER_CAM_4 apply only on a four-camera board.

Apply the change:

sudo systemctl restart automatepro-core-driver

Now you can use the cameras through /dev/automatepro/gmsl2-cam1 to /dev/automatepro/gmsl2-cam4 with any standard V4L2 driver, OpenCV, GStreamer, or another camera driver. For more details on hardware acceleration and GStreamer, see the NVIDIA Jetson multimedia documentation.

Troubleshooting​

Camera Topics Are Missing​

  1. Check whether the camera driver is enabled:

    grep ROS_DRIVER_CAM /etc/opt/automatepro/automatepro.conf
  2. Check the service:

    systemctl status automatepro-core-driver
  3. Check the link state of each camera:

    grep -H . /sys/bus/i2c/devices/*/gmsl_link_state

    ready and streaming mean the camera is set up; empty means no camera is connected on that link; locked means a camera was found and is being set up; fault and unsupported mean the camera could not be set up.

  4. Inspect recent logs:

    sudo journalctl -u automatepro-core-driver -n 100 --no-pager

Restart Camera Hardware​

If the camera hardware needs to be reinitialized, reset the cameras. Nothing needs to be stopped first; a streaming camera is interrupted and its camera node restarts its pipeline:

sudo gmsl2-reset

On a four-camera board, reset a single camera by name:

sudo gmsl2-reset cam2

A two-camera board resets its cameras only together.

Automatic Recovery​

The camera node supervises each camera. If frames stop arriving for supervisor.stall_timeout_s, it resets the camera's pipeline. The GMSL2 kernel drivers check the camera links every 500 ms and set up a camera that appears or comes back by themselves, so a stalled camera needs no service restart. The node waits for a camera that is not connected, or whose link is lost, with the capture device closed and without spending a recovery attempt. The node starts the camera when its link reads ready.

With automatepro-l4t-patches-r36.5.0 installed, the camera source drops the frames that the capture driver flags as failed instead of publishing them as green frames, and never publishes a frame the capture driver did not fill. The camera node counts the dropped frames on /diagnostics as source frames dropped as corrupted.

How the kernel drivers recover a camera depends on the board:

  • On a four-camera board, each camera recovers on its own while the other cameras keep streaming. A camera that comes back is set up alone. A camera whose link reads fault while it stays locked is reset alone and set up again up to three times, waiting 5, 10, and 20 s before each attempt. After that, it waits until you reset it by name, for example sudo gmsl2-reset cam2, or reconnect it.
  • On a two-camera board, the two links share one lock and one reset, so the cameras recover together. A camera plugged in next to a connected camera is found only at the next sudo gmsl2-reset. With both cameras connected, both stop while either cable is out; the camera still plugged in is then set up alone, and the other one is found at the next sudo gmsl2-reset. A link in fault waits until you run sudo gmsl2-reset or reconnect the camera.

While no camera is set up and at least one has failed its set-up, both boards switch the power of every camera off and on, up to three times, waiting 5, 10, and 20 s before each power cycle. Each board switches the power of all its cameras at once, so a power cycle never runs while a camera is set up.

After recovery.max_total_attempts failed attempts, the camera node stays unconfigured and its process keeps running. Configure and activate it again for a fresh attempt budget, without touching the other drivers. Use /automatepro_cam2_node to /automatepro_cam4_node for the other cameras:

. /opt/automatepro/scripts/ros-env.sh && automatepro_source_ros
ros2 lifecycle set /automatepro_cam1_node configure
ros2 lifecycle set /automatepro_cam1_node activate
Developer Notes: launch and recovery internals

automatepro_bringup starts camera nodes with core_driver.launch.py. Cameras 1 to 4 are controlled by the launch arguments enable_cam1 to enable_cam4; the core driver service enables cam3 and cam4 only on a board whose device tree has the MAX96712. When a camera process exits, launch starts it again after core_driver_bringup.respawn_delay_s.camera seconds, 30.0 by default, set in core_driver_bringup_params.yaml; a camera that is absent waits inside its node and does not exit.

The camera node reads each camera's state from the gmsl_link_state file of its sensor device and reports its supervisor state on /diagnostics: Starting, Streaming, RetryPending, WaitingForCamera, UnsupportedCamera, LinkFault, or GaveUp. WaitingForCamera, UnsupportedCamera, and LinkFault spend no recovery attempt.