Project Title: Gyro Controller Input for PySoy

Student: Mayank Singh

Organization: Python Software Foundation

Basic focus has been shifted to Wiimote rather than android as of 16/4/2011.

The idea behind this project is to be able to play a PySoy game like ping pong on your computer using your smartphone/wiimote as a bat or a similar tool. Basic Target is the wiimote and later the android platform. I'll build a simple squash game where you hit a ball to a virtual wall and it bounces back for you to hit again as a working example. After their success, code can be ported to iOS as well(mostly not during this summer).

Controller class
For the device/smartphone to work with PySoy, a controller class is supposed to be written that will handle the input. The device/smartphone has to function as a full fledged controller that will provide all the functions of a game controller plus the accelerometer/gyroscope possibilities. The class can be extended to special classes for android, wii remote and iOS.

Ideas on API
The smartphones/wiimote these days can provide with various kinds of inputs. These include:

  • Orientation input (Tilt of the phone)(Needs accelerometer)
  • Acceleration input (Linear acceleration)(Needs accelerometer)
  • Rotation input (This feature is mostly avaialable with phones having gyroscope)
  • Key input (Normal touch input)

To handle such various types of inputs, the API should be able to handle them. Thus, a possible API to use a wiimote's various abilities can be as described below:

  • Attach a motion controller to the window:
    motion = soy.controllers.Motion(window)
  • So, you can get various outputs from the controller for usage inside your game using instructions as below:
    rmatrix = motion.RotationMatrix
    tilt = motion.Orientation
    acceleration = motion.Acceleration
    #Input mappings of the UI on the smartphone screen
    motion['somebutton'] = somefunction()
  • The wiimote handles all this by sending appropriate signals via bluetooth connection. More on how to handle bluetooth connection in wiimote in the Link section.
  • For the android phone, all this can be accessed from the SensorEvent class and then communicated to the libsoy via a bluetooth or USB connection. This can be referred  here.
  • The game programmer can then program there 3d/2d models/sprites to move/gain force/gain torque based on the values they receive from the motion controller functions.
  • Regarding the real world and game world coordinate system, it's completely upto the game programmer how he utilizes the values he gets from the motion controller. As is clear from the output of the functions, they provide output for all three axes. So, it's upto the game programmer to map the acceleration, rotation from the real world to his game world coordinate system.
  • So, suppose he wants his ball model to gain a force of depending on the acceleration of his wiimote/smartphone's accelerometer in the x direction in the 3d world he can use the instruction like:
    acceleration = motion.Acceleration
    cube.addForce(acceleration['x']*cube.mass, 0, 0)
  • Another idea is to save certain gestures either on the device side or on the console side. So, If suppose you do a swing, libsoy receives a signal of swing which it can interpret in its own way (open menu, do real swing on object, etc.).
  • A wonderful guide to handle motion sensing and orientation sensing input is  here.

The Link
With respect to wiimote, I seem to have found a lot of libraries that can be used to interface with the wiimote and provide bluetooth connections. Some of them include:

Nice article on handling wiimote for communications is  here.
To make the controller work with the device's bluetooth signals or maybe in some cases USB signals, a bluetooth/USB API will have to be written.  This link seems to tell how to do it in C. For the USB part, I'll have to read up on this:  Linux USB guide.

Device side coding(Only for smartphones i.e. for later)
To ease porting between iOS and android,  PhoneGap can be used. Though it does not support bluetooth. This seems like a good plugin:  Bluetooth Plugin for Android. I can build upon this code for using bluetooth with android. Though for iOS, I'll have to write my own plugin. Device coding will involve creating a nice user interface for all different types of inputs so that the device can function as a stand-alone controller apart from all the accelerometer functions. Another alternative is to code directly for android without the help of  PhoneGap and then similarly for iOS and wii remote. Though  PhoneGap is helpful in the fact that the same code will work for iOS except for writing a bluetooth plugin.

The Proof of Concept
As a proof of concept, I plan to develop a squash game using PySoy to simulate a gyro device (android, iOS or wii remote) as a bat. The idea of the game is simple in that you'll have to hit a wall with a ball using your virtual bat.

Start of Program (May 24)
Detail the preparation work you'd need to do before you can start working on code:

  • Try implementing a keyboard controller
  • Read up on Wiimote Bluetooth connections and try running wiimote on linux/windows
  • Get a Wiimote
  • Plan out controller class model and skeleton functions

Midterm Evaluation (July 12)
List your proposed deliverables by the midterm evaluation:

  • Controller class code for wiimote
  • An API to handle wiimote bluetooth connections

Final Evaluation (Aug 16)
List your proposed deliverables by the end of the Summer:

  • The squash game with the ability to play with the wiimote as a bat
  • Switch to android phone if results achieved earlier
  • USB API if possible

Weekly progress will be noted down here.

Who Am I?
I am Mayank Singh from BITS-Pilani, Goa Campus, India. I am currently pursuing B.E.(Hons.) in Computer Science and am currently in the second year of my studies. You can follow the following links for more information regarding my work experience or just about me.