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

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

1#pragma once
2#include "../Modules/OrbitAscent.h"
3#include "AscentAirframePlant.h"
4#include "OrbitLaunchTests.h"
5#include "YspAscentFixture.h"
6
7void FlyAscent(double massScale=1,double aeroError=1,double windKms=0,bool ground=false,double altitude=200,bool mission=false,double meetSeconds=7200,double offHeading=0,const Input* recorded=nullptr)
8{
9 auto in=BillEntryFixture();
10 in.massKg=255406*massScale;in.fuelKg=26965;
11 in.entryForwardKN=in.entryReverseKN=in.entryUpKN=3003.7068;
12 in.entryDownKN=1398;in.entrySideKN=1427;
13 in.thrustKN=in.entryForwardKN;in.flowKgS=2.7;
14 in.bodyDragAcceleration=1.05580505277*130827.7578/in.massKg;
15 in.vneKms=.1526747;
16 SetE11PitchEnvelope(in);
17 in.own={{0,in.radius+10,0},{-in.spin*(in.radius+10),.2*std::sin(20*Pi/180),.2*std::cos(20*Pi/180)}};
18 in.entryVehicle.wind={windKms,0,0};
19 in.ascentConfiguration=true;
20 if(ground) {
21 in.onGround=true;in.freeFlight=false;in.aglKm=0;
22 in.own={{0,in.radius+.3,0},{-in.spin*(in.radius+.3),0,0}};
23 }
24 if(mission) in=LaunchFixture();
25 if(recorded)in=*recorded;
26 const double bodyForce=in.bodyDragAcceleration*in.massKg;
27 const double initialFuel=in.fuelKg,groundAltitude=ground?Norm(in.own.r)-in.radius:0;
28 const Vec fixedWind=in.entryVehicle.wind;
29 const Vec plane={1,0,0};
30 RotationState rotation;rotation.effort=1;
31 RiseMath::Quaternion q;RiseMath::QuaternionRotationYawPitchRoll(&q,float(offHeading*Pi/180),float((ground?0:20)*Pi/180),0);
32 if(recorded) {
33 BodyFrame frame;frame.forward=Unit(in.entryVehicle.nose);frame.right=Unit(Cross(in.bodyUp,frame.forward));frame.up=Cross(frame.forward,frame.right);
34 const Vec error=FrameError({},frame);const double angle=Norm(error);const Vec axis=Unit(error);
35 q=RiseMath::Quaternion(float(-axis.x*std::sin(angle/2)),float(-axis.y*std::sin(angle/2)),float(-axis.z*std::sin(angle/2)),float(std::cos(angle/2)));
36 }
37 rotation.frame=RotationFrame(q);
38 Executor executor;AttitudeController attitude;Guidance g;Vec aircraftHeading;
39 Request request;request.ascent=true;request.ascentWait=false;
40 request.ascentAltitudeKm=altitude;
41 LaunchEstimate estimate;
42 if(mission) {
43 request.ascent=false;request.passTime=PassTime::Manual;request.ascentOrbitSteering=true;request.arrivalEpoch=in.now+meetSeconds;
44 RememberDepartureLeg(request,in);
45 // Exercise the same target-derived altitude used by the cockpit;
46 // overriding it here would hide regressions in mission setup.
47 altitude=request.ascentAltitudeKm;
48 LaunchPlanning::Search search;search.Begin(in,request);
49 while(search.Pending())search.Work(256);
50 estimate=search.Result();Check(estimate.valid&&estimate.fuelEnough,"continuous mission has a feasible immediate ground estimate");
51 }
52 int handoffs=0;const auto meet=request.arrivalEpoch;const auto revision=request.revision;
53 AscentAirframePlant plant;
54 const double epoch=in.now;
55 double output=ground?0:.9,reverse=0;Vec filtered;
56 bool clearedGround=false,reverseCommand=false;
57 double maxIas=0,maxHeat=0,rcs=0,mainImpulse=0,maxPitchError=0,lowClimbRcs=0,lowClimbTime=0;int guards=0;double maxBank=0,maxSlip=0,aircraftTime=0,firstBankAltitude=1e9,headingAt10km=1e9;
58 double poweredTime=0,peakPoweredLoad=0,peakPoweredMain=0,peakPoweredReverse=0,peakPoweredQ=0;
59 std::filesystem::create_directories("outputs/ascent-v1-20261018");
60 std::ofstream trace("outputs/ascent-v1-20261018/plant-"+std::to_string(massScale)+(ground?"-ground":"-air")+
61 (recorded?"-ysp":"")+(mission?"-mission-"+std::to_string(int(altitude)):"")+(offHeading?"-turn-"+std::to_string(int(offHeading)):"")+".csv");
62 trace<<"seconds,altitude,periapsis,apoapsis,radial_speed,tangent_speed,pitch,main,normal,ias_ratio,heat,fuel,actual_pitch,aoa,bank,elevator,pitch_stick,pitch_rcs,roll_rcs,yaw_rcs,heading_error,bank_limit,aircraft,phase,position_error,dv\n";
63 constexpr double dt=.05;
64 int step=0;
65 for(;step<(mission?int((meetSeconds+1801)/dt):int(3600/dt));++step) {
66 auto& ev=in.entryVehicle;
67 if(recorded)ev.wind=Rotate(fixedWind,{0,0,1},in.spin*(in.now-epoch));
68 ev.airVelocity=in.own.v-Cross({0,0,in.spin},in.own.r)-EntryPhysics::Wind(in,in.own.r);ev.nose=rotation.frame.forward;
69 in.bodyUp=rotation.frame.up;
70 ev.temperatureK=EntryPhysics::NominalTemperature(Norm(in.own.r)-in.radius);
71 const Vec body=InBody(rotation.frame,ev.airVelocity);ev.aoa=std::atan2(-body.y,body.z);
72 const auto air=EntryPhysics::Atmosphere(in,in.own,ev.aoa);ev.airIas=air.ias;ev.airQ=air.q;
73 if(step%4==0) {
74 rotation.acceleration=RotationAuthority(in.massKg*2.20462262,124.982147,186.511765,71.806427,16.714558,48.750797,1,1,1,1);
75 auto sensed=in;const double angle=in.spin*(in.now-epoch);
76 auto fixed=[&](Vec v){return Rotate(v,{0,0,1},-angle);};
77 sensed.own={fixed(in.own.r),fixed(in.own.v)};sensed.bodyUp=fixed(in.bodyUp);
78 sensed.entryVehicle.nose=fixed(ev.nose);sensed.entryVehicle.airVelocity=fixed(ev.airVelocity);
79 sensed.entryVehicle.wind=fixed(ev.wind);sensed.entryVehicle.deliveredAcceleration=fixed(ev.deliveredAcceleration);
80 sensed.entryVehicle.aeroAcceleration=fixed(ev.aeroAcceleration);
81 sensed.target={fixed(in.target.r),fixed(in.target.v)};
82 sensed.departureHeading=ArrivalPlanning::Heading(sensed.own.r,fixed(Cross(plane,in.own.r)));
83 if(step==0) {
84 const auto plan=Solve(sensed,request);
85 Check(plan.plan.valid&&plan.plan.ascent,"ascent previews allow engagement");
86 g=executor.Begin(sensed,request,plan,mission?&estimate:nullptr);
87 } else g=executor.Step(sensed,request);
88 if(g.ascentHandoff) {
89 if(!g.valid)std::wcout<<L"Handoff failure "<<g.status<<L" at "<<in.now-epoch<<L"\n";
90 ++handoffs;request.rendezvousAscent=false;attitude.Reset();
91 Check(executor.Active()&&g.valid&&!g.ascentControl&&!executor.ReferencePlan(sensed).ascent,
92 "measured insertion automatically hands to active rendezvous with no disconnect");
93 Check(request.arrivalEpoch==meet&&request.revision==revision,"automatic transfer preserves MEET and plan revision");
94 if(executor.ReferencePlan(sensed).start>0)Check(!g.thrust&&
95 (g.phase==Phase::Wait||(g.poweredRendezvous&&g.attitude)),
96 "a delayed transfer coasts without thrust; a finite powered transfer captures attitude before its boost");
97 }
98 if(g.phase==Phase::Complete)break;
99 if(!g.valid)std::wcout<<L"Ascent failed: "<<g.status<<L" step "<<step<<L" data "<<Ascent::Valid(sensed)
100 <<L" heading "<<sensed.departureHeading<<L" body "<<Norm(sensed.bodyUp)<<L" air "<<ev.airIas<<L"\n";
101 Check(g.valid&&(g.ascentControl||mission),"ascent/mission executor valid through flight");
102 aircraftHeading=Rotate(Ascent::Heading(Unit(sensed.own.r),g.heading),{0,0,1},angle);
103 g.pointing=Rotate(g.pointing,{0,0,1},angle);g.accelerationCommand=Rotate(g.accelerationCommand,{0,0,1},angle);
104 g.deltaVelocity=Rotate(g.deltaVelocity,{0,0,1},angle);
105 Check(attitude.Step(g,rotation,in.own.r,.2),"ascent attitude controllable");
106 if(g.ascentControl)Check(g.thrust,"continuous ascent retains thrust while following pitch cue");
107 if(g.entryLimited)++guards;
108 }
109 Vec command=InBody(rotation.frame,(g.ascentControl||g.poweredRendezvous)&&g.thrust?g.accelerationCommand:g.thrust?g.deltaVelocity:Vec{});
110 const double eff=1+(in.seaLevelEfficiency-1)*air.density;
111 const double limit=in.entryForwardKN*eff/in.massKg;
112 auto main=EntryControl::MainEngine(command.z,limit,in.entryReverseKN*eff/in.massKg,output,reverse,reverseCommand);
113 if(!g.ascentControl&&!g.poweredRendezvous) {
114 // Match the live orbital delta-V controller, including spool
115 // anticipation and RCS allocation; ascent uses acceleration control.
116 const double current=limit*(1-2*reverse)*output;
117 const double wanted=g.thrust?(std::clamp)(2*(command.z-current*ev.spoolSeconds*.5)/std::pow(ev.spoolSeconds*.5,2),-limit,limit):0;
118 main.reverse=wanted<0;main.lever=std::abs(wanted)/limit;
119 command=OrbitalRcsRequest(command,current,true);
120 }
121 reverseCommand=main.reverse;
122 reverse=(std::clamp)(reverse+(main.reverse?dt*.5:-dt*.5),0.0,1.0);
123 output+=(std::clamp)(main.lever-output,-dt/ev.spoolSeconds,dt/ev.spoolSeconds);
124 filtered=filtered+(command-filtered)*dt;
125 const double y=(std::clamp)(filtered.y,-in.entryDownKN/in.massKg,in.entryUpKN/in.massKg);
126 const double x=(std::clamp)(filtered.x,-in.entrySideKN/in.massKg,in.entrySideKN/in.massKg);
127 const double z=(in.entryForwardKN*(1-reverse)-in.entryReverseKN*reverse)*eff/in.massKg*output;
128 const Vec thrust=rotation.frame.forward*z+rotation.frame.up*y+rotation.frame.right*x;
129 ev.deliveredAcceleration=thrust;ev.aftC=EntryPhysics::Heat(ev,air,ev.aftC,dt);
130 maxIas=(std::max)(maxIas,air.ias/in.vneKms);maxHeat=(std::max)(maxHeat,ev.aftC);
131 rcs+=std::sqrt(x*x+y*y)*dt;mainImpulse+=std::abs(z)*dt;
132 const double altitudeNow=Norm(in.own.r)-in.radius;
133 if(g.ascentControl&&altitudeNow>1&&altitudeNow<10) {
134 lowClimbRcs+=std::abs(g.ascentNormal)*dt;lowClimbTime+=dt;
135 }
136 if(g.ascentAircraft) {
137 aircraftTime+=dt;
138 const auto up=Unit(in.own.r);
139 maxBank=(std::max)(maxBank,std::abs(std::atan2(Dot(rotation.frame.right,up),Dot(rotation.frame.up,up)))*180/Pi);
140 if(air.ias>.06)maxSlip=(std::max)(maxSlip,std::abs(std::atan2(body.x,body.z))*180/Pi);
141 if(maxBank>5)firstBankAltitude=(std::min)(firstBankAltitude,altitudeNow);
142 if(altitudeNow>=10&&headingAt10km==1e9)
143 headingAt10km=std::abs(std::remainder(Ascent::AircraftHeading(in.own.r,rotation.frame.forward,aircraftHeading,0),Tau))*180/Pi;
144 Check(Norm(g.rotationCommand)==0,"aircraft ascent receives no orbital flat-yaw command");
145 }
146 plant.Aircraft(in,rotation,g,aircraftHeading,dt);
147 const Vec aero=plant.Step(in,rotation,z,g.rotationCommand.x,dt,g.ascentControl||g.poweredRendezvous)*aeroError;
148 ev.aeroAcceleration=aero/in.massKg;ev.aeroValid=true;
149 if(g.poweredRendezvous) {
150 poweredTime+=dt;peakPoweredMain=(std::max)(peakPoweredMain,reverse<.01?output:0.0);
151 peakPoweredReverse=(std::max)(peakPoweredReverse,reverse>.99?output:0.0);
152 peakPoweredQ=(std::max)(peakPoweredQ,air.q);
153 const double load=EntryEnvelope::Fraction(in,EntryEnvelope::BodyG(thrust+ev.aeroAcceleration,rotation.frame.forward,rotation.frame.up));
154 peakPoweredLoad=(std::max)(peakPoweredLoad,load);
155 Check(load<1&&air.q<=AtmosphereWarningPa&&Norm(in.own.r)-in.radius>=OrbitalClearanceKm&&
156 Dot(Cross(in.own.r,in.own.v),Cross(in.target.r,in.target.v))>0,
157 "independent powered flight remains prograde above clearance and inside pressure and class load limits");
158 }
159 in.own=PoweredStep(in.own,thrust+ev.aeroAcceleration,dt,in.gm);
160 if(mission)in.target=TargetAt(in,dt);
161 in.now+=dt;
162 if(ground) {
163 if(Norm(in.own.r)<in.radius+groundAltitude) {
164 in.own.r=Unit(in.own.r)*(in.radius+groundAltitude);
165 in.own.v=in.own.v-Unit(in.own.r)*(std::min)(0.0,Dot(in.own.v,Unit(in.own.r)));
166 }
167 in.aglKm=Norm(in.own.r)-in.radius-groundAltitude;
168 if(in.aglKm>.1)clearedGround=true;
169 Check(!clearedGround||in.aglKm>.05,"VTOL transition never falls back toward ground after clearing 100 m");
170 if(in.aglKm>.0001) {in.onGround=false;in.freeFlight=true;}
171 }
172 const double flow=in.idleFlowKgS+(in.flowKgS-in.idleFlowKgS)*(output+(std::abs(x)+std::abs(y))*in.massKg/in.thrustKN);
173 in.fuelKg-=flow*dt;in.massKg-=flow*dt;in.bodyDragAcceleration=bodyForce/in.massKg;
174 Vec turn=g.rotationCommand;
175 if(!g.ascentControl&&(g.phase==Phase::Wait||g.phase==Phase::Coast)) {
176 BusState control;control.sourceTime=in.now;control.guidance=g;
177 control.guidance.coastRotation=HorizonRotation(in.own,in.spin);
178 turn=CoastRotationCommand(control,in.now,rotation,{});
179 }
180 plant.Turn(q,rotation,turn,in.massKg,dt);
181 maxPitchError=(std::max)(maxPitchError,Angle(rotation.frame.forward,g.pointing)*180/Pi);
182 if(step%100==0) {
183 const auto orbit=Describe(in.own,in.gm);const double vr=Dot(in.own.v,Unit(in.own.r));
184 trace<<step*dt<<','<<Norm(in.own.r)-in.radius<<','<<orbit.pe-in.radius<<','<<orbit.ap-in.radius<<','<<vr<<','<<Norm(in.own.v-Unit(in.own.r)*vr)<<','<<g.pitch*180/Pi<<','<<g.ascentMain<<','<<g.ascentNormal<<','<<air.ias/in.vneKms<<','<<ev.aftC<<','<<in.fuelKg<<','<<std::asin(Dot(rotation.frame.forward,Unit(in.own.r)))*180/Pi<<','<<ev.aoa*180/Pi<<','<<-std::atan2(Dot(rotation.frame.right,Unit(in.own.r)),Dot(rotation.frame.up,Unit(in.own.r)))*180/Pi<<','<<plant.elevator<<','<<plant.stick<<','<<plant.aircraftRcs.x<<','<<plant.aircraftRcs.z<<','<<plant.aircraftRcs.y<<','<<std::remainder(Ascent::AircraftHeading(in.own.r,rotation.frame.forward,aircraftHeading,0),Tau)*180/Pi<<','<<g.ascentBankLimit*180/Pi<<','<<g.ascentAircraft<<','<<int(g.phase)<<','<<g.positionErrorKm<<','<<g.remainingDeltaV<<'\n';
185 }
186 Check(Norm(in.own.r)>in.radius+(ground?groundAltitude-.01:5)&&in.fuelKg>0,"ascent stays airborne with fuel");
187 }
188 const auto orbit=Describe(in.own,in.gm);
189 std::cout<<"AFCS: turn "<<offHeading<<" bank "<<maxBank<<" slip "<<maxSlip<<" seconds "<<aircraftTime<<"\n";
190 if(offHeading) {
191 Check(maxBank>5&&maxBank<20&&maxSlip<10,"off-heading ascent banks toward insertion without a sideways skid");
192 Check(firstBankAltitude<3&&headingAt10km<10,"departure turns start below 3km and align within ten degrees by 10km");
193 }
194 std::cout<<"Ascent plant: mass "<<massScale<<" time "<<step*dt<<" h "<<Norm(in.own.r)-in.radius<<" PE "<<orbit.pe-in.radius<<" AP "<<orbit.ap-in.radius<<" fuel "<<initialFuel-in.fuelKg<<" IAS "<<maxIas<<" heat "<<maxHeat<<" mains "<<mainImpulse<<" RCS "<<rcs<<" guards "<<guards<<" pitch error "<<maxPitchError<<"\n";
195 Check(g.phase==Phase::Complete&&!executor.Active(),"ascent reaches circular parking orbit and ends execution");
196 Check(maxIas<1&&maxHeat<200,"ascent stays inside Vne and thermal limit");
197 if(ground&&massScale<.7&&!mission) {
198 std::cout<<"Wing-supported 1-10km mean vertical RCS: "<<100*lowClimbRcs/lowClimbTime<<"%\n";
199 Check(lowClimbTime>30&&lowClimbRcs/lowClimbTime<.025,
200 "light E11 climb uses wings and pitch instead of repeated vertical RCS trim, including lift error and crosswind");
201 }
202 struct Controls {bool DorOn=true,TvmOn=false;float DesiredClosingSpeed=.1f;} controls;
203 int disconnects=0;
204 if(mission) {
205 if(poweredTime>0)std::cout<<"Powered segment "<<poweredTime<<"s main "<<peakPoweredMain<<" reverse "<<peakPoweredReverse<<" q "<<peakPoweredQ<<" load "<<peakPoweredLoad<<"\n";
206 Check(handoffs==1,"whole ground-to-station flight performs exactly one insertion handoff");
207 Check(FinishExecution(in,Mode::Rendezvous,g,false,controls,[&]{controls.DorOn=false;++disconnects;}),
208 "whole mission finishes with TVM only after rendezvous completion");
209 Check(controls.TvmOn&&disconnects==1&&g.positionErrorKm<.1,"continuous mission reaches station staging point and enables TVM once");
210 std::cout<<"Ground rendezvous: "<<step*dt<<"s, miss "<<g.positionErrorKm<<"km, handoffs "<<handoffs<<"\n";
211 return;
212 }
213 Check(!FinishExecution(in,Mode::Ascent,g,false,controls,[&]{controls.DorOn=false;++disconnects;}),"ascent never declares station rendezvous or enables TVM");
214 Check(!controls.DorOn&&!controls.TvmOn&&disconnects==1,"parking orbit ends with one ordinary disconnect");
215}
216void AscentRejectionTests()
217{
218 auto in=BillEntryFixture();in.ascentConfiguration=true;in.bodyUp=Unit(in.own.r);
219 in.own.r=Unit(in.own.r)*(in.radius+.3);in.own.v=Cross({0,0,in.spin},in.own.r);
220 in.entryVehicle.nose=Ascent::Heading(Unit(in.own.r),0);in.entryVehicle.airVelocity={};
221 in.entryVehicle.airIas=0;in.aglKm=0;in.onGround=true;in.freeFlight=false;
222 Request r;r.ascent=true;r.ascentWait=false;
223 auto late=in;late.onGround=false;late.targetKind=TargetKind::Station;late.target=LaunchFixture().target;
224 Request selection;
225 RememberDepartureLeg(selection,late);Check(!selection.rendezvousAscent,"airborne station selection retains ordinary rendezvous");
226 late.onGround=true;
227 RememberDepartureLeg(selection,late);Check(selection.rendezvousAscent&&!selection.ascent&&selection.ascentOrbitSteering,
228 "ground station selects the ascent leg without replacing RENDEZVOUS");
229 const auto selectedRevision=selection.revision;
230 RememberDepartureLeg(selection,late);
231 Check(selection.revision==selectedRevision&&selection.ascentOrbitSteering,"ground updates preserve automatic rendezvous steering");
232 Snapshot autoSnapshot;autoSnapshot.targetKind=TargetKind::Station;autoSnapshot.mode=Mode::Rendezvous;
233 autoSnapshot.plan.ascent=true;
234 Edit(selection,Row::AscentSteering,1,autoSnapshot,0);
235 Edit(selection,Row::AscentAltitude,1,autoSnapshot,0);
236 Check(selection.ascentOrbitSteering&&selection.ascentAltitudeKm>=118&&selection.ascentAltitudeKm<123,"rendezvous owns target-derived staging altitude and orbital steering");
237 for(const auto row:Rows(selection,Mode::Rendezvous,false,true))
238 Check(row!=Row::AscentAltitude&&row!=Row::AscentSteering,"rendezvous omits standalone ascent setup rows");
239 late.onGround=false;RememberDepartureLeg(selection,late);Check(selection.rendezvousAscent,"manual liftoff retains rendezvous ascent pickup");
240 selection={};selection.adjust=true;late.onGround=true;
241 RememberDepartureLeg(selection,late);Check(!selection.rendezvousAscent&&selection.adjust,"explicit orbit adjustment remains independent");
242 selection={};late.dockedAtStation=true;
243 RememberDepartureLeg(selection,late);Check(!selection.rendezvousAscent,"station attachment cannot become VTOL departure");
244 late.dockedAtStation=false;late.targetKind=TargetKind::Surface;
245 RememberDepartureLeg(selection,late);Check(!selection.rendezvousAscent,"surface journeys retain separate planning rules");
246 Snapshot grounded;grounded.onGround=true;grounded.targetKind=TargetKind::Station;
247 for(int direction:{-1,1}) {
248 selection={};selection.ascent=true;
249 bool rendezvous=false,adjust=false;
250 for(int i=0;i<2;++i) {Edit(selection,Row::Mode,direction,grounded,0);rendezvous|=Objective(selection,grounded.targetKind)==Mode::Rendezvous;adjust|=selection.adjust;}
251 Check(rendezvous&&!adjust&&selection.ascent,"ground mode cycle includes only RENDEZVOUS and PARKING ORBIT");
252 }
253 Check(Solve(in,r).plan.valid,"configured loaded VTOL ready");
254 auto rejected=[&](Input bad,const char* why){Check(!Solve(bad,r).plan.valid,why);};
255 auto bad=in;bad.entryUpKN=1;rejected(bad,"no hover authority rejects VTOL liftoff");
256 bad=in;bad.bodyUp=Unit(in.own.r)*(-1);rejected(bad,"inverted ground attitude rejected");
257 bad=in;bad.entryVehicle.airAge=1;rejected(bad,"stale ascent air sample rejected");
258 bad=in;bad.ascentConfiguration=false;rejected(bad,"ascent config rejected");
259 bad=in;bad.dockedAtStation=true;rejected(bad,"docked launch rejected");
260 bad=in;bad.aglKm=NAN;rejected(bad,"missing ground clearance rejected");
261 bad=in;bad.entryVehicle.airIas=in.vneKms;rejected(bad,"unsafe IAS pickup rejected");
262 bad=in;bad.entryVehicle.aftC=201;rejected(bad,"hot pickup rejected");
263 bad=in;bad.massKg=NAN;rejected(bad,"nonfinite mass rejected");
264 Executor ex;auto s=Solve(in,r);auto g=ex.Begin(in,r,s);Check(g.ascentLiftoff&&g.valid,"DOR begins VTOL lift on ground");
265 const auto revision=r.revision;Edit(r,Row::AscentSteering,1,s,in.now);
266 Check(r.revision==revision&&ex.Step(in,r).valid,"ATC steering release does not abort climb");
267 Edit(r,Row::AscentAltitude,1,s,in.now);Check(ex.Step(in,r).phase==Phase::Abort,"changing parking orbit cancels active ascent");
268 ex.Begin(in,r,Solve(in,r));bad=in;bad.entryVehicle.airAge=1;bad.now+=.2;
269 g=ex.Step(bad,r);Check(!g.valid&&!g.thrust&&g.phase==Phase::Abort,"loss of air data aborts live ascent");
270 g=ex.Begin(in,r,Solve(in,r));Check(g.valid,"rearm after corrected input starts fresh controller");
271 Check(ManualAttitudeDisconnect(g),"manual attitude input disconnects powered ascent");
272 ex.Cancel();Check(!ex.Step(in,r).valid,"manual DOR cancel clears guidance");
273 for(int direction:{-1,1}) {
274 Request cycle;Snapshot surface;surface.targetKind=TargetKind::Surface;
275 for(int i=0;i<3;++i)Edit(cycle,Row::Mode,direction,surface,in.now);
276 Check(Objective(cycle,TargetKind::Surface)==Mode::Return,"objective selection cycles in both directions");
277 }
278}
279void AscentPitchRegressionTests()
280{
281 auto in=BillEntryFixture();in.massKg=124300;in.bodyDragAcceleration=1.0574;
282 in.own.r={0,in.radius+.7,0};
283 RotationState rotation;rotation.frame={{1,0,0},{0,1,0},{0,0,1}};
284 // Recorded t=38 s flow: RCS was asking for full nose-up while the nose fell.
285 in.own.v=Cross({0,0,in.spin},in.own.r)+Vec{-.0162114,-.00342742,.0440653};
286 in.entryVehicle.wind={};
287 AscentAirframePlant oldPlant,newPlant;
288 oldPlant.Step(in,rotation,.008,1,.1,false);
289 Check(oldPlant.external+oldPlant.tail+oldPlant.rcs<0,
290 "recorded unstalled airflow overwhelms RCS-only nose-up demand");
291 for(int j=0;j<20;++j)newPlant.Step(in,rotation,.008,1,.1);
292 const double capacity=PitchRcsForce*16.714558;
293 Check(newPlant.external+newPlant.tail+newPlant.rcs>oldPlant.external+oldPlant.tail+oldPlant.rcs&&newPlant.residual>0,
294 "recorded failure flow exposes residual authority limit even with elevator correction");
295 SetE11PitchEnvelope(in);
296 Check(Ascent::TrimPenalty(in,4.44754*Pi/180,3199,.008)>100&&
297 Ascent::TrimPenalty(in,0,3199,.008)<1,"pitch selection rejects untrimmable recorded AoA before authority is lost");
298 Check(std::abs(newPlant.elevator)<=.25&&std::abs(newPlant.rcs)<=capacity,
299 "recovery does not increase surface travel or installed thruster authority");
300 for(double airspeed:{0.0,.01,.04,.12,5.0}) {
301 in.own.v=Cross({0,0,in.spin},in.own.r)+Vec{0,airspeed*.05,airspeed};
302 AscentAirframePlant plant;
303 double previous=plant.elevator;
304 for(int j=0;j<100;++j) {
305 plant.Step(in,rotation,0,j<50?1:-1,.02);
306 Check(std::abs(plant.elevator-previous)<=.45*.02+1e-10&&std::abs(plant.rcs)<=capacity,
307 "airflow/command transitions preserve surface rate and RCS limits");
308 previous=plant.elevator;
309 }
310 }
311 auto dead=AllocatePitch(capacity,capacity*3,capacity,0,1,.2,[](double){return 0.0;});
312 Check(dead.rcsMoment==-capacity&&dead.residual<0,"missing tail authority exposes saturation rather than inventing torque");
313 double deflection=.9;
314 for(int i=0;i<100;++i) {
315 const auto a=AllocatePitch(0,capacity*.002,capacity,deflection,1,.05,
316 [&](double surface){return capacity*.005*surface;});
317 Check(std::abs(a.surface-deflection)<=.45*.05+1e-12&&std::abs(a.residual)<1e-9,
318 "negligible orbital tail authority stows without rate jump or lost pitch torque");
319 deflection=a.surface;
320 }
321 Check(std::abs(deflection)<1e-12,"orbital elevator returns to neutral instead of chasing tiny RCS savings");
322 const auto useful=AllocatePitch(0,capacity*.5,capacity,0,1,1,
323 [&](double surface){return capacity*std::sin(surface*Pi);});
324 Check(useful.surface<-.1,"nonmonotonic useful tail authority is retained even with zero endpoint moments");
325 BusState bus;bus.sourceTime=10;bus.guidance.valid=bus.guidance.attitude=bus.guidance.ascentControl=true;
326 Check(AscentPitchControl(bus,true,10.1,true,false),"fresh powered ascent owns pitch surface");
327 Check(!AscentPitchControl(bus,false,10.1,true,false)&&!AscentPitchControl(bus,true,10.6,true,false)&&
328 !AscentPitchControl(bus,true,9.9,true,false)&&!AscentPitchControl(bus,true,10.1,false,false)&&
329 !AscentPitchControl(bus,true,10.1,true,true),"disconnect, stale guidance, dock/ground and freeze release surface override");
330 bus.guidance.ascentControl=false;
331 Check(!AscentPitchControl(bus,true,10.1,true,false),"orbit/coast/entry retain their existing surface ownership");
332
333 in=BillEntryFixture();in.ascentConfiguration=true;in.massKg=124300;
334 in.own.r={0,in.radius+.65,0};
335 in.own.v=Cross({0,0,in.spin},in.own.r)+Vec{0,-.04,.07};
337 rotation.frame=RotationFrame(q);in.bodyUp=rotation.frame.up;
338 auto& ev=in.entryVehicle;ev.nose=rotation.frame.forward;ev.wind={};
339 ev.airVelocity=in.own.v-Cross({0,0,in.spin},in.own.r);
340 ev.aoa=-2*Pi/180;ev.aeroValid=true;ev.airIas=.08;
341 AscentAirframePlant falling;ev.aeroAcceleration=falling.Step(in,rotation,0,1,.1)/in.massKg;
342 Ascent::Controller controller;auto command=controller.Step(in,150,{0,0,1},.2);
343 Check(command.valid&&command.normal>0&&Dot(command.acceleration+ev.aeroAcceleration,Unit(in.own.r))>
344 in.gm/std::pow(Norm(in.own.r),2),"falling nose receives actual-attitude lift support, not downward thrust from hoped-for lift");
345}
346#include "OrbitMissionTests.h"
347void AscentTests() {
348 YspInsertionTests();FlyAscent(.6,1,0,true,200,false,7200,150);FlyAscent(.6,1,0,true,200,false,7200,-150);
349 const auto ysp=YspAscentFixture();FlyAscent(.4867,1,0,true,200,true,3938.8035,0,&ysp);
350 AscentRejectionTests();AscentPitchRegressionTests();LaunchTests();GroundRendezvousTests();
351 FlyAscent(124315.5859/255406,1,0,true,150);FlyAscent();FlyAscent(1,1,0,true);FlyAscent(.6,1.1,.015,true);
352 FlyAscent(124315.5859/255406,1,0,true,200,true);
353 auto high=LaunchFixture();high.target.r=Unit(high.target.r)*(high.radius+1000);
354 high.target.v=Unit(high.target.v)*std::sqrt(high.gm/Norm(high.target.r));
355 high.stationRate=std::sqrt(high.gm/std::pow(Norm(high.target.r),3));
356 FlyAscent(124315.5859/255406,1,0,true,1000,true,10800,0,&high);
357}
SCRIPT_CONTROL SCRIPT_STATE const void int
DeathType dead
Definition globals.cpp:37
bool Unit(Vector3 &v)
float Dot(const Vector3 &a, const Vector3 &b)
Plan Solve(const Input &in, const Request &r, bool geometry)
Definition OrbitEntry.h:332
double Angle(Vec a, Vec b)
Definition OrbitMath.h:21
Vec CoastRotationCommand(const BusState &data, double now, const RotationState &in, Vec pilot)
State TargetAt(const Input &in, double seconds)
Definition OrbitModel.h:82
bool AscentPitchControl(const BusState &b, bool engaged, double now, bool airborne, bool frozen)
Vec HorizonRotation(State own, double spin)
Vec FrameError(const BodyFrame &current, const BodyFrame &target)
Vec InBody(const BodyFrame &f, Vec v)
Mode Objective(const Request &r, TargetKind target)
Definition OrbitState.h:368
bool FinishExecution(const Input &in, Mode mode, Guidance &g, bool frozen, Afcs &afcs, Disconnect stopDor)
Vec Rotate(Vec v, Vec axis, double angle)
Definition OrbitMath.h:22
void RememberDepartureLeg(Request &r, const Input &in)
Definition OrbitState.h:381
Vec OrbitalRcsRequest(Vec deltaBody, double mainGrossAcceleration, bool hasMains)
Definition OrbitBurn.h:10
constexpr double PitchRcsForce
std::vector< Row > Rows(const Request &r, Mode mode, bool entry=false, bool ascent=false, bool recordingAllowed=false)
Definition OrbitState.h:414
constexpr double Pi
Definition OrbitMath.h:10
Elements Describe(State s, double gm)
Definition OrbitMath.h:43
Vec RotationAuthority(double weight, double pitchInertia, double yawInertia, double rollInertia, double arm, double span, double leftWing, double rightWing, double effort, double wear)
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
Vec Cross(Vec a, Vec b)
Definition OrbitMath.h:17
bool ManualAttitudeDisconnect(const Guidance &g)
Definition OrbitState.h:355
PitchAllocation AllocatePitch(double desired, double external, double rcsCapacity, double previous, double surfaceLimit, double dt, TailMoment tail)
Quaternion * QuaternionRotationYawPitchRoll(Quaternion *out, float yaw, float pitch, float roll)
Definition ClientMath.h:169