Skip to main content

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, TurismoGame
from gt_telem.errors.playstation_errors import *

class MySimpleTelemetryRecorder():
    def __init__(self, tc: TurismoClient):
        self.tc = tc
        self.storage = []

    def start(self):
        tc.register_callback(MySimpleTelemetryRecorder.receive_telem, [self])

    def stop(self):
        self.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:
        tg = TurismoGame(tc)
        mstr = MySimpleTelemetryRecorder(tc)
        tg.on_in_race.append(mstr.start)
        tg.on_race_end.append(mstr.stop)
        tg.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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gt-telem-0.2.0.tar.gz (52.6 kB view details)

Uploaded Source

Built Distribution

gt_telem-0.2.0-py3-none-any.whl (42.1 kB view details)

Uploaded Python 3

File details

Details for the file gt-telem-0.2.0.tar.gz.

File metadata

  • Download URL: gt-telem-0.2.0.tar.gz
  • Upload date:
  • Size: 52.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.0

File hashes

Hashes for gt-telem-0.2.0.tar.gz
Algorithm Hash digest
SHA256 42417b19ba6417f7fc721416576a19a5f31ccf1455b644e5afceb7b0fedc2412
MD5 4edef3fdc495bcc8ae577b73bf494774
BLAKE2b-256 63268d8f6a33ceb09a1e771e0fbe7c96dce2b01a7fa49913ec88d5e4f6502e89

See more details on using hashes here.

File details

Details for the file gt_telem-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: gt_telem-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 42.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.0

File hashes

Hashes for gt_telem-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 98012644b3a010f5ade3c79343f01f8cfc531707bc4391aa5baacb367eb9d677
MD5 c3f7f65f5290323f8871993414d05957
BLAKE2b-256 e717b9492a943c2d57e675391ef2a35ac7e624f562f4d183702ef143c9adc3eb

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page