Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get data from other SimObjects? #78

Open
Revel8804 opened this issue Jan 7, 2021 · 7 comments
Open

Get data from other SimObjects? #78

Revel8804 opened this issue Jan 7, 2021 · 7 comments

Comments

@Revel8804
Copy link

I am trying to pull the data from other SimObjects, such as AI aircraft.

I can use the simvar watcher sample program, to see that the data can be pulled. Just not sure how to do that with this program

@odwdinc
Copy link
Owner

odwdinc commented Jan 7, 2021

Not really 100% on what you are asking for.
is this related? #62

Just to confirm "simvar watcher sample program"

MSFS SDK\Samples\SimvarWatcher\bin\x64\Release\Simvars.exe

Can you prove sample of how you receive the data in Simvars.exe
or better yet can you save and share the .simvars file.

@Revel8804
Copy link
Author

Sorry I will try to be more clear. I was going through a lot of documents when I wrote the original question.

Yes the SimVar watcher program is the one from

MSFS SDK\Samples\SimvarWatcher\bin\x64\Release\Simvars.exe

Here is a screenshot of an example
image

So in the screenshot I am pulling the PLANE ALTITUDE, PLANE HEADING DEGREES TRUE, PLANE LATITUDE and PLANE LONGITUDE of Aircraft SimObject 2607.

I would like to be able to pull that same data into the Python_SimConnect

@odwdinc
Copy link
Owner

odwdinc commented Jan 7, 2021

Ok I may be able to help, how do you get the SimObject ObjectID?

@odwdinc
Copy link
Owner

odwdinc commented Jan 7, 2021

I think this is what you are looking for. Could you test the code below with the code form Tree

https://github.com/odwdinc/Python-SimConnect/tree/AI-SimObject-Data-Test

from SimConnect import *
import logging
from SimConnect.Enum import *
from time import sleep

logging.basicConfig(level=logging.DEBUG)
LOGGER = logging.getLogger(__name__)
LOGGER.info("START")

# creat simconnection and pass used user classes
sm = SimConnect()
aq = AircraftRequests(sm)

AI_OBJECT_ID = 2607
pa = aq.find("PLANE_ALTITUDE")
pa.OBJECT_ID = AI_OBJECT_ID

phdyt = aq.find("PLANE_HEADING_DEGREES_TRUE")
phdyt.OBJECT_ID = AI_OBJECT_ID

pla = aq.find("PLANE_LATITUDE")
pla.OBJECT_ID = AI_OBJECT_ID

plo = aq.find("PLANE_LONGITUDE")
plo.OBJECT_ID = AI_OBJECT_ID


while not sm.quit:
	print("PLANE ALTITUDE:", pa.value)
	print("PLANE HEADING DEGREES TRUE:", phdyt.value)
	print("PLANE LATITUDE:", pla.value)
	print("PLANE LONGITUDE:", plo.value)
	sleep(2)

sm.exit()
quit()

@Revel8804
Copy link
Author

Ok I may be able to help, how do you get the SimObject ObjectID?

I am going to test that now.

Right now though I am getting the SImObjectID from ...
Enable Dev Mode then Options -> Sim Objects.
It will show all the objects in a certain area around you.

@Revel8804
Copy link
Author

from SimConnect import *
import logging
from SimConnect.Enum import *
from time import sleep

logging.basicConfig(level=logging.DEBUG)
LOGGER = logging.getLogger(__name__)
LOGGER.info("START")

# creat simconnection and pass used user classes
sm = SimConnect()
aq = AircraftRequests(sm)

AI_OBJECT_ID = 2607
pa = aq.find("PLANE_ALTITUDE")
pa.OBJECT_ID = AI_OBJECT_ID

phdyt = aq.find("PLANE_HEADING_DEGREES_TRUE")
phdyt.OBJECT_ID = AI_OBJECT_ID

pla = aq.find("PLANE_LATITUDE")
pla.OBJECT_ID = AI_OBJECT_ID

plo = aq.find("PLANE_LONGITUDE")
plo.OBJECT_ID = AI_OBJECT_ID


while not sm.quit:
	print("PLANE ALTITUDE:", pa.value)
	print("PLANE HEADING DEGREES TRUE:", phdyt.value)
	print("PLANE LATITUDE:", pla.value)
	print("PLANE LONGITUDE:", plo.value)
	sleep(2)

sm.exit()
quit()

FANTASTIC that is working.
PLANE HEADING DEGREES TRUE: 0.5611127944972876 PLANE LATITUDE: 32.07699151244722 PLANE LONGITUDE: -101.56553905217461 PLANE ALTITUDE: 2512.946367107889 PLANE HEADING DEGREES TRUE: 0.5611127944972876 PLANE LATITUDE: 32.07699151244722 PLANE LONGITUDE: -101.56553905217461 PLANE ALTITUDE: 2512.946367107889 PLANE HEADING DEGREES TRUE: 0.5611127944972876 PLANE LATITUDE: 32.07699151244722 PLANE LONGITUDE: -101.56553905217461 PLANE ALTITUDE: 2512.946367107889 PLANE HEADING DEGREES TRUE: 0.5611127944972876 PLANE LATITUDE: 32.07699151244722 PLANE LONGITUDE: -101.56553905217461 PLANE ALTITUDE: 2512.946367107889 PLANE HEADING DEGREES TRUE: 0.5611127944972876 PLANE LATITUDE: 32.07699151244722 PLANE LONGITUDE: -101.56553905217461

Now to add on to that I would like to be able to do something like (Not great at python yet. I may not be using the correct language, but i hope you get the point.)
for x in AI_OBJECT_ID.AIRPLANE long = aq.find("PLANE_LATITUDE")
lat = aq.find("PLANE_LONGITUDE")

Then I can have the Coordinates or each plane to plot on the map.

@odwdinc
Copy link
Owner

odwdinc commented Jan 8, 2021

I working out how to get the list of ID's in python.

what I can tell form the documentation.
OBJECT_ID = 1 is the users aircraft

Next to get a list of id's it looks like we need to call SimConnect_RequestDataOnSimObjectType

Remarks
The data will be returned on all the relevant objects within the specified radius, but they will not be returned in any specific order. It is the responsibility of the client program to sort the returned data into order, if that is required. Information is returned in a SIMCONNECT_RECV_SIMOBJECT_DATA_BYTYPE structure, one structure per object.

For testing I set up this request.
Data definition: PLANE ALTITUDE
SIMCONNECT_SIMOBJECT_TYPE: AIRCRAFT
RadiusMeters: 200000
I sleep for 5s to collect data.
putting a logger on the SIMCONNECT_RECV_SIMOBJECT_DATA_BYTYPE
only seems to return 2-3 objects :( not the 20 -30 form SimVar watcher...

from SimConnect import *
import logging
from SimConnect.Enum import *
from time import sleep

logging.basicConfig(level=logging.DEBUG)
LOGGER = logging.getLogger(__name__)
LOGGER.info("START")

# creat simconnection and pass used user classes
sm = SimConnect()
aq = AircraftRequests(sm)
pa = aq.find("PLANE_ALTITUDE")
pa._deff_test()

sm.dll.RequestDataOnSimObjectType(
	sm.hSimConnect,
	pa.DATA_REQUEST_ID.value,
	pa.DATA_DEFINITION_ID.value,
	DWORD(200000),
	SIMCONNECT_SIMOBJECT_TYPE.SIMCONNECT_SIMOBJECT_TYPE_AIRCRAFT,
)
temp = DWORD(0)
sm.dll.GetLastSentPacketID(sm.hSimConnect, temp)
pa.LastID = temp.value

sleep(5)

sm.exit()
quit()

For now you can hard-set with code below.

Note: fill AI_OBJECT_ID_LIST with list of the ID's you want to check.

from SimConnect import *
import logging
from SimConnect.Enum import *
from time import sleep

logging.basicConfig(level=logging.DEBUG)
LOGGER = logging.getLogger(__name__)
LOGGER.info("START")

# creat simconnection and pass used user classes
sm = SimConnect()
aq = AircraftRequests(sm)


pa = aq.find("PLANE_ALTITUDE")
phdyt = aq.find("PLANE_HEADING_DEGREES_TRUE")
pla = aq.find("PLANE_LATITUDE")
plo = aq.find("PLANE_LONGITUDE")


AI_OBJECT_ID_LIST = [1, 2607]

while not sm.quit:
	for ob_id in AI_OBJECT_ID_LIST:
		plo.OBJECT_ID = ob_id
		pla.OBJECT_ID = ob_id
		phdyt.OBJECT_ID = ob_id
		pa.OBJECT_ID = ob_id
		print("PLANE ALTITUDE:", pa.value)
		print("PLANE HEADING DEGREES TRUE:", phdyt.value)
		print("PLANE LATITUDE:", pla.value)
		print("PLANE LONGITUDE:", plo.value)
		sleep(2)

sm.exit()
quit()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants