Board index FlightGear Support Interfacing

Inconsistent Latitude when using Serial Generic Protocol

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

Inconsistent Latitude when using Serial Generic Protocol

Postby mmarcos » Tue Jun 29, 2021 1:41 am

Hello,

I'm trying to output the airplane coordinates using serial Generic Protocol to an embedded device. The values that are being sent are position/latitude-deg and position/longitude-deg. The longitude value is being correctly converted into binary, but I'm still having trouble with the latitude value. Below you will find images that will better explain the problem.

The command I'm using to run FGFS with Serial Generic Protocol is:
Code: Select all
fgfs --generic=serial,out,1,\\.\COM9,115200,f5serial

The XML file f5serial:
Code: Select all
<?xml version="1.0"?>

<PropertyList>
   <generic>

      <output>
         <line_separator></line_separator>
         <var_separator></var_separator>
            <binary_mode>true</binary_mode>
         <byte_order>network</byte_order>

         <chunk>
            <name>Lat</name>
            <node>/position/latitude-deg</node>
            <format>%.6f</format>
            <type>float</type>
         </chunk>

         <chunk>
            <name>Lon</name>
            <node>/position/longitude-deg</node>
            <format>%.6f</format>
            <type>float</type>
         </chunk>

      </output>

   </generic>

</PropertyList>

I can see the coordinates of the airplane on the Internal Property Browser as follows. You can see that the value for Latitude-Degrees is 63.991 and the value for Longitude-Degrees is -22.605:
Image

Reading the serial output sent by FG using a serial terminal program such as CoolTerm (https://freeware.the-meiers.org/) I get the following:
Image
The hexadecimal binary value in RED is the Latitude and hexadecimal binary value in BLUE is the Longitude.

When I convert these two values into a decimal float using the online converter at https://gregstoll.com/~gregstoll/floattohex/ I get the following:
Image
Image

You can see then that the Latitude converted from the binary value to a decimal float is not the same as the value shown in the Internal Property Browser.

Now the funny thing is when I configure the Generic Protocol to write to a text file, it will write the values exactly as shown in the Internal Property Browser:
Image

which were generated using the following command and XML file:
Code: Select all
fgfs --generic=file,out,1,data.txt,f6serial

Code: Select all
<?xml version="1.0"?>

<PropertyList>
   <generic>

      <output>
         <binary_mode>false</binary_mode>

         <line_separator>newline</line_separator>
         <var_separator>newline</var_separator>
            
         <preamble></preamble>

         <postamble></postamble>

         <chunk>
            <name>Lat</name>
            <format>LAT: %.6f</format>
            <node>/position/latitude-deg</node>
            <type>float</type>
         </chunk>

         <chunk>
            <name>Lon</name>
            <format>LON: %.6f</format>
            <node>/position/longitude-deg</node>
            <type>float</type>
         </chunk>

      </output>

   </generic>

</PropertyList>


I decided to investigate the code found on GitHub a little bit and I found that at least for the Socket output (I couldn't see where the code for Serial output was) the Latitude value is treated differently then the Longitude value.
Image
Link to the GitHub repository: https://github.com/FlightGear
Link to the source file shown in the image above: https://github.com/FlightGear/flightgear/blob/next/src/FDM/JSBSim/input_output/FGOutputFG.cpp

I'm not sure if this applies, but at least as per the code one can see why the the values when received from serial Generic Protocol would be different. Any and all help is very welcome.

Thanks in advance.
mmarcos
 
Posts: 2
Joined: Mon Jun 28, 2021 1:02 pm

Re: Inconsistent Latitude when using Serial Generic Protocol

Postby Johan G » Tue Jun 29, 2021 12:54 pm

Welcome to the forum! :D

I think the GitHub repository at best is a mirror, the main repositories are at SourceForge. :wink:
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: Inconsistent Latitude when using Serial Generic Protocol

Postby mmarcos » Tue Jun 29, 2021 4:23 pm

Thank you very much for your reply Johan. Thank you for sharing the correct location of the FG repositories.

Do you happen to know anything about why the Latitude Value is different when sent by Serial Generic Protocol then when sent by File Generic Protocol?

Cheers.
mmarcos
 
Posts: 2
Joined: Mon Jun 28, 2021 1:02 pm

Re: Inconsistent Latitude when using Serial Generic Protocol

Postby Johan G » Tue Jun 29, 2021 8:00 pm

mmarcos wrote in Tue Jun 29, 2021 4:23 pm:Thank you for sharing the correct location of the FG repositories.

You are welcome. :)

mmarcos wrote in Tue Jun 29, 2021 4:23 pm:Do you happen to know anything about why the Latitude Value is different when sent by Serial Generic Protocol then when sent by File Generic Protocol?

No, I have no idea why, sorry.
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


Return to Interfacing

Who is online

Users browsing this forum: No registered users and 2 guests