Board index FlightGear Support Interfacing

Interface Arduino with FlightGear on windows  Topic is solved

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

Interface Arduino with FlightGear on windows

Postby simone04 » Thu Jun 13, 2019 9:10 pm

Hello Everyone! :)
I have a windows 7 computer where I installed FlightGear 2018.3.2
I have also some experience with Arduino.
My Specs are:
Code: Select all
-Windows 7 x64
-Intel Core Duo @ 3.06GHz
-3GB Ram
-FlightGear 2018.3.2

I want to interface arduino to FlightGear as a joystick.
From this link:
http://wiki.flightgear.org/Howto:Use_Ar ... FlightGear
I created an XML file into the folder "Protocol", and its name is ArduinoThrottle.xml
The content of the xml file is:
Code: Select all
<?xml version="1.0"?>
<PropertyList>
<generic>
    <input>   
        <line_separator>\n</line_separator>
        <var_separator>,</var_separator>
   
         <chunk>
            <name>Throttle</name>
            <node>/controls/engines/engine/throttle</node>
            <type>float</type>
         </chunk>
         
         <chunk>
            <name>Mixture</name>
            <node>/controls/engines/engine/mixture</node>
            <type>float</type>
         </chunk>
      
    </input>
</generic>
</PropertyList>

(anyone can tell me if "mixture" chunk is set correctly? I am not sure if this is the right property....)
Anyway... I started the FlightGear Qt Launcher and in additional settings i put this line:
Code: Select all
--generic=serial,in,30,\\.\COM6,9600,ArduinoThrottle

(I verified that is COM6 Port)
(I also put "--console" option for debugging)
So then I started FlightGear.. I waited, and the whole program was stuck.. :(
Here it is my console:
https://www.dropbox.com/s/lgfzvw8jqow677n/ConsoleStuck.PNG?dl=0
(P.S. : I understood all the sintax of the "--generic" option, the only thing that I cannot understand is the value "30" here:
--generic=serial,in,30,\\.\COM6,9600,ArduinoThrottle
someone can explain me what it does exactly? thanks)

If you need more information, just ask :)
I hope that someone can resolve this problem...
simone04
 
Posts: 28
Joined: Tue May 28, 2019 5:58 pm
Location: Italy
Callsign: MR-BEAN
Version: 2018.3.2
OS: Ubuntu 18.04.1 LTS

Re: Interface Arduino with FlightGear on windows

Postby Johan G » Thu Jun 13, 2019 10:06 pm

simone04 wrote in Thu Jun 13, 2019 9:10 pm:[...] I am not sure if this is the right property.... [...]

While most of this is a bit beyond me, I do know that you can verify if that is the right property with the property browser (permalink) when you run FlightGear. Since your FlightGear freezes/crashes when you try using the generic protocol, you will need to run FlightGear without it, when checking the properties.
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)
Johan G
Moderator
 
Posts: 5528
Joined: Fri Aug 06, 2010 5:33 pm
Location: Sweden
Callsign: SE-JG
IRC name: Johan_G
Version: 3.0.0
OS: Windows 7, 32 bit

Re: Interface Arduino with FlightGear on windows

Postby simone04 » Fri Jun 14, 2019 9:54 am

Ok, I verified that mixture property is correct.
But, I cannot find any "throttle" property..
I only found "rpm" property, but I am not sure if this is the right property... :?
simone04
 
Posts: 28
Joined: Tue May 28, 2019 5:58 pm
Location: Italy
Callsign: MR-BEAN
Version: 2018.3.2
OS: Ubuntu 18.04.1 LTS

Re: Interface Arduino with FlightGear on windows

Postby Johan G » Fri Jun 14, 2019 10:50 am

Usually the throttle control is somewhere in the /controls/engine/ subtree, but I would guess that you have already looked there. If there is an animated throttle in the cockpit you could also look into the XML configuration file with the models and animations in the cockpit, as the position of the throttle would depend on the throttle property.

By the way, since properties might differ from aircraft to aircraft, what aircraft are you trying to get this to work with?
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)
Johan G
Moderator
 
Posts: 5528
Joined: Fri Aug 06, 2010 5:33 pm
Location: Sweden
Callsign: SE-JG
IRC name: Johan_G
Version: 3.0.0
OS: Windows 7, 32 bit

Re: Interface Arduino with FlightGear on windows

Postby simone04 » Fri Jun 14, 2019 3:08 pm

Actually I didn't.
I will search in /controls/engine/
I want to fly a cessna 172p (the default in FG)
UPDATE:
Ok, I found It! mixture and throttle are in the same "folder": /controls/engines/current-engine
Now I will try it on the xml file and see if it works .. :)
simone04
 
Posts: 28
Joined: Tue May 28, 2019 5:58 pm
Location: Italy
Callsign: MR-BEAN
Version: 2018.3.2
OS: Ubuntu 18.04.1 LTS

Re: Interface Arduino with FlightGear on windows

Postby wkitty42 » Fri Jun 14, 2019 4:11 pm

with the default c172p, you certainly want to use current engine because the craft has two available that can be selected from within the sim...
"You get more air close to the ground," said Angalo. "I read that in a book. You get lots of air low down, and not much when you go up."
"Why not?" said Gurder.
"Dunno. It's frightened of heights, I guess."
User avatar
wkitty42
 
Posts: 5695
Joined: Fri Feb 20, 2015 3:46 pm
Location: central NC, USA
Callsign: wk42
Version: git next
OS: Kubuntu 14.04.5

Re: Interface Arduino with FlightGear on windows

Postby simone04 » Fri Jun 14, 2019 4:20 pm

Ok I tried it and... It doesn't work.. :(
I forgot to post also my (simple) arduino code if it helps:
Code: Select all

void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
}
void loop() {
  double sensorValue0 = analogRead(A0);
  double sensorValue1 = analogRead(A1);
  // print out the value you read:
  Serial.print(sensorValue0/1020);
  Serial.print(",");
  Serial.print(sensorValue1/1020);
  Serial.print("\n");
  delay(10);        // delay in between reads for stability
}


Also now the xml is modified. It looks like this:
Code: Select all
<?xml version="1.0"?>
<PropertyList>
<generic>
    <input>   
        <line_separator>\n</line_separator>
        <var_separator>,</var_separator>
   
         <chunk>
            <name>Throttle</name>
            <node>/controls/engines/current-engine/throttle</node>
            <type>float</type>
         </chunk>
         
         <chunk>
            <name>Mixture</name>
            <node>/controls/engines/current-engine/mixture</node>
            <type>float</type>
         </chunk>
      
    </input>
</generic>
</PropertyList>
simone04
 
Posts: 28
Joined: Tue May 28, 2019 5:58 pm
Location: Italy
Callsign: MR-BEAN
Version: 2018.3.2
OS: Ubuntu 18.04.1 LTS

Re: Interface Arduino with FlightGear on windows

Postby wlbragg » Fri Jun 14, 2019 4:35 pm

Maybe this will help, this is the filters for the throttle section for the engine. These filters drive the final throttle per engine selected. You will have to account for and adjust the input portion of the logic in order to tie into the final output.

Code: Select all
    <filter>
        <name>Engine 160 HP Throttle</name>
        <type>gain</type>
        <input>
            <condition>
                <equals>
                    <property>/controls/engines/active-engine</property>
                    <value>0</value>
                </equals>
            </condition>
            <property>/controls/engines/current-engine/throttle</property>
        </input>
        <input>
            <property>/controls/engines/engine[1]/throttle</property>
        </input>
        <output>
            <property>/controls/engines/engine[0]/throttle</property>
        </output>
    </filter>

    <filter>
        <name>Engine 180 HP Throttle</name>
        <type>gain</type>
        <input>
            <condition>
                <equals>
                    <property>/controls/engines/active-engine</property>
                    <value>1</value>
                </equals>
            </condition>
            <property>/controls/engines/current-engine/throttle</property>
        </input>
        <input>
            <value>0.0</value>
        </input>
        <output>
            <property>/controls/engines/engine[1]/throttle</property>
        </output>
    </filter>
Kansas(2-27-15)/Ohio/Midwest scenery development.
KEQA (2-27-15), 3AU, KRCP Airport Layout
User avatar
wlbragg
 
Posts: 4909
Joined: Sat Aug 25, 2012 11:31 pm
Location: Kansas (Tornado Alley), USA
Callsign: WC2020
Version: next
OS: Win10/Debain/nVGT640

Re: Interface Arduino with FlightGear on windows

Postby simone04 » Fri Jun 14, 2019 5:33 pm

I think is not a matter of editing the xml file...
Because when I press "/", and I go to /controls/engines/current-engine
The cockpit responds correctly, and vice-versa...
So I don't know what is the problem here.... :(
Also
wkitty42 wrote in Fri Jun 14, 2019 4:11 pm:with the default c172p, you certainly want to use current engine

He says that there is no need of changing the engine "folder" (I mean editing the xml file by changing current-engine to "enigne[1]" or "engine[0]")
(P.S. Thanks to everyone for helping I really appreciate it)
Also:
simone04 wrote in Thu Jun 13, 2019 9:10 pm:(P.S. : I understood all the sintax of the "--generic" option, the only thing that I cannot understand is the value "30" here:
--generic=serial,in,30,\\.\COM6,9600,ArduinoThrottle
someone can explain me what it does exactly? thanks)
simone04
 
Posts: 28
Joined: Tue May 28, 2019 5:58 pm
Location: Italy
Callsign: MR-BEAN
Version: 2018.3.2
OS: Ubuntu 18.04.1 LTS

Re: Interface Arduino with FlightGear on windows

Postby wlbragg » Fri Jun 14, 2019 5:58 pm

If you care to use the c172p as written, then you have to supply the inputs to the filter. Not by changing any code in the c172p folders but by controlling the properties that feed the output of those filters. Supply the correct input properties to those filters from the Arduino.
Kansas(2-27-15)/Ohio/Midwest scenery development.
KEQA (2-27-15), 3AU, KRCP Airport Layout
User avatar
wlbragg
 
Posts: 4909
Joined: Sat Aug 25, 2012 11:31 pm
Location: Kansas (Tornado Alley), USA
Callsign: WC2020
Version: next
OS: Win10/Debain/nVGT640

Re: Interface Arduino with FlightGear on windows

Postby wlbragg » Fri Jun 14, 2019 6:07 pm

Off the top of my head, pass...
Code: Select all
/controls/engines/active-engine = 0 or 1
and
/controls/engines/current-engine/throttle
Kansas(2-27-15)/Ohio/Midwest scenery development.
KEQA (2-27-15), 3AU, KRCP Airport Layout
User avatar
wlbragg
 
Posts: 4909
Joined: Sat Aug 25, 2012 11:31 pm
Location: Kansas (Tornado Alley), USA
Callsign: WC2020
Version: next
OS: Win10/Debain/nVGT640

Re: Interface Arduino with FlightGear on windows

Postby simone04 » Sat Jun 15, 2019 2:22 pm

So what I should do now?
I should add a filter tag with all those settings or what?
Sorry I cannot understand very well....
simone04
 
Posts: 28
Joined: Tue May 28, 2019 5:58 pm
Location: Italy
Callsign: MR-BEAN
Version: 2018.3.2
OS: Ubuntu 18.04.1 LTS

Re: Interface Arduino with FlightGear on windows

Postby wlbragg » Sat Jun 15, 2019 4:59 pm

Looking at your post a bit more carefully leads me to realize the property you were looking for is only /controls/engines/current-engine/throttle.
The filter gets the engine choice from the selection in the GUI so unless you wanted to be able to change the engine choice remotely, the property /controls/engines/active-engine is irrelevant.

So the following looks correct assuming that is the correct syntax for the protocol and the correct code Arduino side.

Code: Select all
<?xml version="1.0"?>
<PropertyList>
<generic>
    <input>   
        <line_separator>\n</line_separator>
        <var_separator>,</var_separator>
   
         <chunk>
            <name>Throttle</name>
            <node>/controls/engines/current-engine/throttle</node>
            <type>float</type>
         </chunk>
         
         <chunk>
            <name>Mixture</name>
            <node>/controls/engines/current-engine/mixture</node>
            <type>float</type>
         </chunk>
     
    </input>
</generic>
</PropertyList>



Code: Select all
void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
}
void loop() {
  double sensorValue0 = analogRead(A0);
  double sensorValue1 = analogRead(A1);
  // print out the value you read:
  Serial.print(sensorValue0/1020);
  Serial.print(",");
  Serial.print(sensorValue1/1020);
  Serial.print("\n");
  delay(10);        // delay in between reads for stability
}


You were asking for the correct property to use for the throttle, I think you have the correct input.
Did you try adjusting /controls/engines/current-engine/throttle manually in the property tree and did that work? If it did then you should have the correct property for throttle.
Are you passing any correct data from the Arduino to FG? In other words is your Arduino code sending and changing any of the properties in the property tree FG side?
If not then that is as far as I can help as I have never used an Arduino to send inputs to FG, I've never written code for it or the interface. If it is not changing any properties then the issue is in the code and interface being correctly written and not the properties being used. Sorry I can't be of more help.
Kansas(2-27-15)/Ohio/Midwest scenery development.
KEQA (2-27-15), 3AU, KRCP Airport Layout
User avatar
wlbragg
 
Posts: 4909
Joined: Sat Aug 25, 2012 11:31 pm
Location: Kansas (Tornado Alley), USA
Callsign: WC2020
Version: next
OS: Win10/Debain/nVGT640

Re: Interface Arduino with FlightGear on windows

Postby simone04 » Sun Jun 16, 2019 9:39 am

Thanks anyway for your help. I really appreciate it.
simone04 wrote in Fri Jun 14, 2019 5:33 pm:when I press "/", and I go to /controls/engines/current-engine
The cockpit responds correctly, and vice-versa...

So yes, the cockpit responds correctly when I change manually the properties(Also noticed that the range is from 0.00 to 1.00)
The problem is that FG gets stuck at the loading..
then I enabled the "--console" option for debugging and it get stuck here:
KI266 dme indicator #0 initialized
the whole program is frozen and the console has only that blinking cursor. nothing more. :(
(see this image: https://www.dropbox.com/s/lgfzvw8jqow677n/ConsoleStuck.PNG?dl=0)
simone04
 
Posts: 28
Joined: Tue May 28, 2019 5:58 pm
Location: Italy
Callsign: MR-BEAN
Version: 2018.3.2
OS: Ubuntu 18.04.1 LTS

Re: Interface Arduino with FlightGear on windows

Postby massima » Sun Jun 16, 2019 11:19 am

I'm starting to studying arduino for school and i've just dismantled my "Hotas" [2 axis joy, 2x potentiometer(flaps, rudder), linear potentiometer, mini side switch (gear)].

Everything works on linux, only issue is i can control only the first engine
Code: Select all
controls/engines/engine/throttle
.

If you browse all available commands from "debug->browse internal properties" your command doesn't exist. neither in the keyboard.xml file. Pick your commands from here.

I started from the wiki: http://wiki.flightgear.org/Howto:Use_Arduino_with_FlightGear

I've also built the LCD project with arduino UNO with a simplier coding
Image


Bye

P.S.: i've just found the command "/controls/engines/throttle-all
User avatar
massima
 
Posts: 229
Joined: Sat Jan 03, 2015 6:48 pm
Location: Italy
Callsign: M-AXX
Version: 2019.1.1
OS: debian testing

Next

Return to Interfacing

Who is online

Users browsing this forum: No registered users and 1 guest