Eye-to-hand camera calibration

In this workshop you mount a RealSense camera somewhere in the cell and calibrate it against a UR robot. The camera is fixed. A ChArUco target is mounted on the robot wrist and moves with it. At the end you have the transform base_link → camera_N_link, so camera data can be used in the robot TF tree.

What you use:

Part

Where

Camera drivers (Docker)

realsense_docker, see also ROS 2 and Docker

Calibration solver + RViz panel

industrial_calibration / industrial_calibration_ros2

Reference guide, target, past results

camera_calibration

Do I need to know where the camera is? Yes, but only roughly. The solver starts from a guess of the camera pose and refines it. A few centimetres and about 15° of error is fine. In step 6 you place it by eye in RViz, until the point cloud matches the robot model: no tape measure or CAD is needed.

Throughout this guide:

  • camera_N is the camera slot you choose in step 2. The examples use camera_3.

  • <ur_type> is your robot model (ur3e, ur5e, ur10e, …).

Before you start

Camera drivers. Clone realsense_docker and download its image:

git clone https://github.com/ROS-Industrial-Session-Common/realsense_docker.git
cd realsense_docker
docker compose pull

Calibration solver. In the src/ folder of your ROS 2 Jazzy workspace, get industrial_calibration and its dependencies with the .repos file of the camera_calibration repository, then build:

git clone https://github.com/ROS-Industrial-Session-B/camera_calibration.git
vcs import . < camera_calibration/calibration_dependencies.repos
cd ..
rosdep install --from-paths src --ignore-src -y
colcon build --symlink-install
source install/setup.bash

You also need the UR driver and SciPy (step 11):

sudo apt install ros-jazzy-ur-robot-driver python3-scipy

0. Overview

 1. Place the camera
 2. Identify the camera (serial number)     ← do not skip
 3. Start the camera container
 4. Start the robot driver
 5. Check topics, frames and intrinsics
 6. Estimate the initial guesses in RViz
 7. Start data collection
 8. Collect 10–20 observations
 9. Write extrinsic_calibration.yaml
10. Run the calibration in RViz
11. Convert and publish the result
12. Validate

Run each long-running command in its own terminal. In every host terminal, set the same DDS settings as the containers:

source /opt/ros/jazzy/setup.bash
export RMW_IMPLEMENTATION=rmw_cyclonedds_cpp
export ROS_DOMAIN_ID=0

1. Place the camera

Choose the camera position before calibrating. Any movement afterwards, even a bump, invalidates the result.

  • Rigid mount: use a clamp or bracket that cannot rotate. A camera that wobbles cannot be calibrated.

  • Distance: 0.5–1.2 m from where the board will be. A D435 sees depth best between 0.3 and 3 m, and the ChArUco corners need enough pixels.

  • View: the camera should see the robot’s working area, and the board on the wrist must stay fully visible across many wrist orientations.

  • Reach: the robot must be able to bring the board into the whole camera image, near and far, tilted in several directions.

  • Facing the robot: the board must face the camera, so the wrist points back towards the camera during collection. Check that the arm itself does not hide the board, and that the cable and joint limits allow those wrist poses.

  • Lighting: avoid backlight (windows behind the board) and direct reflections on the board.

Start the camera (steps 2–3) and use rqt_image_view to fine-tune the placement before you tighten the mount.


2. Identify the camera (serial number)

The Docker setup selects cameras by serial number. If the serial is wrong, the container either fails to start or, worse, starts a different camera than the one you are calibrating.

2.1 List the connected cameras

The RealSense tools are in the image. From the realsense_docker folder:

cd realsense_docker
source set_camera_env.sh
docker compose run --rm realsense_1 rs-enumerate-devices -s

Example output:

Device Name                   Serial Number       Firmware Version
RealSense D435I               419522073259        5.17.0.10

The serial is also printed on the label underneath the camera.

Tip: if several cameras are connected and you are unsure which is which, unplug all but one, run the command, and write down the serial. Repeat for each camera.

2.2 Put the serial in set_camera_env.sh

Open set_camera_env.sh in the realsense_docker folder and set the slot you want to use:

export REALSENSE_1_SERIAL="_117322070913"
export REALSENSE_2_SERIAL="_236522071516"
export REALSENSE_3_SERIAL="_419522073259"   # ← your camera
  • The value needs a leading underscore (_419522073259). The RealSense ROS wrapper otherwise reads the serial as a number and drops leading zeros.

  • The slot number sets the ROS names: camera_N, /camera/camera_N/..., camera_N_color_optical_frame.

2.3 Check before launching

cd realsense_docker
source set_camera_env.sh          # vga (640x480) by default; "hd" for 1280x720

The script echoes the serials. Check that your slot shows the serial from step 2.1.


3. Start the camera container

cd realsense_docker
source set_camera_env.sh
docker compose up realsense_3
  • Start only the camera service. Do not start a realsense_N_static_tf service. Those services hold old calibration results for other camera positions. They are commented out in compose.yaml and should stay that way.

  • The image was downloaded with docker compose pull (Before you start). Without it, the first run builds the image, which takes a few minutes.

In the log, check that the driver found the device with your serial. If you see REALSENSE_3_SERIAL is not set, you forgot source set_camera_env.sh in this terminal.


4. Start the robot driver

ros2 launch ur_robot_driver ur_control.launch.py \
  ur_type:=<ur_type> \
  robot_ip:=<robot_ip> \
  reverse_ip:=<this_pc_ip> \
  launch_rviz:=true \
  launch_dashboard_client:=false

(UR5e in this cell: robot_ip:=192.168.1.10, reverse_ip:=192.168.1.5.)

Check the robot TF:

ros2 run tf2_ros tf2_echo base_link tool0

5. Check topics, frames and intrinsics

ros2 topic list | grep camera_3

Expected:

/camera/camera_3/color/image_raw
/camera/camera_3/color/camera_info
...

Look at the image to confirm you have the right physical camera. Wave a hand in front of it:

ros2 run rqt_image_view rqt_image_view /camera/camera_3/color/image_raw

Check the optical frame published by the driver, and keep the output for step 11:

ros2 run tf2_ros tf2_echo camera_3_link camera_3_color_optical_frame

Read the intrinsics, which you need in step 9:

ros2 topic echo --once /camera/camera_3/color/camera_info

k is [fx, 0, cx, 0, fy, cy, 0, 0, 1]. The intrinsics depend on the resolution. Use the same profile (vga/hd) for data collection and for the yaml.


6. Estimate the initial guesses in RViz

The solver needs two rough transforms:

Guess

From → To

How

Camera

base_link → camera_3_color_optical_frame

Place camera_3_link by eye in RViz, then read the optical frame (6.1)

Target

wrist_3_link → cal_target_frame

Look at the board on the wrist (6.2)

6.1 Camera guess: place the camera frame by eye

The camera has two frames:

  • camera_3_link, the body of the camera, with the usual ROS axes: X forward (the viewing direction), Y left, Z up. Its pose is easy to guess.

  • camera_3_color_optical_frame, the frame the solver needs, with the camera axes: Z forward, X right, Y down. The driver already publishes camera_3_link → camera_3_color_optical_frame.

RealSense optical frame convention
Optical frame: X red (right), Y green (down), Z blue (forward)

So you only place camera_3_link, and TF computes the optical frame for you.

A. Publish a guess of camera_3_link in base_link (metres and radians):

  • --x --y --z: where the camera is. The TF display in RViz shows the axes of base_link.

  • --yaw: where the camera looks, turned around Z of base_link: 0 along +X, 3.14 along −X.

  • --pitch: how much it looks down (positive = down).

  • --roll: only for a camera mounted sideways (1.57, -1.57) or upside down (3.14).

# example: camera at the side of the cell, looking down at the robot
ros2 run tf2_ros static_transform_publisher \
  --x 1.0 --y 0.5 --z 0.8 --yaw -2.7 --pitch 0.4 --roll 0.0 \
  --frame-id base_link --child-frame-id camera_3_link

Publish the guess on camera_3_link, not on the optical frame. The driver already publishes camera_3_link → camera_3_color_optical_frame, and a second parent would break TF.

Option: the Frame Editor. Instead of restarting static_transform_publisher after every change, add a frame camera_3_link with parent base_link in the Frame Editor, and type its pose (a, b, c are roll, pitch, yaw) or drag it in RViz (InteractiveMarkers display). The point cloud follows at once.

B. Check it in RViz (Fixed Frame base_link): add RobotModel, TF and PointCloud2 (/camera/camera_3/depth/color/points) displays. Correct the values until:

Check

Expected

Camera frame position

Where the camera physically is

Blue Z axis of camera_3_color_optical_frame

Points at the workspace

Red X axis

Points to the image’s right

Point cloud

Roughly overlaps the robot model, maybe off by some cm or degrees

A few centimetres and about 15° of error is fine.

C. Read the optical frame guess, which you need in step 9:

ros2 run tf2_ros tf2_echo base_link camera_3_color_optical_frame

Note the translation (x, y, z) and the quaternion (qx, qy, qz, qw).

6.2 Target guess

cal_target_frame is the board frame. wrist_3_link is the last robot link, at the flange centre, with Z pointing out of the flange.

For a board mounted roughly flat on the flange, facing away from the robot, this guess is usually close enough:

x: 0.05  y: -0.10  z: 0.01   qx: 0.0  qy: 1.0  qz: 0.0  qw: 0.0

If your board sits on a bracket, measure its offset from the flange along the wrist_3_link axes shown in RViz.

Check it in RViz:

# target guess (wrist_3_link -> cal_target_frame)
ros2 run tf2_ros static_transform_publisher \
  --x 0.05 --y -0.10 --z 0.01 \
  --qx 0.0 --qy 1.0 --qz 0.0 --qw 0.0 \
  --frame-id wrist_3_link --child-frame-id cal_target_frame

cal_target_frame must move with the wrist, near the board.

Stop both publishers (and remove camera_3_link from the Frame Editor) before step 11. They are only guesses.


7. Start data collection

source install/setup.bash   # from the root of your workspace
ros2 launch industrial_calibration_ros data_collection.launch.xml \
  static_camera:=true \
  camera_mount_frame:=base_link \
  target_mount_frame:=wrist_3_link \
  camera_frame:=camera_3_color_optical_frame \
  image_topic:=/camera/camera_3/color/image_raw

Argument

Eye-to-hand value

Why

static_camera

true

The camera does not move

camera_mount_frame

base_link

The camera is fixed relative to the base

target_mount_frame

wrist_3_link

The board is on the wrist

⚠️ Do not swap camera_mount_frame and target_mount_frame. If you do, every recorded robot pose is inverted and the result is wrong. Nothing warns you about it.

Use the printed 10×6 board at 1:1 scale. Measure one square and one marker with a caliper. The board size in target_detector_config.yaml (in industrial_calibration_ros2/config/) must match your printed board.


8. Collect 10–20 observations

Move the robot so that the board is fully visible. For each pose, click “Calls the observation trigger service using ROS” in the RViz panel:

Trigger an observation

Example of a good observation from an earlier run in this cell (the whole board is visible, tilted, sharp):

Example observation

How to choose good poses:

  • Vary the orientation: tilt the board ±30–45° around different axes. Changes in rotation are what make the result accurate. Translation alone is not enough.

  • Cover different areas of the image: centre, corners, near and far.

  • Keep the robot still when you trigger, to avoid motion blur and TF lag.

  • Avoid reflections and glare on the board.

When you are done, click “Save dataset”:

Save dataset

RViz prints the output folder, for example /tmp/calibration/2026-12-01_14:22:11/. /tmp is cleared on reboot, so copy the folder somewhere permanent, for example camera_calibration/Collected_data/Eye-to-hand/.

Headless alternative to the buttons:

ros2 service call /trigger std_srvs/srv/Trigger {}   # each pose
ros2 service call /save    std_srvs/srv/Trigger {}   # at the end

9. Write extrinsic_calibration.yaml

Create the file next to your dataset. Replace every value marked ← with your own:

static_camera: true            # eye-to-hand
homography_threshold: 2.0

intrinsics:                    # ← from step 5 (camera_info), same resolution as the dataset
  fx: 606.75
  fy: 606.80
  cx: 319.22
  cy: 251.27

target_finder:                 # must match the printed board (measure it!)
  type: CharucoGridTargetFinder
  rows: 10
  cols: 6
  chessboard_dim: 0.0275       # ← square size [m]
  aruco_marker_dim: 0.0213     # ← marker size [m]
  dictionary: 2                # DICT_4X4_250

camera_mount_to_camera_guess:  # ← from step 6.1 C: tf2_echo base_link camera_3_color_optical_frame
  x: 0.600
  y: -0.400
  z: 0.900
  qx: 0.0
  qy: 0.0
  qz: 0.0
  qw: 1.0

target_mount_to_target_guess:  # ← wrist_3_link -> cal_target_frame (step 6.2)
  x: 0.05
  y: -0.10
  z: 0.01
  qx: 0.0
  qy: 1.0
  qz: 0.0
  qw: 0.0

The camera guess here is for the optical frame (tf2_echo base_link camera_3_color_optical_frame), not for camera_3_link. If you get “Projected target feature lies behind the image plane”, you probably used the camera_3_link pose, or the guess points away from the target.


10. Run the calibration in RViz

  1. Load observations file… → select cal_data.yaml from your dataset.

    Load observations

  2. Load extrinsic calibration configuration file… → select extrinsic_calibration.yaml.

    Load configuration

  3. Open the Observations tab and click through the rows. The detected corners must sit on the board. Remove bad observations.

  4. Click Run calibration (green play button).

    Run calibration

  5. Click Save calibration results.

    Save calibration results

Is the result good?

Open extrinsic_calibration_result.yaml and check:

Field

Good

Bad

converged

true

false → check the guesses (step 6) and frames

final_cost_per_obs

< 0.5 px (an earlier run in this cell: 0.22)

> 2 px → bad observations, wrong board size or wrong intrinsics

final_cost_per_obs is the average reprojection error in pixels: the gap between where the board actually appears in the image and where the result predicts it.

Also compare the result with your guess. A difference of a few centimetres is normal. A difference of tens of centimetres or a flipped orientation means something is wrong.


11. Convert and publish the result

The solver gives camera_mount_to_camera = base_link → camera_3_color_optical_frame. The driver owns camera_3_link → optical, so you publish base_link → camera_3_link:

T_base_link = T_base_optical · (T_link_optical)⁻¹

Get T_link_optical from step 5 (tf2_echo camera_3_link camera_3_color_optical_frame). Then run:

# convert_result.py  —  python3 convert_result.py
import numpy as np
from scipy.spatial.transform import Rotation as R

def T(xyz, q):                       # q = [qx, qy, qz, qw]
    M = np.eye(4); M[:3, :3] = R.from_quat(q).as_matrix(); M[:3, 3] = xyz; return M

# ← camera_mount_to_camera from extrinsic_calibration_result.yaml
T_base_opt = T([-0.58289, -0.29823, 1.09909], [0.95568, -0.06344, 0.01721, -0.28699])
# ← from: ros2 run tf2_ros tf2_echo camera_3_link camera_3_color_optical_frame
T_link_opt = T([0.0, 0.015, 0.0], [-0.5, 0.5, -0.5, 0.5])

T_base_link = T_base_opt @ np.linalg.inv(T_link_opt)
x, y, z = T_base_link[:3, 3]
qx, qy, qz, qw = R.from_matrix(T_base_link[:3, :3]).as_quat()
print(f"--x {x:.6f} --y {y:.6f} --z {z:.6f} "
      f"--qx {qx:.6f} --qy {qy:.6f} --qz {qz:.6f} --qw {qw:.6f}")

Publish it:

ros2 run tf2_ros static_transform_publisher \
  <values printed above> \
  --frame-id base_link --child-frame-id camera_3_link

To make it permanent, add a realsense_N_static_tf service with these values to compose.yaml (copy the commented example). Record the result in camera_calibration/Collected_data/result.md with the date, the dataset and the final cost.

For a URDF that uses camera_N_bottom_screw_frame instead, use camera_calibration/base_link_to_camera_link/calcul_tf.py.


12. Validate

  • In RViz, show the robot model and the point cloud /camera/camera_3/depth/color/points in the base_link fixed frame. The robot links in the cloud should line up with the robot model within about 1 cm.

  • Move the wrist slowly. The cloud of the gripper or board must follow the model without lag or offset.

  • Touch a known point with the TCP and compare its position with the same point in the cloud.


Troubleshooting

Symptom

Likely cause

Container exits: REALSENSE_N_SERIAL is not set

source set_camera_env.sh was not run in that terminal

Container starts but no device found

Wrong serial or missing _ prefix → redo step 2

Wrong image on /camera/camera_N/...

Serial assigned to the wrong slot → redo step 2.2

No topics visible on the host

Host RMW_IMPLEMENTATION / ROS_DOMAIN_ID differ from the container

Point cloud upside down or rotated around the view axis

Camera not upright → change --roll of the camera guess (6.1)

TF flickering, “frame has two parents”

Guess published on the optical frame, or an old *_static_tf service is still running

“Projected target feature lies behind the image plane”

Camera guess is the camera_3_link pose instead of the optical frame, or Z points away from the target

final_cost_per_obs high

Wrong board dimensions, intrinsics from another resolution, blurry or partly visible boards

Result is mirrored or far off

camera_mount_frame and target_mount_frame swapped in step 7

Result was good, now it is off

The camera mount moved → recalibrate