Rise
The Vieneo Province
Loading...
Searching...
No Matches
FlightPath.h
Go to the documentation of this file.
1#pragma once
2#include <algorithm>
3#include <cmath>
4
5// Geometry in the local, rotating ground frame. This is not pitch or air-relative
6// AoA: winds change the pitch needed to hold this angle. No Earth atmosphere is
7// assumed. Hover has no meaningful forward flight path and captures PIT instead.
8namespace FlightPath {
9constexpr double Degrees=0.017453292519943295;
10constexpr double Minimum=-20*Degrees, Maximum=20*Degrees;
11inline bool Valid(double horizontal,double vertical)
12{ return std::isfinite(horizontal)&&std::isfinite(vertical)&&horizontal>=.010; }
13inline double Capture(double horizontal,double vertical)
14{ return Valid(horizontal,vertical)?(std::clamp)(std::atan2(vertical,horizontal),Minimum,Maximum):0; }
15// Use the same availability gate as the running FPA controller. Otherwise a
16// press from PIT selects FPA, which immediately falls back to PIT, trapping the
17// cycle on the ground or in hover before VS/SPD/ALT can be reached.
18template<class Afcs> auto NextVertical(typename Afcs::VerticalModes current,bool onGround,double horizontal,double vertical)
19{
20 auto next=static_cast<typename Afcs::VerticalModes>(int(current)+1);
21 if(next==Afcs::FlightPathAngle&&(onGround||!Valid(horizontal,vertical))) next=Afcs::VerticalSpeed;
22 return next;
23}
24inline double Pitch(double selected,double horizontal,double vertical,double pitch,double previous,double dt)
25{
26 if(!Valid(horizontal,vertical)||!std::isfinite(selected)||!std::isfinite(pitch)||!std::isfinite(previous)||!std::isfinite(dt)) return previous;
27 const double error=(std::clamp)(selected,Minimum,Maximum)-std::atan2(vertical,horizontal);
28 // Pitch is not FPA: retain correction authority with a negative AoA/wind.
29 const double target=(std::clamp)(pitch+error,-25*Degrees,25*Degrees);
30 return previous+(std::clamp)(target-previous,-3*Degrees,3*Degrees)*(std::clamp)(dt,0.0,1.0);
31}
32template<class Afcs> bool SpeedHoldModes(const Afcs& a)
33{
34 return a.AutopilotEngaged&&!a.DorOn&&!a.TvmOn&&
35 (a.CurrentVerticalMode==Afcs::AltitudeMsl||a.CurrentVerticalMode==Afcs::AltitudeAgl||
36 a.CurrentVerticalMode==Afcs::FlightPathAngle||a.CurrentVerticalMode==Afcs::Glideslope||
37 a.CurrentVerticalMode==Afcs::VerticalSpeed||a.CurrentVerticalMode==Afcs::Pitch)&&
38 (a.CurrentLateralMode==Afcs::Heading||a.CurrentLateralMode==Afcs::Navigation||a.CurrentLateralMode==Afcs::Localizer);
39}
40}
SCRIPT_CONTROL SCRIPT_STATE const void int
constexpr double Degrees
Definition FlightPath.h:9
auto NextVertical(typename Afcs::VerticalModes current, bool onGround, double horizontal, double vertical)
Definition FlightPath.h:18
constexpr double Maximum
Definition FlightPath.h:10
double Capture(double horizontal, double vertical)
Definition FlightPath.h:13
bool Valid(double horizontal, double vertical)
Definition FlightPath.h:11
double Pitch(double selected, double horizontal, double vertical, double pitch, double previous, double dt)
Definition FlightPath.h:24
constexpr double Minimum
Definition FlightPath.h:10
bool SpeedHoldModes(const Afcs &a)
Definition FlightPath.h:32