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 that runs the client on a separate thread:

from gt_telem import TurismoClient
from time import sleep

tc = TurismoClient()

tc.start()
for i in range(10):
    sleep(1)
    print(tc.telemetry.position)
tc.stop()

If you're working inside of an asynchronous framework, use run_async()

from gt_telem import TurismoClient

class MyAsyncClass:
    def __init__(self, tc: TurismoClient):
        self.tc = tc
        self.cancel_tkn: asyncio.Event = None

    async def start_telem(self):
        await self.tc.run_async(self.cancel_tkn)

Otherwise run like this if you only care for callbacks:

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() #blocking call

The full list of telemetry is available here.

Events

The following events are currently supported:

  • gt_telem.events.GameEvents
    • on_running - The game has started/is running
    • on_in_game_menu - Outside of a race or track screen
    • on_at_track - Player has entered a track screen
    • on_in_race - Fired when the simulation starts, before player control
    • on_paused - When the player pauses the race
    • on_race_end - Fires when a player leaves the simulation
  • gt_telem.events.RaceEvents
    • on_race_start - Fired at the beginning of Lap 1
    • on_race_finish - Fired when the last lap is completed (checkered flag)
    • on_lap_change - Fires when the lap counter changes (including 0->1)
    • on_best_lap_time - A new best lap is set
    • on_last_lap_time - A new last lap time is available
  • gt_telem.events.DriverEvents
    • on_gear_change - A gear has changed
    • on_flash_lights - High Beams have been activated
    • on_handbrake - Player has utilized handbrake
    • on_suggested_gear - Fires when the game suggests a gear change
    • on_tcs - Traction Control System activated
    • on_asm - Active Stability Management activated
    • on_rev_limit - Engine revs exceed threshold
    • on_brake - Player depresses brake
    • on_throttle - Player depresses throttle
    • on_shift_light_low - Engine revs entered lower bound for shift light
    • on_shift_light_high - Engine revs exceed upper bound for shift light

Example using 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)
        exit()
    except PlayStationNotFoundError as e:
        print("Maybe I'm on the wrong network")
        print(e)
        exit()
    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.

Advanced Example

See this jupyter notebook that displays a live race view and how to properly pass a token to shut down gracefully.

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.9.tar.gz (54.9 kB view details)

Uploaded Source

Built Distribution

gt_telem-0.2.9-py3-none-any.whl (43.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: gt-telem-0.2.9.tar.gz
  • Upload date:
  • Size: 54.9 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.9.tar.gz
Algorithm Hash digest
SHA256 a690b5e26c11d04e14bc3fb56a7b6f43a7b4c7690fc5038a7b23943fe5a32a0f
MD5 3612819f44163f1aba93a4af985aa637
BLAKE2b-256 3c090636df3bc4fe9bb4c738ae3dbd4a3a9a8174c11f725df47815649f4bbeee

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gt_telem-0.2.9-py3-none-any.whl
  • Upload date:
  • Size: 43.9 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.9-py3-none-any.whl
Algorithm Hash digest
SHA256 31f2a7b97dc2986b885c96ccd496dd51db24ddf43709f13f333d057b5437ff75
MD5 042731af24c569d74f6a126a0e630628
BLAKE2b-256 36c879939e04c5c869ca748a8e587cff4f960fa581a911b1e39f95eefe7deb7e

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