GameController

class quanser.devices.interfaces.GameController

A Python wrapper for the Quanser Devices API interface to game controllers.

Example

>>> from quanser.devices import GameController
>>> joystick = GameController()
close()

Close the game controller.

Example

>>> from quanser.devices import GameController
>>> joystick = GameController()
>>> joystick.open(1)
>>> ...
...
>>> joystick.close()
open(controller_number)

Opens a game controller.

Example

>>> from quanser.devices import GameController
>>> joystick = GameController()
>>> joystick.open(1)
>>> ...
...
>>> joystick.close()
poll()

Poll the game controller state.

The first return value contains the state of the game controller axes, sliders and buttons as an object. The properties of the object are:
xfloat

The x-coordinate as a percentage of the range. Spans -1.0 to +1.0.

yfloat

The y-coordinate as a percentage of the range. Spans -1.0 to +1.0.

zfloat

The z-coordinate as a percentage of the range. Spans -1.0 to +1.0.

rxfloat

The rx-coordinate as a percentage of the range. Spans -1.0 to +1.0.

ryfloat

The ry-coordinate as a percentage of the range. Spans -1.0 to +1.0.

rzfloat

The rz-coordinate as a percentage of the range. Spans -1.0 to +1.0.

slidersfloat[2]

The slider positions as a percentage of the range. Spans 0.0 to 1.0.

point_of_viewsfloat[4]

The point-of-view positions in positive radians or -1 (centred).

buttonsuint32

The state of each of 32 buttons as a bitmask. A bit value of 0 indicates the button is released, while a value of 1 indicates the button is pressed.

The second return value is a boolean indicating whether the state is new since the last time it was polled.

Example

Poll the state of the joystick.

>>> from quanser.devices import GameController
>>> joystick = GameController()
>>> joystick.open(1)
>>> state, is_new = joystick.poll()
>>> print("new=%d x=%f y=%f z=%f" % (is_new, state.x, state.y, state.z))
...
>>> joystick.close()