Board index FlightGear Support Interfacing

AI traffics data (especially ships)

Connecting two computers, using generic protocol, connecting with Matlab?

AI traffics data (especially ships)

Postby martial.chateauvieux » Mon Apr 15, 2019 1:49 pm

Hi all,
I would like to read the location information of all ships around my aircraft (let's say 20nm).
We have been using the standard xml interface to send udp messages to move some of them.
But the list of properties I can send over this interface is fixed, so I cannot have a dynamic list of ships around me.
so how do I get the list, and the id, position, speed of all the ships?

I did not find an answer in the forum of documentation. but please point me there if I missed it.
Thanks.
Martial
martial.chateauvieux
 
Posts: 5
Joined: Fri Apr 12, 2019 10:04 am

Re: AI traffics data (especially ships)

Postby wkitty42 » Sat Apr 20, 2019 12:06 am

you should be able to get/send updates in a batched round robin style... you would be simulating a radar sweep if you do it like i'm thinking about with your info above... update them after each sweep or portion of such...

you can ignore the following if it doesn't apply...

i say the above but i'm also kinda confused... are you speaking of your own AI craft you are moving about via the MP protocol or are you talking about detecting AI craft flying about and being controlled by the sim's built-in traffic manager? i know you can get a list of craft around you that are there via MP or via the traffic manager... i do so via a python script to request and pull the data... once the data arrives, it is formatted for the ASCII text screen i'm viewing it with on my terminal... in reality, right now, my script is only pulling the AI traffic from the traffic manager but i should be able to add another property branch and get the others just as easily...

anyway, that's what i do to display/detect other craft within the default 100nm or 200nm (i forget which) of my location... i don't know the math, yet, to take those location values i get and convert them to a bearing and distance but that may be something i do when i get back to flying again... right now, i'm not even trying to plot them... just displaying them...
"You get more air close to the ground," said Angalo. "I read that in a book. You get lots of air low down, and not much when you go up."
"Why not?" said Gurder.
"Dunno. It's frightened of heights, I guess."
User avatar
wkitty42
 
Posts: 5577
Joined: Fri Feb 20, 2015 3:46 pm
Location: central NC, USA
Callsign: wk42
Version: git next
OS: Kubuntu 14.04.5

Re: AI traffics data (especially ships)

Postby Thorsten » Sat Apr 20, 2019 5:04 am

i don't know the math, yet, to take those location values i get and convert them to a bearing and distance but that may be something i do when i get back to flying again.


It's pretty much all available in geo.nas

Code: Select all

var myPos = geo.aircraft_position();

var otherPos = geo.Coord.new();
otherPos.set_latlon(latitude, longitude);

var bearing = myPos.course_to(otherPos);
var distance = myPos.distance_to(otherPos);

Thorsten
 
Posts: 10844
Joined: Mon Nov 02, 2009 8:33 am

Re: AI traffics data (especially ships)

Postby wkitty42 » Sat Apr 20, 2019 10:32 am

yeah but i can't get to that nasal code from python ;)

it was a bit of a ramble... not even sure if it will help the OP...
"You get more air close to the ground," said Angalo. "I read that in a book. You get lots of air low down, and not much when you go up."
"Why not?" said Gurder.
"Dunno. It's frightened of heights, I guess."
User avatar
wkitty42
 
Posts: 5577
Joined: Fri Feb 20, 2015 3:46 pm
Location: central NC, USA
Callsign: wk42
Version: git next
OS: Kubuntu 14.04.5

Re: AI traffics data (especially ships)

Postby martial.chateauvieux » Tue Apr 23, 2019 8:31 pm

wkitty42 wrote in Sat Apr 20, 2019 12:06 am:i say the above but i'm also kinda confused... are you speaking of your own AI craft you are moving about via the MP protocol or are you talking about detecting AI craft flying about and being controlled by the sim's built-in traffic manager? i know you can get a list of craft around you that are there via MP or via the traffic manager...


I think about the traffics (ships on the sea) which are already in the sim. Probably from the traffic manager as I do not have anything talking or running the MP protocol (as far as i'm aware).

I need to somehow send their coordinates (basically the equivalent of the AIS transponder) and may be more information (attitude) to something that can receive UDP messages.
martial.chateauvieux
 
Posts: 5
Joined: Fri Apr 12, 2019 10:04 am

Re: AI traffics data (especially ships)

Postby wkitty42 » Wed Apr 24, 2019 4:13 pm

the properties for the AI/MP craft are found in the sim's property tree starting at node /ai/models... to see what's there while you are in the sim, hit the '/' key to bring up the property tree dialog... then navigate to the given node and have a look around at what's there...

how to access the data from outside of the sim is another matter... i have a small python script that pulls the data from the configured sim http server... it pulls the data in JSON format and emits the values in a table on the command line terminal screen... if you are interested, i can share it... it isn't pretty but it works well for what i do...

the main thing is to get the data in a format you can handle... from there, what you do with it is up to you...
"You get more air close to the ground," said Angalo. "I read that in a book. You get lots of air low down, and not much when you go up."
"Why not?" said Gurder.
"Dunno. It's frightened of heights, I guess."
User avatar
wkitty42
 
Posts: 5577
Joined: Fri Feb 20, 2015 3:46 pm
Location: central NC, USA
Callsign: wk42
Version: git next
OS: Kubuntu 14.04.5

Re: AI traffics data (especially ships)

Postby Gijs » Wed Apr 24, 2019 4:22 pm

Are you sure they are actually AI controlled? Note that we have static ships that are randomly positioned on water surfaces (see data/Materials/base/water.xml for the settings).
Airports: EHAM, EHLE, KSFO
Aircraft: 747-400
User avatar
Gijs
Moderator
 
Posts: 9363
Joined: Tue Jul 03, 2007 2:55 pm
Location: Amsterdam/Delft, the Netherlands
Callsign: PH-GYS
Version: Git
OS: Windows 10

Re: AI traffics data (especially ships)

Postby wkitty42 » Wed Apr 24, 2019 4:39 pm

yeah, what Gijs said... some ships are simply static models in place with wake flow added to make them appear to be moving... there is one at 0,0 if i recall correctly...
"You get more air close to the ground," said Angalo. "I read that in a book. You get lots of air low down, and not much when you go up."
"Why not?" said Gurder.
"Dunno. It's frightened of heights, I guess."
User avatar
wkitty42
 
Posts: 5577
Joined: Fri Feb 20, 2015 3:46 pm
Location: central NC, USA
Callsign: wk42
Version: git next
OS: Kubuntu 14.04.5

Re: AI traffics data (especially ships)

Postby martial.chateauvieux » Tue Apr 30, 2019 8:13 am

Oooh! Now that you say it. yes they are indeed static!
Are the AI ships then only the one I can select in the AI menu?
What about the static ones? could I get their position and move them?
Thanks
Martial
martial.chateauvieux
 
Posts: 5
Joined: Fri Apr 12, 2019 10:04 am

Re: AI traffics data (especially ships)

Postby martial.chateauvieux » Tue Apr 30, 2019 8:22 am

wkitty42 wrote in Wed Apr 24, 2019 4:13 pm:the properties for the AI/MP craft are found in the sim's property tree starting at node /ai/models... to see what's there while you are in the sim, hit the '/' key to bring up the property tree dialog... then navigate to the given node and have a look around at what's there...

We found that. we also figured out how to read that from the standard protocol and modify the values, so we can have our own ships moving around.
But of course I don't need to have MY ships if there are enough around already... I just need to figure out where I get the information...

wkitty42 wrote in Wed Apr 24, 2019 4:13 pm:how to access the data from outside of the sim is another matter... i have a small python script that pulls the data from the configured sim http server... it pulls the data in JSON format and emits the values in a table on the command line terminal screen... if you are interested, i can share it... it isn't pretty but it works well for what i do...

the main thing is to get the data in a format you can handle... from there, what you do with it is up to you...


Yes, I think that will be useful if you can share this.
martial.chateauvieux
 
Posts: 5
Joined: Fri Apr 12, 2019 10:04 am

Re: AI traffics data (especially ships)

Postby wkitty42 » Tue Apr 30, 2019 5:11 pm

it ain't pretty but it is my brother :)

i generally run it and then grep for the info i'm looking for... an example would be if i want to list all craft headed to KRDU...

eg: arriveAirport KRDU

the following script is one long line...

arriveAirport
Code: Select all
~/myflightgear/getcraft.py | head -n 3 ; ~/myflightgear/getcraft.py | egrep -e "^/.*{1,26} .*{1,5} .*{1,26} [[:alpha:]]{4} [[:digit:]]{4}-[[:digit:]]{2}-[[:digit:]]{2} [[:digit:]]{2}:[[:digit:]]{2}:[[:digit:]]{2} Z $1 [[:digit:]]{4}-[[:digit:]]{2}-[[:digit:]]{2} [[:digit:]]{2}:[[:digit:]]{2}:[[:digit:]]{2} Z" | sort -k 5,6


getcraft.py
Code: Select all
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Copyright (C) 2017  Waldo Kitty (wkitty42)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
#
# getcraft.py - gather and output the craft nodes for AI/MP craft
#

import requests
import json
import datetime
#import os

# this is the user agent string we're using so the script doesn't set off IDS/IPS tools by using the default user agent string.
myUA = 'getcraft.py/0.0.3'

# the following is the system and port the http server is running on in FG.
# use the same port number as your --http= option line uses.
# 127.0.0.1 is your system running FG. it could be another system on the network.
# host names or IP numbers are valid
myURL = 'http://127.0.0.1:5500/json/ai/models/'

# this depth parameter defines how deep into each node the data will be pulled from.
myDepth = '3'
myURLoptions = { 'd': myDepth, 'i': 'y' }
myHeaders = { 'user-agent': myUA }                                                                                                                                                                                         
                                                                                                                                                                                                                           
r = requests.get(myURL, params=myURLoptions, headers=myHeaders)                                                                                                                                                             
                                                                                                                                                                                                                           
# Easiest-to-read representation of the JSON data                                                                                                                                                                           
# with open(os.path.expanduser("~/flightgear/tmp/json-wkitty.out"), "w") as f:                                                                                                                                             
#     f.write(r.text)                                                                                                                                                                                                       
                                                                                                                                                                                                                           
#print(type(r.json()), end="\n\n") # What type of object is r.json()?                                                                                                                                                       
                                                                                                                                                                                                                           
modelsNode = r.json()                                                                                                                                                                                                       
# General pretty-printing, but not very readable here because of the order used                                                                                                                                             
# when printing the contents of a dict:                                                                                                                                                                                     
# import pprint                                                                                                                                                                                                             
# pprint.pprint(modelsNode)

assert modelsNode["path"] == "/ai/models", \
    "unexpected root node: {!r}".format(modelsNode)

# these next two lines are each long lines
print("\n{0:26} {1:5} {2:26} {3:4} {4:21} {5:4} {6:21} {7:4} {8:13} {9:13} {10:13} {11:13} {12:13}".format("Property Path", "ID", "CallSign", "Dptr", "Time      ", "Arvl", "Time      ", "Sqwk", "Airspeed KTS", "Climb FPS", "AltSeaLvl", "Latitude", "Longitude"))
print("========================== ===== ========================== ==== ===================== ==== ===================== ==== ============= ============= ============= ============= =============")
for modelsChild in modelsNode["children"]:
  if modelsChild["name"] == "multiplay":
#    print("\nAircraft node: {}".format(modelsChild["path"]))
    myCraftPath = modelsChild["path"]
    myCraftDepTimeZ = datetime.datetime.utcfromtimestamp(0)
    myCraftArrTimeZ = datetime.datetime.utcfromtimestamp(0)
    for node in modelsChild["children"]:
      if node["name"] == "valid":
        myCraftValid = node["value"]
      if node["name"] == "id":
        myCraftId = node["value"]
      if node["name"] == "callsign":
        myCraftCallsign = node["value"]
      if node["name"] == "departure-airport-id":
        myCraftDepAP = node["value"]
      if node["name"] == "departure-time-sec":
        myCraftDepTimeZ = datetime.datetime.utcfromtimestamp(node["value"])
      if node["name"] == "arrival-airport-id":
        myCraftArrAP = node["value"]
      if node["name"] == "arrival-time-sec":
        myCraftArrTimeZ = datetime.datetime.utcfromtimestamp(node["value"])
      if node["name"] == "transponder-id":
        myCraftTransponder = node["value"]
      if node["name"] == "position":
        for nodeChild in node["children"]:
          if nodeChild["name"] == "altitude-ft":
            myCraftAltitude = nodeChild["value"]
          if nodeChild["name"] == "latitude-deg":
            myCraftLatitude = nodeChild["value"]
          if nodeChild["name"] == "longitude-deg":
            myCraftLongitude = nodeChild["value"]
      if node["name"] == "velocities":
        for nodeChild in node["children"]:
          if nodeChild["name"] == "true-airspeed-kt":
            myCraftSpeed = nodeChild["value"]
          if nodeChild["name"] == "vertical-speed-fps":
            myClimbRate = nodeChild["value"]

  if modelsChild["name"] == "aircraft":
#    print("\nAircraft node: {}".format(modelsChild["path"]))
    myCraftPath = modelsChild["path"]
    myCraftDepTimeZ = datetime.datetime.utcfromtimestamp(0)
    myCraftArrTimeZ = datetime.datetime.utcfromtimestamp(0)
    for node in modelsChild["children"]:
      if node["name"] == "valid":
        myCraftValid = node["value"]
      if node["name"] == "id":
        myCraftId = node["value"]
      if node["name"] == "callsign":
        myCraftCallsign = node["value"]
      if node["name"] == "departure-airport-id":
        myCraftDepAP = node["value"]
      if node["name"] == "departure-time-sec":
        myCraftDepTimeZ = datetime.datetime.utcfromtimestamp(node["value"])
      if node["name"] == "arrival-airport-id":
        myCraftArrAP = node["value"]
      if node["name"] == "arrival-time-sec":
        myCraftArrTimeZ = datetime.datetime.utcfromtimestamp(node["value"])
      if node["name"] == "transponder-id":
        myCraftTransponder = node["value"]
      if node["name"] == "position":
        for nodeChild in node["children"]:
          if nodeChild["name"] == "altitude-ft":
            myCraftAltitude = nodeChild["value"]
          if nodeChild["name"] == "latitude-deg":
            myCraftLatitude = nodeChild["value"]
          if nodeChild["name"] == "longitude-deg":
            myCraftLongitude = nodeChild["value"]
      if node["name"] == "velocities":
        for nodeChild in node["children"]:
          if nodeChild["name"] == "true-airspeed-kt":
            myCraftSpeed = nodeChild["value"]
          if nodeChild["name"] == "vertical-speed-fps":
            myClimbRate = nodeChild["value"]

    if myCraftValid:
      # this next line is one long line
      print("{0:26} {1:5} {2:26} {3:4} {4:%Y-%m-%d %H:%M:%S} Z {5:4} {6:%Y-%m-%d %H:%M:%S} Z {7:4} {8:13} {9:13} {10:13} {11:13} {12:13}".format(myCraftPath, myCraftId, myCraftCallsign, myCraftDepAP, myCraftDepTimeZ, myCraftArrAP, myCraftArrTimeZ, myCraftTransponder, myCraftSpeed, myClimbRate, myCraftAltitude, myCraftLatitude, myCraftLongitude))

#  else:
#    print("Skipping over node '{}'".format(modelsChild["path"]))

"You get more air close to the ground," said Angalo. "I read that in a book. You get lots of air low down, and not much when you go up."
"Why not?" said Gurder.
"Dunno. It's frightened of heights, I guess."
User avatar
wkitty42
 
Posts: 5577
Joined: Fri Feb 20, 2015 3:46 pm
Location: central NC, USA
Callsign: wk42
Version: git next
OS: Kubuntu 14.04.5


Return to Interfacing

Who is online

Users browsing this forum: No registered users and 0 guests