Board index FlightGear Support Interfacing

Auto Control of aircraft via UDP

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

Auto Control of aircraft via UDP

Postby aero.vish30 » Mon Apr 05, 2021 12:41 pm

Hello,

I am currently working to integrate a small functionality where on detecting a specific altitude number i want to move the aircraft up or down. I am using generic protocol file and UDP connections in Matlab (also where my custom logic resides). i am using this :

Code: Select all
--generic=socket,out,10,127.0.0.1,510853,udp,testCom
--generic=socket,in,10,127.0.0.1,510308,udp,testCom


and
my genric protocol have two sections - input and output (output works fine as i am able to fetch the required data)
Input is :
Code: Select all
<PropertyList>
 <generic>
    
    <input>

            <binary_mode>false</binary_mode>
           <line_separator>newline</line_separator>
           <var_separator>:</var_separator>

      <chunk>
         <name>pitch-deg</name>
         <type>float</type>
         <node>/orientation/pitch-deg</node>
      </chunk>
       
      <chunk>
         <name>pitch-trim</name>
         <type>float</type>
         <node>/controls/flight/elevator-trim</node>
      </chunk>
       
        <chunk>
         <name>pitch-ip</name>
         <type>float</type>
         <node>/controls/flight/elevator</node>
      </chunk>
      
    </input>




But i am not able to control the aircraft the way I want. What now I want ot understand is how can i override the Yoke / pilot input to control the pitch of the aircraft ?
aero.vish30
 
Posts: 3
Joined: Wed Mar 17, 2021 5:25 am

Re: Auto Control of aircraft via UDP

Postby zakalawe » Tue Apr 06, 2021 11:37 am

Writing to a controls property likely won't work because the joystick (or mouse) is also writing to them. This depends exactly on your use case however. There are ways to move the aircraft in space (reposition, effectively), but it you want to make control inputs, I'd look at customising the autopilot (for your selected aircraft): when the autopilot is active, it could make control inputs like you're proposing above.

Of course, it's possible to have an external process drive the /controls property, so long as FlightGear itself isn't changing them. But that would normally for be FG as a viewer for some other FDM/simulation, I think.
zakalawe
 
Posts: 1259
Joined: Sat Jul 19, 2008 5:48 pm
Location: Edinburgh, Scotland
Callsign: G-ZKLW
Version: next
OS: Mac

Re: Auto Control of aircraft via UDP

Postby aero.vish30 » Tue Apr 06, 2021 2:42 pm

I am trying to research into a functionality similar to auto GCAS, where i would need to override pilot inputs in case pilot is not functioning, irrespective of AP is on or not.

Could you help me understand the customization that you mentioned - what modifications are needed. Since i am new to FG sim , wanted to know if there is something possible by writing NASAL code for this ? or any example which i use to create my own nas file ?
aero.vish30
 
Posts: 3
Joined: Wed Mar 17, 2021 5:25 am

Re: Auto Control of aircraft via UDP

Postby jano » Wed Apr 07, 2021 1:17 pm

Hi,
instead of trying to overwrite the control properties directly from the input protocol, you can add new properties like matlab-elevator-control, and a bool like "matlab-in-control" telling fg you take control and add property rules with condition logic based on your boolean. this can be a jsbsim system if you use a plane with a jsbsim fdm.
about property rules or autopilot configuration:
https://wiki.flightgear.org/Autopilot_c ... _reference

you may need to change the props used as elevator input for the fdm to match the output of your condition filter

jano
jano
 
Posts: 221
Joined: Fri Nov 30, 2007 12:32 am
Location: france
Callsign: jano
Version: git
OS: debian SID

Re: Auto Control of aircraft via UDP

Postby erik » Wed Apr 07, 2021 1:31 pm

Indeed, within a flight control system it would be possible to add up the different input method properties to a total sum which is used for the actual control position. You could use something similar to sum two properties to drive the elevator.

But this is FDM and aircraft dependent as to how to implement it.

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: Auto Control of aircraft via UDP

Postby kwikius » Sun May 30, 2021 11:15 am

To send control inputs you need to disable joystick input.
$< fgfs --prop:/input/joysticks/js[0]=0 ...

Now you can write the control properties using telnet interface (for example). Telnet is demonstrated nicely by example at:
https://sourceforge.net/p/flightgear/fl ... client.cxx

You can also browse the FlightGear property tree by telnet at command line to see what is there (also updates in real time, here 50 times per sec)
$< fgfs --telnet=socket,bi,50,localhost,5501,tcp ...

$< telnet localhost 5501

# now use ls, cd etc to find what is in the tree

Example ( derived from the above example) to control FlightGear by external app here, where I can control the aircraft externally.
https://github.com/kwikius/fg_ext_fdm/b ... in.cpp#L49
There I just send control values from joystick but obviously now you can inject values from whatever you want by your own app!

In case of aileron, elevator, rudder Flighgear values range from -1 to 1.
for throttle I think range is 0 to 1.
kwikius
 
Posts: 7
Joined: Fri May 28, 2021 10:24 pm


Return to Interfacing

Who is online

Users browsing this forum: No registered users and 3 guests