Rise
The Vieneo Province
Loading...
Searching...
No Matches
OrbitAscentAfcs.h
Go to the documentation of this file.
1#pragma once
2#include "OrbitState.h"
3
4namespace Orbital { namespace Ascent {
5// Rise ascent policy, not an Earth aircraft envelope. 50 km is the earliest
6// release; the existing ascent model's 500 Pa attitude-freedom threshold must
7// also be met. Hysteresis restores aircraft steering on a descending pickup.
9 bool aircraft=true;
10public:
11 bool Step(double altitudeKm,double qPa) {
12 if(!std::isfinite(altitudeKm)||!std::isfinite(qPa)||qPa<0) return aircraft=true;
13 if(altitudeKm<=45||qPa>=750) aircraft=true;
14 else if(altitudeKm>=50&&qPa<=500) aircraft=false;
15 return aircraft;
16 }
17};
18inline double SurfaceSupport(const Input& in,double q) {
19 const double weight=in.massKg*in.gm/Dot(in.own.r,in.own.r);
20 double lift=0;
21 for(const auto& a:in.entryAero)
22 lift=(std::max)(lift,q*std::pow(std::cos(a.angle),2)*(in.wingAreaM2*a.cl+a.tailLiftArea)/1000);
23 // A 1.1..1.5 weight lift reserve fades low-speed attitude assistance. This
24 // uses the vehicle's current aero data; measured lift alone would couple
25 // the fade back into elevator motion and make the two actuators hunt.
26 return (std::clamp)((lift/weight-1.1)/.4,0.0,1.0);
27}
28inline double BankLimit(const Input& in,double q) {
29 const Vec up=Unit(in.own.r);
30 const double gravity=in.gm/Dot(in.own.r,in.own.r);
31 const double support=in.entryVehicle.aeroValid?Dot(in.entryVehicle.aeroAcceleration,up)/gravity:0;
32 // Do not bank away VTOL lift before the wings provide positive support.
33 // Main thrust also carries weight in a climb; requiring wing lift alone
34 // to carry most of the weight delays turns until after useful airflow. Use the
35 // existing AFCS high-altitude 15 degree limit throughout the DOR climb.
36 return 15*Pi/180*(std::min)(SurfaceSupport(in,q),(std::clamp)((support-.1)/.2,0.0,1.0));
37}
38inline double HeadingBank(double desired,double actual,double limit) {
39 return (std::clamp)(std::remainder(desired-actual,Tau),-limit,limit);
40}
41inline double AircraftHeading(Vec radial,Vec nose,Vec target,double indicatedHeading) {
42 const Vec up=Unit(radial),forward=Unit(nose-up*Dot(up,nose));
43 const Vec right=Cross(up,forward);
44 const double turn=std::atan2(Dot(target,right),Dot(target,forward));
45 const double heading=std::fmod(indicatedHeading+turn+Tau,Tau);
46 return heading;
47}
48template<class Afcs> void ReleaseAircraft(Afcs& a) {
49 if(!a.DorAircraft) return;
50 a.DorAircraft=false;a.AutopilotEngaged=false;
51 a.CurrentLateralMode=Afcs::LateralMode_Off;a.CurrentVerticalMode=Afcs::VerticalMode_Off;
52 a.StandbyLateralMode=Afcs::LateralMode_Off;a.StandbyVerticalMode=Afcs::VerticalMode_Off;
53 a.DesiredRollRadians=0;a.PitchInput=a.RollInput=a.YawInput=0;
54}
55template<class Afcs> void AircraftModes(Afcs& a,const Guidance& g,bool assignedSteering=false) {
56 if(!a.DorOn||!g.valid||!g.ascentControl||!g.ascentAircraft||g.ascentWaiting||g.ascentLiftoff) {
57 ReleaseAircraft(a);return;
58 }
59 a.DorAircraft=true;a.AutopilotEngaged=true;
60 if(!assignedSteering||a.CurrentLateralMode!=Afcs::Navigation)a.CurrentLateralMode=Afcs::Heading;
61 a.CurrentVerticalMode=Afcs::Pitch;
62 a.StandbyLateralMode=Afcs::LateralMode_Off;a.StandbyVerticalMode=Afcs::VerticalMode_Off;
63 a.DorHeadingRadians=assignedSteering?a.DesiredHeadingRadians:float(g.heading);
64 a.DesiredPitchRadians=float(g.pitch);
65}
66}}
bool Step(double altitudeKm, double qPa)
void AircraftModes(Afcs &a, const Guidance &g, bool assignedSteering=false)
double HeadingBank(double desired, double actual, double limit)
double BankLimit(const Input &in, double q)
double SurfaceSupport(const Input &in, double q)
double AircraftHeading(Vec radial, Vec nose, Vec target, double indicatedHeading)
void ReleaseAircraft(Afcs &a)
constexpr double Tau
Definition OrbitMath.h:10
Vec Unit(Vec a)
Definition OrbitMath.h:20
double Dot(Vec a, Vec b)
Definition OrbitMath.h:16
constexpr double Pi
Definition OrbitMath.h:10
Vec Cross(Vec a, Vec b)
Definition OrbitMath.h:17
bool aeroValid
Definition OrbitState.h:96
Vec aeroAcceleration
Definition OrbitState.h:97
EntryVehicle entryVehicle
Definition OrbitState.h:123
std::array< AeroPoint, 9 > entryAero
Definition OrbitState.h:114
double wingAreaM2
Definition OrbitState.h:112