Welcome to Cockpitbuilders.com. Please login or sign up.

April 27, 2024, 02:33:04 PM

Login with username, password and session length

PROUDLY ENDORSING


Fly Elise-ng
449 Guests, 0 Users
Members
  • Total Members: 4,154
  • Latest: xyligo
Stats
  • Total Posts: 59,641
  • Total Topics: 7,853
  • Online today: 514
  • Online ever: 582
  • (January 22, 2020, 08:44:01 AM)
Users Online
Users: 0
Guests: 449
Total: 449

COUNTDOWN TO WF2022


WORLDFLIGHT TEAM USA

Will Depart in...

Recent

Welcome

flap indicator interface with Fs9

Started by Mach7, August 03, 2023, 04:23:14 PM

Previous topic - Next topic

0 Members and 4 Guests are viewing this topic.

ame

Ha, you posted while I was typing, and posed the same question. :)

I don't know. Will have to google harder. Although I'd expect somebody here to have some experience with SIOC.

Mach7

Yes I agree...but i was never sure if Arduino could accept SIOC language...and also the boards are for dc servo motors...but if there is a chance we could use the existing code and go SIOC > arduino > gauge..then yes for sure.

Mach7

The only thing that attracts me to the Link2fs is that if I successfully integrate the flap gauge, then the fuel quantity gauges should be easy to interface.

The only thing that detracts me from Link2fs is the lack of tutorial or programming information.

Mach7

@ame...im going to have a look see at MobiFlight...I was lead to believe it was only for FSX FS2020 and PD3D...but for what I have read so far it seems to support FS9 as well.

The good thing about MobiFlight is it will write and install the firmware to operate the respective gauge...or at least that's what I read into it.

Mach7

@ame and Arturo,

Another option, although not ideal, would be for arduino to read flap selector position as opposed to actual flap position and avoid outputs from fs9 altogether. It could be done by connecting a parallel pot to the lever, or some other way of sending inputs to the board.

Just floating ideas

ame

Sounds great. Yes, mobiflight keeps popping up as a viable solution. If it might work for you then it is probably a better choice than link2fs as it is currently active and being developed and maintained.

ame

Quote from: Mach7 on August 11, 2023, 05:46:25 PM@ame and Arturo,

Another option, although not ideal, would be for arduino to read flap selector position as opposed to actual flap position and avoid outputs from fs9 altogether. It could be done by connecting a parallel pot to the lever, or some other way of sending inputs to the board.

Just floating ideas
This is not a terrible idea, as it will help with verisimilitude, but will lack the interactive property of working with the sim.

Mach7

@ame..yes I agree with your last statement.

I have just finished getting up to speed on Mobiflight and there is maybe two references to FS9, and when you look at the internal drop down menu there seems to be NO FS9 selection.

Having said that I will now assume it is not supported.

At the very least we are eliminating options.

ame

Well, if link2fs actually works then it might still be a good choice, despite being out of date and out of development. If the documentation is sparse it doesn't matter.

I'll look at the zip file and see if I can figure something out.

Mach7

#59
@ame, thanks for that.

I have been reviewing it as well, (link2fs)...it seems to me that a script will still have to be written even once the variable has been selected.

The screen shots the webpage provides are very small and difficult to make out.

I too downloaded the zip file and began to review it,  but I do not find the page information intuitive. But then again I like tutorials that start with step 1 to 10, with 10 being the end result.

ame

Quote from: Mach7 on August 11, 2023, 08:34:54 PM@ame, thanks for that.

I have been reviewing it as well, (link2fs)...it seems to me that a script will still have to be written even once the variable has been selected.


Yes, indeed, a script must be written, tailored to the specific hardware you have attached to specific pins on the Arduino. In the DemoINOs folder there are a bunch of Arduino programs that illustrate how to handle the incoming data.

The Arduino basically appears as a serial port (COMx:). Link2FS is an application written on top of FSConnect, from here:
https://www.dirks-software.ca/

FSConnect.dll does all the hard work. Link2FS makes the interface to FSConnect easier.

Once you have chosen which data elements you want to send out of FS9 link2fs fetches them and packages them all up into a string. The string is sent to the serial port, with each data element tagged with a letter, and separated with an equals sign.

So, in the Arduino code you just have to look at the incoming serial data stream, look for the '=' sign, then look at the next character. The next character tells you which data element you are going to get (and you know which ones to expect, because you set it up). So, in the case of flaps this is going to be a number, but the number is a sequence of numeric characters. We bring in however many numeric characters then convert the string of characters into a number. That number is the flap degrees. Then, multiply that number by a scaling factor and write it to the PWM output. Done.

The screen shots are a lot more visible on a laptop. Almost illegible on a phone.

If link2fs works then great, but there are others that you could investigate. You might find they won't go back as far as FS9.

ame

Quote from: Mach7 on August 11, 2023, 03:32:11 PMYes I agree...but i was never sure if Arduino could accept SIOC language...and also the boards are for dc servo motors...but if there is a chance we could use the existing code and go SIOC > arduino > gauge..then yes for sure.
Sorry, meant to reply to this. Yes, this is probably a good choice because you already have it working. I'm going to look at SIOC too.

_alioth_

I was going to explain how link2fs + arduino works but Ame has done better than I would have done it.

I used this method years ago with 5 arduino megas in a whole cockpit (inputs and outputs) and it was reliable and fine.

It seems to be a little complex (and it is if you are only interfacing one gauge). But if you are interfacing several gauges, then the work for the second gauge it is just a tick in the link2fs window and a few lines more in the arduino sketch. If coded with care (word "delay" is forbidden) you can drive lots of gauges just with one arduino. Darsonvals, steppers, leds, dc motors, encoders etc etc..

Years later I migrate everything to FSUIPC (lua script + arduino).
The arduino part is the same (read data in com port), but you write the lua script that takes from simulator the data you want and sends it through com port when you want, in the way you want etc you want.
And the lua script reads data incoming from arduino to send data to simulator too.


But I think link2fs is better to start, because you only need to understand one part of the system. The arduino part (the fun part, in my opinion)  :)

Arturo.










Mach7

#63
@ame,

Thanks for reviewing that ame...I think that the best direction, after reading all of your comments, seems to be link2fs. If we are successful with the flap gauge then this means I should be able to connect my three fuel gauges as well...(left, center, and right)

I am also curious with what you come up with SIOC as the code is already in the OpenCockpits network and is presently operating my existing, (make shift), flap gauge.

The next step I suppose is trying to find a flap script then tailor it to my own application. I have never written script before, I just modified it as per your instructions during the TMS project.

@Arturo

You seem to have a good working knowlege of Link2fs, so I hope I can lean on you as i stumble through the setup process...i might even make a step by step checklist and have you read it over to make sure I am moving in the correct direction. I have a lot of USB hubs and plugins in my simpit, so I want to make sure I do not reassign something using Link2fs by mistake.

Also...you mentioned that you ran a number of items off one Arduino board...will I be able to use one board to run 4 gauges, (flap, & the three fuel quantity gauges), or is it one board per gauge?

Thanks to both of you..

Jim

Mach7

So...what I can gather after going through a very good youtube video

https://www.youtube.com/watch?v=OSzE6hgFWCM

the steps to use Link2fs may be a bit more straight forward than I thought...so correct me if I am wrong here...assuming the code is written to the Arduino board...by link2fs selections would be as follows

1. set up serial com(s) for the Arduino card (select respective serial port and select "connect")

Question....This is where I hit a bump in the road...how do I know which com (USB) port to select as I have many USB plugin on my sim.

2. Select "FSsimconnect extractions, page 2 and check the box that indicates "?x flap handle %"

3. Select Simconnect inputs (?? not sure about this one...but assuming it needs to know the pot values of the mechanical flap selector lever??) scroll down and to highlight one of the flap variables, (either c15, Decrements flap handle postion or, c17xx  sets flap handle to closest increment...not sure which one or either for my application at this point)

4. Finally select "other stuff" for PWM outputs for
meters ($F flap position) click this box.

how many missteps or misinterpretations have I made so far??



Mach7

@ame

Here is a copy of the SIOC code, (notepad) that runs my (DC Servo motor driven) Flap gauge at present...not sure if this gives us any insight into preparing the code for the type of Flap Gauge we are dealing with now;



Var 0033, name servo_flaps, Link USB_SERVOS, Device 2, Output 5, PosL 471, PosC 715, PosR 959

Var 0034, name flaps_fsuipc, Link FSUIPC_IN, Offset $0BE0, Length 4 // flap indicator gauge
{
  L0 = &flaps_fsuipc   
  L0 = ABS L0
  IF L0 = 0
  {
    &ind_le_extend = 0   
    &ind_le_trans = 0   
  }
  ELSE
  {
    L1 = 0   
    &ind_le_trans = 1   
    IF L0 = 409
    {
      L1 = 1   
      &ind_le_trans = 0   
    }
    IF L0 = 819
    {
      L1 = 1   
      &ind_le_trans = 0   
    }
    IF L0 = 2047
    {
      L1 = 1   
      &ind_le_trans = 0   
    }
    IF L0 = 4095
    {
      L1 = 1   
      &ind_le_trans = 0   
    }
    IF L0 = 6143
    {
      L1 = 1   
      &ind_le_trans = 0   
    }
    IF L0 = 10239
    {
      L1 = 1   
      &ind_le_trans = 0   
    }
    IF L0 = 12287
    {
      L1 = 1   
      &ind_le_trans = 0   
    }
    IF L0 = 16383
    {
      L1 = 1   
      &ind_le_trans = 0   
    }
    &ind_le_extend = L1   
  }
  L2 = L0   
  C0 = L0 >= 0
  C1 = L0 <= 496
  IF C0 AND C1
  {
    &flaps_low_val = 0         
    &flaps_high_val = 496
    &servo_high_val = 471
    &servo_low_val = 742        // 0 and 18 degrees
 }
  C0 = L0 >= 496
  C1 = L0 <= 8000
  IF C0 AND C1
  {
    &flaps_low_val = 496
    &flaps_high_val = 8000
    &servo_high_val = 742   
    &servo_low_val = 867         // 18 and 24 degrees
  }
  C0 = L0 >= 8000
  C1 = L0 <= 11000
  IF C0 AND C1
  {
    &flaps_low_val = 8000
    &flaps_high_val = 11000
    &servo_high_val = 867   
    &servo_low_val = 910        // 24 and 30 degrees
  }
  C0 = L0 >= 11000
  C1 = L0 <= 14000
  IF C0 AND C1
  {
    &flaps_low_val = 11000
    &flaps_high_val = 14000
    &servo_high_val = 910
    &servo_low_val = 959         // 30 and 33 degrees
}
  &servo_calc = &servo_low_val - &servo_high_val
  &flaps_calc = &flaps_high_val - &flaps_low_val
  &flaps_val = L0 - &flaps_low_val
  &servo_val = &servo_calc * &flaps_val
  &servo_val = &servo_val / &flaps_calc
  L1 = &servo_high_val + &servo_val
  &servo_flaps = L1   
}

Var 0003, name servo_val

Var 0004, name flaps_calc

Var 0005, name servo_calc

Var 0006, name flaps_val

Var 0007, name flaps_low_val

Var 0008, name flaps_high_val

Var 0009, name servo_high_val

Var 0010, name servo_low_val

Var 0011, name ind_le_extend, Link IOCARD_OUT, Output 22

Var 0012, name ind_le_trans, Link IOCARD_OUT, Output 21

_alioth_

#66
Quote from: Mach7 on August 12, 2023, 05:37:51 AM1. set up serial com(s) for the Arduino card (select respective serial port and select "connect")
Question....This is where I hit a bump in the road...how do I know which com (USB) port to select as I have many USB plugin on my sim.

Go to  Device Manager in Windows, plug and unplug the arduino usb and look in Com ports. there will be one appearing and disappearing.


Quote2. Select "FSsimconnect extractions, page 2 and check the box that indicates "?x flap handle %"
Fine.

Quote3. Select Simconnect inputs (?? not sure about this one...but assuming it needs to know the pot values of the mechanical flap selector lever??) scroll down and to highlight one of the flap variables, (either c15, Decrements flap handle postion or, c17xx  sets flap handle to closest increment...not sure which one or either for my application at this point)
you weren't using a leo bodnar card for this? So you don't need. Perhaps you can use it in future. But keep things simple first. So Leo bodnar moves the flaps, and you read the flap position with link2fs. That's fine.

Quote4. Finally select "other stuff" for PWM outputs for
meters ($F flap position) click this box.

I don't know what this is. When you get the flap position in arduino, you will do PWM thing there, in the arduino sketch.



ame

I can't find a simple solution for SIOC to Arduino, so that might be a non-starter I'm afraid. And some of the other solutions that pop up don't work for fs9.

You are right, keeping track of the Arduino serial port might be tricky. In general, windows seems to attach the same device to the same serial port if it can. You may find that every time you boot up you will get the same COM port for this Arduino. One possible solution is to buy a genuine Arduino, which has a serial number (clones do not). This allows you to see exactly where the Arduino is by following the serial number. But that's not a problem yet.

You can drive up to six PWM pins on the Arduino, so four instruments that work like the flaps gauge is no problem. And yes, you can measure a pot to get the position of the flaps lever and send that back to the sim (so the data makes a round trip: pot -> Arduino input -> Arduino serial output -> PC serial input -> link2fs -> simulator -> link2fs -> PC serial output -> Arduino serial input -> PWM output -> gauge).

I'll get back to you about the link2fs settings. At the moment I suggest you focus only on getting a single piece of data out and into the Arduino, specifically the current flaps position. Don't worry about the other gauges or the simconnect inputs.

There is a monitor section on link2fs which shows the data going to the Arduino. If you get it going you should see an equals sign followed by a lowercase letter followed by a string of numeric digits representing the flaps position. I think it is live, so if you vary the flaps the number will change.

Doing development like this at arm's length will take a while, but it will be methodical.

Once you know that link2fs can extract the data element that you want, and you can see the format of the number the next step is to write the Arduino code. Fortunately that appears to be really straightforward.

ame

I think Arturo and I agree.

If we ever disagree it will be an interesting exercise for you to decide who is right.

Mach7

Hey...both you guys are great and I cannot thank you enough for the help...all good agreeable information so far...

So...I am going to take ame's advice and concentrate on building the flap program from scratch. Once the Arduino has the flap code...then it will be on to Link2fs.

I have spent the day going over programming tutorials, and I think I might be able to pull this off...of course I will need answers to a lot of questions.

lets see how far i get...

Mach7

So i need a bit of a launching pad to get started...I have successfully written a few codes using the arduino examples section..some from scratch and others by just modifying the existing code.

I was hoping the examples would contain a pwm circuit that I could copy and modify...but no joy so far.

Can I actually write and download the code on my laptop then install the arduino uno and configure useing link2fs? or am I going to have to do it all at once.

Not sure if my rambling makes any sense.

ame

Woah, Trigger! You pretty much have to work with link2fs and the Arduino code together. For the Arduino code you need to know what data to expect, which you only know after you've set it up in link2fs.

Yes, you can write the Arduino code on your laptop, download it to the Arduino itself, then unplug the Arduino and plug it in to the flight simulator pc. That might become a bit tiresome, but hopefully you only need to do it a couple of times.

Don't worry too much about the pwm. You're basically going to get a number from link2fs representing the flaps position, do a bit of maths to convert it to 0-255, then analogWrite(pin, value) to drive the gauge.

ame

I've read a little more, and I now realise that stuff coming out of link2fs is not always separated by an equals sign. Sometimes it's equals, sometimes a question mark, sometimes less than, etc., followed by another letter (upper or lower case).

Doesn't matter. All you need to know is the marker for the flaps angle. Are you sure it's "?x flap handle %"? That sounds like the control lever, not the flaps themselves. In one of the screenshots I saw it's "FSConnect Extractions (1)" "<G Flaps Position", but it could be different for your aircraft.

Whatever it is you should be able to see it in the Traffic Monitor "to card". When you change the flaps the number should change. Please report back the marker (maybe ?x, maybe <G) and the format of the number. Change the flaps and note down a few values at key flap positions, so you know the range of values to expect. For the purposes of illustration let's say it's ?x followed by zero padded three digits of degrees (from 000 to 359, but actually you only see from 000 to 033 because that's the range of the gauge). I have no idea if that is correct, but it's an example.

Next, copy one of the sample INO files for Arduino. The setup code has to set up the pwm output pin that has the gauge attached, and drive it to zero. The loop code continually waits for incoming serial data. In the example case, if you see an incoming "?" then you wait for the next character. If it's an "x" then you know the next three characters are your degree value. So you bring in three more characters, convert them to a number, do some maths (maybe just multiply by 7.727) and write the pwm value. Obviously there are a few details to take care of, but that's basically it.
Then you loop around and do it all again.

Mach7

Ok thanks ame,

Yes...I was wondering how I would see the inputs outputs then remembered the "traffic" monitor on linkf2fs itself.

With respect to the flap box...i think you may be correct as i am not sure it would be ?x flap handle %.

I will do some experimenting today.

Jim

Mach7

@ame & Arturo

Some progress has been made...

So I downloaded link2fs onto my main sim computer...the computer already had "FSconnect.dll" in the FS9 modules folder, so that is one step i could skip.(most likely due to the OpenCockpits program).

I had some trial and error, but found you cannot read anything off the (link2fs) monitor unless fs9 is up and running with the respective sim platform booted up...in my case Quality Wings 146.

Next I connected the USB + Arduino and found that it would only take info from com port 1, if anything else was selected, (say com 2, 3, 4 etc), it would flash on and off (green) at the communications portal box. Since it seemed happy at this selection I left well enough alone.

Regardless, the next step was to select card one, move to the FS extractions page where I selected <G flaps position, then moved to cycle the flaps from zero to 18, then to 24, then to 30, then to 33, (Fs9 + qw146 program booted up).

With each flap selection the monitor would indicate an increasing value from <G000 to <G002..003 etc etc until the flaps stopped at 18 degress where the monitor showed <G020. (Not sure why it did not say <G018, but that is something we can deal with later)

Anyway, once the flaps were moved all the way to 33, the monitor showed (and stopped counting) at <G033.

When I retracted the flaps, the counter went from <G033 all the way to <G000 once the flaps were indicating at zero.

I have included some screen shots...take note they are random, but they outline the selections I made on Link2fs and also what the monitor was showing when the flap lever was being selected.

As the flaps travelled to

Like the Website ?
Support Cockpitbuilders.com and Click Below to Donate