rrennoir / PyAccSharedMemory

ACC shared memory reader written in python
MIT License
40 stars 6 forks source link

car_coordinates #8

Open rajuramlall opened 9 months ago

rajuramlall commented 9 months ago

Hello, I'm running an Assetto Corsa Server and would like to get the coordinates of all cars on the track. I call for car_coordinates and it returns a [60][3] list, however, only the first entry is populated. It only returns the coordinates of one car (corresponding to the machine I'm running the script on). The rest of entries are zeros or nan. Is there a way to get the coordinates of all the cars on the track?

-raju

andreasntr commented 6 months ago

hi, can you show your code?

I'm actually able to retrieve all the cars' coordinates when my car is not in the pit menu:

from pyaccsharedmemory import accSharedMemory
from time import sleep
import numpy as np

asm = accSharedMemory()

sm = asm.read_shared_memory()
num_cars = sm.Static.num_cars
car_ids = list(map(str, sm.Graphics.car_id[:num_cars]))

step = 0.1 #seconds
minutes_to_keep = 5

for _ in np.arange(0, int(minutes_to_keep*60), step):
    sm = asm.read_shared_memory()

    if (sm is not None):
        car_coords = sm.Graphics.car_coordinates[:num_cars]
        # do something
    else:
      break
    sleep(step)