Board index FlightGear Support Interfacing

Interface Arduino with FlightGear on windows  Topic is solved

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

Re: Interface Arduino with FlightGear on windows

Postby simone04 » Sun Jun 16, 2019 1:35 pm

simone04 wrote in Fri Jun 14, 2019 4:20 pm: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>

As I wrote here I changed the property... now is no longer /controls/engines/engine , now is /controls/engines/current-engine
I will try now only the throttle without the mixture and see if it works....
Also I don't understand what does this value:
--generic=serial,in,30,\\.\COM6,9600,ArduinoThrottle
what does exactly?
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 » Sun Jun 16, 2019 2:36 pm

simone04 wrote in Sun Jun 16, 2019 1:35 pm:Also I don't understand what does this value:
--generic=serial,in,30,\\.\COM6,9600,ArduinoThrottle
what does exactly?

If you look at the bottom of the wiki article about the Generic protocol (permalink) you will find links to readme files. The README.IO file states that the number is the frequency in Hz that data is read/written.
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 » Sun Jun 16, 2019 2:55 pm

ok, so what value should I put on there?
Also I tried another tutorial( http://www.scottbouch.com/flightgear-sim-arduino-serial-hardware-2-axis-potentiometer-joystick.html )
and it didn't work as well. I don't know what's wrong with my flightgear....
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 » Sun Jun 16, 2019 4:10 pm

the value you put there is determined by how fast you want/need the data to be flowing... 30Hz is 30 times a second... do you need/want that much data? can your device handle that much data flowing in/out? this is something you will have to determine yourself, AFAIK...
"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 wlbragg » Sun Jun 16, 2019 5:17 pm

Not at all sure about this but maybe your missing a value position?

Code: Select all
--generic=serial,in,30,,9600,,ArduinoThrottle
instead of
--generic=serial,in,30,,9600,ArduinoThrottle
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 » Sun Jun 16, 2019 5:19 pm

Also is \\.\COM6 needed or possible even causing problems?
Verify this is the name of your serial port connection!
Last edited by wlbragg on Sun Jun 16, 2019 11:12 pm, edited 1 time in total.
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 » Sun Jun 16, 2019 6:33 pm

Well now you really got my curiosity going. I had an old Arduion Uno laying around and decided to see if I could at least manually send some input directly from Arduino code using the tutorials your referencing and I too am unable to pass any data. All looks correct but FG isn't receiving. Serial monitor shows the correct output? I'm on Linux.
Protocol string is...

Code: Select all
--generic=serial,in,30,/dev/ttyACM1,9600,arduino.xml


Interface...

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

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

            <chunk>
                <name>aileron</name>
                <type>float</type>
                <node>/controls/flight/aileron</node>
            </chunk>

            <chunk>
                <name>elevator</name>
                <type>float</type>
                <node>/controls/flight/elevator</node>
            </chunk>

            <chunk>
                <name>throttle</name>
                <type>float</type>
                <node>/controls/engines/current-engine/throttle</node>
            </chunk>

            <chunk>
                <name>mixture</name>
                <type>float</type>
                <node>/controls/engines/current-engine/mixture</node>
            </chunk>
        </input>
   </generic>
</PropertyList>


Arduino code...

Code: Select all
float aileron = 0;
float elevator = 0;
float throttle = 0;       
float mixture = 0;

void setup() {
  Serial.begin(9600);
}

void loop() {

  aileron = 0;
  elevator = 0;
  throttle = 1;       
  mixture = 0;
 
  Serial.print(aileron);
  Serial.print(",");
  Serial.print(elevator);
  Serial.print(",");
  Serial.print(throttle);
  Serial.print(",");
  Serial.print(mixture);
  Serial.print("\n");
  delay(10); 
}
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 » Sun Jun 16, 2019 11:21 pm

Also, have you seen this?

Note: Remember to unplug Arduino's USB cable and plug it back.
FlightGear will not be able to read serial without doing this!
You have to do this every time after you use the Arduino IDE.
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 » Mon Jun 17, 2019 2:31 am

Hum, at least I am getting some information as to what is going on, or not!
Code: Select all
   12.11 [ALRT]:io         Cannot open /dev/ttyACM0 for serial I/O
   12.11 [ALRT]:io         Error opening device: /dev/ttyACM0
   12.11 [ALRT]:io         Error opening channel communication layer.
   12.11 [ALRT]:io         I/O Channel config failed.
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 » Mon Jun 17, 2019 4:18 am

OK, I finally figured out the issue for me. It was a permission issue for /dev/ttyACM0.

This was helpful for Linux permission of tty.

So long as \\.\COM6 is the right serial device address or name for you then that device needs the proper permission to be accessed.
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 » Mon Jun 17, 2019 4:46 am

It also has a warning about unplugging and reconnecting the Arduino each time, I found this was not necessary with a Rev 3 Arduino Uno.

I also found out this is not the case with my Arduino. It was tty and dialout permissions.
Code: Select all
sudo usermod -a -G tty $USER
sudo usermod -a -G dialout $USER

I am able to connect with the Arduino IDE upload code to the Arduino and as long as I have the protocol interface configured it immediately sends to FG. Next it would be really useful, not to mention cool, for testing to establish a two way communication to/from the Arduino so I can send a signal to the Arduino to then execute a piece of code that does something in FG.
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 massima » Mon Jun 17, 2019 1:31 pm

@wlbragg: In the wiki on Arduino is well explained hot to write the right code. In the void loop replace:

aileron = 0;
elevator = 0;
throttle = 1;
mixture = 0;


with:

Code: Select all
aileron= ((analogRead(A0)/512.00)-0.99);
elevator = ((analogRead(A1)/512.00)-0.99);
throttle= analogRead(A2)/1023.0;
mixture= analogRead(A3)/1023.0;


I suppose your sensors are attached to analogic ports A0, A1, A2, A3. Then you must convert the output (0-1023) in a format readable for FG (from -1<-->0<-->+1 or 0<-->+1).
Open in arduino sw the "monitor serial" to check the output.
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

Re: Interface Arduino with FlightGear on windows

Postby wlbragg » Mon Jun 17, 2019 3:04 pm

Mine is already working, my code was a test just to verify it was outputting to serial port. I am not trying to read from any device hooked up to the Arduio. I was only writing code that automatically sent 1 (full throttle) to FG. The issue of my setup not working was strictly the permission problem. If your getting the correct data to the Adrunio IDE serial monitor then your code is OK and your connection to the computer serial port is OK. If that is the case then your remaining problem lies in permissions as best I can tell.
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 » Mon Jun 17, 2019 3:41 pm

@simone04

If your still trying to get this to work check the following

1) Do you have any valid data visible in the Arduino IDE serial monitor?

If yes...

Check FG log and see if your getting any serial port connection errors?

If no...

The issue is still on the Arduino side either in the card connection to the computer or the implementation of the hardware to 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 massima » Mon Jun 17, 2019 8:39 pm

wlbragg wrote in Mon Jun 17, 2019 3:04 pm:Mine is already working, my code was a test just to verify it was outputting to serial port. I am not trying to read from any device hooked up to the Arduio. I was only writing code that automatically sent 1 (full throttle) to FG. The issue of my setup not working was strictly the permission problem. If your getting the correct data to the Adrunio IDE serial monitor then your code is OK and your connection to the computer serial port is OK. If that is the case then your remaining problem lies in permissions as best I can tell.


Ok, i garanted permission simply creating a udev rule and adding my user to the dialout group.
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

PreviousNext

Return to Interfacing

Who is online

Users browsing this forum: No registered users and 1 guest