Rise
The Vieneo Province
Loading...
Searching...
No Matches
Tests/OrbitAscentAfcsTests.h

Source at documentation-generation time. See Test catalog for fixture associations.

1#pragma once
2#include "../Modules/OrbitAscentAfcs.h"
3
4void AscentAfcsTests()
5{
6 Snapshot orbit;orbit.radius=2939.6;orbit.own.bound=true;orbit.own.pe=orbit.radius+200;
7 for(const auto target:{TargetKind::Station,TargetKind::Vessel,TargetKind::Surface}) {
8 orbit.targetKind=target;Request selected;
9 for(int direction:{-1,1})for(int j=0;j<6;++j) {
10 Edit(selected,Row::Mode,direction,orbit,0);
11 Check(!selected.ascent,"established orbit never offers a parking/ascent mode");
12 }
13 }
14 Snapshot surface;surface.onGround=true;surface.targetKind=TargetKind::Station;
15 Request selected;selected.ascent=true;Edit(selected,Row::Mode,1,surface,100);
16 Check(selected.fastestMeet&&!selected.ascent&&!selected.adjust,"ground rendezvous defaults to fastest MEET");
17 selected.arrivalEpoch=100+21600;Edit(selected,Row::Arrival,1,surface,100);
18 Check(!selected.fastestMeet&&selected.passTime==PassTime::Manual&&selected.arrivalEpoch==21700,
19 "explicit future meeting up to six hours replaces fastest selection without a fuel-optimum upper limit");
20 Ascent::AircraftSteering steering;
21 Check(steering.Step(0,0)&&steering.Step(49.9,0),"aircraft steering covers low-density VTOL and climb below 50km");
22 Check(steering.Step(50,2000)&&steering.Step(75,501),"altitude alone cannot permit orbital yaw in appreciable airflow");
23 Check(!steering.Step(75,500)&&!steering.Step(49,600),"orbital transition requires both gates and retains hysteresis");
24 Check(steering.Step(45,100)&&steering.Step(49,600),"descending pickup restores AFCS below lower altitude boundary");
25 Check(!steering.Step(80,0)&&steering.Step(80,750),"increasing aerodynamic load independently restores AFCS");
26 Check(steering.Step(NAN,0)&&steering.Step(80,NAN),"invalid transition inputs cannot authorize a flat yaw");
27 for(double delta:{-150.0,-90.0,-1.0,0.0,1.0,90.0,150.0}) {
28 const Vec radial={0,1,0},nose={0,0,1},target=Rotate(nose,radial,delta*Pi/180);
29 const double indicated=180*Pi/180;
30 const double heading=Ascent::AircraftHeading(radial,nose,target,indicated);
31 Check(std::abs(std::remainder(heading-indicated,Tau)-delta*Pi/180)<1e-12,
32 "world target maps through actual body axes into AFCS compass convention");
33 const double bank=Ascent::HeadingBank(heading,indicated,15*Pi/180);
34 Check(std::abs(bank)<=15*Pi/180&&bank*delta>=0,"HDG banks the short way within its aircraft limit");
35 }
36 Check(std::abs(Ascent::HeadingBank(Pi/180,359*Pi/180,15*Pi/180)-2*Pi/180)<1e-12,"heading north crossing is a two-degree turn");
37 auto in=BillEntryFixture();in.own.r={0,in.radius+10,0};in.entryVehicle.aeroValid=true;
38 const double weight=in.gm/Dot(in.own.r,in.own.r);
39 in.entryVehicle.aeroAcceleration={0,weight*.05,0};
40 Check(Ascent::BankLimit(in,10000)==0,"initial forward acceleration retains wings level until supported");
41 in.entryVehicle.aeroAcceleration={0,weight,0};
42 Check(Ascent::BankLimit(in,100000)==15*Pi/180&&Ascent::SurfaceSupport(in,100000)==1,
43 "wing-supported aircraft uses bank authority and no routine attitude RCS");
44 Check(Ascent::SurfaceSupport(in,0)==0,"lost aerodynamic authority restores augmentation");
45
46 struct Afcs {
47 enum Lateral {LateralMode_Off,Heading,Navigation};
48 enum Vertical {VerticalMode_Off,Pitch,AltitudeMsl};
49 bool DorOn=true,DorAircraft=false,AutopilotEngaged=false;
50 Lateral CurrentLateralMode=Navigation,StandbyLateralMode=Navigation;
51 Vertical CurrentVerticalMode=AltitudeMsl,StandbyVerticalMode=AltitudeMsl;
52 float DorHeadingRadians=0,DesiredHeadingRadians=0,DesiredPitchRadians=0,DesiredRollRadians=.1f,PitchInput=1,RollInput=1,YawInput=1;
53 } a;
54 Guidance g;g.valid=g.ascentControl=g.ascentAircraft=g.attitude=true;g.heading=1;g.pitch=.2;
55 Ascent::AircraftModes(a,g);
56 Check(a.DorOn&&a.DorAircraft&&a.AutopilotEngaged&&a.CurrentLateralMode==Afcs::Heading&&a.CurrentVerticalMode==Afcs::Pitch,
57 "DOR source enables ordinary AFCS HDG and PIT servos");
58 Check(a.StandbyLateralMode==Afcs::LateralMode_Off&&a.StandbyVerticalMode==Afcs::VerticalMode_Off,
59 "stale armed modes cannot capture during DOR climb");
60 Check(a.DorHeadingRadians==1&&a.DesiredHeadingRadians==0&&std::abs(a.DesiredPitchRadians-.2)<1e-7,"AFCS follows DOR commands without overwriting the assigned heading");
61 Ascent::AircraftModes(a,g,true);
62 Check(a.DorHeadingRadians==0,"returning to assigned steering restores selected heading");
63 a.CurrentLateralMode=Afcs::Navigation;Ascent::AircraftModes(a,g,true);
64 Check(a.CurrentLateralMode==Afcs::Navigation,"assigned steering retains live NAV course tracking");
65 AttitudeController attitude;RotationState unavailable;g.rotationCommand={1,1,1};
66 Check(attitude.Step(g,unavailable,{0,1,0},.2)&&Norm(g.rotationCommand)==0&&g.attitude&&g.thrust==false,
67 "AFCS ownership bypasses orbital rotation even when orbital RCS authority is unavailable");
68 BusState b;b.sourceTime=10;b.guidance=g;
69 Check(!AscentPitchControl(b,true,10.1,true,false),"orbital surface allocator cannot overwrite the AFCS elevator");
70 for(int end=0;end<5;++end) {
71 g.valid=g.ascentControl=g.ascentAircraft=true;g.ascentWaiting=g.ascentLiftoff=false;a.DorOn=true;
72 Ascent::AircraftModes(a,g);
73 if(end==0)g.ascentAircraft=false; // orbital insertion steering
74 if(end==1)g.valid=false; // abort / completion
75 if(end==2)g.ascentControl=false; // rendezvous / return / coast
76 if(end==3)a.DorOn=false; // manual disengagement
77 if(end==4)g.ascentWaiting=true; // rearmed ground countdown
78 Ascent::AircraftModes(a,g);
79 Check(!a.DorAircraft&&!a.AutopilotEngaged&&a.CurrentLateralMode==Afcs::LateralMode_Off&&a.CurrentVerticalMode==Afcs::VerticalMode_Off,
80 "handoff/abort/manual/rearm removes DOR-owned AFCS and stale modes");
81 Check(a.PitchInput==0&&a.RollInput==0&&a.YawInput==0,"release neutralizes owned command inputs");
82 }
83 a.DorAircraft=false;a.AutopilotEngaged=true;a.CurrentVerticalMode=Afcs::AltitudeMsl;
84 Ascent::ReleaseAircraft(a);
85 Check(a.AutopilotEngaged&&a.CurrentVerticalMode==Afcs::AltitudeMsl,"cleanup preserves independent manual AFCS and entry handoff");
87 const auto first=pitch.Step(0,.1f,0,100,0,.02f);
88 Check(first.stick>0&&first.stick<=.00901,"shared PIT servo obeys existing finite input slew");
89 pitch.Reset();
90 const auto held=pitch.Step(.1f,.1f,0,100,0,.02f);
91 Check(held.stick==0,"reengagement clears old PIT derivative and integrator state");
92}
float RollInput(float desired, float actual, float rate, float previous, float aggression, float weight, float dt)
Definition AfcsControl.h:81
double Pitch(double selected, double horizontal, double vertical, double pitch, double previous, double dt)
Definition FlightPath.h:24
float Dot(const Vector3 &a, const Vector3 &b)
double Heading(Vec position, Vec direction)
bool AscentPitchControl(const BusState &b, bool engaged, double now, bool airborne, bool frozen)
Vec Rotate(Vec v, Vec axis, double angle)
Definition OrbitMath.h:22
constexpr double Pi
Definition OrbitMath.h:10
double Norm(Vec a)
Definition OrbitMath.h:18
void Edit(Request &r, Row row, int direction, const Snapshot &s, double now, bool circularize=false, bool recordingAllowed=false)
Definition OrbitState.h:438
Result Step(float pitchAtt, float desiredPitch, float stick, float qz, float f_augment, float elapsed)
Definition AfcsControl.h:15