Board index FlightGear Support Interfacing

Controlling FlightGear from Python

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

Controlling FlightGear from Python

Postby adityarajiv » Tue Jul 27, 2021 7:42 am

This topic contains posts split off from two other topics, Generic Protocol Input Control and Input generic protocol - doesn't work don't know why. Some posts may seem out of order.


Hello,
I want to send data to flight gear from a python application. The value of the air speed should be changed, that is what my target is. How to configure the xml file, and moreover how does flight gear understand that airspeed needs to be changed?
Last edited by Johan G on Tue Jul 27, 2021 4:24 pm, edited 2 times in total.
Reason: This topic contains posts split off from two topics, "Generic Protocol Input Control" and "Input generic protocol - doesn't work don't know why". Some posts may seem out of order.
adityarajiv
 
Posts: 10
Joined: Tue Jul 27, 2021 7:15 am

Controlling FlightGear from Python

Postby adityarajiv » Tue Jul 27, 2021 7:53 am

Hello,
I want to know how to send data to flight gear in such a way that a parameter value is changed, and this change is reflected in the property browser. For example, I have a python application and I want to change the airspeed value and send that to flight gear. How to configure the xml file, what commands due I need to give, and how to write the send to part in python socket program.

Please help me.
Last edited by Johan G on Tue Jul 27, 2021 4:07 pm, edited 2 times in total.
adityarajiv
 
Posts: 10
Joined: Tue Jul 27, 2021 7:15 am

Re: Generic Protocol Input Control

Postby erik » Tue Jul 27, 2021 7:56 am

The protocol is described here:
https://wiki.flightgear.org/Generic_protocol

But you might be misunderstanding how it should work:
Usually you do not set the airspeed in FlightGear but instead set the throttle to reach that airspeed.

Unless you want to use FlightGear just for visuals in which case you will need to start FlightGear with --fdm=null
But this requires you to also set everything else like position, orientation, etc.

Erik
Current: Parachutist, Paraglider, Pterosaur, Pilatus PC-9M and variants, ERCO Ercoupe, Fokker Dr.1, Fokker 50, Fokker 100
Less active: Cessna T-37, T-38, Santa Claus. Previous: General Dynamics F-16. Worked on: Wright Flyer
erik
 
Posts: 2244
Joined: Thu Nov 01, 2007 2:41 pm

Re: Generic Protocol Input Control

Postby adityarajiv » Tue Jul 27, 2021 8:57 am

So are you telling me that if I want to just see a change in airspeed in the property browser, i need to change the throttle?
Also how does flight gear read data?, as in how does it know which parameter value i am referring to. That part of code i dont know what to write
adityarajiv
 
Posts: 10
Joined: Tue Jul 27, 2021 7:15 am

Re: Generic Protocol Input Control

Postby wkitty42 » Tue Jul 27, 2021 2:00 pm

adityarajiv wrote in Tue Jul 27, 2021 8:57 am:So are you telling me that if I want to just see a change in airspeed in the property browser, i need to change the throttle?

yes, just like in a real craft or even like when flying a craft manually within the sim...

adityarajiv wrote in Tue Jul 27, 2021 8:57 am:Also how does flight gear read data?, as in how does it know which parameter value i am referring to. That part of code i dont know what to write

the data packets contain the IDs of the properties... read the link above and it should help to clarify things for 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: 9146
Joined: Fri Feb 20, 2015 4:46 pm
Location: central NC, USA
Callsign: wk42
Version: git next
OS: Kubuntu 20.04

Re: Input generic protocol - doesn't work don't know why

Postby Johan G » Tue Jul 27, 2021 3:53 pm

adityarajiv wrote in Tue Jul 27, 2021 7:53 am:I want to know how to send data to flight gear in such a way that a parameter value is changed, and this change is reflected in the property browser. For example, I have a python application and I want to change the airspeed value and send that to flight gear.

I think a good starting point showing some different options could be the FlightGear wiki article Interfacing FlightGear (permalink).
Low-level flying — It's all fun and games till someone looses an engine. (Paraphrased from a YouTube video)
Improving the Dassault Mirage F1 (Wiki, Forum, GitLab. Work in slow progress)
Some YouTube videos
Johan G
Moderator
 
Posts: 6629
Joined: Fri Aug 06, 2010 6:33 pm
Location: Sweden
Callsign: SE-JG
IRC name: Johan_G
Version: 2020.3.4
OS: Windows 10, 64 bit

Re: Controlling FlightGear from Python

Postby Hooray » Tue Jul 27, 2021 5:20 pm

if you want to change things like airspeed without using actuators/controls, then you are more likely interested in creating a new flight dynamics engine (FDM).
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 12707
Joined: Tue Mar 25, 2008 9:40 am
Pronouns: THOU

Re: Generic Protocol Input Control

Postby adityarajiv » Wed Jul 28, 2021 9:29 am

wkitty42 wrote in Tue Jul 27, 2021 2:00 pm:
adityarajiv wrote in Tue Jul 27, 2021 8:57 am:So are you telling me that if I want to just see a change in airspeed in the property browser, i need to change the throttle?

yes, just like in a real craft or even like when flying a craft manually within the sim...

adityarajiv wrote in Tue Jul 27, 2021 8:57 am:Also how does flight gear read data?, as in how does it know which parameter value i am referring to. That part of code i dont know what to write

the data packets contain the IDs of the properties... read the link above and it should help to clarify things for you...


can you please elaborate on data packets contains the IDs of the properties?
adityarajiv
 
Posts: 10
Joined: Tue Jul 27, 2021 7:15 am

Re: Generic Protocol Input Control

Postby wkitty42 » Wed Jul 28, 2021 4:17 pm

adityarajiv wrote in Wed Jul 28, 2021 9:29 am:can you please elaborate on data packets contains the IDs of the properties?

have you thoroughly read the above linked wiki page for the generic protocol? the details are in there... especially pay attention to how the xml is set up detailing the property and the values...


[edit] fixed bad quoting
Last edited by wkitty42 on Wed Aug 04, 2021 11:07 am, edited 1 time in total.
"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: 9146
Joined: Fri Feb 20, 2015 4:46 pm
Location: central NC, USA
Callsign: wk42
Version: git next
OS: Kubuntu 20.04

Re: Controlling FlightGear from Python

Postby vanosten » Wed Jul 28, 2021 4:45 pm

You can have a look at https://gitlab.com/vanosten/hunter/-/bl ... rcrafts.py. It is a primitive way of using Python to control a plane in an FG instance through Telnet and httpd.
Maintaining osm2city. Contributing with ground attack stuff to the OPRF FlightGear military-simulation community.
vanosten
 
Posts: 540
Joined: Sat Sep 25, 2010 6:38 pm
Location: Denmark - but I am Swiss
Pronouns: he/his
Callsign: HB-VANO
Version: latest
OS: Win 10 and Ubuntu

Re: Controlling FlightGear from Python

Postby adityarajiv » Thu Jul 29, 2021 5:15 am

vanosten wrote in Wed Jul 28, 2021 4:45 pm:You can have a look at https://gitlab.com/vanosten/hunter/-/bl ... rcrafts.py. It is a primitive way of using Python to control a plane in an FG instance through Telnet and httpd.


Thank you for your response. Can you tell me if I have to only send a value to change air speed then will the code be just:
self.fg_httpd.set_single_property('/velocities/airspeed-kt',new_value)
adityarajiv
 
Posts: 10
Joined: Tue Jul 27, 2021 7:15 am

Re: Controlling FlightGear from Python

Postby daweed » Thu Jul 29, 2021 3:44 pm

vanosten wrote in Wed Jul 28, 2021 4:45 pm:You can have a look at https://gitlab.com/vanosten/hunter/-/bl ... rcrafts.py. It is a primitive way of using Python to control a plane in an FG instance through Telnet and httpd.


You should use socket connexion TCP type , have a look to the socket module in python. If you just have to manage one or 2 properties, telnet class can do the job, but if you want to manage more, you should establish a permanent connexion between FG and your interface as socket does.

That the way i am using with my FG Interface [ have a look on the FG Wiki ]
I am using 2 protocol file [ 1 for input, 1 for output ] per interface [ ie per raspberry pi ]

Regards

Daweed
Windows 10 / Linux Mint 20
AMD Ryzen 7 3700X |32 Go RAM GeForce RTX 3070 Ti 8 Go
FG Interface
Lyon Saint Exupery Scenery

ATC on LFLL on Friday 19:00 UTC => 22:00 UTC
daweed
 
Posts: 398
Joined: Thu Dec 11, 2014 11:45 am
Location: LFKP LFLL
Callsign: daweed
OS: Linux Mint 20

Re: Controlling FlightGear from Python

Postby vanosten » Sat Jul 31, 2021 8:40 am

adityarajiv wrote in Thu Jul 29, 2021 5:15 am:
vanosten wrote in Wed Jul 28, 2021 4:45 pm:You can have a look at https://gitlab.com/vanosten/hunter/-/bl ... rcrafts.py. It is a primitive way of using Python to control a plane in an FG instance through Telnet and httpd.


Thank you for your response. Can you tell me if I have to only send a value to change air speed then will the code be just:
self.fg_httpd.set_single_property('/velocities/airspeed-kt',new_value)


Like has been said before: you cannot influence velocities etc. directly. You need to tell the plane what to do (e.g. more thrust or change an autopilot configuration) and then the simulation will lead to a change in velocity. Your change in e.g. thrust might not lead to the correct velocity, which is why you have to check the velocity after the change (with some lag time) and then based on that result again adapt the e.g. thrust.
Maintaining osm2city. Contributing with ground attack stuff to the OPRF FlightGear military-simulation community.
vanosten
 
Posts: 540
Joined: Sat Sep 25, 2010 6:38 pm
Location: Denmark - but I am Swiss
Pronouns: he/his
Callsign: HB-VANO
Version: latest
OS: Win 10 and Ubuntu

Re: Controlling FlightGear from Python

Postby Hooray » Sat Jul 31, 2021 9:39 am

right, stuff like /fdm, /orientation, /velocities, /position is conceptually "read-only" - unless you happen to be coding an FDM (scripted or not).

Otherwise, you will have to use input properties that are writable (route manager, autopilot, fdm inputs like aileron, rudder, thrust etc).

Typically, you cannot request a certain velocity that way, but you'd rather use a PID controller (autopilot)
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 12707
Joined: Tue Mar 25, 2008 9:40 am
Pronouns: THOU

Re: Controlling FlightGear from Python

Postby adityarajiv » Sun Aug 01, 2021 10:45 am

Hooray wrote in Sat Jul 31, 2021 9:39 am:right, stuff like /fdm, /orientation, /velocities, /position is conceptually "read-only" - unless you happen to be coding an FDM (scripted or not).

Otherwise, you will have to use input properties that are writable (route manager, autopilot, fdm inputs like aileron, rudder, thrust etc).

Typically, you cannot request a certain velocity that way, but you'd rather use a PID controller (autopilot)



Okay, I am understanding more now.
But what if I want to create a new node itself, say its called my_airspeed and send data value to it so that it is displayed in the property browser?.
I am able to make change in the protocol file and also the new node is shown in the property browser but not the value.
Socket is created socket binding has worked(udp socket). But the value is not being shown.
adityarajiv
 
Posts: 10
Joined: Tue Jul 27, 2021 7:15 am

Next

Return to Interfacing

Who is online

Users browsing this forum: No registered users and 3 guests