Board index FlightGear Support Interfacing

IMU data, and GPS

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

IMU data, and GPS

Postby asic_designer » Sat Jul 16, 2011 1:51 am

Hi

How do I get flightgear to output IMU data ie gyro scope info (pitch, yaw, roll) angles and accelerometer data ( x,y,z) magnitudes and finally gps data, in a binary format? I need this data sent to a com port, using standard serial protocol like rs232. I did do some searches in the forums, I found some info on sending gps NEMA sentences through a com port but I need the data in binary format so I don't have to do a conversion is that possible?
asic_designer
 
Posts: 64
Joined: Tue May 24, 2011 12:58 am

Re: IMU data, and GPS

Postby Johan G » Sat Jul 16, 2011 11:10 am

I'm not sure this helps, but there is a functionality supporting output of formatted binary or ASCII data, called the generic protocol (FlightGear Wiki articles: Generic Protocol and Howto: Create a generic protocol).
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: IMU data, and GPS

Postby asic_designer » Sun Jul 17, 2011 7:36 am

Thanks for the reply, I read over the information and I think I figured out where to get the data and how to setup the file, but I know next to nothing about xml so hopefully someone here can help me out and point out my mistakes in the code.
asic_designer
 
Posts: 64
Joined: Tue May 24, 2011 12:58 am

Re: IMU data, and GPS

Postby Johan G » Sun Jul 17, 2011 7:54 am

If you post your code inside code tags, like below, we can more easily help you, or point out your errors. :wink:

Code: Select all
Put code inside code tags like this.
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: IMU data, and GPS

Postby asic_designer » Sun Jul 17, 2011 7:15 pm

OK

So I've put together the file as best I can, and I know it isn't correct, I want to thank everyone who pitches in to help in advance I really appreciated it. Lets start with the inputs first.

Inputs

What I am trying to accomplish is very simple, I want to allow my HiL to control the plane from point A to point B, and I figure that all I really need to accomplish this in the way of inputs are a few controls, like throttle, gear, steering, control surfaces and thats about it. OK so I think I found those and put them in the file properly but I am a little lost on a few things.

1. Most of the planes I'll be flying will have more that one rudder, they will have a left and a right rudder --> F14, B2, and the SR-71 BlackBird. I only found an input for one rudder in the tree, and I want to understand better exactly how I can control both rudders with only one input, because for example in the case of the B2, there are scenarios where I'll need to open up both of the rudders at the same time during landing for example, how do I accomplish this with one input. I have the same question and problem with the input for the ailerons.

2. Also I need all these inputs to be integers and if possible I'd like to define the range, can I do this?


Outputs

Now for the outputs, have several questions here, first a little about what I am trying to accomplish. I am designing an autopilot system using some custom hardware and of course I want to use FlightGear to simulate a flight using my hardware and software. I would like to as much as possible have the outputs from flightgear mimic the actual outputs my hardware will be getting from the real GPS, and IMU sensors it will be using once its is in the field, that way the simulations will be as close as possible to the real thing, and I won't have to make major changes to my software going from simulation to actual hardware test. OK with that said here are my concerns.

1. For the Gyro Angular rates I need the outputs to be integers with a sensitivity factor of 14.375 LSB/(º/s) just as the actual gyro sensor I am using will give them to me. When I pull the values in I'll convert the to floating point by simple dividing each angular rate by 14.375. And I simply have no idea how to do this in xml.

2. For the Accelerometer magnitudes I need the outputs to be integers The conversion is based on a +/-4G range just as the actual accelerometer sensor I am using will give them to me. When I pull the values in I'll convert the to floating point by multiplying each value by 0.0078.

3. Lastly I would actually like to receive the GPS data as an actual GPS sentences and not just grabbing the lon/lat/alt. Don't get me wrong I like the simplicity here but again I am trying to mimic the sensors and gps I'll actually be using in the field as close as possible so I actually need the information send out as GPS sentences in binary format.


OK when you look at the code below you are going to see me use the factor option like <factor>0.0174532925199433</factor>, and sometimes the format option like this for example <format>rudder=%.6f</format>, I have no idea what these things do, I put this file together by using parts of other files that I have come across and my limited understanding of what I read on the wiki.

Your help is much appreciated!!

Code: Select all
 

<?xml version="1.0"?>
<PropertyList>
<generic>


<!--  INPUT CONTROLS -->


   <input>

      <line_separator></line_separator>
      <var_separator></var_separator>


   <chunk>
         <name>Steering (rad)</name>
         <format>steering=%.6f</format>
         <type>float</type>
         <node>/controls/gear/steering</node>
         <factor>0.0174532925199433</factor> 
        </chunk>
   
   <chunk>
         <name>Gears (rad)</name>
         <format>gears=%.6f</format>
         <type>float</type>
         <node>/controls/gear/gear-down</node>
         <factor>0.0174532925199433</factor> 
        </chunk>
   
   <chunk>
         <name>Throttle (rad)</name>
         <format>throttle=%.6f</format>
         <type>float</type>
         <node>/controls/engines/engine[%d]/throttle</node>
         <factor>0.0174532925199433</factor> 
        </chunk>

   <chunk>
         <name>Aileron (rad)</name>
         <format>aileron=%.6f</format>
         <type>float</type>
         <node>/controls/flight/aileron</node>
         <factor>0.0174532925199433</factor> 
        </chunk>

   <chunk>
         <name>Elevator (rad)</name>
         <format>elevator=%.6f</format>
         <type>float</type>
         <node>/controls/flight/elevator</node>
         <factor>0.0174532925199433</factor> 
        </chunk>

   <chunk>
         <name>rudder (rad)</name>
         <format>rudder=%.6f</format>
         <type>float</type>
         <node>/controls/flight/rudder</node>
         <factor>0.0174532925199433</factor> 
        </chunk>


   </input>


   <output>

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

<!--  GPS output of course to allow the plane to actually fly to it destination, and for some angle calculations -->

     <chunk>
       <name>Speed</name>
       <format>V=%d</format>
       <type>float</type>
       <node>/velocities/airspeed-kt</node>
     </chunk>

     <chunk>
       <name>Altitude (rad)</name>
       <format>A=%.6f</format>
       <type>float</type>
       <node>/position/altitude-ft</node>
       <factor>0.0174532925199433</factor> 
     </chunk>

      <chunk>
       <name>Latitude-deg (rad)</name>
       <format>Lat=%.6f</format>
       <type>float</type>
       <node>/position/latitude-deg</node>
       <factor>0.0174532925199433</factor> 
     </chunk>

     <chunk>
       <name>Longitude-deg (rad)</name>
       <format>Lon=%.6f</format>
       <type>float</type>
       <node>/position/longitude-deg</node>
       <factor>0.0174532925199433</factor> 
     </chunk>

<!--  Orientation Angles output for comparason with calculated angles done by my HiL -->

     <chunk>
       <name>Roll Angle (deg)</name>
       <format>RD=%03.2f</format>
       <node>/orientation/roll-deg</node>
     </chunk>

     <chunk>
       <name>Pitch Angle (deg)</name>
       <format>PD=%03.2f</format>
       <node>/orientation/pitch-deg</node>
     </chunk>

     <chunk>
       <name>Yaw Rate (deg)</name>
       <format>YD=%03.2f</format>
       <node>/orientation/yaw-deg</node>
     </chunk>

<!--  Orientation angular rate outputs to allow my HiL to calculate the orientation angles -->

    <chunk>
       <name>Pitch rate (deg per sec)</name>
       <format>PR=%03.2f</format>
       <node>/orientation/pitch-rate-degps</node>
     </chunk>

     <chunk>
       <name>Roll rate (deg per sec)</name>
       <format>RR=%03.2f</format>
       <node>/orientation/roll-rate-degps</node>
     </chunk>

     <chunk>
       <name>Yaw Rate (deg per sec )</name>
       <format>YR=%03.2f</format>
       <node>/orientation/yaw-rate-degps</node>
     </chunk>

<!-- Accelerometer magnitude outputs to allow my HiL to calculate the orientation angles --> 
 
     <chunk>
       <name>Accelerometer X (ft per sec)</name>
       <format>AX=%03.2f</format>
       <node>/accelerations/x-accel-fps_sec</node>
     </chunk>

     <chunk>
       <name>Accelerometer Y (ft per sec)</name>
       <format>AY=%03.2f</format>
       <node>/accelerations/y-accel-fps_sec</node>
     </chunk>

     <chunk>
       <name>Accelerometer Z (ft per sec)</name>
       <format>AZ=%03.2f</format>
       <node>/accelerations/z-accel-fps_sec</node>
     </chunk>



  </output>

</generic>
</PropertyList>
asic_designer
 
Posts: 64
Joined: Tue May 24, 2011 12:58 am

Re: IMU data, and GPS

Postby curt » Mon Jul 18, 2011 3:31 pm

FlightGear flight inputs (like aileron, rudder commands, etc.) are normalized on a range of -1.0 to +1.0 (throttle is in the range of 0-1) If you need a different range you could do the conversion on your side, or develop a nasal script that reads your value from a different property name, does the conversion to the normalized -1 to +1 range, and writes the value to the corresponding FlightGear's property.

Sensor outputs are in engineering units. Again, you'll need to convert to your own units in your code, or write a nasal script to convert units, write them to a new property name, and then export that new value instead.
curt
Administrator
 
Posts: 1168
Joined: Thu Jan 01, 1970 1:00 am
Location: Minneapolis, MN

Re: IMU data, and GPS

Postby asic_designer » Mon Jul 18, 2011 8:04 pm

Hi Curt

Thanks for the reply. As far as the inputs go I think I can just do the conversions on my side that shouldn't be too hard. With regards to the outputs, you said that the outputs are given in "engineering units" ahhh yes I think I get that, you mean like degrees per second, feet per second, yes thats fine, but are the values integers, floating point and how do I convert them if thats possible in the language.

Did you by any chance take a look at the code I posted? Any suggestions/corrections there?
asic_designer
 
Posts: 64
Joined: Tue May 24, 2011 12:58 am

Re: IMU data, and GPS

Postby curt » Mon Jul 18, 2011 10:13 pm

It's hard to pick through code on a forum and spot potential errors. It's easier (for me) to run it, do some flying, and see if the data makes sense. Yes, the sensor data in "engineering units" is output as a floating point value (usually.) Usually the property name gives a strong clue of what the units are. I don't know anything about your own code that receives the sensor data and generates the control inputs, so I can't say much about "how" to do the conversion, other than for most cases it's usually multiplying by a constant. If you are converting to integer you need to decide if you are going to round to the nearest int or just discard the fractional part. For some situations this might matter and for other situations it might not.
curt
Administrator
 
Posts: 1168
Joined: Thu Jan 01, 1970 1:00 am
Location: Minneapolis, MN

Re: IMU data, and GPS

Postby asic_designer » Mon Jul 18, 2011 11:13 pm

Fair enough...

How to I go about accomplishing this -->
I would actually like to receive the GPS data as an actual GPS sentences and not just grabbing the lon/lat/alt. Don't get me wrong I like the simplicity here but again I am trying to mimic the sensors and gps I'll actually be using in the field as close as possible so I actually need the information send out as GPS sentences in binary format.


And again thanks for your input.
asic_designer
 
Posts: 64
Joined: Tue May 24, 2011 12:58 am

Re: IMU data, and GPS

Postby curt » Tue Jul 19, 2011 3:11 am

I believe we still have NMEA and Garmin output formats ... see README.IO in the docs directory.
curt
Administrator
 
Posts: 1168
Joined: Thu Jan 01, 1970 1:00 am
Location: Minneapolis, MN

Re: IMU data, and GPS

Postby asic_designer » Wed Jul 27, 2011 3:46 am

So you made the comment that --->
FlightGear flight inputs (like aileron, rudder commands, etc.) are normalized on a range of -1.0 to +1.0 (throttle is in the range of 0-1)


does this mean that I have to send in the values in as floats from -1.0 to 1.0 through the UART(RS232)? Because that only sends data in a byte format, a byte at a time and you can't actually break up floating point numbers to bytes in C++ without converting it to an integer first and the values being from range -1.0 to 1.0 you would loose the 0.1 precision. Now since this is my hardware I could tell my UART to simply send the floating point value in a byte at a time msbyte first, is that how FlightGear is expecting the data thought?


Anyone who has insight into this please feel free to comment.
asic_designer
 
Posts: 64
Joined: Tue May 24, 2011 12:58 am

Re: IMU data, and GPS

Postby asic_designer » Fri Jul 29, 2011 1:11 am

No input at all? Come on guys I can't be the only person who has read binary data from flightgear.
asic_designer
 
Posts: 64
Joined: Tue May 24, 2011 12:58 am

Re: IMU data, and GPS

Postby Johan G » Fri Jul 29, 2011 8:31 am

It almost seems like that. :( My experience is limited to ASCII output only, and that was some time ago...

Maybe you're stuck with trial and error, as the documentation that's there unfortunately isn't all that easy to decode... :(

You might get better support if you join the developer mailing list. :|

And if you figure out what works, please report back, or write in the wiki, for the benefit of others with the same problem. :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: IMU data, and GPS

Postby AndersG » Fri Jul 29, 2011 4:30 pm

asic_designer wrote in Fri Jul 29, 2011 1:11 am:No input at all? Come on guys I can't be the only person who has read binary data from flightgear.


As far as I can see the protocol you posted above uses ASCII mode and there you'd send your floats as strings formatted according to the C locale.
If you indeed intend to send float values in binary mode, yes you have to convert the float value to 4 bytes (a double to 8 bytes) and put those on the wire in network byte order. You might have to look at streams and stream encoding to get that done in C#.

To see exactly what generic protocols in FlightGear supports look in src/Network/generic.cxx.

/Anders
Callsign: SE-AG
Aircraft (uhm...): Submarine Scout, Zeppelin NT, ZF Navy free balloon, Nordstern, Hindenburg, Short Empire flying-boat, ZNP-K, North Sea class, MTB T21 class, U.S.S. Monitor, MFI-9B, Type UB I submarine, Gokstad ship, Renault FT.
AndersG
 
Posts: 2524
Joined: Wed Nov 29, 2006 10:20 am
Location: Göteborg, Sweden
Callsign: SE-AG
OS: Debian GNU Linux

Re: IMU data, and GPS

Postby 3elwa » Thu Jul 12, 2012 7:09 pm

I may be wrong as I am new to flightgear. But if you are trying to collect IMU data they you need the angular velocity with respect to the inertial frame, i.e., it has earth rate in it. So I am think you need to get

/fdm/jsbsim/velocities/pi-rad_sec
/fdm/jsbsim/velocities/qi-rad_sec
/fdm/jsbsim/velocities/ri-rad_sec
3elwa
 
Posts: 5
Joined: Thu Jul 12, 2012 6:11 pm


Return to Interfacing

Who is online

Users browsing this forum: No registered users and 1 guest