Rise
The Vieneo Province
Toggle main menu visibility
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.
8
namespace
FlightPath
{
9
constexpr
double
Degrees
=0.017453292519943295;
10
constexpr
double
Minimum
=-20*
Degrees
,
Maximum
=20*
Degrees
;
11
inline
bool
Valid
(
double
horizontal,
double
vertical)
12
{
return
std::isfinite(horizontal)&&std::isfinite(vertical)&&horizontal>=.010; }
13
inline
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.
18
template
<
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
}
24
inline
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
}
32
template
<
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
}
int
SCRIPT_CONTROL SCRIPT_STATE const void int
Definition
Controls.cpp:5032
FlightPath
Definition
FlightPath.h:8
FlightPath::Degrees
constexpr double Degrees
Definition
FlightPath.h:9
FlightPath::NextVertical
auto NextVertical(typename Afcs::VerticalModes current, bool onGround, double horizontal, double vertical)
Definition
FlightPath.h:18
FlightPath::Maximum
constexpr double Maximum
Definition
FlightPath.h:10
FlightPath::Capture
double Capture(double horizontal, double vertical)
Definition
FlightPath.h:13
FlightPath::Valid
bool Valid(double horizontal, double vertical)
Definition
FlightPath.h:11
FlightPath::Pitch
double Pitch(double selected, double horizontal, double vertical, double pitch, double previous, double dt)
Definition
FlightPath.h:24
FlightPath::Minimum
constexpr double Minimum
Definition
FlightPath.h:10
FlightPath::SpeedHoldModes
bool SpeedHoldModes(const Afcs &a)
Definition
FlightPath.h:32
Modules
FlightPath.h
Generated on
for Rise by
1.18.0