Board index FlightGear Support Interfacing

Success with FGFS controlling real cockpit indicators!

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

Success with FGFS controlling real cockpit indicators!

Postby ScottBouch » Tue Jun 18, 2019 11:29 am

Firstly, many thanks to dhudach for giving me a good grounding in Arduino code and parsing data.

I recently got these indicators working. The undercarriage indicator is typical of Lightning, Gnat, Hunter etc..

The JPT indicator, I'm not sure what aircraft it's from but isn't a million miles off Lightning.

JPT:
https://youtu.be/c9u9xZfog4E

Undercarriage:
https://youtu.be/EQEtn3T0Bvs

I'll be demonstrating this simulator project at Newark Air Museum's CockpitFest event this weekend. Hope to add a little more functionality by then too.

Cheers, Scott
User avatar
ScottBouch
 
Posts: 73
Joined: Wed Jun 22, 2016 3:14 pm
Location: Midlands, UK
OS: Manjaro,Mint,Ubuntu.

Re: Success with FGFS controlling real cockpit indicators!

Postby Isaak » Tue Jun 18, 2019 2:45 pm

Very nice work!
Isaak
 
Posts: 465
Joined: Sat Jun 04, 2011 2:52 pm
Location: Leuven, Belgium
Callsign: OO-ISA
Version: 2019.1.1
OS: Windows 10

Re: Success with FGFS controlling real cockpit indicators!

Postby wlbragg » Tue Jun 18, 2019 4:52 pm

Hi Scott,
I'm having no trouble going from Arduino to FG but not FG to Arduino. I don't know if it is the interface or wrong Arduino parsing code. I don't see any data on the serial line.
Do you know if bi direction works or even in and out simultaneously? Also does the same FG command line string connecting to tty using in work by simply changing it to out?
Do you have a protocol code example for FG to Arduino you could share? Also the command line string you use for FG to Arduino?
Kansas(2-27-15)/Ohio/Midwest scenery development.
KEQA (2-27-15), 3AU, KRCP Airport Layout
User avatar
wlbragg
 
Posts: 4904
Joined: Sat Aug 25, 2012 11:31 pm
Location: Kansas (Tornado Alley), USA
Callsign: WC2020
Version: next
OS: Win10/Debain/nVGT640

Re: Success with FGFS controlling real cockpit indicators!

Postby dhudach » Fri Jun 21, 2019 11:58 pm

wlbragg:

I'm coming into this conversation a few days late, but I thought I would check in. You may know a lot of what I'm going to mention. Why you are not seeing FG output Serial data, if you haven't already done so, check the log for any obvious issues. Also, especially for linux environment, make sure the Arduino board is plugged in before starting FG. Otherwise, the OS may not have created the tty that FG is looking for and will just ignore writing data at that point. And if that's the case, you should see it in the log file.

Does your protocol file use <output> for the data you want FG to send?

I too was curious if FG could use in/out with a single command line option, but I don't think it can. However, you can specify in or out with the same protocol file as long as the tags are correct for <input> and <output> in the protocol file.

Here is an example output protocol file that I'm using to display compass headings on LCD:

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

<PropertyList>
  <generic>
    <output>
      <line_separator>\n</line_separator>
        <var_separator>,</var_separator>

        <chunk>
          <name>Magnetic Compass</name>
          <type>int</type>
          <node>/instrumentation/magnetic-compass/indicated-heading-deg</node>
        </chunk>

        <chunk>
          <type>int</type>
          <node>/instrumentation/kcs55/kg102/indicated-heading-deg</node>
        </chunk>
      </output>
    </generic>
</PropertyList>


I hope this helps,
Dave
dhudach
 
Posts: 75
Joined: Mon Apr 13, 2015 11:46 pm

Re: Success with FGFS controlling real cockpit indicators!

Postby wlbragg » Sat Jun 22, 2019 3:38 am

Thanks Dave,

I think I have all in your post accounted for. It's not a problem with tty not being online yet, I can tell when it is wrong as I do get an error in the log if tty is either not created or I am calling the wrong number. As I posted in my previous post, the Arduino to FG works fine, I just don't seem to be able to get the FG to Arduino to work. I am relatively sure I have the command line args correct and the protocol "output" xml tags correct. But the Arduino IDE serial monitor is not showing any data on the line except the data coming from the Arduino to FG. What I would like to see is some example code of Scott's on the Arduino side that parses data coming from FG.
Kansas(2-27-15)/Ohio/Midwest scenery development.
KEQA (2-27-15), 3AU, KRCP Airport Layout
User avatar
wlbragg
 
Posts: 4904
Joined: Sat Aug 25, 2012 11:31 pm
Location: Kansas (Tornado Alley), USA
Callsign: WC2020
Version: next
OS: Win10/Debain/nVGT640

Re: Success with FGFS controlling real cockpit indicators!

Postby dhudach » Sat Jun 22, 2019 9:46 am

Ok, not knowing what you've done, I just wanted to cover some of the most obvious issues.

Here is a complete sample that works. I am flying the Seneca II but the example here uses airspeed and altimeter which should be about the same properties, but you can verify on the plane you are flying and make appropriate changes in the protocol code. I am running linux, so tty is ttyACM0, you can change it for your system.

Command line argument to FG:

--generic=serial,out,2,/dev/ttyACM0,9600,serial_test

My protocol file is called serial_test.xml and it is in the Protocol directory (you already know where it goes). I am only sending data 2 times per second, you can change that to whatever value you want.

Items of note. Make sure you are running Serial.begin(baud_rate) in your setup function and make sure they match what you are sending to FG in your command line argument. I am using 9600.

Code: Select all
void setup() {
  Serial.begin(9600);
}

void parse_fields() {
  if (Serial.available() > 0) {

    //  Get the integer value
    //
    int int_val = Serial.parseInt();

    //  Send the value to see it in the Serial Monitor
    //
    Serial.print("Int: ");
    Serial.print(int_val);

    //  Read the comma but don't do anything with it
    //
    char c = Serial.read();

    //  Get the float value
    //
    float float_val = Serial.parseFloat();

    //  Send the value to see it in the Serial Monitor
    //
    Serial.print("  Float: ");
    Serial.println(float_val);

    //  Read the end of line character "\n"
    //
    c = Serial.read();
  }
}

//  Call parse_fields in loop.
//
void loop() {
  parse_fields();
}


Protocol file:

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

<PropertyList>
  <generic>
    <output>
      <line_separator>\n</line_separator>
        <var_separator>,</var_separator>

        <chunk>
          <name>Airspeed</name>
          <type>int</type>
          <node>/instrumentation/airspeed-indicator/indicated-speed-kt</node>
        </chunk>

        <chunk>
          <name>Altimeter</name>
          <type>float</type>
          <format>%.3f</format>
          <node>/instrumentation/altimeter/indicated-altitude-ft</node>
        </chunk>
      </output>
    </generic>
</PropertyList>


Let me know if this works for you.

Dave
dhudach
 
Posts: 75
Joined: Mon Apr 13, 2015 11:46 pm

Re: Success with FGFS controlling real cockpit indicators!

Postby wlbragg » Sat Jun 22, 2019 3:02 pm

For anyone following, I received a PM with the following...
You can keep the IDE loaded but, to see anything on any other app, the serial monitor window must be closed.
The first application to bind /dev/ttyACM0 ( or /devttyUSB0 ) will exclude any others. It's a pain for debug, the only way around it that I have found is to use the ESP8266 with wifi and run a separate channel using MQTT publish/subscribe for messaging .

That makes total sense, I don't think I ever tried it without the serial monitor running. I'll report back after I try it without the serial monitor.

Thanks for the Arduino side code example Dave.
Kansas(2-27-15)/Ohio/Midwest scenery development.
KEQA (2-27-15), 3AU, KRCP Airport Layout
User avatar
wlbragg
 
Posts: 4904
Joined: Sat Aug 25, 2012 11:31 pm
Location: Kansas (Tornado Alley), USA
Callsign: WC2020
Version: next
OS: Win10/Debain/nVGT640

Re: Success with FGFS controlling real cockpit indicators!

Postby dhudach » Sat Jun 22, 2019 3:14 pm

I was basically responding and assisting with this in your post:

But the Arduino IDE serial monitor is not showing any data on the line except the data coming from the Arduino to FG. What I would like to see is some example code of Scott's on the Arduino side that parses data coming from FG.


And that's what I sent you, a working example that shows code getting to Arduino from FG. When I run it, I have the Arduino board plugged in, the Arduino IDE open. I start FG and open the IDE Serial Monitor and I see the output from Arduino Serial.print statements. This demonstrates that FG is sending data to Arduino, Arduino code is parsing and sending back out to Serial to verify.

Best of Luck,
Dave
dhudach
 
Posts: 75
Joined: Mon Apr 13, 2015 11:46 pm

Re: Success with FGFS controlling real cockpit indicators!

Postby wlbragg » Sun Jun 23, 2019 4:19 am

Dave,

I got it working, thanks for the help.

My test is a simple start command from FG to Arduino which in turn sends back an autostart command from the Arduino to FG which I catch with a listener in nasal that passes it on to the nasal autostart function. bi direction flag does not work but a single protocol file with input and output chunks does as long as you call the single file with both an in and out command line switch.

Here is the entire code for anyone that may need an example to test bi-directional Arduino.

command line flags in FG...
Code: Select all
--generic=serial,in,30,/dev/ttyACM0,9600,autostart
--generic=serial,out,30,/dev/ttyACM0,9600,autostart


protocol autostart.xml file...
Code: Select all
<?xml version="1.0"?>

<PropertyList>
    <generic>

        <input>
            <line_separator>\n</line_separator>
            <var_separator>,</var_separator>

            <chunk>
                <name>autostart</name>
                <type>int</type>
                <node>/controls/engines/current-engine/autostart</node>
            </chunk>
        </input>

        <output>
            <line_separator>\n</line_separator>
            <var_separator>,</var_separator>

            <chunk>
                <name>start</name>
                <type>int</type>
                <node>/controls/engines/current-engine/start</node>
            </chunk>
        </output>

    </generic>
</PropertyList>


Arduino parse code...
Code: Select all
    void setup() {
      Serial.begin(9600);
    }

    void parse_fields() {
      if (Serial.available() > 0) {

        int int_val = Serial.parseInt();

        Serial.print(int_val);
        Serial.print("\n");
     
      }
    }

    void loop() {
      parse_fields();
    }


listener in c172p.nas..
Code: Select all
setlistener("/controls/engines/current-engine/autostart", func (node) {
    if (node.getValue()) {
        c172p.autostart(0);
    }
}, 0, 0);


property initialization in c172p-set.xml...
Code: Select all
    <controls>
        <engines>
            <current-engine>
                <start type="int">0</start>
                <autostart type="int">0</autostart>
            </current-engine>
        </engines>
    </controls>
Kansas(2-27-15)/Ohio/Midwest scenery development.
KEQA (2-27-15), 3AU, KRCP Airport Layout
User avatar
wlbragg
 
Posts: 4904
Joined: Sat Aug 25, 2012 11:31 pm
Location: Kansas (Tornado Alley), USA
Callsign: WC2020
Version: next
OS: Win10/Debain/nVGT640

Re: Success with FGFS controlling real cockpit indicators!

Postby dhudach » Sun Jun 23, 2019 8:48 am

It's nice to get this stuff working!! Good work.
dhudach
 
Posts: 75
Joined: Mon Apr 13, 2015 11:46 pm

Re: Success with FGFS controlling real cockpit indicators!

Postby ScottBouch » Mon Jun 24, 2019 7:30 pm

Hi all,

Sorry for the hiatus, was utterly tied up with getting my sim ready for CockpitFest 2019, which was a blast.

My proof of concept FG setup:

Image

Plenty of cockpits came, there was even a Shackleton that came on a trailer all the way from Holland!

Image

Cheers, Scott.
User avatar
ScottBouch
 
Posts: 73
Joined: Wed Jun 22, 2016 3:14 pm
Location: Midlands, UK
OS: Manjaro,Mint,Ubuntu.

Re: Success with FGFS controlling real cockpit indicators!

Postby dhudach » Mon Jun 24, 2019 7:38 pm

Excellent!! Great stuff Scott!!
dhudach
 
Posts: 75
Joined: Mon Apr 13, 2015 11:46 pm

Re: Success with FGFS controlling real cockpit indicators!

Postby ScottBouch » Mon Jun 24, 2019 7:39 pm

Oh quick note on the bidirectiona l comms..

me and dave discussed tbhis last week over emails, but I recall in the old RGRUN interface you could specify something like "in" or "out" or "both", I just cant recall if it was "both" or "bi" or "inout" or somehtig else, but I imahine there is a way to reduce the command to one line,

However, using two separate lines means you can set different frequencies that data is sent / observed, eg:
Code: Select all
--generic=serial,in,30,/dev/ttyACM0,9600,autostart
--generic=serial,out,30,/dev/ttyACM0,9600,autostart


Could become:
--generic=serial,in,5,/dev/ttyACM0,9600,autostart
--generic=serial,out,30,/dev/ttyACM0,9600,autostart[/code]

I'll get my proof of concept written up this week / next week... now the chaos of CockpitFest is done I have some breathing space!

Cheers, Scott.
User avatar
ScottBouch
 
Posts: 73
Joined: Wed Jun 22, 2016 3:14 pm
Location: Midlands, UK
OS: Manjaro,Mint,Ubuntu.

Re: Success with FGFS controlling real cockpit indicators!

Postby dhudach » Mon Jun 24, 2019 7:45 pm

Right, I don't think there is a way to tell FG to use the protocol for both in and out. It would be convenient. But for me, I'm kind of ok with things as they are. I may be using the same file, but to me it makes it clear my intentions when I specify separate in and out command line options. I don't think it puts any undue load on FG. It would seem to me that command line processing occurs up front and when it's done, everything is assigned and the simulator can then run. But we all have our preferences and comfort zones .... !!
dhudach
 
Posts: 75
Joined: Mon Apr 13, 2015 11:46 pm

Re: Success with FGFS controlling real cockpit indicators!

Postby wlbragg » Mon Jun 24, 2019 10:42 pm

I did a quick search through the c++ protocol code and the correct flag is "bi", but for some reason it doesn't seem to work for me. If i get a chance I'll look a little closer and see if I can figure out what is wrong with it.
It's not absolutely necessary to have bi available, but in some instances it would be nice to be able to use one argument line for an entire process.
Kansas(2-27-15)/Ohio/Midwest scenery development.
KEQA (2-27-15), 3AU, KRCP Airport Layout
User avatar
wlbragg
 
Posts: 4904
Joined: Sat Aug 25, 2012 11:31 pm
Location: Kansas (Tornado Alley), USA
Callsign: WC2020
Version: next
OS: Win10/Debain/nVGT640

Next

Return to Interfacing

Who is online

Users browsing this forum: No registered users and 1 guest