Equations of motion for an inertial computer mouse

I'm struggling with a seemingly simple problem in 2D motion. It has been many years since I looked at basic kinematics and my mind seems to be too slow and confused now. Imagine we want to build a computer mouse using a 2D accelerometer and a 1D gyroscope. An accelerometer measures linear acceleration along a single axis so our 2D accelerometer measures $a_x$ and $a_y$. The Gyroscope measures angular velocity ($\omega$).

Whenever there is a movement, a computer mouse reports $\Delta x$ and $\Delta y$ for a sampling period $\Delta t$. So the problem is simply formulating the $\Delta x$ and $\Delta y$ in terms of $a_x$, $a_y$, $\omega$ and $\Delta t$. Let's assume sensors are ideal and we are starting to move from position $(0,0)$.

If there was no rotation involved, the solution would be very easy as I guess I could simply integrate the acceleration for each axis separately:

$(1) \quad \left[ {\begin{array}{c} v_x \\ v_y \end{array}} \right]_{t+1} \leftarrow \left[ {\begin{array}{c} v_x \\ v_y \end{array}} \right]_{t} +\Delta t \left[ {\begin{array}{c} a_x \\ a_y \end{array}} \right]_{t}$

$(2) \quad \left[ {\begin{array}{c} x \\ y \end{array}} \right]_{t+1} \leftarrow \left[ {\begin{array}{c} x \\ y \end{array}} \right]_{t} + \Delta t \left[ {\begin{array}{c} v_x \\ v_y \end{array}} \right]_{t} + \Delta t^2 \left[ {\begin{array}{c} a_x \\ a_y \end{array}} \right]_{t}$

Now if we add rotations, in the global frame I also seem to know how to solve the problem: the orientation of the sensor at any time $t$ can be represented using a rotation matrix $R$ as:

$R= \left[ {\begin{array}{cc} \cos \alpha & -\sin \alpha \\ \sin \alpha & \cos \alpha \end{array}} \right]$

We observe that differentiating $R$ in time gives us:

$\dot{R}= \left[ {\begin{array}{cc} -\omega\sin \alpha & -\omega \cos \alpha \\ \omega\cos \alpha & -\omega\sin \alpha \end{array}} \right] = R \times \left[ {\begin{array}{cc} 0 & -\omega \\ \omega & 0 \end{array}} \right]$

So we can simply write:

$(3) \quad R_{t+1} \leftarrow R_t + \Delta t \cdot R_t \times \left[ {\begin{array}{cc} 0 & -\omega_t \\ \omega_t & 0 \end{array}} \right]$

Now all we need to do is to correct the direction of the accelerations according to $R$ at each step:

$(4) \quad \left[ {\begin{array}{c} A_x \\ A_y \end{array}} \right]_{t+1} \leftarrow R_t \cdot \left[ {\begin{array}{c} a_x \\ a_y \end{array}} \right]_{t}$

After this correction we can re-use equations (1) and (2).

However, the thing is a computer mouse should report position in it's local frame (I hope I'm stating the problem correctly) so in this figure,

in case (a) it should only show movements in the $x$ axis while in case (b) it should report movements in both $x$ and $y$. The above equations work on a global frame so for both cases we get the same results.

For some reason I cannot turn my head round the problem and fail to get the right equations for the movement in the local frame. I guess what I want to do is to to move my equations from an inertial frame of motion to a non-inertial frame and I don't know how to do that. Any hints or solutions to go forward?

-
You do know that, for a mouse, $\omega r_{ball}=\sqrt{v%x^t+v_y^2}$? Theres a similar relation for acceleration. My apologies if you did infact mention this, mathjax isn't working for me atn. – Manishearth Mar 15 '12 at 17:44
Fwiw, a mouse has no accelerometer/gyroscopes. It jas two wheels in contact with the roller. These wheels are attached a slotted wheel each. Lihht is passed through the wheel and a detector measures it. The frequency of oscillation of the light signal is proportional to the speed. Mind you, this is for a mechanical mouse. An optical mouse uses some nifty technique (akin to barcode scanners) that I forgot. – Manishearth Mar 15 '12 at 17:50
@Manishhearh thanks for your comments. My question does not really concern existing computer mice. I am just thinking about building one only with accelerometers and gyros. – Shapul Mar 15 '12 at 18:07
Why the gyroscope? Just double-integrate x,y. Also, truncate small velocities to zero, to prevent drift. – Mike Dunlavey Mar 16 '12 at 12:39

In this hypothetical situation, you can transform the unit vectors in the global reference frame $\hat{x}$ and $\hat{y}$ using the same rotation matrix, to the unit vectors in the transformed coordinate system:

$$\hat{x}' = R \hat{x}\\ \hat{y}' = R \hat{y}$$

This is what you did implicitly by transforming $x\hat{x}+y\hat{y}$

In the same way, you can do the back transformation

$$\hat{x}=R^{-1}\hat{x}'\\ \hat{y}=R^{-1}\hat{y}'$$

Which can be used for the back-transformation of the dislpacement in the local frame to displacement in the global frame.

A practical issue will be that errors in you integrated angle $\alpha$ will accumulate, making the mouse annoying to use.

-
 Ah, yes, I think you are right. It is not really complicated but in my confusion after returning back to basic kinematics after many years, I totally missed it. You are right accumulation of errors in integration. Real sensors will also have drift making integration (and double integration) really difficult. – Shapul Mar 15 '12 at 19:48 @Shapul I'm glad I could help! – Bernhard Mar 15 '12 at 20:32