Skip to content

Understanding ROS 2 Camera Coordinate Traps: camera_link, camera_link_optical, and rpy="-1.5708 0 -1.5708" Explained

Understand why ROS 2 separates camera_link and camera_link_optical in URDF, with rotation matrix derivations for rpy="-1.5708 0 -1.5708" and projection math.

Contents

Key takeaways

  1. Standard ROS 2 robot body frames (REP-103) point +X forward, +Y left, and +Z up, whereas standard computer vision optical frames point +Z forward along the optical axis, +X right, and +Y down—requiring two separate frames (camera_link and camera_link_optical) per camera.
  2. The static transform from camera_link to camera_link_optical uses rpy="-1.5708 0 -1.5708" (extrinsic Roll -90° followed by Yaw -90°, or Rz(-90°)·Rx(-90°)), which corresponds to the unit quaternion (x, y, z, w) = (-0.5, 0.5, -0.5, 0.5).
  3. All image, CameraInfo, and PointCloud2 topics must set their header.frame_id to camera_link_optical; binding them to camera_link rotates 3D point clouds sideways by 90 degrees.
  4. Physical mounting tilts (such as pitching a camera downward to see the floor) belong in camera_joint’s pitch attribute, while camera_optical_joint must always keep the canonical rpy="-1.5708 0 -1.5708" rotation.

When bringing up an RGB or RGB-D depth camera on a mobile robot for the first time, seeing the 3D point cloud (sensor_msgs/PointCloud2) stand vertically sideways like a wall or flip upside down in RViz2 is an almost universal rite of passage. In our previous tutorial on modeling 2D LiDAR (laser_frame) and IMU (imu_link) frames, both the sensor origins and the robot base shared the same coordinate convention where $+Z$ points straight up. Camera imaging pipelines, however, operate under a fundamentally different axis definition.

Grounded in REP-103 (Standard Units of Measure and Coordinate Conventions) and REP-105 (Coordinate Frames for Mobile Platforms), this explainer breaks down why ROS 2 uses a two-frame pattern (camera_link and camera_link_optical) for every camera, derives the exact rotation matrix behind rpy="-1.5708 0 -1.5708", and demonstrates how pinhole projection equations fail without it.


Why Two Coordinate Conventions Collide: Robot Body (REP-103) vs. Camera Optical

In mobile robotics and rigid-body dynamics, standard body frames assign $+X$ to the forward direction of travel, $+Y$ to the left, and $+Z$ upward against gravity. In computer vision libraries such as OpenCV and projective geometry frameworks, however, 2D image coordinates index columns from left to right ($+X$ right) and rows from top to bottom ($+Y$ down), leaving the forward optical axis (depth into the scene) as $+Z$.

The _optical frame suffix specification in REP-103 bridges these two domains by defining two distinct coordinate frames for a single physical camera:

Coordinate Convention+X Axis+Y Axis+Z AxisPrimary Responsibility in ROS 2
Robot Body Frame (camera_link)ForwardLeftUpMechanical CAD mounting, bracket offsets, housing collision and inertial tags
Camera Optical Frame (camera_link_optical)RightDownForward (Optical Depth Axis)OpenCV pinhole projection, depth back-projection, header.frame_id for Image, CameraInfo, and PointCloud2

Separating the mechanical housing frame (camera_link) from the optical convention frame (camera_link_optical) decouples hardware engineering from perception software. When you adjust a camera bracket or tilt angle, you edit only camera_joint; when perception nodes project 3D points onto 2D pixels, they always operate inside camera_link_optical.


In the myros_sketch robot model, the camera sits at the front edge of the body so the chassis does not occlude its field of view. Parenting camera_joint to base_link places camera_link at $x = 0.100\text{ m}$ forward and $z = 0.020\text{ m}$ up (or <origin xyz="0.13 0 0.05" rpy="0 0 0"/> in layouts where camera_joint attaches directly to chassis). We then attach camera_link_optical as a child of camera_link with zero translation (xyz="0 0 0") and the canonical optical rotation.

<!-- Stage 1: Mechanical housing frame (REP-103 body convention: +X forward, +Y left, +Z up) -->
<joint name="camera_joint" type="fixed">
  <parent link="base_link"/>
  <child link="camera_link"/>
  <origin xyz="0.100 0 0.020" rpy="0 0 0"/>
</joint>

<link name="camera_link">
  <visual>
    <geometry>
      <box size="0.025 0.030 0.025"/>
    </geometry>
    <material name="camera_dark">
      <color rgba="0.15 0.15 0.18 1.0"/>
    </material>
  </visual>
  <collision>
    <geometry>
      <box size="0.025 0.030 0.025"/>
    </geometry>
  </collision>
  <inertial>
    <mass value="0.030"/>
    <inertia ixx="3.81e-6" ixy="0" ixz="0"
             iyy="3.13e-6" iyz="0" izz="3.81e-6"/>
  </inertial>
</link>

<!-- Stage 2: Optical convention transform (+Z forward optical axis, +X right, +Y down) -->
<joint name="camera_optical_joint" type="fixed">
  <parent link="camera_link"/>
  <child link="camera_link_optical"/>
  <origin xyz="0 0 0" rpy="-1.5708 0 -1.5708"/>
</joint>

<!-- Massless, geometry-free dummy link used exclusively for optical TF frames -->
<link name="camera_link_optical"/>

Notice two important structural details in the XML snippet above:

  • Physical properties live exclusively on camera_link: The bounding box geometry (visual and collision), mass ($0.030\text{ kg}$), and moment of inertia tensor (inertial) belong on camera_link. As explained in our next tutorial on URDF collision simplification and inertial tensor calculations, assigning duplicate mass to a co-located frame distorts the robot’s center of mass, so camera_link_optical is declared as an empty <link name="camera_link_optical"/> element.
  • Co-located origin with pure rotation: camera_optical_joint sets xyz="0 0 0" and rotates the axes via rpy="-1.5708 0 -1.5708" ($-\pi/2, 0, -\pi/2\text{ rad}$).

Matrix Derivation: Why Two $-90^\circ$ Rotations (rpy="-1.5708 0 -1.5708")?

According to the ROS 2 Jazzy URDF specification, the rpy="r p y" attribute applies rotations about the parent frame’s fixed (extrinsic) axes in the sequence Roll ($r$ about fixed $X$), Pitch ($p$ about fixed $Y$), and Yaw ($y$ about fixed $Z$). Using the 3D rotation matrix formalism covered in our robot arm kinematics and minimum pick-and-place math guide, this extrinsic sequence corresponds to the matrix product:

R=Rz(y)⋅Ry(p)⋅Rx(r)R = R_z(y) \cdot R_y(p) \cdot R_x(r)

Substituting $r = -\frac{\pi}{2}\ (-90^\circ \approx -1.5708\text{ rad})$, $p = 0$, and $y = -\frac{\pi}{2}\ (-90^\circ \approx -1.5708\text{ rad})$, where $\cos(-90^\circ) = 0$ and $\sin(-90^\circ) = -1$, gives the individual elementary rotation matrices:

Rx(−90∘)=[1000cos⁡(−90∘)−sin⁡(−90∘)0sin⁡(−90∘)cos⁡(−90∘)]=[1000010−10]R_x(-90^\circ) = \begin{bmatrix} 1 & 0 & 0 \\ 0 & \cos(-90^\circ) & -\sin(-90^\circ) \\ 0 & \sin(-90^\circ) & \cos(-90^\circ) \end{bmatrix} = \begin{bmatrix} 1 & 0 & 0 \\ 0 & 0 & 1 \\ 0 & -1 & 0 \end{bmatrix}Rz(−90∘)=[cos⁡(−90∘)−sin⁡(−90∘)0sin⁡(−90∘)cos⁡(−90∘)0001]=[010−100001]R_z(-90^\circ) = \begin{bmatrix} \cos(-90^\circ) & -\sin(-90^\circ) & 0 \\ \sin(-90^\circ) & \cos(-90^\circ) & 0 \\ 0 & 0 & 1 \end{bmatrix} = \begin{bmatrix} 0 & 1 & 0 \\ -1 & 0 & 0 \\ 0 & 0 & 1 \end{bmatrix}

Multiplying $R_z(-90^\circ)$ by $R_x(-90^\circ)$ produces the rotation matrix $R_{\text{link}}^{\text{opt}}$ that expresses the orientation of camera_link_optical relative to camera_link:

R=Rz(−90∘)⋅Rx(−90∘)=[010−100001][1000010−10]=[001−1000−10]R = R_z(-90^\circ) \cdot R_x(-90^\circ) = \begin{bmatrix} 0 & 1 & 0 \\ -1 & 0 & 0 \\ 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} 1 & 0 & 0 \\ 0 & 0 & 1 \\ 0 & -1 & 0 \end{bmatrix} = \begin{bmatrix} 0 & 0 & 1 \\ -1 & 0 & 0 \\ 0 & -1 & 0 \end{bmatrix}

In rigid-body kinematics, the three columns of $R$ represent the child frame’s unit basis vectors ($\hat{x}{\text{opt}}, \hat{y}{\text{opt}}, \hat{z}_{\text{opt}}$) expressed in the coordinates of the parent frame (camera_link):

Optical Basis VectorColumn of Matrix $R$ (in camera_link coordinates)Physical Direction Relative to Robot Body
$\hat{x}_{\text{opt}}$ (Column 1)$(0, -1, 0)^T = -\hat{y}_{\text{link}}$Opposite of robot Left ($+Y$) = Camera Right
$\hat{y}_{\text{opt}}$ (Column 2)$(0, 0, -1)^T = -\hat{z}_{\text{link}}$Opposite of robot Up ($+Z$) = Image Down
$\hat{z}_{\text{opt}}$ (Column 3)$(1, 0, 0)^T = +\hat{x}_{\text{link}}$Aligned with robot Forward ($+X$) = Forward Optical Axis

Converting this rotation matrix to a unit quaternion yields $(x, y, z, w) = (-0.5, 0.5, -0.5, 0.5)$ (or its antipodal equivalent $(0.5, -0.5, 0.5, -0.5)$).


How Pinhole Projection and Depth Back-Projection Depend on the Optical Frame

To see why skipping camera_link_optical breaks computer vision math rather than merely rotating a display, examine the standard pinhole camera projection equations. A 3D point $\mathbf{P}_{\text{opt}} = (X, Y, Z)^T$ in optical coordinates projects onto pixel coordinates $(u, v)$ as:

u=fxXZ+cx,v=fyYZ+cyu = f_x \frac{X}{Z} + c_x, \qquad v = f_y \frac{Y}{Z} + c_y

Assume a $640 \times 480$ camera with focal lengths $f_x = f_y = 600\text{ px}$ and principal point $(c_x, c_y) = (320, 240)\text{ px}$. Consider an object located $1.0\text{ m}$ forward, $0.2\text{ m}$ to the right, and $0.1\text{ m}$ below the lens center:

Evaluation MetricUsing camera_link_optical (Correct)Passing camera_link Coordinates Directly (Broken)
3D Point Coordinates $(X, Y, Z)$$(0.2, 0.1, 1.0)\text{ m}$$(1.0, -0.2, -0.1)\text{ m}$
Point Dead Ahead on Optical Axis ($1\text{ m}$)$(0, 0, 1.0)\text{ m} \implies Z = 1.0\text{ m}$$(1.0, 0, 0)\text{ m} \implies Z = 0.0\text{ m}$
Projected Pixel $(u, v)$$u = 600(0.2/1.0)+320 = 440\text{ px}$
$v = 600(0.1/1.0)+240 = 300\text{ px}$
Dead-ahead point divides by $Z = 0 \to \infty$ (Division-by-Zero Singularity)
Off-axis points divide by vertical height ($Z_{\text{link}}$) instead of depth

The exact same dependency applies in reverse when an RGB-D sensor or stereo pipeline back-projects a depth image pixel $(u, v)$ with depth $Z$ into a 3D PointCloud2 point:

X=(u−cx)Zfx,Y=(v−cy)Zfy,Z=ZX = \frac{(u - c_x) Z}{f_x}, \qquad Y = \frac{(v - c_y) Z}{f_y}, \qquad Z = Z

Because these reconstructed $(X, Y, Z)$ points live in optical coordinates, tagging the PointCloud2 message with header.frame_id = "camera_link_optical" instructs ROS 2 tf2 to multiply them by $R = \begin{bmatrix} 0 & 0 & 1 \ -1 & 0 & 0 \ 0 & -1 & 0 \end{bmatrix}$ when transforming into camera_link and base_link. As explored in our analysis of LiDAR sensor fusion versus vision-only occupancy networks, multi-modal sensor fusion relies on this exact transform chain to project 3D LiDAR returns onto 2D camera images.


Isolating Mounting Pitch Angles and Setting Message frame_id Values

Suppose your robot’s camera is tilted $15^\circ$ ($0.2618\text{ rad}$) downward toward the floor to inspect near-field obstacles. Where should that $15^\circ$ angle live in URDF? It belongs in camera_joint, never in camera_optical_joint:

<!-- Physical 15-degree downward tilt goes into camera_joint; optical joint remains canonical -->
<joint name="camera_joint" type="fixed">
  <parent link="base_link"/>
  <child link="camera_link"/>
  <origin xyz="0.100 0 0.020" rpy="0 0.2618 0"/>
</joint>

<joint name="camera_optical_joint" type="fixed">
  <parent link="camera_link"/>
  <child link="camera_link_optical"/>
  <origin xyz="0 0 0" rpy="-1.5708 0 -1.5708"/>
</joint>

By the right-hand rule around the $+Y$ axis (which points left under REP-103), curling your fingers pitches the $+X$ nose downward for positive pitch angles and upward for negative pitch angles. Keeping the physical tilt inside camera_joint tilts camera_link’s $+X$ axis toward the floor, and camera_link_optical’s $+Z$ optical axis follows automatically without altering the standard optical rotation.

Ensure all camera driver topics reference the optical link name in their message headers:

ROS 2 Message TypeRecommended header.frame_idPurpose in Vision Pipeline
sensor_msgs/msg/Imagecamera_link_opticalAligns image pixel axes $(u, v)$ with $+X_{\text{opt}}$ and $+Y_{\text{opt}}$
sensor_msgs/msg/CameraInfocamera_link_opticalTies intrinsic matrix $K$ and projection matrix $P$ to the optical frame
sensor_msgs/msg/PointCloud2camera_link_opticalAnchors back-projected 3D depth points $(X, Y, Z)$
sensor_msgs/msg/CompressedImagecamera_link_opticalMaintains identical frame convention as raw images

Verifying the Optical Transform with tf2_echo and Troubleshooting

After adding both camera links to your URDF, run tf2_echo to verify that the quaternion and Euler angles match the derived matrix:

# 1) Launch robot_state_publisher
ros2 launch myros_sketch display.launch.py

# 2) Inspect the rotation from camera_link to camera_link_optical
ros2 run tf2_ros tf2_echo camera_link camera_link_optical
# Translation: [0.000, 0.000, 0.000]
# Rotation: in quaternion [-0.500, 0.500, -0.500, 0.500]
# Rotation: in RPY (radian) [-1.571, -0.000, -1.571]
# Rotation: in RPY (degree) [-90.000, -0.000, -90.000]

# 3) Inspect the cumulative pose of camera_link_optical from base_link
ros2 run tf2_ros tf2_echo base_link camera_link_optical
# Translation: [0.100, 0.000, 0.020]

If your vision pipeline exhibits projection or point-cloud artifacts, cross-check the symptom against the diagnostic table below:

Observed SymptomRoot CauseSolution
3D point cloud (PointCloud2) stands vertically sideways or points toward the ceiling in RViz2Topic frame_id is set to camera_link, or camera_optical_joint has rpy="0 0 0"Set topic frame_id to camera_link_optical and configure rpy="-1.5708 0 -1.5708"
Point cloud renders upside down or mirrored left-to-rightPositive +1.5708 used instead of -1.5708, or degrees (-90) entered instead of radiansCheck tf2_echo quaternion output against [-0.5, 0.5, -0.5, 0.5]
Flat floor appears sloped upward or downward in RViz2Physical camera bracket pitch tilt was omitted from camera_jointMeasure the physical tilt angle in radians and add it to camera_joint’s pitch
TF lookup errors (frame does not exist) in image_geometry or RViz2Driver publishes camera_optical_frame while URDF defines camera_link_opticalInspect ros2 topic echo /camera/image_raw --once --field header.frame_id and unify names

Common mistakes

  • Applying the optical rotation to both camera_joint and camera_optical_joint, rotating the projected point cloud twice
  • Entering degrees (-90 0 -90) instead of radians (-1.5708 0 -1.5708) or flipping the signs, which inverts the point cloud upside down
  • Mounting a physical camera pitched 15 degrees downward while leaving camera_joint pitch at 0 in URDF, causing floor obstacles to project at wrong distances and heights

Pre-flight checklist

  • Is camera_link defined using the REP-103 body convention (+X forward) and camera_link_optical defined using the optical convention (+Z forward, +X right, +Y down)?
  • Does camera_optical_joint specify origin xyz=“0 0 0” rpy="-1.5708 0 -1.5708"?
  • Do the header.frame_id fields of sensor_msgs/Image, CameraInfo, and PointCloud2 reference camera_link_optical?
  • Are physical housing tilt angles isolated inside camera_joint and verified with tf2_echo?

Frequently asked questions

What happens if I omit camera_link_optical and use camera_link directly for vision tasks?
Pinhole camera projection formulas in OpenCV and image_geometry (u = fx·X/Z + cx) assume +Z is the forward depth axis. If you pass coordinates from camera_link (+X forward, +Z up) directly into the pinhole equation, an object sitting 1 meter dead ahead at (1, 0, 0) has Z = 0, causing a division-by-zero singularity, while 3D point clouds in RViz2 render sideways.
In what order does URDF apply the angles in rpy="-1.5708 0 -1.5708"?
In URDF XML, rpy=“r p y” specifies rotations around the parent frame’s fixed (extrinsic) X, Y, and Z axes in Roll (r), Pitch (p), Yaw (y) order, which evaluates to the matrix product R = Rz(y)·Ry(p)·Rx(r). With r = -π/2, p = 0, and y = -π/2, Rz(-90°)·Rx(-90°) maps the optical +Z axis onto the parent’s +X forward axis.
If my camera is tilted downward by 15 degrees, should I modify the rpy values on camera_optical_joint?
No. camera_optical_joint is a pure convention adapter between REP-103 body coordinates and optical coordinates, so its rpy must always remain -1.5708 0 -1.5708. Encode the physical 15-degree tilt in the parent camera_joint pitch attribute so mechanical adjustments never break your downstream computer vision code.

Sources & verification

  1. REP-0103 — Standard Units of Measure and Coordinate Conventions
  2. REP-0105 — Coordinate Frames for Mobile Platforms
  3. ROS 2 Jazzy — tf2 Tutorials
  4. ROS 2 Jazzy — URDF Tutorials

Last verified: