Library to interface with Gran Turismo's motion rig telemetry service.
Project description
Gran Turismo Telemetry
Python library for interfacing with Polyphony Digital's telemetry service for motion rigs in GT6/GTS/GT7 (maybe older?)
Features
- Playstation IP Address discovery
- Asynchronous callbacks
- Game event observer
- Telemetry as an object or a dictionary
Installation
Install with pip:
pip install gt-telem
Usage
Getting telemetry is fairly straightforward. Here's a simple example:
import json
from gt_telem import TurismoClient
from gt_telem.models import Telemetry
async def print_telem(t: Telemetry):
print(json.dumps(t.as_dict, indent=4))
tc = TurismoClient()
tc.register_callback(print_telem)
tc.run()
print_telem()
is invoked with each frame rendered (60hz). This tends to produces a lot of noise, especially when in menus, or even if the race is paused.
Hooking into game events
Here's a more complex example of a telemetry recorder that hooks into race start, pause, and race end:
from gt_telem import TurismoClient
from gt_telem.events import GameEvents
from gt_telem.errors.playstation_errors import *
class MySimpleTelemetryRecorder():
def __init__(self, tc: TurismoClient):
self.tc = tc
self.storage = []
def start(self):
self.tc.register_callback(MySimpleTelemetryRecorder.receive_telem, [self])
def stop(self):
self.tc.deregister_callback(MySimpleTelemetryRecorder.receive_telem)
# save self.storage somewhere
@staticmethod
async def receive_telem(t, context):
context.storage.append(t)
print(f"{t.engine_rpm}RPM - {t.boost_pressure}kPa")
print(f"Best: {t.best_lap_time}\tLast: {t.last_lap_time}")
if __name__ == "__main__":
try:
tc = TurismoClient()
except PlayStatonOnStandbyError as e:
print("Turn the playstation on")
print(e)
except PlayStationNotFoundError:
print("Maybe I'm on the wrong network")
print(e)
else:
ge = GameEvents(tc)
mstr = MySimpleTelemetryRecorder(tc)
ge.on_in_race.append(mstr.start)
ge.on_race_end.append(mstr.stop)
ge.on_paused.append(mstr.stop)
print("Listening for telemetry. CTRL+C to stop")
tc.run()
TurismoClient.run()
is a blocking call, but does shut down gracefully when a keyboard interrupt is issued. It also accepts a cancellation token.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file gt-telem-0.2.6.tar.gz
.
File metadata
- Download URL: gt-telem-0.2.6.tar.gz
- Upload date:
- Size: 52.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 13dc89256595f3e30432a6e1530e828a67c1e88a66c7508843a6001c2614d706 |
|
MD5 | ae062a34ab6889721e03b7aa6bd8c33f |
|
BLAKE2b-256 | 970e7dd12a9696cebe8926c76b0bf68e80220b1427419309bee7f191834323b0 |
File details
Details for the file gt_telem-0.2.6-py3-none-any.whl
.
File metadata
- Download URL: gt_telem-0.2.6-py3-none-any.whl
- Upload date:
- Size: 42.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5679a3b268e096e7140e2ed79e2538e9fb43893443b3280155f4ae6c91527cac |
|
MD5 | 7b400eba263cbc0c296ccabb9030a385 |
|
BLAKE2b-256 | c171a412be9196d342531ac0489c2c2fe2ec41b105e41a5aebd18aa3819d5559 |