Board index FlightGear Support Interfacing

Generic Protocol Input Control

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

Generic Protocol Input Control

Postby joef1993 » Fri Jan 06, 2017 2:16 pm

I'm attempting to set the throttle level value through generic protocol input. The contents of the protocol file are:

Code: Select all
<PropertyList>
<generic>
    <input>
      <line_separator>newline</line_separator>
      <var_separator>tab</var_separator>
       
      <chunk>
         <node>/controls/engines/engine/throttle</node>
         <type>double</type>
         <format>%f</format>
      </chunk>
      
   </input>
</generic>
</PropertyList>


I start flightgear with the following:

Code: Select all
fgfs --generic=socket,in,1,127.0.0.1,52867,udp,UDP_Write


And the program I run with Matlab is:

Code: Select all
u = udp('localhost',52867,'localport',5000);
fopen(u);

while(1)
fwrite(u, '0.55');
end


I can see the value 0.55 being output using sockettest, but the value does not change in FG. From reading through threads on similar topics I understand that the physical throttle controller may be overriding the value read into FG, is that the case here? Is there a simple way to check that the protocol is working, perhaps a different variable?
joef1993
 
Posts: 12
Joined: Wed Oct 19, 2016 11:08 am

Re: Generic Protocol Input Control

Postby curt » Fri Jan 06, 2017 3:10 pm

In your protocol xml file you could change the <node> value from /controls/engines/engine/throttle to something like <node>/my-throttle</node>

Then use the property browser to see if that value is being updated. I wouldn't expect FlightGear to override the external throttle setting unless you have a joystick plugged in or some other internal autopilot active and running.

Best regards,

Curt.
Aerospace Engineering and Mechanics
University of Minnesota
curt
Administrator
 
Posts: 1168
Joined: Thu Jan 01, 1970 1:00 am
Location: Minneapolis, MN

Re: Generic Protocol Input Control

Postby joef1993 » Sat Jan 07, 2017 1:45 pm

Hi Curt,

Thanks for your reply. Having changed the node to your example, it now shows up in the property browser so I know the protocol is being loaded correctly. I've then tried to output the values to FG but it does not show, so I'm thinking its something to do with the formatting of the values that I want to send. Using SocketTest, listening to port 52867, the sniffer reads the value of 0.55 repeatedly - I guess FG doesn't like this?

Thanks,
joef1993
 
Posts: 12
Joined: Wed Oct 19, 2016 11:08 am

Re: Generic Protocol Input Control

Postby tauchergreg » Sat Jan 07, 2017 2:30 pm

hi joef1993,

I start flightgear with the following:

Code: Select all
fgfs --generic=socket,in,1,127.0.0.1,52867,udp,UDP_Write

can you try this:

fgfs --generic=socket,in,1,,52867,udp,UDP_Write

regrads,
greg
C160 Transall , Twin Otter DHC6, both with small modification
EF2000
ETMN & EDXN under development
User avatar
tauchergreg
 
Posts: 58
Joined: Tue Jul 03, 2012 8:36 am
Location: near ETMN
Callsign: OFD001 ; BRT0192
Version: 20xx
OS: Linux & W7

Re: Generic Protocol Input Control

Postby joef1993 » Sat Jan 07, 2017 3:16 pm

Hi Greg, thanks for the reply. I've tried that and still no success. SocketTest still picks up the value though. This time however, I can run SocketTest at the same time as FG, whereas before I would get the error message that the address was already in use. I presume this is because FG is now looking at all addresses, rather than just 127.0.0.1?
joef1993
 
Posts: 12
Joined: Wed Oct 19, 2016 11:08 am

Re: Generic Protocol Input Control

Postby tauchergreg » Sat Jan 07, 2017 4:02 pm

hi joef1993,

please put this line as first line in your protocol file

<?xml version="1.0"?>

and try again.

have a look at this post maybe this can help you

viewtopic.php?f=24&t=24099&start=15#p274187


regrads,
greg
C160 Transall , Twin Otter DHC6, both with small modification
EF2000
ETMN & EDXN under development
User avatar
tauchergreg
 
Posts: 58
Joined: Tue Jul 03, 2012 8:36 am
Location: near ETMN
Callsign: OFD001 ; BRT0192
Version: 20xx
OS: Linux & W7

Re: Generic Protocol Input Control

Postby joef1993 » Sun Jan 08, 2017 1:47 am

Hi Greg, thanks for the reply. I missed out the first line when copying the code over so that line is actually in the xml file already. I'll take a look at that thread though, thanks.
joef1993
 
Posts: 12
Joined: Wed Oct 19, 2016 11:08 am

Re: Generic Protocol Input Control

Postby joef1993 » Mon Jan 09, 2017 1:55 am

Ok so I've narrowed this down to being the formatting of the data sent I believe. I'm using the following code:
Code: Select all
u = udp('localhost',52867,'localport',5000);
fopen(u);

while(1)
fprintf(u, 5);
end

A variable that I have set up in the property browser is set at '0' (none) initially, but when I run this code it then changed to '0' (int). Can anyone point me in the right direction of how the data should be formatted?
joef1993
 
Posts: 12
Joined: Wed Oct 19, 2016 11:08 am

Re: Generic Protocol Input Control

Postby joef1993 » Mon Jan 09, 2017 11:59 pm

All solved, used fprintf instead:

Code: Select all
u = udp('localhost',52867,'localport',5000);
fopen(u);

z = 0.99;

fprintf(u, '%f\n', z);

fclose(u);
joef1993
 
Posts: 12
Joined: Wed Oct 19, 2016 11:08 am

Re: Generic Protocol Input Control

Postby akram » Sun Nov 12, 2017 9:44 am

Could you please explaine how it had been solved in more detail.
I suffer from the same problem
akram
 
Posts: 1
Joined: Sun Nov 12, 2017 8:22 am

Re: Generic Protocol Input Control

Postby Johan G » Tue Jul 27, 2021 4:22 pm

Some posts were split off to the new topic Controlling FlightGear from Python.
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: Generic Protocol Input Control

Postby adityarajiv » Thu Jul 29, 2021 11:58 am

joef1993 wrote in Mon Jan 09, 2017 1:55 am:Ok so I've narrowed this down to being the formatting of the data sent I believe. I'm using the following code:
Code: Select all
u = udp('localhost',52867,'localport',5000);
fopen(u);

while(1)
fprintf(u, 5);
end

A variable that I have set up in the property browser is set at '0' (none) initially, but when I run this code it then changed to '0' (int). Can anyone point me in the right direction of how the data should be formatted?



Hello,
The same piece of code i am trying in python like this:
import socket

cs=socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
msg='100'
while True:
cs.sendto(bytes(msg),("127.0.0.1",1234))

But the value is not being displayed on the property browser. Can you please help me?
adityarajiv
 
Posts: 10
Joined: Tue Jul 27, 2021 7:15 am


Return to Interfacing

Who is online

Users browsing this forum: No registered users and 4 guests