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

April 28, 2024, 05:52:29 AM

Login with username, password and session length

PROUDLY ENDORSING


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

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 2 Guests are viewing this topic.

ame

Ok. It's not a problem. Ironically for this kind of thing you have to think inside the box. In this case, imagine you are the Arduino. You get three numbers. That's it. You have to convert those three numbers to needle positions.

At this moment in time your simulator configuration is fixed, so you have to work within the restrictions you have.

What you are saying, I think, is that you will never see a value of 100 for your left/right tanks? Instead, the largest value you will see is 088. Is that right?

Mach7

Yes...that is correct...in fact..there is no way the system will let me go above that value,therefore there is no way I could 'hurt' or damage the gauge.

_alioth_

#177
Quote from: Mach7 on August 21, 2023, 04:49:37 PM...therefore there is no way I could 'hurt' or damage the gauge.

I think this sentence means you don't understand yet how the system you are building works. And I want to help you.

Why are you thinking the gauge is or not safe depeding on simulator variables values? I am interested in your thoughts in order to help you understand the system.

Mach7

#178
@Arturo,

Probably not the best sentence to use on my behalf. I think I am just reinforcing the fact that...if program was written in a way that allowed variables above the maximum limit, (which it won't be),and for some reason I in inadvertently entered a value of 110 or 120 percent fuel. The FS9 program would see that as an aircraft exceedence in fuel quantity and not allow that value to be pushed through link2fs to the gauge and possible exceeding the needle authority.


Mach7

@ame. With respect to the code, would it be prudent to run a test code on one gauge before we include the entire string of gauges under one script?

ame

Quote from: Mach7 on August 22, 2023, 05:05:43 AM@ame. With respect to the code, would it be prudent to run a test code on one gauge before we include the entire string of gauges under one script?
Yes and no. Once the operation of the gauge has been understood it can be incorporated into the other code running on the Arduino. Although the Arduino is running only one program it's very compartmentalised, so the section that drives one gauge is independent of the others. Even link2fs can be configured right now to export all the data that will be needed for all four gauges. The current code will ignore anything except the data that is tagged to mean flaps.

Mach7

Ok, i understand. Do you need anything additional from my end with regards to values?

_alioth_

I see.

Part 1:
We'll think about it the other way around.  Think only about the Arduino first and forget about the fs9/link2fs.
The arduino pin can send 0v when the state is LOW. And 5v when the pin is HIGH (HIGH is the maximum that Arduino can send through the pin).
You have already tested that when you send 5v, the fuel gauge is not damaged. It doesn't even reach the top of the scale. So... there is nothing you can do inside the Arduino code to make the needle go beyond the limit.
You cannot physically send more than 5v (HIGH) from an Arduino UNO pin.

Whether you get a value from the simulator that says 1, 100, or 10000, you can't send more than 5v through the pin.

Part 2:
We don't want the needle to be only in the rest position and in the maximum position. We want intermediate positions.
This is what PWM is for.
Although it is not quite correct, for now you think that with pwm we can send from 0 to 5v, in 255 intermediate steps.
But we can't send less than 0, nor more than 5v. Even if we want to, we can't. Physically we can't. There is no more than 5v on the Arduino pin.
The important thing here is that we can send 255 possible positions between the minimum of 0v and the maximum of 5v.


Part 3:
This is where we receive data from the simulator, no matter what the values are. We need to know the total range, and that's why Ame asks you what numbers you see link2fs sending in reference to the fuel. We convert those values to the different steps between 0v and 5v.  But again, even if we want to, or if we miscalculate, we cannot send less than 0v, nor more than 5v. Physically you can't.
What we do is to convert the fuel values (in this case they seem to be from 0 to 100) into pwm values from 0 to 255, so that the needle matches in the software and in our cockpit.
When we find the correlation, both needles will be synchronised.


So... there is no value that you can receive from link2fs... that can damage the fuel gauge... are you understanding why?
It is the basis for programming any gauge.

Mach7

I do understand, thanks for the clarification.

ame

Quote from: Mach7 on August 22, 2023, 05:26:15 AMOk, i understand. Do you need anything additional from my end with regards to values?
Actually, I'm not sure where we're at.

I think I'd like to review two things.

1) We have established that the fuel gauge reaches fsd at much less than 5V. You installed a 660R resistor as a multiplier (and to protect the gauge), but you no longer got fsd. You then replaced it with a multiturn pot, but the needle only hits 95. Is that right? I'd really like to fix it so that 100% PWM hits 100 on the gauge.

2) We have established that link2fs sends a number for the left, centre, and right tanks:
"<X" for the left tank in percent.
"<Y" for the center tank in percent
"<Z" for the right tank in percent.
These values are sent as three numeric characters 000 to 100.
The gauge face is marked 0 to 10,000lbs (as 0 to 100 x100lbs), and the left and right tanks hold 8120 lbs of fuel. Therefore if link2fs reports <X100 it means 100% fuel in the left tank, so the gauge points to 81.2? Further to this, the centre tank has a capacity of 4400 lbs, so when link2fs reports <Y100 it means 100% fuel in the centre tank, so the gauge points to 44?
I'm going to ignore the extra 1000 lbs fuel tank that you don't have, and concentrate on the current configuration. If you add the upgrade later you will have to edit the Arduino code because 100% will mean something different.

I should have made two posts with these questions, sorry. Feel free to answer in two different replies.

Mach7

#185
Hello ame,

1) We have established that the fuel gauge reaches fsd at much less than 5V. You installed a 660R resistor as a multiplier (and to protect the gauge), but you no longer got fsd. You then replaced it with a multiturn pot, but the needle only hits 95. Is that right? I'd really like to fix it so that 100% PWM hits 100 on the gauge.

That was a suggestion by Arturo, but I never installed the pot...i still have the resistors in place. With the resistors in place the gauge goes to "just" about full scale..on the fade program it goes up to 95 to 96 out of 100...100 being full scale. I could probably make adjustments to have it go right to 100 if it is absolutely necessary.

2) We have established that link2fs sends a number for the left, centre, and right tanks:
"<X" for the left tank in percent.
"<Y" for the center tank in percent
"<Z" for the right tank in percent.
These values are sent as three numeric characters 000 to 100.


This is correct.

The gauge face is marked 0 to 10,000lbs (as 0 to 100 x100lbs), and the left and right tanks hold 8120 lbs of fuel. Therefore if link2fs reports <X100 it means 100% fuel in the left tank, so the gauge points to 81.2?

Yes,..(sort of). If I use the FS9 drop down menu and put a value of "100" percent it will tell me that I have exceeded the fuel load. If I put "88" percent, the tank will read 81.2. When I note the link2fs monitor..it too shows a value of <X088. The resaon for this is the values are a percentage of 9200 pounds not 8120 pounds...just the way the sim is set up....so 88 percent of 9200 is approx 8120.

Further to this, the centre tank has a capacity of 4400 lbs, so when link2fs reports <Y100 it means 100% fuel in the centre tank, so the gauge points to 44?

Yes, this is correct..but again, i have to put a value in of 99.9 or the program will tell me I have exceeded the fuel capacity by 2 pounds. I have not tested it..but I am confident that the monitor would show <Y099

I'm going to ignore the extra 1000 lbs fuel tank that you don't have, and concentrate on the current configuration. If you add the upgrade later you will have to edit the Arduino code because 100% will mean something different.

I will never add the upgrade later...most 146 variants did not have this extra fuel anyway.


ame

Thanks for clarifying things. I think that's everything, but I'll state my assumptions every time so please stop me if I make a mistake.

It's not critical for 100% PWM to cause the needle to hit fsd, but I assert it will make a bunch of future headscratching disappear if you don't have to remember why you didn't do it the first time around. If I can convince you to do it then please do. Unfortunately it means you can't just pick up three identical resistors, one for each gauge. Instead you'll have three identical pots, but each one must be adjusted until it's correct. Actually, you can do it any way you like, if you choose to do it.

It also means that the table you made for PWM to gauge reading will have to be re-done, and the maths recalculated, but that's a good exercise.

And I understand that because of the way the simulator is written, 100% represents 9200 lbs (because, reasons). The good news is that if you ever buy the upgrade you won't need to change the code.

So, in order to proceed we need a definite decision on whether you will or will not adjust the resistor to get 100% PWM hitting 100 on the gauge. Either way I don't mind, but I recommend that you do it.

Then, double check the table of results for PWM to gauge position if you didn't change the resistance, or create a new table of PWM to gauge position if you did.

I'll hack together a quick Arduino program to drive the gauges and you can try it out. You'll see it looks very similar to the flaps code, and is basically: get some data in from link2fs, do some simple maths, write to the PWM pin.

For the fuel gauge I think it is unnecessary to dampen the needle movement. In normal use they will move very slowly. At start up they will jump instantly to the initial position. However, if that's not what you want we can look at that later.

Mach7

I will endeavour to get the gauge to 100 mark using various resistors...I am pretty sure I can achieve that so that will be my work for tonight/tomorrow.

Following this I will re due the numbers and send these values to you.

fuel needle movement at start up will be fine..whether it is fast or slow.

Mach7

Ok...testing complete...

I reduced the resistor value to 637 ohms giving me a needle indication of exactly, or very close to 100 on the gauge. (Maybe a mm away from the 100 mark)

Following this I tabulated the values again, and actually found little to no difference...here are my findings, (I did not populate the increase/ decrease list as the values were the same...some more accurate on the way up..and others more accurate on the way down..that is to say the needle stopped at exactly a benchmark value like 10..20..30 etc.)

needle value / serial monitor

    0..............75
   10..............90
   20..............110
   30..............130
   40..............145
   50..............165
   60..............180
   70..............205
   80..............220
   90..............240
  100..............255


ame

Ok. Try this. It does compile, but it has not been tested at all. What could possibly go wrong?

Quote/*
    This code is in the public domain
    For use with "Link2fs_Multi"
    Jimspage.co.nz (via archive.org)

*/

int CodeIn;// used on all serial reads

String flaps;
String fuel;    // Re-use this variable for all fuel gauges as we only do one at a time

// PWM pins for gauges. Must be one of 3, 5, 6, 9, 10, or 11 for Arduino Uno
// Flaps
int flaps_PWM_out_pin = 3;
// Fuel
int fuel_L_PWM_out_pin = 5; // Left fuel gauge
int fuel_C_PWM_out_pin = 6; // Centre fuel gauge
int fuel_R_PWM_out_pin = 9; // Right fuel gauge

// Variables for fuel gauges
// Can be reused for each gauge as we do one at a time.
int fuel_PWM_out;
float fuel_percent;
float fuel_lbs;


// Variables to support incremental update of gauges
unsigned long currentMillis; // store the current time

unsigned long previousMillis;
unsigned long period = 100; // 100millis = 0.1s, 10 updates per second

// Variables for flaps gauge
const int flaps_max_PWM_per_slot=1; // Maximum amount we can move in 0.1s

int flaps_PWM_target; // Target PWM value, based on last flaps degrees
int flaps_PWM_current; // Current PWM value, can only move slowly

bool first_flaps_PWM_value; // Flag to see if we should go directly to target



void setup()
{
  Serial.begin(115200);
 
  // Set up PWM pins.
  pinMode(flaps_PWM_out_pin, OUTPUT);
  pinMode(fuel_L_PWM_out_pin, OUTPUT);
  pinMode(fuel_C_PWM_out_pin, OUTPUT);
  pinMode(fuel_R_PWM_out_pin, OUTPUT);

  // Set PWM values to zero.
  analogWrite(flaps_PWM_out_pin, 0);
  analogWrite(fuel_L_PWM_out_pin, 0);
  analogWrite(fuel_C_PWM_out_pin, 0);
  analogWrite(fuel_R_PWM_out_pin, 0);
 
  flaps_PWM_target=0;
  flaps_PWM_current=0;
  first_flaps_PWM_value=true;
}


void loop() {
  // Deal with incoming data from link2fs
  if (Serial.available()) {
    CodeIn = getChar();
    if (CodeIn == '=') {EQUALS();} // The first identifier is "="
    if (CodeIn == '<') {LESSTHAN();}// The first identifier is "<"
    if (CodeIn == '?') {QUESTION();}// The first identifier is "?"
    if (CodeIn == '/') {SLASH();}// The first identifier is "/" (Annunciators)
  }

  // Other tasks
  // Currently we have to smooth the flaps output.
  // Fuel gauges don't need smoothing.
  currentMillis = millis(); // store the current time
  if (currentMillis - previousMillis >= period) { // check if 100ms passed
  // We're on a 100ms boundary
    previousMillis = currentMillis;   // update the time we were here
    if (flaps_PWM_target > flaps_PWM_current) {
      flaps_PWM_current += flaps_max_PWM_per_slot;
      if (flaps_PWM_current > flaps_PWM_target) flaps_PWM_current=flaps_PWM_target;
    }
    else if (flaps_PWM_target < flaps_PWM_current) {
      flaps_PWM_current -= flaps_max_PWM_per_slot;
      if (flaps_PWM_current < flaps_PWM_target) flaps_PWM_current=flaps_PWM_target;
    }
    else {
      // target and current are equal. Nothing to do.
    }
    analogWrite(flaps_PWM_out_pin, flaps_PWM_current);
  }

}


char getChar()// Get a character from the serial buffer
{
  while(Serial.available() == 0);// wait for data
  return((char)Serial.read());// Thanks Doug
}


void EQUALS(){      // The first identifier was "="
  CodeIn = getChar(); // Get another character
  switch(CodeIn) {// Now lets find what to do with it
    case 'A'://Found the second identifier
       //Do something
    break;
     
    case 'B':
       //Do something
    break;
     
    case 'C':
       //Do something
    break;
  }
}


void LESSTHAN(){    // The first identifier was "<"
  CodeIn = getChar(); // Get another character
  switch(CodeIn) {// Now lets find what to do with it
    case 'A'://Found the second identifier
       //Do something
    break;
     
    case 'B':
       //Do something
    break;
     
    case 'G': //Found the second identifier ("G" Flaps position)
      // Next three characters should be numeric
      flaps = "";
      flaps += getChar();
      flaps += getChar();
      flaps += getChar();
      // convert 3-character numeric string to a float
      // Expected range is 000 to 033
      float flaps_degrees = flaps.toFloat();
      // Convert degrees to PWM 0-255.
      // 33 degrees is full scale, so multiplier is 255/33=7.727
      int PWM_out = flaps_degrees*7.727;
      // Clip output to maximum if (for some reason) it's >255
      if(PWM_out > 255) PWM_out=255;
      // New flaps PWM is calculated. Copy to other variables to
      // be handled by main loop on next 100ms boundary
      flaps_PWM_target=PWM_out;
      // If this is the first value we have received, go directly there.
      if (first_flaps_PWM_value) {
        flaps_PWM_current=flaps_PWM_target;
        first_flaps_PWM_value=false;
      }
    break;
   
    case 'X': // "X" left fuel gauge
      // Next three characters should be numeric
      fuel = "";
      fuel += getChar();
      fuel += getChar();
      fuel += getChar();
      // convert 3-character numeric string to a float
      // It's a percentage of full, where full is 9200 lbs (left)
      // Expected range is 000 to 100
      fuel_percent = fuel.toFloat();
      fuel_lbs = fuel_percent * 9200;
      // Convert lbs to PWM 0-255.
      // 0 lbs on gauge is PWM 75
      // 10,000 lbs on gauge is 255
      // So PWM is (1.8 x (lbs/100)) + 75
      fuel_PWM_out = ((fuel_lbs * 1.8)/100.0)+75.0;
      // Clip output to maximum if (for some reason) it's >255
      if(fuel_PWM_out > 255) fuel_PWM_out=255;
      // Drive the gauge
      analogWrite(fuel_L_PWM_out_pin, fuel_PWM_out);
    break;

    case 'Y': // "Y" centre fuel gauge
      // Next three characters should be numeric
      fuel = "";
      fuel += getChar();
      fuel += getChar();
      fuel += getChar();
      // convert 3-character numeric string to a float
      // It's a percentage of full, where full is 4400 lbs (centre)
      // Expected range is 000 to 100
      fuel_percent = fuel.toFloat();
      fuel_lbs = fuel_percent * 4400;
      // Convert lbs to PWM 0-255.
      // 0 lbs on gauge is PWM 75
      // 10,000 lbs on gauge is 255
      // So PWM is (1.8 x (lbs/100)) + 75
      fuel_PWM_out = ((fuel_lbs * 1.8)/100.0)+75.0;
      // Clip output to maximum if (for some reason) it's >255
      if(fuel_PWM_out > 255) fuel_PWM_out=255;
      // Drive the gauge
      analogWrite(fuel_C_PWM_out_pin, fuel_PWM_out);
    break;

    case 'Z': // "Z" right fuel gauge
      // Next three characters should be numeric
      fuel = "";
      fuel += getChar();
      fuel += getChar();
      fuel += getChar();
      // convert 3-character numeric string to a float
      // It's a percentage of full, where full is 9200 lbs (left)
      // Expected range is 000 to 100
      fuel_percent = fuel.toFloat();
      fuel_lbs = fuel_percent * 9200;
      // Convert lbs to PWM 0-255.
      // 0 lbs on gauge is PWM 75
      // 10,000 lbs on gauge is 255
      // So PWM is (1.8 x (lbs/100)) + 75
      fuel_PWM_out = ((fuel_lbs * 1.8)/100.0)+75.0;
      // Clip output to maximum if (for some reason) it's >255
      if(fuel_PWM_out > 255) fuel_PWM_out=255;
      // Drive the gauge
      analogWrite(fuel_R_PWM_out_pin, fuel_PWM_out);
    break;
   
  }
 
}

void QUESTION(){    // The first identifier was "?"
CodeIn = getChar(); // Get another character
  switch(CodeIn) {// Now lets find what to do with it
    case 'A'://Found the second identifier
       //Do something
    break;
     
    case 'B':
       //Do something
    break;
     
    case 'C':
       //Do something
    break;
     }
}
void SLASH(){    // The first identifier was "/" (Annunciator)
  //Do something
}

Mach7

Thank you ame!!!

Will give it a try today and report back

ame

Eek! There's a bug!

We have to divide by 10000, not 100!

Change this line:
fuel_PWM_out = ((fuel_lbs * 1.8)/100.0)+75.0;

To this:
fuel_PWM_out = ((fuel_lbs * 1.8)/10000.0)+75.0;

In three places.

Mach7


_alioth_

#193
If 100% full is 9200lbs I think it should be:

fuel_PWM_out = ( 1.8 * 100/9200 ) * fuel_lbs + 75;

or just:

fuel_PWM_out = 0.01956522 * fuel_lbs + 75;


But why not use the percent read, and map function?

fuel_PWM_out = map ( fuel_percent, 0, 100, 75, 255);

and limit max and min values (just in case..):

fuel_PWM_out = constrain ( fuel_PWM_out, 0, 255);




Mach7

Ok, couple of issues.

First I just want to make sure that I do not have to have all 3 fuel gauges connected to test the system...right now I am using a single spare and connecting up to pin 5 for test purposes.

The flaps work fine, but the fuel gauge does not move at all.

I have checked the link2fs monitor, and it seems to be giving the output to the x,y,z axis.

I have checked the gauge and the wiring is all sound...using a 1.5 battery following disconnect form the board I confirmed that the harness is allowing to receive power., (small needle movement).

I opened the Arduino and downloaded the program a second time..no issues with the upload.

I opened the serial monitor port and typed in <X088 and the gauge did not move...I tried the other axis as well.

Just to confirm the monitor was working..i typed in <G020 and the flaps work fine.

The com port is good...it is selected to comm port 4 with everything in the green.

will do a bit more troubleshooting unless you see something obvious here.

thanks!

jim

Mach7

Hello Arturo..i when i sent my last message...and we were both sending at the same time, so i just saw what you wrote.

Do you think the change in code as you suggested may have something to do with my current issue?

Also...is there another selection I must make in Link2fs other than checking the boxes for X, Y and Z?

Jim

ame

Quote from: _alioth_ on August 23, 2023, 06:47:14 AMIf 100% full is 9200lbs I think it should be:

fuel_PWM_out = ( 1.8 * 100/9200 ) * fuel_lbs + 75;

or just:

fuel_PWM_out = 0.01956522 * fuel_lbs + 75;


But why not use the percent read, and map function?

fuel_PWM_out = map ( fuel_percent, 0, 100, 75, 255);

and limit max and min values:

fuel_PWM_out = constrain ( fuel_PWM_out, 0, 255);





I don't agree. 100% of the tank is 9200 lbs, but 100% of the gauge is 100 x100 lbs. So, if the tank is 100% full the gauge should be driven with less than 255 PWM, so that the needle points to 92.

For the current configuration the simulator won't allow the tank to be 100% "full" and caps the percentage at 88%, representing 8120 lbs, thus the needle should point to 81.

_alioth_

#197
QuoteI don't agree. 100% of the tank is 9200 lbs, but 100% of the gauge is 100 x100 lbs.

Sorry, I thought gauge showed 100%, and not 100x100lbs.
Thanks Ame.

Mach7

Hey guys...anything in the code that would stop this gauge from moving?....it appears that (as per the link2fs monitor) outputs are being sent...but for some reason the gauge (fuel) does not move.

Have triple checked all the connections...the com port 4 shows green...all the necessary boxes have been ticked off.

Ill do some additional troubleshooting...just seeing if anything obvious stands out in the code.

Jim

Mach7

#199
So some additional troubleshooting..as I am looking at this assuming the code is correct.

I replaced both the flap and fuel gauges with LEDz.

The flap out put from the arfuino serial monitor works fine with flaps..
<G020

But nothing happens when testing the fuel outputs

<X088
<Y088
<Z088

And like I said in previous post..with Link2fs connected and fs9/qw146 up and running..the monitor shoes the correct outputs for fuel..but no life at the gauge..flaps work fine with this code.

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