A tool to estimate the latency

In a series of posts I am talking about the sixaxis emulator latency.

What kind of latency am I talking about? Basically, the time between event reception from PC peripherals, and event emission to the PS3. The most critical event to me is a mouse left clic in a FPS game.

The most accessible estimation is to measure the difference between usb timestamps. See this post for more details. I created a small utility to make this estimation easier. It has to be launched in a terminal, but I am thinking to add it some day in sixemugui.

matlo@matlo-hcpc:~/hack/test$ wget http://diyps3controller.googlecode.com/svn/trunk/tools/sixemulat.c
matlo@matlo-hcpc:~/hack/test$ gcc -lm -o sixemulat sixemulat.c

matlo@matlo-hcpc:~/hack/test$ lsusb
...
Bus 003 Device 008: ID 0a12:0001 Cambridge Silicon Radio, Ltd Bluetooth Dongle (HCI mode)
Bus 003 Device 005: ID 046d:c041 Logitech, Inc. G5 Laser Mouse

matlo@matlo-hcpc:~/hack/test$ ./sixemulat
usage: ./sixemulat <mouse bus id> <mouse device id> <dongle bus id> <dongle device id>
matlo@matlo-hcpc:~/hack/test$ ./sixemulat 3 5 3 8

Be sure to use the correct mouse/dongle bus/device ids, specifically if you have several mice and/or several dongles!

Sixemulat displays:
– the number of caught left clics
– the worst latency
– the average latency

About a hundred of samples should be enough to get significant values.

The average latency is an interesting value, but the most important value is the worst latency. Commercial products will tend to give you only the average latency, as it is a lower (generally half) value…

I only tested this tool with two logitech mice. If it doesn’t work for you, please get in touch with me.

Mouse mapping improvement – 2

Last mouse mapping improvement was about tweaking the dead zone shape, and was proposed by a reader of this blog. Another reader suggested me to change the way the mouse motion is processed.

The sixaxis emulator currently approximates the velocity from the mouse report average over 10ms (=the sixaxis report period). For ex, if it receives N mouse reports, it assumes a constant 10/N ms period.

Example 1:


t0-1ms report x = some value
t0 all mouse report processed, a report is sent to the ps3, x = 0
t0 report x = +10
t0+1ms report x = +8
t0+2ms report x = +6
t0+3ms report x = +4
t0+4ms report x = +2
... no other report
t0+10ms all mouse report processed, a report is sent to the ps3


5 reports, report period is approximated to 2ms.
Mouse report average: (10+8+6+4+2)/5 = 6 units/ms

Well, this is overestimated.


With a simple accumulation + division:
Mouse report average: (10+8+6+4+2)/10 = 3 units/ms

For this example, the computed velocity is 2x the real one o_O

This is not harmful if the computed velocity is always 2x the real one.
But let’s take another example.

Example 2:


t0-1ms  report x = some value
t0      all mouse report processed, a report is sent to the ps3, x = 0
t0      report x = +10
t0+1ms  report x = +8
t0+2ms  report x = +6
...     no other report
t0+10ms all mouse report processed, a report is sent to the ps3

 

3 reports, report period is approximated to 3/10ms.
Mouse report average: (10+8+6)/3 = 8 units/ms

 

With a simple accumulation + division:
Mouse report average: (10+8+6)/10 = 2.4 units/ms

For this example, the computed velocity is 3.33x the real one…

The previous computation was introducing a non constant multiplier ๐Ÿ™

Multiple mice and keyboards support

I managed to build a custom SDL library (from libSDL 1.2 sources) that exposes the source of mouse & keyboard events. People interested in how I did that will find the patch there: patch. It uses XI2/RawEvents. It’s very hackish and ugly, but it does the job. Note that it probably breaks stuffs useless to the sixaxis emulator.

This allows to use several mice and keyboards with the sixaxis emulator, which is a nice feature to play split-screen FPS games with friends ๐Ÿ™‚

About the "Kinect-PS3" project

The Kinect-PS3 project from Shantanu Goel makes some huge buzz on the web. The Kinect-PS3 uses -among others things- the sixaxis emulator (called “diyps3controller” everywhere because of the name of my googlecode page), and probably wouldn’t be there without it. Many websites are talking about the Kinect-PS3, and they only give credits to only one person… guess who. This is not very fair, and I really would have appreciated getting a few credits for what I am working on.

That said, the Kinect-PS3 is a great showcase for the sixaxis emulator, and my googlecode page and blog are currently receiving an unusual amount of visitors.

I guess Sony will not enjoy this stuff at all, and I hope they won’t try to break the compatibility with the sixaxis emulator. But if they try to, be sure I will do my best to fix it.

QtSixA – Sixaxis control mapping for all!

The Sixaxis emulator supports standard joysticks thanks to the SDL library.
The sixaxis itself is not a standard joystick. This means some ugly patches have to be done to get it work.

It already works fine in usb mode, which makes it usable as-is with the sixaxis emulator, BUT bluetooth mode doesn’t work out of the box.

If you want to use your sixaxis in bluetooth mode, there is an excellent tool called QtSixA. There is a big thread about it in Ubuntu forums.

It turns out that QtSixA (current version is 1.5.0) works fine with the sixaxis emulator ๐Ÿ˜€

This tool even let you use the motion sensing! This is not supported by the sixaxis emulator… for now ๐Ÿ™‚

To install it, from a terminal:

sudo add-apt-repository ppa:falk-t-j/qtsixa
sudo apt-get update
sudo apt-get install qtsixa

There is a shortcut in menu Applications > Accessories.

The pairing is currently broken, to fix it, just type in a terminal:

sudo mv /usr/bin/sixpair /usr/sbin/sixpair

All buttons and sticks are working with the sixaxis emulator. There is an issue with some ‘analog’ (pressure sensitive) buttons that are not working as axes: square/triangle/circle/cross.

There also is a minor compatibility issue regarding the joystick name which is different in bt mode. The joystick name is used to distinguish joystick models, so that this will require a small patch.

Remember: don’t use the same bluetooth address at the same time! This requires 2 sixaxis (1 turned off, 1 turned on). Or a usb dev board (such as the teensy++) to pair custom bluetooth addresses.