1#pragma once
2
3void GroundRendezvousTests()
4{
5 auto in=LaunchFixture();Request r;r.passTime=PassTime::Manual;r.arrivalEpoch=in.now+7200;r.ascentWait=false;
6 RememberDepartureLeg(r,in);
7 const auto initial=Solve(in,r);
8 Check(initial.mode==Mode::Rendezvous&&initial.plan.ascent&&initial.plan.valid&&!r.ascent,
9 "ground RENDEZVOUS previews an executable ascent leg with the mission objective intact");
10 const auto rows=Rows(r,initial.mode,false,initial.plan.ascent);
11 Check(std::find(rows.begin(),rows.end(),Row::AscentLaunch)!=rows.end()&&
12 std::find(rows.begin(),rows.end(),Row::AscentAltitude)==rows.end()&&
13 std::find(rows.begin(),rows.end(),Row::AscentSteering)==rows.end(),"ground mission exposes launch with automatic staging and steering");
14 LaunchPlanning::Search search;search.Begin(in,r);
15 int work=0;while(search.Pending()&&work++<2000)search.Work(256);
16 const auto e=search.Result();
17 Check(e.valid&&!e.pending&&e.evaluated==1&&e.launchEpoch==in.now,
18 "RENDEZVOUS NOW compares the immediate departure only");
19 Executor ex;Check(!ex.Begin(in,r,initial).valid,"ground mission NOW requires a whole-trip estimate");
20 auto bad=e;bad.fuelEnough=false;
21 Check(!ex.Begin(in,r,initial,&bad).valid,"ground mission refuses known total fuel shortfall");
22 bad=e;bad.launchEpoch+=10;
23 Check(!ex.Begin(in,r,initial,&bad).valid,"NOW cannot use an AUTO recommendation for a later launch");
24 auto automatic=r;automatic.ascentWait=true;
25 search.Begin(in,automatic);work=0;while(search.Pending()&&work++<2000)search.Work(256);
26 const auto scheduled=search.Result();
27 Check(scheduled.valid&&!scheduled.pending,"continuous rendezvous supports a completed AUTO launch comparison");
28 auto pending=scheduled;pending.pending=true;
29 auto comparing=ex.Begin(in,automatic,Solve(in,automatic),&pending);
30 Preview(in,automatic,"rendezvous-launch-comparing",&comparing,&pending);
31 auto g=ex.Begin(in,automatic,Solve(in,automatic),&scheduled);
32 Preview(in,automatic,"rendezvous-launch-armed",&g,&scheduled);
33 Check(g.valid&&ex.Active()&&(g.ascentWaiting||g.ascentLiftoff),"AUTO arms the mission's ascent leg");
34 if(g.ascentWaiting)Check(!g.thrust&&!g.attitude,"armed mission issues no flight commands before departure");
35 ex.Cancel();Check(!ex.Step(in,automatic).valid,"cancelling an armed mission never starts its next leg");
36 LaunchPlanning::Climb climb;climb.Begin(in,r,0);
37 int steps=0;while(!climb.done&&steps++<22000)climb.Step();
38 Check(climb.valid,"mission boundary fixture actually reaches parking orbit");
39 const Input inserted=climb.insertion;
40 for(int failure=0;failure<7;++failure) {
41 g=ex.Begin(in,r,initial,&e);Check(g.valid&&g.ascentLiftoff,"mission begins in VTOL before boundary test");
42 auto at=inserted;auto settings=r;
43 if(failure==1)at.fuelKg=1;
44 if(failure==2)at.now=settings.arrivalEpoch;
45 if(failure==3)++at.targetId;
46 if(failure==4)++settings.revision;
47 if(failure==5)at.powered=false;
48 if(failure==6)at.target={};
49 for(int j=0;j<5&&ex.Active();++j) {at.now+=1;g=ex.Step(at,settings);if(g.ascentHandoff)break;}
50 if(failure==0) {
51 Check(g.ascentHandoff&&g.valid&&ex.Active()&&!g.ascentControl,
52 "insertion hands directly to active orbital guidance");
53 const auto plan=ex.ReferencePlan(at);
54 Check(!plan.ascent&&plan.burns.size()==2&&std::abs(at.now+plan.end-r.arrivalEpoch)<.001,
55 "automatic transfer uses the original absolute MEET");
56 Check(g.fuelUsedKg>1000,"mission fuel accounting includes the ascent after automatic transfer");
57 ex.Cancel();Check(!ex.Step(at,settings).valid,"cancellation after insertion stops rendezvous");
58 } else {
59 Check(g.phase==Phase::Abort&&!g.valid&&!g.thrust&&!ex.Active(),
60 "invalid insertion boundary aborts without thrust or a false completion");
61 struct Controls {bool DorOn=true,TvmOn=false;float DesiredClosingSpeed=0;} controls;
62 Check(!
FinishExecution(at,Mode::Rendezvous,g,
false,controls,[&]{controls.DorOn=
false;})&&!controls.TvmOn,
63 "failed mission never enables TVM");
64 }
65 }
66 auto airborne=inserted;airborne.own.r=
Unit(in.own.r)*(in.radius+10);
67 airborne.own.v=
Cross({0,0,in.spin},airborne.own.r)+Vec{0,.05,.18};
68 airborne.onGround=false;airborne.freeFlight=true;airborne.now=in.now+200;
69 airborne.entryVehicle.airIas=.08;airborne.entryVehicle.aftC=30;
70 const auto pickup=
Solve(airborne,r);
71 Check(pickup.mode==Mode::Rendezvous&&pickup.plan.ascent,"manual departure retains the pending rendezvous ascent leg");
72 g=ex.Begin(airborne,r,pickup);
73 Check(g.valid&&g.ascentControl&&!g.ascentWaiting,"continuous mission can pick up an airborne manual departure");
74 BusState data;data.request=r;data.snapshot=initial;data.launch=e;
75 bool autoLabel=false,replan=false;
76 for(
const auto& label:
Readouts(data,rows,0,
false)) {
77 autoLabel|=label.text==L"AUTO TRANSFER AFTER INSERTION";
78 replan|=label.text==L"REPLAN RENDEZVOUS IN ORBIT";
79 }
80 Check(autoLabel&&!replan,"ground mission tells the pilot that transfer is automatic");
81}
Plan Solve(const Input &in, const Request &r, bool geometry)
bool FinishExecution(const Input &in, Mode mode, Guidance &g, bool frozen, Afcs &afcs, Disconnect stopDor)
std::vector< Label > Readouts(const BusState &data, const std::vector< Row > &rows, int uiRow, bool dorActive, bool showKeys=true)