I have an IMU rigidly attached to the end effector of a robotic arm. The goal is to compare the orientation of the IMU to the orientation of the robot arm. The 9-axis IMU data is used in a sensor fusion algorithm to compute the IMU quaternion. When static, after removing gravity, the linear acceleration magnitude is approximately zero as expected. The static quaternion is converted to a rotation matrix $R_1$. The corresponding robot orientation is calculated using the manufacturer's nominal DH parameters to get the rotation matrix $R_2$. The DH transform computation were validated using the spreadsheet provided by the manufacturer. A mapping $M$ from the IMU reference frame to the robot reference is then estimated as $$\begin{equation}[U,S,V] = svd(R_2R^T_1)\end{equation}$$ $$M = VU^T$$
Given the following measurements at time index $n$ for the IMU quaternion $q(n)$ and resulting rotation matrix $R_1(n)$ $$q(n)=[0.6888 \ \ 0.1354 \ \ 0.7017 \ \ -0.1218]\rightarrow R_1(n) = \begin{bmatrix} -0.0144&0.3579&0.9336\\\ 0.0222&0.9336&-0.3576\\\ -0.9996&0.0156&-0.0214\end{bmatrix}$$
and the robot orientation $R_2(n)$
$$R_2(n) = \begin{bmatrix} -0.0008&0.0017&1.0000\\\ -1.0000&0.0000&-0.0008\\\ -0.0001&-1.0000&0.0017\end{bmatrix}$$
the resulting transformation is $$M = \begin{bmatrix} 0.9343&0.0136&-0.3563\\\ -0.3560&-0.0219&-0.9342\\\ -0.0206&0.9997&-0.0156\end{bmatrix}$$
which correctly yields $$\begin{equation} R_2(n) \approx M^TR_1(n) \end{equation}$$
However, moving to the next stationary orientation, where the measurements are $$q(n+1)=[0.7744\ \ 0.4419 \ \ 0.0104 \ \ -0.4528]\rightarrow R_1(n+1) = \begin{bmatrix} 0.5898&0.7104&-0.3841\\\ -0.6920&0.1995&-0.6938\\\ -0.4162&0.6750&0.6092\end{bmatrix}$$
$$R_2(n+1)=\begin{bmatrix}-0.5830&0.8093&-0.0722\\\ -0.4532&-0.3976&-0.7978\\\ -0.6744&-0.4324&0.5986 \end{bmatrix}$$
the transform $M$ is no longer valid and
$$R_2(n+1) \neq M^TR_1(n+1)$$
I assumed the initial rotation transformation would be applicable to all orientations since the IMU is rigidly attached to the end effector, but clearly this is not the case. How should the IMU orientation be properly transformed into the robot reference frame?