Using a Wiimote as a 6-DOF Vrui Input Device

Current versions of Vrui contain a tracking driver for the Wiimote using the camera-based tracking approach described on the technology page. As this driver is part of Vrui's device driver (VRDeviceDaemon), getting the Wiimote into Vrui applications requires a few simple configuration steps.

Step 1: Build IR Beacon

The Wiimote tracking driver relies on a beacon consisting of four infrared LEDs in a known, non-planar configuration. The Wiimote can only be tracked while its camera sees all four LEDs. A detailed description of a canonical beacon's layout, and a simple wiring diagram, are available on the IR beacon page.

Step 2: Configure VRDeviceDaemon

VRDeviceDaemon is configured via its own configuration file, VRDevices.cfg. For more information on Vrui, VRDeviceDaemon, and their configuration files, see the Vrui HTML documentation.

Step 2.1: Create New VRDevices.cfg

The recommended process is to create a new VRDevices.cfg file in Vrui's configuration directory, and create a new root section named after the local computer, i.e., the result of running echo $HOSTNAME, or, if that fails, echo $HOST in a terminal. The computer name needs to be enclosed in double quotes. In the following, we will use "localhost.localdomain" as a placeholder for the actual computer name. Inside that root section, create the skeleton file shown below:
section "localhost.localdomain"
	section DeviceManager
		deviceNames (Wiimote)

		section Wiimote
		endsection
	endsection

	section DeviceServer
		serverPort 8555
	endsection
endsection

Step 2.2: Configure Wiimote Tracking Driver

VRDeviceDaemon needs to be told what driver module to use for the Wiimote, and the Wiimote tracking driver needs to know the bluetooth ID of the Wiimote device to which to connect, and some basic information about the device itself. In the skeleton VRDevices.cfg file, insert the following in section Wiimote:
section "localhost.localdomain"
	section DeviceManager
		...
		section Wiimote
			deviceType WiimoteTracker
			deviceName "xx:xx:xx:xx:xx:xx"
			enableTracker true

			homeTransform translate (0.0, -12.0, -2.0)

			cameraCenter (512, 384)
			cameraFocalLength 1280
		endsection
	endsection
	...
endsection

Step 2.3: IR Beacon Configuration

The Wiimote driver needs to know the absolute positions of the IR beacon's four LEDs in Vrui's physical space in order to calculate the Wiimote's position and orientation in the same physical space. Because a beacon is typically internally rigid but movable, it is configured via two steps: the positions of the four LEDs are first defined in some arbitrary local coordinate system, and are then transformed to Vrui physical space via a rigid body transformation. This simplifies updating the driver's configuration when the beacon is moved to a different position or orientation.

Vrui physical space is the (arbitrary) coordinate space in which an environment's screens and viewers are defined, and is described in more detail in Vrui's HTML documentation. The typical physical space layout for a desktop environment has the coordinate origin in the center of the screen, the X axis going to the right, and the Z axis going up. The Y axis, then, points into the screen.

The configuration settings for the IR beacon are:

section "localhost.localdomain"
	section DeviceManager
		...
		section Wiimote
			...
			targetPoints ((-2.0, 0.0, 0.0), (0.0, -1.0, 2.0), (2.0, 0.0, 0.0), (0.0, -1.0, -2.0))
			targetTransformation translate (0.0, 0.0, 10.0) * rotate (1.0, 0.0, 0.0), 15.0
		endsection
	endsection
	...
endsection

Step 3: Configuring Vrui

To use the Wiimote, Vrui needs to be told to connect to a VRDeviceDaemon instance on start-up, and to create a 6-DOF input device using the Wiimote's position and orientation, buttons, and analog axes. This is done by adding another input device adapter to Vrui's configuration file, Vrui.cfg. One can either modify Vrui.cfg itself, or create a "patch" configuration file which is merged into the main configuration file on request. Using the second approach, one first creates an empty configuration file, called Vrui-Wiimote.cfg, in the same directory as Vrui.cfg, and inserts the following content:
section Vrui
	section Desktop
		inputDeviceAdapterNames (MouseAdapter, DeviceDaemonAdapter)

		section DeviceDaemonAdapter
			inputDeviceAdapterType DeviceDaemon
			serverName localhost
			serverPort 8555
			inputDeviceNames (Wiimote)
			
			section Wiimote
				name Wiimote
				trackType 6D
				trackerIndex 0
				numButtons 13
				numValuators 2
				deviceGlyphType Cone
			endsection
		endsection
	endsection
endsection

Step 4: Starting VRDeviceDaemon

In order to use the Wiimote, one first has to start VRDeviceDaemon, Vrui's external device driver. Running VRDeviceDaemon from a terminal, without command line arguments, will start the driver and configure it according to the VRDevices.cfg file. On start-up, the driver will print several status messages, and then ask the user to press buttons "1" and "2" on the Wiimote simultaneously on the Wiimote. This will put the Wiimote into discovery mode, indicated by four flashing LEDs. After a few seconds, the driver should pick up the connection, turn off the flashing LEDs, and print Waiting for client connection... At this point the driver is ready to accept connections from Vrui applications, and serve tracking data. The driver can be kept running throughout multiple Vrui application sessions, but the Wiimote will use battery power while the driver is running, even when idle. To preserve battery life, it is best to stop the driver by pressing Ctrl-C in its terminal window when noone will be using it for a longer time.

Step 5: Starting Vrui Applications

While VRDeviceDaemon is running and ready, Vrui applications can be started in the usual manner. If the Wiimote was configured via a "patch" configuration file, as recommended, one has to add -mergeConfig <config file name> to the application's command line, where <config file name> is the absolute or relative path to the created configuration file. If invoked in that way, VRDeviceDaemon should print connection and disconnection messages as applications are started and terminated, and a grey cone indicating the Wiimote's position and orientation should appear in the main window whenever the Wiimote's camera can see all four LEDs on the IR beacon.

Step 6: Pre-Assigning Tools

Up to this point, the Wiimote should appear as a 6-DOF device, but it will not yet have any functionality associated with it. As a result, pressing and holding any of its buttons should show Vrui's tool selection menu. It is possible to pre-assign common tools to several buttons via the same patch configuration file. How this is done varies between 1.0-xxx versions of Vrui and 2.x versions. In all versions, one starts by inserting the following sections into the patch configuration file:
section Vrui
	section Desktop
		...

		section Tools
			toolNames (MouseNavTool, \
			          FPSNavTool, \
			          MenuTool, \
			          WiiNavTool, \
			          WiiMenuTool)
			
			section WiiNavTool
				toolClassName WandNavigationTool
			endsection
			
			section WiiMenuTool
				toolClassName RayScreenMenuTool
			endsection
		endsection
	endsection
endsection

Vrui Versions Prior To 2.0

In pre-2.0 versions of Vrui, tool bindings were specified by button and valuator indices. To bind a wand navigation tool to the "A" button and the direction pad's down arrow, and to bind a menu tool to the "Home" button, one would insert:
section Vrui
	section Desktop
		...

		section Tools
			...

			section WiiNavTool
				toolClassName WandNavigationTool
				deviceName0 Wiimote
				device0ButtonIndex0 3
				device0ButtonIndex1 8
			endsection
			
			section WiiMenuTool
				toolClassName RayScreenMenuTool
				deviceName0 Wiimote
				device0ButtonIndex0 5
			endsection
		endsection
	endsection
endsection

Vrui Versions 2.0 And Later

In Vrui version 2.0 and later, tool bindings designate buttons and valuators by name instead of index, and using a list of assignments instead of individual settings. Additionally, Vrui 2.0 allows stacking of button bindings, which makes it possible to use the down arrow to scale space when pressed together with the "A" button, and to pop up and interact with an application's main menu if pressed by itself. To achieve this binding, which is more comfortable than the one in the previous section, one would insert:
section Vrui
	section Desktop
		...

		section Tools
			...

			section WiiNavTool
				toolClassName WandNavigationTool
				bindings ((Wiimote, A, Down))
			endsection
			
			section WiiMenuTool
				toolClassName RayScreenMenuTool
				bindings ((Wiimote, Down))
			endsection
		endsection
	endsection
endsection