Another post about latency

My previous work on that subject

I already worked on measuring how much latency the sixaxis emulator is adding compared to a real sixaxis. I did that using a microphone, measuring the overall response time for a gunshot.

Assuming we have:
R=C+G
R=overall response time
C=controller latency
G=game latency

For the real sixaxis:
R1=C1+G
For the sixaxis emulator:
R2=C2+G

Assuming G is constant:
R2-R1=C2-C1

To estimate the controller latency difference, which is C2-C1, I just had to subtract the overall response time.
The result was about 15ms, which is not that bad compared to the overall response time (>100ms) and the human response time (>100ms).

A way to estimate the latency of the sixaxis emulator

The basic idea is to measure the time between a usb packet coming from the mouse (or any other usb controller) and a packet sent to the usb bt dongle.

For ex, the time between the usb packet for a left clic and the usb packet that sends the R1 button press (via the bluetooth dongle).

A great tool provided with the Linux kernel is usbmon, which allows to sniff the usb traffic. It’s possible to use it with wireshark (with root user rights), but it’s better to play in a terminal to automate extraction of valuable information.

The usbmon documentation is available there: link.

First of all, what the lsusb output says:

matlo@matlo-hcpc:~/hack/test$ lsusb
Bus 004 Device 002: ID 050d:0200 Belkin Components
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 003 Device 009: ID 054c:0268 Sony Corp. Batoh Device
Bus 003 Device 008: ID 0a12:0001 Cambridge Silicon Radio, Ltd Bluetooth Dongle (HCI mode)
Bus 003 Device 006: ID 054c:0268 Sony Corp. Batoh Device
Bus 003 Device 005: ID 046d:c041 Logitech, Inc. G5 Laser Mouse
Bus 003 Device 003: ID 046d:c517 Logitech, Inc. LX710 Cordless Desktop Laser
Bus 003 Device 002: ID 058f:9254 Alcor Micro Corp. Hub
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 002 Device 003: ID 046d:0809 Logitech, Inc. Webcam Pro 9000
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

What is useful there is the bus and device ids. The G5 mouse is device 5 on usb bus 3, and the bt dongle is device 8 on usb bus 3.

To start the capture:

matlo@matlo-hcpc:~/hack/test$ sudo cat /sys/kernel/debug/usb/usbmon/0u > test

Generate left clics into the sixaxis emulator, and stop the capture (ctrl+c).

Then, to display the mouse packets:

matlo@matlo-hcpc:~/hack/test$ cat test.txt | grep “3:005”

And for the bt dongle packets:

matlo@matlo-hcpc:~/hack/test$ cat test.txt | grep “3:008”

Both these commands may give a huge amount of data.

To only display packets that correspond to left clicks:

matlo@matlo-hcpc:~/hack/test$ cat test.txt | grep “3:005:1 0:1 10 = 01000000 00000000 0000”
f6747a40 967102843 C Ii:3:005:1 0:1 10 = 01000000 00000000 0000
f6747a40 968852805 C Ii:3:005:1 0:1 10 = 01000000 00000000 0000
f6747a40 970341772 C Ii:3:005:1 0:1 10 = 01000000 00000000 0000
f6747a40 971609742 C Ii:3:005:1 0:1 10 = 01000000 00000000 0000
f6747a40 972760716 C Ii:3:005:1 0:1 10 = 01000000 00000000 0000

To only display packets that correspond to R1 button presses:

matlo@matlo-hcpc:~/hack/test$ cat test.txt | grep “3:008:2 -115 58 = 2b203600 32004300 a1010000 08000080 80808000 00000000 00000000 0000ff00”
f32e2640 967105205 S Bo:3:008:2 -115 58 = 2b203600 32004300 a1010000 08000080 80808000 00000000 00000000 0000ff00
f32e2640 968861926 S Bo:3:008:2 -115 58 = 2b203600 32004300 a1010000 08000080 80808000 00000000 00000000 0000ff00
f32e2640 970345964 S Bo:3:008:2 -115 58 = 2b203600 32004300 a1010000 08000080 80808000 00000000 00000000 0000ff00
f3a904c0 971618231 S Bo:3:008:2 -115 58 = 2b203600 32004300 a1010000 08000080 80808000 00000000 00000000 0000ff00
f3a90ac0 972769407 S Bo:3:008:2 -115 58 = 2b203600 32004300 a1010000 08000080 80808000 00000000 00000000 0000ff00

What is to be extracted from this is the timestamp in microseconds, which is the second column.

matlo@matlo-hcpc:~/hack/test$ cat test.txt | grep “3:005:1 0:1 10 = 01000000 00000000 0000” | awk ‘{ print $2 }’
967102843
968852805
970341772
971609742
972760716

matlo@matlo-hcpc:~/hack/test$ cat test.txt | grep “3:008:2 -115 58 = 2b203600 32004300 a1010000 08000080 80808000 00000000 00000000 0000ff00” | awk ‘{ print $2}’
967105205
968861926
970345964
971618231
972769407

Then, it’s easy to copy-paste this data into a spreadsheet, compute the difference, compute the average, and the standard deviation.

For this example (with 5 more samples), it gives a 7.6ms average difference, with a 2.9ms standard deviation. The max difference is about 12ms.

It has to be reminded that the event polling period is 10ms (equal to the sixaxis report period), so that the maximum latency added by the event polling is 10ms, and the average is 5ms. Thus, the processing time is in average 7.6-5=2.6ms. It has to be noticed that I’m using a Linux kernel with realtime/low latency capabilities.

It’s also possible that there is some more latency added by the usb stack and the bt dongle, but it’s probably less than the 7.6ms processing time.

Conclusion:

– it’s probably not possible to have a lower response time with a sixaxis emulation (bt or usb)
– to lower the controller latency, the only potential way is to use a usb device to usb device controller (a custom usb link between the PC and the PS3), with a report period lower than 10ms

Thanks to that work I found a latency issue (about 50ms) that only impacts left and right mouse clics. The work-around -I’m not joking!- is to press the middle button after the mouse is plugged to the PC (see next post).

One GUI to rule them all

Last WE I started working on issue 19.

The idea is to make a simple GUI that can help the user in steps 2/3/4 of the (new) tutorial.
That means, no more “scary” commands to type in a terminal, and no more typos issues 😀
This also will make my work easier, since it will help people to report their issues.

Hopefully that will make windows users come to the Linux live USB solution…

Now, a few words for people that like technical stuffs and C/C++ programming.
To make my work easier and the code lighter, I’m not using the bluetooth and libusb libraries directly into the GUI app. I’m using a GLIB function called g_spawn_sync that allows to launch a command (bdaddr, hciconfig, sixaddr, emu, emuclient…) and to store the output of that command into a buffer (the output that is usually displayed into the terminal). This buffer is parsed so as to read interesting values (bdaddrs, dongle name, chip version, manufacturer…), which are lastly displayed in the GUI. I admit it is “quick and dirty”, but it works, and it’s time-saving 🙂

Voice control

This is my first post about “voice control” for the PS3.

Voice control is only #4 in my todo list, but as I’m curious, I wanted to know how hard this stuff is, and I decided to begin searching for Linux tools.

Speech recognition is a wider area than voice control. Considering what I want to do (voice control), it is a hard and wasteful thing (cpu consumption, complexity).

There are many projects that allow voice control stuffs. I will only focus on projects that are widely used/tested and still developed/maintained.

Project to watch regularly:

Some projects that are probably good enough to make a “hackish” proof-of-concept:

  • Simon: the wiki tells the installation is easy, but this sadly seems to be broken with Ubuntu Maverick. I need to work more on that cross-platform (Linux+Windows) solution.
  • Julius+Voxforge: seems to be very easy to install, but no GUI.
  • Pocketsphinx: a recognizer library written in C.

To be continued!

Support for Xbox 360 gamepad

Thanks to the sixaxis emulator, it’s possible to use a Xbox 360 gamepad with the PS3.

This requires a small patch for the d-pad, which is defined as a “joystick hat”.

The configuration file is available there.

The d-pad support will be included in next packages.

English tutorial


Moved: link.

[spoiler]Warning: this tutorial is updated frequently. Don’t copy it. Link to it.

Please note that I don’t give support for anything else than Ubuntu running in a non-virtualized machine.

Introduction

This tutorial explains how to control a PS3 with PC peripherals (keyboards, mice, joysticks) plugged on a PC running Linux and using a bluetooth dongle.

This is possible thanks to the early work of Jim Paris.

I applied many modifications to its source code, developed a GUI to make the launch and the configuration easier, and simplified the installation steps for debian-based Linux distros such as Ubuntu.

If you want to see how well this works, have a look at this video made byMcKack (version 0.11):

PS3 games with keyboard & mouse - Sixaxis Emulator v0.11


Requirements

  • a sixaxis already used with the target PS3
  • a bluetooth dongle with a chip that can have its bdaddr (bluetooth device address) changed. Just perform the tutorial to discover if your dongle works.

Notes

Do it at your own risk. I’m not responsible for any damage you can cause to your PS3 or PC.

Some cheap (a few $) CSR Bluecore4 dongles on ebay are reported to work. Bluecore4 is the first CSR bluecore chip that implements EDR (Enhanced Data Rate), so that the keywords to look for are CSR and EDR. Warning: most of these dongle are counterfeits! Please note that I’m not responsible for any not working dongle you might buy.

Don’t try to use the sixaxis emulator and the sixaxis at the same time, and restore the bdaddr of the dongle if you don’t use it with the sixaxis emulator anymore.

This tutorial was written running ubuntu from a live usb disk (nothing is saved on the hard drive).

Feel free to install ubuntu on your PC! If you have a Windows OS installed, you can read this tutorial if you want to install ubuntu on your hard drive without erasing the Windows OS.

Another way to use the sixaxis emulator is to run it from a Ubuntu Live USB Persistent Flash Drive (read this post).

1 Installation

Add “universe” to your repositories:
– Clic System>Administration>Synaptic Package Manager.
– Clic Settings>Repositories.
– Select universe, close.
– Clic reload, close.

Download following file:

Install it (double clic, then install).

2 Quick start

Plug your sixaxis (and the bt dongle, if external) to your PC.
Launch sixemugui (shortcut: Applications>Game>Sixemugui).

  1. Select the sixaxis
  2. Select the bt dongle
  3. Set the dongle address (don’t forget to write the old one down)
  4. Re-select the sixaxis and the bt dongle
  5. Unplug your sixaxis and if it doesn’t power off by itself, press the PS3 button until it powers off
  6. Select emuclient parameters
  7. Select the configuration file to use
  8. Start emu (emuclient starts automatically if the connection is established)
  9. Play (press Escape to quit emuclient)
  10. Stop emu

Note: File>Save lets you save the sixaxis and PS3 addresses so that you don’t require to plug the sixaxis anymore after that.

3 Custom mappings for mouse, keyboard and joysticks

It is recommended to change the mappings and to calibrate the mouse for each game.

Configuration files have to be saved into the ~/.emuclient/config directory (~ is the home directory).

Launch sixemuconf (shortcut: Applications>Game>Sixemuconf).

Screenshots of my configuration for COD: Black Ops:

It’s possible to define a configuration for aiming: copy-paste the configuration #1 to configuration #2, define the right mouse clic as configuration #2 trigger with switch back, and adjust the mouse multipliers & exponents.

Items of the “Edit” menu that allow to convert a configuration:

The “Replace Mouse” item allows to change the mouse name and id.
The “Replace Keyboard” item allows to change the keyboard name and id.
The “Replace Mouse DPI” item allows to adjust the mouse multipliers according to old/new dpi values (the higher the better).

Stick intensity control for button to stick mappings:

See this post for more details about this functionnality: link.

4 Mouse calibration mode

Before calibrating the mouse, be sure to set the in-game sensitivity to the highest, and be sure to set the mouse dpi to the highest value.

To start emuclient with the mouse calibration mode enabled, select Mouse>Calibrate in the sixemugui application. Then start emuclient.

Current mouse calibration values appear in the “Mouse calibration” part of the gui.

This calibration mode lets you calibrate each mouse independently. It reads values from the loaded configuration. To change values, use rctrl+FX key combinations and use the mouse wheel.

The dead zone value has to be set to the highest stable position.
Different dead zones for x & y only makes sense for a “rectangle” dead zone shape.
The dead zone shape has to be set to the most stable one.

5 Keyboard macros

It’s possible to configure keyboard macros.

A key press will generate a series of events, with timing conditions.

Commands are the following:
– key down
– key up
– key press (= key down + delay + key up)
– delay (unit = ms)

Each macro has to be defined in a file saved into the ~/.emuclient/macros directory (~ is the home directory, .emuclient folder is hidden).

Example: macro_example.txt

#Defines the action that triggers the macro execution
MACRO F1
#Performs a keystroke (key down + delay 50ms + key up)
KEY e
#Sleep 50ms
DELAY 50
#Perform a key down
KEYDOWN SPACE
#Sleep 50ms (minimum delay between KEYDOWN and KEYUP)
DELAY 50
#Perform a key up
KEYUP SPACE

Lines beginning with # are comments.

All keys of the keyboard can trigger a macro. The complete list can be found in conversion.c.

6 Troubleshooting / Feedback

I’m sharing my project for free, so please give me a feedback.

Tell me if it works or doesn’t work, and especially add the following details:

  • the Linux distribution
  • the PS3 hardware version (slim, fat 40Gb, fat 60Gb, …)
  • the PS3 firmware version
  • the bluetooth dongle (exact model + revision if there is one + output of commands “hciconfig -a hci0” and “sudo hciconfig hci0 revision” in a terminal)
  • the hardware of the PC (at least the CPU and the amount of RAM)

Report that in commentary to this post.

And if it doesn’t work, first verify if you have the latest packages. Then look at the FAQ and the bug list, see if your problems are already known, and if it’s not, report them.

If you want to contribute to this project, have a look at this page.
Paypal donation links are on the top right corner of this page.[/spoiler]

New stuffs coming very soon

The configuration reader for the emuclient process is finished.

I tested it (=played!) with my G5 mouse and n52 keyboard, and it works well for COD: Black Ops 🙂

All game controllers are now supported. Great examples of game controllers that are now possible to use: Xbox gamepads, racing wheels (no force feedback yet), joysticks.

I tested with a sixaxis (wired, but it should work wireless too). You may ask, why would I need to do that? The response is simple: button mapping & dead zone removal.

I’m now focusing on making .deb packages, so as to make the installation easier.

There also will be an update for the tutorial.

For now, the tutorial has been modified to use a specific revision of the code, which is not the head revision.

Stay tuned!