Room coordinates are following my walls, to use the guidance system I build the position from various other sensors & built a GPS position from it.
As I also need the a "fake" compass I'm trying to interface a moving robot with a sensor I made.
Robot expect compass to send him the values of a 3-axis magnometer. As my sensor gives me the orientation pitch & roll I have this formula:
$\text{Orientation}=\text{atan2}( (-\text{ymag}*\cos(\text{Roll}) + \text{zmag}*\sin(\text{Roll}) ) , (\text{xmag}*\cos(\text{Pitch}) + \text{ymag}*\sin(\text{Pitch})*\sin(\text{Roll})+ \text{zmag}*\sin(\text{Pitch})*\cos(\text{Roll})))$
as I've 3 unknown variables & one equation I need more equations. But I'm stuck, there should be a way based on Orientation values to get constraints (i.e in $\text{atan2}(y,x) = \arctan(y/x)$ if $x > 0$, etc.) but I can translate those relations to equations.
Am I missing something or is it impossible?
What Im trying to do:
-get Xmag,Ymag and Zmag, those are the expected output of the fake compass.
-Known variables are: Orientation (Yaw) Pitch & Roll, on the robot system (X: right of robot, Y: front of robot, Z: going up) Yaw is the rotation on Z in reference to a "North" arbitrary selected, Pitch the rotation on X and Roll the rotation on Y.
I don't know how a 3-axis magnometer works, but based on the equation you gave I'm assuming it measures the components of the $x,y$ and $z$ unit vectors relative to some "north" direction. To save some typing I'll denote orientation, pitch and roll by $\theta$, $\phi$ and $\rho$ respectively.
I am also not sure how your axes are oriented. Your formula
suggests that Roll is a rotation in the $yz$-plane, ie around the $x$-axis (note that the Roll terms all multiply $y$ or $z$). This is inconsistent with
If roll is around the $y$-axis, then the rotation that takes your robot from its resting position (pointing along the $y$-axis of the room) to its current position is $$ \begin{bmatrix}\cos\theta&\sin\theta&0\\-\sin\theta&\cos\theta&0\\0&0&1\end{bmatrix} \begin{bmatrix}1&0&0\\0&\cos\phi&\sin\phi\\0&-\sin\phi&\cos\phi\end{bmatrix} \begin{bmatrix}\cos\rho&0&-\sin\rho\\0&1&0\\\sin\rho&0&\cos\rho\end{bmatrix} $$ $$ =\begin{bmatrix} \cos\theta\cos\rho+\sin\theta\sin\phi\sin\rho& \sin\theta\cos\phi& -\cos\theta\sin\rho+\sin\theta\sin\phi\cos\rho\\ -\sin\theta\cos\rho+\cos\theta\sin\phi\sin\rho& \cos\theta\cos\phi& \sin\theta\sin\rho+\cos\theta\sin\phi\cos\rho\\ \cos\phi\sin\rho&-\sin\phi&\cos\phi\cos\rho \end{bmatrix} $$ Assuming your "fake north" is the room's $y$-axis, the fake compass output is the second row, namely $$ x_\mathrm{mag}=-\sin\theta\cos\rho+\cos\theta\sin\phi\sin\rho, $$ $$ y_\mathrm{mag}=\cos\theta\cos\phi, $$ $$ z_\mathrm{mag}=\sin\theta\sin\rho+\cos\theta\sin\phi\cos\rho. $$ See this geogebra demo.
On the other hand, if roll is around the $x$-axis and "fake north" is the $x$-axis, then $$ x_\mathrm{mag}=\cos\theta\cos\phi, $$ $$ y_\mathrm{mag}=-\sin\theta\cos\rho+\cos\theta\sin\phi\sin\rho, $$ $$ z_\mathrm{mag}=\sin\theta\sin\rho+\cos\theta\sin\phi\cos\rho. $$ This agrees with your formula, since $$ -y_\mathrm{mag}\cos\rho+z_\mathrm{mag}\sin\rho=\sin\theta, $$ $$ x_\mathrm{mag}\cos\phi+y_\mathrm{mag}\sin\phi\sin\rho +z_\mathrm{mag}\sin\phi\cos\rho=\cos\theta. $$ See this geogebra demo.