IMU Game Controller
Project members: Lucas Christian, Justin Gensel, Sara Srivastav, Neha Nair
Overview¶
With the advent of the Wii, motion control for games has been all the rage, with nearly every console vendor rolling out their own motion detection and control hardware. This project is our attempt to create our own motion control/VR system targeting PC games, albeit at a much smaller scale.
Hardware¶
The project consists of three mbed-based modules:
- Hand module, worn on the wrist, detects up/down/left/right gestures
- Foot module, worn on one foot, detects steps in 4 directions
- USB emulator module, receives commands from the other three modules, and appears as a USB keyboard to the connected PC.
The three modules communicate using XBee Series 1 radios, implemented in API mode to allow for lower latencies. By default, the XBee radios simply emulate a serial port, buffering up characters received, then after a brief delay sending them out in a packet to the other end, which replays the characters on the remote serial port.
Software¶
The hand and foot modules both leverage the existing LSM9DS1 IMU library, with a few small modifications to speed up the calibration procedure. The hand module relies solely on the accelerometer, while the foot module uses the accelerometer to detect steps and the compass to detect direction.
To implement the XBee modules, we ported the xbee-arduino project to mbed. The library handles generating and decoding XBee API packets over the serial port, which allows us to exert more control over when the module sends packets as well as access underlying details, such as the address of the sending module.
Radio addresses are currently hardcoded, but using API mode lays the groundwork for future revisions to implement a pairing/discovery process.
Components needed¶
Item | Quantity |
---|---|
LSM9DS1 IMU | 2 |
mbed | 3 |
Pushbutton | 3 |
Xbee S1 | 3 |
USB Connector | 1 |
Battery Packs | 2 |
Wiring¶
There are three separate mbeds used on three separate breadboards.
Foot Module¶
LSM9DS1 IMU | mbed |
---|---|
GND | GND |
VDD | VOUT |
SCL | p26 |
SDA | p27 |
You must also add pull up resistors on the SDA and SCL lines.
Xbee | mbed |
---|---|
GND | GND |
VCC | VOUT |
DOUT | p10 |
DIN | p9 |
Battery Pack | mbed |
---|---|
VDD | Vin |
GND | GND |
Pushbutton connected to p17 and ground
Hand Module¶
LSM9DS1 IMU | mbed |
---|---|
GND | GND |
VDD | VOUT |
SCL | p10 |
SDA | p9 |
You must also add pull up resistors on the SDA and SCL lines.
Xbee | mbed |
---|---|
GND | GND |
VCC | VOUT |
DOUT | p27 |
DIN | p28 |
Battery Pack | mbed |
---|---|
VDD | Vin |
GND | GND |
Pushbutton 1 connected to p21 and ground Pushbutton 2 connected to p5 and ground
Reciever Module¶
Xbee | mbed |
---|---|
GND | GND |
VCC | VOUT |
DOUT | p27 |
DIN | p28 |
USB Connector | mbed |
---|---|
VCC | VIN |
D- | D- |
D+ | D+ |
GND | GND |
Configuring XBees¶
The XBee radios require additional configuration before use. The easiest method is to use Digi's X-CTU software with a USB emulator board, but they can also be configured over a serial port using the AT command escape sequence documented on the datasheet.
In X-CTU, the following settings are required for each module:
- Reset the module to its default to clear out any settings from previous projects
- Set MY to a unique address for each module.
- Set AP = 2 to enable API mode.
After this, the modules should be ready to go. Make sure the Wireless.h file defines the proper 16-bit address set in the MY field of the XBee connected to the emulator module.
Example Code¶
Here is example code that detect inputs from walking and turn it into directional movement for movement input into a game. The hand module detects hand motions for moving through menus and two push buttons for additional input. The game used in the example is Pokemon Fire Red running on a Game Boy Advance emulator.
Import programFootModuleCode
Code to detect walking and convert to input for video game
Import programHandController
Code to detect hand movement for use in video game
Import programWirelessControllerRecieve
Code to receive input from foot and hand module and sends data to computer as a key press
The foot should be fastened securely to one foot. When powered on, hold the module still until the first LED on the mbed lights up. Then rotate the foot module at least 360 degrees until the second LED on the mbed lights up. After that, face the direction you want to be forward and press the button on the foot module.
For the hand module, it must be held still for a few seconds after powering on. Hold the module with the USB port facing away from your body, with the surface of the mbed facing up towards the sky.
The receiving module must be connected to the computer through the added USB connector.
Set up your game emulator so that movement is controlled by the arrow keys of the keyboard and the A button is attached to the "A" key and the B button is attached to the "B" key.
To move your character, simply walk in place facing the direction you want to travel. To navigate through menus, tilt your hand in the direction you want to move the cursor, using the push buttons for selections.