Skip to content

Commit

Permalink
Merge pull request #34 from dkavolis/airspeed
Browse files Browse the repository at this point in the history
Expose IAS and EAS in FARAPI
  • Loading branch information
dkavolis authored Mar 25, 2019
2 parents 8b1dbbb + 59169f7 commit 777aa07
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 11 deletions.
20 changes: 20 additions & 0 deletions FerramAerospaceResearch/FARAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,26 @@ public static FlightGUI VesselFlightInfo(Vessel v)
return Instance.GetFlightInfo(v);
}

public static double ActiveVesselIAS()
{
return VesselIAS(FlightGlobals.ActiveVessel);
}

public static double VesselIAS(Vessel vessel)
{
return VesselFlightInfo(vessel)?.airSpeedGUI?.CalculateIAS() ?? 0;
}

public static double ActiveVesselEAS()
{
return VesselEAS(FlightGlobals.ActiveVessel);
}

public static double VesselEAS(Vessel vessel)
{
return VesselFlightInfo(vessel)?.airSpeedGUI?.CalculateEAS() ?? 0;
}

public static double ActiveVesselDynPres()
{
return VesselDynPres(FlightGlobals.ActiveVessel);
Expand Down
33 changes: 22 additions & 11 deletions FerramAerospaceResearch/FARGUI/FARFlightGUI/AirspeedSettingsGUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,24 @@ public bool GetVelocityDisplayString(out string value_out, out SurfaceVelMode mo
return allEnabled && enabled && active;
}

public double CalculateIAS()
{
double pressureRatio = FARAeroUtil.RayleighPitotTubeStagPressure(_vessel.mach); //stag pressure at pitot tube face / ambient pressure

double velocity = pressureRatio - 1;
velocity *= _vessel.staticPressurekPa * 1000 * 2;
velocity /= 1.225;
velocity = Math.Sqrt(velocity);

return velocity;
}

public double CalculateEAS()
{
double densityRatio = (FARAeroUtil.GetCurrentDensity(_vessel) / 1.225);
return _vessel.srfSpeed * Math.Sqrt(densityRatio);
}

public void ChangeSurfVelocity()
{
// No need to build the string
Expand All @@ -152,7 +170,7 @@ public void ChangeSurfVelocity()
return;

double unitConversion = 1;
string unitString;// = "m/s";
string unitString; // = "m/s";
string caption;
if (unitMode == SurfaceVelUnit.KNOTS)
{
Expand Down Expand Up @@ -184,22 +202,15 @@ public void ChangeSurfVelocity()
{
caption = surfModel_str[1];
//double densityRatio = (FARAeroUtil.GetCurrentDensity(_vessel) / 1.225);
double pressureRatio = FARAeroUtil.RayleighPitotTubeStagPressure(_vessel.mach); //stag pressure at pitot tube face / ambient pressure

double velocity = pressureRatio - 1;
velocity *= _vessel.staticPressurekPa * 1000 * 2;
velocity /= 1.225;
velocity = Math.Sqrt(velocity);

velString = (velocity * unitConversion).ToString("F1") + unitString;
velString = (CalculateIAS() * unitConversion).ToString("F1") + unitString;
}
else if (velMode == SurfaceVelMode.EAS)
{
caption = surfModel_str[2];
double densityRatio = (FARAeroUtil.GetCurrentDensity(_vessel) / 1.225);
velString = (_vessel.srfSpeed * Math.Sqrt(densityRatio) * unitConversion).ToString("F1") + unitString;
velString = (CalculateEAS() * unitConversion).ToString("F1") + unitString;
}
else// if (velMode == SurfaceVelMode.MACH)
else // if (velMode == SurfaceVelMode.MACH)
{
caption = surfModel_str[3];
velString = _vessel.mach.ToString("F3");
Expand Down
Binary file not shown.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ CHANGELOG
=======================================================
-------------------master branch-------------------

Expose IAS and EAS used by FAR in FARAPI ([#34](https://github.com/dkavolis/Ferram-Aerospace-Research/pull/34))
Enable/disable FAR speed display on the navball from FARAPI ([#33](https://github.com/dkavolis/Ferram-Aerospace-Research/pull/33))

0.15.9.7V "Lumley"------------------------------------
Expand Down

0 comments on commit 777aa07

Please sign in to comment.