Line 11: |
Line 11: |
| == Finding the Sensor Bar == | | == Finding the Sensor Bar == |
| | | |
− | The first step in the algorithm is locating the sensor bar. Since spurious IR sources may be present, we need to locate the two dots that most likely correspond to the sensor bar. To do this, we look for the two dots that are at least spaced a certain minimum distance appart (to remove any possible duplicated dots if the wiimote picks up several dots clustered around one IR emmitter) that lie in a horizontal plane, using the wiimote's tilt calculated from the accelerometers to determine what this plane should be. Any pairs off by a certain margin or more (say, 10 degrees) are thrown away. From the remaining pairs we should pick the two that are closest to the horizontal, while avoiding any pair with a third dot very close to the imaginary line between them. This is because there should never be an IR emmitter between the sensor bad edges, so the outermost pair of a horizontal line of three dots can't be the sensor bar, for example. | + | The first step in the algorithm is locating the sensor bar. Since spurious IR sources may be present, we need to locate the two dots that most likely correspond to the sensor bar. To do this, we look for the two dots that are at least spaced a certain minimum distance appart (to remove any possible duplicated dots if the wiimote picks up several dots clustered around one IR emitter) that lie in a horizontal plane, using the wiimote's tilt calculated from the accelerometers to determine what this plane should be. Any pairs off by a certain margin or more (say, 10 degrees) are thrown away. From the remaining pairs we should pick the two that are closest to the horizontal, while avoiding any pair with a third dot very close to the imaginary line between them. This is because there should never be an IR emitter between the sensor bad edges, so the outermost pair of a horizontal line of three dots can't be the sensor bar, for example. |
| | | |
| If the Wiimote loses tracking of one of the ends (it disappears from view after being close to the edge of the sensor area), it should attempt to continue using the other dot and making a best guess as to where the first one is. For example, the algorithm should keep the distance between the dots constant, and use the accelerometer data to calculate the angle: | | If the Wiimote loses tracking of one of the ends (it disappears from view after being close to the edge of the sensor area), it should attempt to continue using the other dot and making a best guess as to where the first one is. For example, the algorithm should keep the distance between the dots constant, and use the accelerometer data to calculate the angle: |
Line 23: |
Line 23: |
| | | |
| == Pointing position == | | == Pointing position == |
− | Once we know the two dots of the sensor bar, we rotate the sensor field to make the two dots appear on a horizontal line (using the accelerometer values to make sure we're in the right quadrant if the wiimote is upside down). The angle of rotation corresponds to the angle of the wiimote as reported to the software. We should probably apply at least a basic moving average filter to this to reduce jerkiness. Once we have the sensor bar mapped into a new coordinate system where it is horizontal, we can simply take the average position of the two dots and use that to calculate the pointer position by defining a box to map the screen to it. The position of this box will vary depending on the sensor bar position setting (above, below TV). The box should probably be small enough to accomodate several angles without any dead areas (Mario Galaxy seems to be an offender here; I have trouble getting to one of the screen corners if the wiimote is at an angle to the sensor bar). | + | Once we know the two dots of the sensor bar, we rotate the sensor field to make the two dots appear on a horizontal line (using the accelerometer values to make sure we're in the right quadrant if the wiimote is upside down). The angle of rotation corresponds to the angle of the wiimote as reported to the software. We should probably apply at least a basic moving average filter to this to reduce jerkiness. Once we have the sensor bar mapped into a new coordinate system where it is horizontal, we can simply take the average position of the two dots and use that to calculate the pointer position by defining a box to map the screen to it. The position of this box will vary depending on the sensor bar position setting (above, below TV). The box should probably be small enough to accommodate several angles without any dead areas (Mario Galaxy seems to be an offender here; I have trouble getting to one of the screen corners if the wiimote is at an angle to the sensor bar). |
| | | |
| == Smoothing the cursor == | | == Smoothing the cursor == |