Get traffic information #559
-
|
Hi eveyone, from bluesky import traf
def traffic(self):
retry_count = 0
while traf is None and retry_count < 5:
print("'traf' object is not available yet. Retrying in 2 seconds...")
time.sleep(2)
retry_count += 1
if traf is None:
print("Could not initialize 'traf' after several attempts.")
return
for i in range(traf.ntraf):
callsign = traf.id[i]
...
When I run the simulator and create some airplanes, traf remains None. I can see the airplanes in the simulator’s GUI and even get their info via the POS command, but my agent doesn't seem to pick up any traffic data through traf. Is this import method correct, or is there something I need to adjust in the initialization or configuration of BlueSky to ensure that traf is properly populated? Has anyone experienced a similar issue or found a workaround for accessing traffic data in a shared process? I also ensured that the simulation was running and the execution mode was render. Any help would be greatly appreciated. Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
|
Hi @Santisoutoo, The problem you are encountering is that on first import, no objects within import bluesky as bs
def traffic(self):
for i in range(bs.traf.ntraf):
callsign = traf.id[i]
...Note that this approach is not necessary in plugins, as these are only imported after bluesky is initialised, so by then all simulation objects exist. |
Beta Was this translation helpful? Give feedback.
-
|
Thanks for your response, @jooste. |
Beta Was this translation helpful? Give feedback.
Hi @Santisoutoo,
The problem you are encountering is that on first import, no objects within
blueskyare initialised yet, so when you dofrom bluesky import traf, all you get isNone. The way to avoid this is by importing the module instead of only specific objects from the module:Note that this approach is not necessary in plugins, as these are only imported after bluesky is initialised, so by then all simulation objects exist.