This question is in the context of a robotics problem. The goal is to track a robot using both its onboard odometry system and a VR system (HTC Vive Pro) using a VR controller mounted to the robot.
What is known is the transformation between odometry origin and the robot (measurements $A_n$) and between the VR origin and the controller (measurements $C_n$). Ignoring both systems' inaccuracies for now, we can also assume the robot's pose according to both systems is identical ($I$). Driving around will result in many pairs of measurements ($A_n$, $C_n$).
What is unknown is the fixed transformation $B$ between the two coordinate systems and the fixed transformation $D$ between the robot's origin and the VR controller. All transformations involved are proper rigid.
The chain of transformation looks as follows.
This leaves us with an equation system of $4 \times 4$ homogeneous transformation matrices
$$A_n \cdot B \cdot C_n \cdot D = I$$
with $I$ being the $4 \times 4$ identity matrix and $(A_n, C_n)$ being (many) pairs of measurements.
I am looking for the optimal (least-squares, I suppose) solution for $B$ and $D$, so that the equation holds approximately true for all pairs of measurements.

Too long for a note.
Follows a MATHEMATICA script to solve numerically this problem according to a nonlinear least squares paradigm. The optimization procedure can be implemented with a sequential quadratic programming approach.