Pages

Thursday, October 14, 2010

WiiMote Velocity and Position

The Wiimote provides acceleration data on 3 axis (x,y,z). The acceleration data provided from the Python Cwiid module is an integer and not a direct m/s2 or g value. I have looked a little bit online, but have not utilized a conversion factor yet, so this program just displays the output without any units.

Data is gathered about every hundredth of a second and averaged across 3 points. So the plot resolution is about 0.03 seconds. Velocity is calculated using simple numerical integration:
      vi = vi-1 + ai(ti - ti-1)

    (where a is acceleration, v is velocity, t is time, i is the current data point, i-1 is the previous data point)

To improve the accuracy of the velocity integration, the program ignores changes in acceleration below a specified threshhold. So if acceleration changes less than "x", the velocity equals the previous data points velocity.

Position is calculated similar to velocity. It is the integration of velocity.
      pi = pi-1 + vi(ti - ti-1)

    (where p is position, v is velocity, t is time, i is the current data point, i-1 is the previous data point)

To test the data analysis I came up with a simple experiment. The Wiimote starts out at rest on my desk. I then proceed to lift it up about 2 feet and then bring it back down to the desk, and again let it sit at rest. I tried not to rotate the Wiimote or alter the x or y positions. Here are the results:
Notice that the position does not get back to 0 even though I set the Wiimote back on my desk. This has to do with the summation of errors from integration. You can also see that even though the Wiimote is at rest at the end, the position is moving up slightly. This is due to a velocity slightly over 0. The acceleration data is good but the position and velocity data are not good enough for a real experiment, but can provide a ballpark answer. Searching online about this topic, someone mentioned that the Wii designers added the sensor bar to account for this inaccuracy.


DOCUMENTATION - IR Sensor Position

The Wiimote also has an infrared (IR) camera and the Wii sensor bar is actually just 2 infrared LEDs. Using the Python Cwiid library, you can get the IR (infrared sensor) data from the sensor bar or another IR device (like a IR LED). This provides a better measurement of position. The Wiimote provides position and intensity values for up to 4 IR sources and the Cwiid Python module can provide this data for us also.

For this experiment I did not actually have a Wii Sensorbar, so I just used a IR LED that I purchased at RadioShack. It is a high intensity IR LED with a forward current of 100 mA and a forward voltage of 1.2V. Hooking it up to a 5 volt source, I used a 47 ohm resistor in series.

Velocity is calculated using numerical differentiation:
      yi+1 - yi
      ------------
      ti+1 - ti


Acceleration is calculated as the second derivative of position with numerical methods:
      yi+2 - 2yi+1 + yi
      -----------------------------
      (ti+2 - ti+1)(ti+1 - ti)

The following plot shows the raw output of the y position of the IR LED and also the calculated velocity and acceleration using differentiation.