A Legoized version of the Wii motion plus gyro

For some time now I've been interested in using a gyro as part of a robot navigation/localization system. I have one of the HiTechnics devices (and have used it in a segway style model), but for this application you really need a 3 axis device. Then this thread caught my eye. It describes using a Wii motion plus with the NXT. This device provides a 3 axis gyro and is low cost, which seems ideal. 

I managed to pick one up locally for £20 (I'm sure it can be got on line for less), and set to work. 

The first task was to extract the actual sensor board from the Wii packaging. A little bit of work with drill (the package is held together with anti tamper screws I didn't have a driver for them!), and I had this:

The next task was how to connect it to the NXT and how to package it. The Wii device needs a 3.3V supply and will also require pull up resistors on the i2c lines. I used a couple of diodes to drop the NXT 4.5V supply and added a couple of 47K resistors. I decided to use a small strip board to hold these parts. Finally I hacked an existing Lego Ultrasonic sensor board (no longer working due to an earlier experiment!), to use the NXT connector from that. The results of all of this work can be seen below:


Once I had the above complete, I hooked the sensor up to my NXT and a few lines of Java later had me looking at the 3 axis gyro output. Great it works fine!

Now came the tricky part how to package all of this for use with Lego parts. If you are a sensitive Lego purist now is the time to look away... As mentioned I had a broken Ultrasonic sensor, so with a little bit of work with a cutting disk and some brute force, I had this:

Which as you can see just allows the board to squeeze into the housing:


Comparing Wii and Hitechnics gyros

With a working Wii gyro I wanted to compare it with the Hitechnics version. I built a simple test rig that I could mount both gyros on and rotate them at various speeds for a short distance (90 degrees in this case). You can see the rig below:

The software that drives the test samples both gyros for a period of 25 seconds taking an average of the results to establish a zero point for both devices. It then rotates the test rig by 90 degrees at a selected speed and samples both gyros every 2ms storing the results. Finally the results are corrected for the respective zero pints and upload to a PC for further analysis. The Hitechnics device (which is analogue) reads directly in degrees/second (so a reading of 1 = 1 degree/second). The Wii gyro (which is an i2c device) has a higher resolution, reports seem to vary on exactly what the scale factor should be, but with the device I have it seems to be that that a reading of 20 is equal to 1 degree/second. Using this scale factor and plotting the results from the test at a speed of 100 degrees/second we get the following:

In this graph the red points are the Hitechnics device, the Blue the Wii. We can clearly see the classic overshoot then correct signature of the current leJOS motor driver then the speed settles to 100 degrees/second before slowing to a stop. Both gyros give very close results. Taking a closer look at part of the above results set we see:

From the above (and close examination of all of the data), we can see a couple of things, firstly the outputs from both gyros track pretty closely. Secondly (and perhaps more interestingly), we can see that the Hitechnics gyro output seems to clump together in runs of one or two points, while the Wii gyro seems to have clumps of 2 and three points. Given the 2ms sample time this probably points to an actual sample period of approximately 5ms for the Wii gyro. It seems likely that the onboard micro-controller in the motion plus is sampling each of the 3 axis every 5ms. I've not seen any data on this sample rate from other sources (most other users of this device have been sampling it at rates much slower than 5ms), so it would be interesting to have this confirmed. The clumping seen for the Hitechnics device is not surprising given the well known NXT sampling method. The AVR processor reads the analogue sensors every 3ms and the NXT reads these results every 2ms. This rather odd process, tends to result in new values only being available every 4ms and can be seen in other tests.


Fast and slow mode

Next I decided to test the two gyros at a faster rotation speed, I chose a target speed of 500 degrees/second. Using the same test process as described above I obtained the following results:

Again red is Hitechnics and blue the Wii motion plus. Clearly something strange is happening with the Wii output values! What we see here is the effect of the Wii output having both a slow mode and a fast mode. Basically below some speed threshold (which from the above seems to be around 300 degrees/second) the Wii controller uses an additional amplification stage on the actual gyro sensor to boost the analogue voltage and provide higher resolution when the device is moving at slow speeds. The i2c output from the device has a set of three bits (one per axis) that indicate which mode (fast or slow) the axis is reporting in. Here we see what happens when the device switches from one mode to the other. As mentioned above there is some debate as to the actual scale factors used by the device (there may actually be different sensors in use in some versions of the motion plus), with my unit it would seem that in slow mode 1 degree/second = 20units in slow mode and 5 units in fast mode. Adding code to detect the mode and switch the scale factors results in the following output:

It can be seen that when operating in fast mode the two devices do not agree so closely on the result. At the moment I'm not sure if this is a result of a slightly incorrect scale factor for the Wii or possibly a difference in sensitivity between the two devices. 

Copyright 1998-2011 Andy Shaw