Rise
The Vieneo Province
Loading...
Searching...
No Matches
Tests/FmaModeTests.cpp

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

1// Compile the actual FMA2 class, constructor, FrameMove and Render. Only the
2// surrounding services and graphics sink are replaced; assertions inspect the
3// text and colors that Render submits, not a duplicate annunciation model.
4#include <windows.h>
5#include <cmath>
6#include <cwchar>
7#include <cwctype>
8#include <cstdlib>
9#include <iostream>
10#include <string>
11#include <vector>
12#include "../Modules/OrbitState.h"
13#include "../Modules/OrbitAttitude.h"
14#include "../Modules/FlightPath.h"
15#include "../StringUtilities.h"
16
17struct Bus {
18#include "FmaAfcs.generated.h"
20 bool OnGround = false;
21 bool FlightFreeze = false;
22 double ProgramTime = 0;
25 float TargetBearingDeg = 0;
26};
27struct Logger { void AddToCallStack(const char*) {} };
28struct Font {};
29struct DeviceObject {};
30struct Sprite {
31 template<class... Args> explicit Sprite(Args...) {}
32 void Draw(DWORD = 0xffffffff) {}
33};
34namespace RiseMath {
35 inline float ToDegree(float value) { return value * 57.29577951308232f; }
36 inline float ToRadian(float value) { return value / 57.29577951308232f; }
37 constexpr float Tau = 6.283185307179586f;
38}
39struct { int reference = -1; float mslKm = 0; } playerships[1];
40struct Draw { std::wstring text; int x, y; DWORD color; };
41std::vector<Draw> draws;
42class Instrument {
43protected:
44 Bus* bus;
45 Logger* logger;
46 DeviceObject* pDevice;
47 unsigned defaultFont = 0;
48public:
49 Instrument(int, int, float, float, Bus* b, Logger* l, DeviceObject* d, std::vector<Font*>)
50 : bus(b), logger(l), pDevice(d) {}
51 virtual void Render() = 0;
52 virtual void FrameMove(float) = 0;
53 void DrawText(const WCHAR* value, int x, int y, float, int, DWORD color, int, const char*) {
54 draws.push_back({value, x, y, color});
55 }
56 void DrawTextW(const WCHAR* value, int x, int y, float z, int flags, DWORD color, int font, const char* name) {
57 DrawText(value, x, y, z, flags, color, font, name);
58 }
59};
60#include "FmaProduction.generated.h"
61
62int checks = 0;
63void Check(bool ok, const char* message) {
64 ++checks;
65 if (!ok) { std::cerr << "FAIL: " << message << '\n'; std::exit(1); }
66}
67bool TextAt(int x, int y, const wchar_t* text) {
68 for (const auto& draw : draws)
69 if (draw.x == x && draw.y == y && draw.text == text) return true;
70 return false;
71}
72bool HasText(const wchar_t* text) {
73 for (const auto& draw : draws) if (draw.text == text) return true;
74 return false;
75}
76DWORD ColorAt(int x, int y) {
77 for (const auto& draw : draws) if (draw.x == x && draw.y == y) return draw.color;
78 return 0;
79}
80
81// External services are outside these active-mode tests; fail if a case
82// unexpectedly tries to engage the flight director or cancel orbital guidance.
83struct CycleServices {
84 Bus* bus;
85 __declspec(noinline) void TurnOffDOR() { Check(false, "unexpected DOR cancellation"); }
86 void FlightDirectorOn() { Check(false, "unexpected flight director engagement"); }
87};
88void CycleVertical(Bus& bus, bool repeating = false) {
89 CycleServices services{&bus};
90 auto* gameclass = &services;
91 constexpr float cloudTopsMslC = 10.0f;
92 const float f_AGL = playerships[0].mslKm;
93 [[maybe_unused]] float verticaltime = 0;
94#include "FmaVerticalCycle.generated.h"
95}
96void CycleLateral(Bus& bus, bool repeating = false) {
97 CycleServices services{&bus};
98 auto* gameclass = &services;
99 const float insthdgDegrees = 90;
100 [[maybe_unused]] float lateraltime = 0;
101#include "FmaLateralCycle.generated.h"
102}
103
104void GroundStateTests() {
105 using Afcs=Bus::Afcs;
106 Bus bus; CycleServices services{&bus};
107 struct View {CycleServices* gameclass;} view{&services}; auto* viewscreen=&view;
108 constexpr int REF_ONGROUND=-2;
109 bus.GroundSpeedKms=.48f;bus.VerticalSpeedKms=-.05f;
110 bus.AFCS.CurrentLateralMode=Afcs::Navigation;
111 // Ground -> VTOL/hover -> flight -> space -> landing -> dock -> flight.
112 for(int reference:{REF_ONGROUND,-1,-1,10,REF_ONGROUND,0,-1}) {
113 playerships[0].reference=reference;
114#include "FmaGroundState.generated.h"
115 Check(bus.OnGround==(reference==REF_ONGROUND),"bus contact state follows the live reference in both directions");
116 bus.AFCS.CurrentVerticalMode=Afcs::Pitch;
117 CycleVertical(bus);
118 Check(bus.AFCS.CurrentVerticalMode==(reference==REF_ONGROUND?Afcs::VerticalSpeed:Afcs::FlightPathAngle),
119 "live airborne publication permits FPA after PIT while ground still skips it");
120 }
121}
122
123void AxisDefaultTests() {
124 using Afcs = Bus::Afcs;
125 // Selector behavior is independent of flight envelope and A/F engagement.
126 // Ground, hover, atmospheric cruise, ascent, coast, orbit and reentry.
127 struct FlightCase { bool ground; float speed, vertical, msl; };
128 for (const auto flight : {FlightCase{true,0,0,0}, FlightCase{false,0,.002f,.02f},
129 FlightCase{false,.25f,0,5}, FlightCase{false,2,1,50},
130 FlightCase{false,4,0,150}, FlightCase{false,7.5f,0,400},
131 FlightCase{false,7,-.4f,80}})
132 for (bool engaged : {false, true})
133 for (auto vertical : {Afcs::AltitudeMsl, Afcs::Pitch, Afcs::FlightPathAngle, Afcs::VerticalSpeed,
134 Afcs::SpeedPitch, Afcs::AltitudeAgl, Afcs::Glideslope, Afcs::VerticalMode_TakeOff, Afcs::VerticalMode_Off})
135 for (auto lateral : {Afcs::Localizer, Afcs::Roll, Afcs::Heading, Afcs::Navigation, Afcs::LateralMode_TakeOff}) {
136 Bus bus;
137 bus.OnGround = flight.ground; bus.GroundSpeedKms = flight.speed;
138 bus.VerticalSpeedKms = flight.vertical; playerships[0].mslKm = flight.msl;
139 bus.PitchAttitudeRadians = .123f;
140 bool expectedEngaged = engaged;
141 bus.AFCS.AutopilotEngaged = engaged;
142 bus.AFCS.CurrentLateralMode = lateral; bus.AFCS.CurrentVerticalMode = vertical;
143 bus.AFCS.StandbyLateralMode = Afcs::Localizer;
144 bus.AFCS.StandbyVerticalMode = Afcs::Glideslope;
145 bus.AFCS.DesiredPitchRadians = -.2f; bus.AFCS.DesiredFpaRadians = .04f;
146 bus.AFCS.DesiredVsiKms = .003f; bus.AFCS.DesiredIasKms = .15f;
147 bus.AFCS.DesiredAltitudeKm = 8;
148 CycleLateral(bus, true);
149 Check(bus.AFCS.CurrentLateralMode == lateral && bus.AFCS.CurrentVerticalMode == vertical,
150 "lateral key repeat leaves both axes unchanged");
151 // Two full cycles cover wrapping/reselection and engagement changes.
152 for (int step = 0; step < 6; ++step) {
153 CycleLateral(bus);
154 const bool fallback = vertical == Afcs::VerticalMode_Off;
155 Check(bus.AFCS.CurrentVerticalMode == (fallback ? Afcs::Pitch : vertical),
156 "lateral cycle preserves active vertical guidance; only Off defaults to PIT");
157 Check(bus.AFCS.DesiredPitchRadians == (fallback ? .123f : -.2f) &&
158 bus.AFCS.DesiredFpaRadians == .04f && bus.AFCS.DesiredVsiKms == .003f &&
159 bus.AFCS.DesiredIasKms == .15f && bus.AFCS.DesiredAltitudeKm == 8,
160 "lateral selection captures pitch only for an unset vertical axis");
161 Check(bus.AFCS.AutopilotEngaged == expectedEngaged && bus.AFCS.StandbyLateralMode == Afcs::Localizer &&
162 bus.AFCS.StandbyVerticalMode == Afcs::Glideslope,
163 "lateral cycle preserves A/F engagement and armed modes");
164 if (step == 2) { expectedEngaged = !expectedEngaged; bus.AFCS.AutopilotEngaged = expectedEngaged; }
165 }
166 // On every vertical selection, an unset lateral axis gets the existing
167 // roll capture (wings level near zero bank), without changing A/F state.
168 if (vertical != Afcs::VerticalMode_Off) for (float bank : {-.2f, .01f, .2f}) {
169 bus.AFCS.CurrentVerticalMode = vertical; bus.AFCS.CurrentLateralMode = Afcs::LateralMode_Off;
170 bus.RollAttitudeRadians = bank; bus.AFCS.DesiredRollRadians = .4f;
171 CycleVertical(bus);
172 Check(bus.AFCS.CurrentLateralMode == Afcs::Roll &&
173 bus.AFCS.DesiredRollRadians == (bank == .01f ? 0 : bank),
174 "vertical selection with lateral Off supplies ROL and captures current bank");
175 if (vertical == Afcs::VerticalMode_TakeOff)
176 Check(bus.AFCS.CurrentVerticalMode == Afcs::Pitch &&
178 "cycling the takeoff vertical mode captures PIT without passing through Off");
179 }
180 }
181}
182
183void VerticalCycleTests() {
184 using Afcs = Bus::Afcs;
185 // Ground, hover, cruise, ascent, suborbital coast, orbit and reentry.
186 // These are selector inputs, not assertions of controller suitability.
187 struct FlightCase { bool ground; float speed, vertical, msl; };
188 for (const auto flight : {
189 FlightCase{true, 0, 0, 0}, FlightCase{false, 0, .002f, .02f},
190 FlightCase{false, .25f, 0, 5}, FlightCase{false, 2, 1, 50},
191 FlightCase{false, 4, 0, 150}, FlightCase{false, 7.5f, 0, 400},
192 FlightCase{false, 7, -.4f, 80}, FlightCase{false, .0101f, 0, 10},
193 FlightCase{false, .009f, 0, 10.001f}})
194 for (bool engaged : {false, true})
195 for (auto lateral : {Afcs::Heading, Afcs::Navigation, Afcs::Localizer, Afcs::Roll, Afcs::LateralMode_TakeOff}) {
196 Bus bus; Logger logger; DeviceObject device;
197 FMA2 fma(0, 0, 1, 1, &bus, &logger, &device, {});
198 bus.OnGround = flight.ground;
199 bus.GroundSpeedKms = flight.speed;
200 bus.VerticalSpeedKms = flight.vertical;
201 bus.IndicatedAirspeedKms = .15f;
202 bus.PitchAttitudeRadians = .123f;
203 bus.RollAttitudeRadians = .2f;
204 playerships[0].mslKm = flight.msl;
205 bus.AFCS.CurrentLateralMode = lateral;
206 bus.AFCS.CurrentVerticalMode = Afcs::Pitch;
207 bus.AFCS.AutopilotEngaged = engaged;
208 bus.AFCS.DesiredHeadingRadians = 1.2f;
209 bus.AFCS.DesiredCourseRadians = 2.3f;
210 bus.AFCS.DesiredRollRadians = -.3f;
211 bus.AFCS.StandbyLateralMode = Afcs::Localizer;
212 bus.AFCS.StandbyVerticalMode = Afcs::Glideslope;
213 fma.FrameMove(11); fma.FrameMove(4);
214 // Two complete cycles also verify re-arming the cycle after PIT.
215 for (int cycle = 0; cycle < 2; ++cycle) {
216 int presses = 0;
217 do {
218 CycleVertical(bus);
219 Check(bus.AFCS.CurrentLateralMode == lateral,
220 "vertical cycle preserves active lateral guidance including PIT wrap");
221 Check(bus.AFCS.DesiredHeadingRadians == 1.2f &&
222 bus.AFCS.DesiredCourseRadians == 2.3f && bus.AFCS.DesiredRollRadians == -.3f,
223 "vertical cycle preserves lateral targets");
224 Check(bus.AFCS.AutopilotEngaged == engaged &&
225 bus.AFCS.StandbyLateralMode == Afcs::Localizer &&
226 bus.AFCS.StandbyVerticalMode == Afcs::Glideslope,
227 "vertical cycle preserves Autoflyte engagement and armed modes");
228 Check(bus.AFCS.CurrentVerticalMode != Afcs::Glideslope && ++presses <= 6,
229 "vertical cycle wraps without selecting separately armed glideslope");
230 draws.clear(); fma.FrameMove(.1f); fma.Render();
231 const auto* label = lateral == Afcs::Heading ? L"HDG" :
232 lateral == Afcs::Navigation ? L"NAV" : lateral == Afcs::Localizer ? L"LOC" :
233 lateral == Afcs::LateralMode_TakeOff ? L"T/O" : L"ROL";
234 Check(TextAt(96, 13, label) && ColorAt(96, 13) == 0xff00ff00,
235 "FMA retains lateral label without a false mode-change highlight");
236 } while (bus.AFCS.CurrentVerticalMode != Afcs::Pitch);
237 const int expected = (flight.ground || flight.speed < .010f ? 5 : 6) - (flight.msl > 10 ? 1 : 0);
238 Check(presses == expected, "complete cycle respects existing FPA and AGL availability");
239 Check(TextAt(158, 13, L"PIT") && bus.AFCS.DesiredPitchRadians == bus.PitchAttitudeRadians,
240 "return to PIT captures current pitch and displays PIT");
241 }
242 bus.AFCS.CurrentVerticalMode = Afcs::Glideslope;
243 CycleVertical(bus, true);
244 Check(bus.AFCS.CurrentVerticalMode == Afcs::Glideslope, "key repeat does not cycle modes");
245 CycleVertical(bus);
246 Check(bus.AFCS.CurrentVerticalMode == Afcs::Pitch && bus.AFCS.CurrentLateralMode == lateral,
247 "cycling out of captured glideslope preserves lateral mode");
248 // The separate no-lateral-mode fallback must still capture roll.
249 bus.AFCS.CurrentLateralMode = Afcs::LateralMode_Off;
250 bus.AFCS.CurrentVerticalMode = Afcs::AltitudeAgl;
251 CycleVertical(bus);
252 Check(bus.AFCS.CurrentLateralMode == Afcs::Roll && bus.AFCS.DesiredRollRadians == .2f,
253 "PIT wrap with lateral Off initializes the normal roll fallback");
254 }
255}
256void HeadingOwnershipTests() {
257 using Afcs = Bus::Afcs;
258 struct Owner { bool tvm, autopilot; Afcs::LateralModes lateral; };
259 const Owner owners[] = {{false,false,Afcs::LateralMode_Off}, {true,false,Afcs::LateralMode_Off},
260 {false,true,Afcs::Heading}, {false,true,Afcs::Navigation}, {false,true,Afcs::Localizer}};
261 // The same disengagement contract applies on the ground, in hover,
262 // atmosphere, ascent, suborbital coast, orbit (Bill's case) and reentry.
263 for (float altitude : {0.f,.02f,5.f,50.f,150.f,563.6f,80.f})
264 for (int selection = 0; selection < 3; ++selection) for (const auto owner : owners) {
265 Bus bus; Logger logger; DeviceObject device;
266 FMA2 fma(0, 0, 1, 1, &bus, &logger, &device, {});
267 playerships[0].mslKm = altitude; bus.OnGround = altitude == 0;
268 bus.orbit.snapshot.powered = true;
269 bus.orbit.request.ascent = selection == 0;
270 bus.orbit.request.rendezvousAscent = selection == 1;
271 bus.orbit.snapshot.plan.ascent = selection == 2;
273 bus.AFCS.DesiredHeadingRadians = float(55 * Orbital::Pi / 180);
274 bus.AFCS.DesiredCourseRadians = float(72 * Orbital::Pi / 180);
275 bus.AFCS.DesiredPitchRadians = .12f; bus.AFCS.DesiredRollRadians = .34f;
276 const float selectedHeading = bus.AFCS.DesiredHeadingRadians, selectedCourse = bus.AFCS.DesiredCourseRadians;
277 bus.AFCS.DorOn = true;
279 fma.FrameMove(11);
280 Check(std::abs(bus.AFCS.DesiredRadians - float(bus.orbit.guidance.ascentOrbitHeading)) < 1e-6f,
281 "engaged DOR may show its commanded orbital heading");
282 bus.AFCS.DorOn = false;
283 bus.AFCS.TvmOn = owner.tvm; bus.AFCS.AutopilotEngaged = owner.autopilot;
284 bus.AFCS.CurrentLateralMode = owner.lateral;
285 const bool course = owner.lateral == Afcs::Navigation || owner.lateral == Afcs::Localizer;
286 const float expected = course ? selectedCourse : selectedHeading;
287 // An inactive planner can keep refreshing its advisory, including the
288 // two reported values, without changing the shared cockpit readout.
289 for (int tick = 0; tick < 20; ++tick) {
290 bus.orbit.guidance.ascentOrbitHeading = (tick % 2 ? 136 : 41) * Orbital::Pi / 180;
291 fma.FrameMove(.1f);
292 Check(bus.AFCS.DesiredRadians == expected,
293 "DOR OFF preview cannot replace the manual, TVM, HDG, NAV or LOC heading readout");
294 Check(bus.AFCS.DesiredHeadingRadians == selectedHeading && bus.AFCS.DesiredCourseRadians == selectedCourse &&
295 bus.AFCS.DesiredPitchRadians == .12f && bus.AFCS.DesiredRollRadians == .34f,
296 "heading presentation does not change flight-control targets");
297 }
298 bus.AFCS.TvmOn = false; bus.AFCS.DorOn = true;
299 fma.FrameMove(.1f);
300 Check(std::abs(bus.AFCS.DesiredRadians - float(bus.orbit.guidance.ascentOrbitHeading)) < 1e-6f,
301 "re-engaging DOR restores its commanded orbital heading");
303 fma.FrameMove(.1f);
304 Check(bus.AFCS.DesiredRadians == expected,
305 "DOR assigned AFCS steering displays the assigned heading or course");
306 }
307}
308
309void DorPanelTests() {
310 using namespace Orbital;
311 using Afcs = Bus::Afcs;
312 Bus bus; Logger logger; DeviceObject device;
313 FMA2 fma(0, 0, 1, 1, &bus, &logger, &device, {});
314 auto frame = [&](float dt = .1f) { draws.clear(); fma.FrameMove(dt); fma.Render(); };
315 auto phase = [&](const wchar_t* label) {
316 const int x = 51 + (28 - 5 * int(wcslen(label))) / 2;
317 Check(TextAt(x, 13, label), "DOR phase occupies the former A/T cell");
318 Check(!HasText(L"A/T"), "DOR phase replaces A/T even if autothrottle flag is set");
319 Check(x >= 51 && x + 5 * wcslen(label) <= 79, "phase text fits existing cell");
320 int sources = 0;
321 for (const auto& d : draws) if (d.text == L"DOR") ++sources;
322 Check(sources == 1 && TextAt(56, 1, L"DOR"), "DOR appears once as source, including AFCS ascent");
323 };
324 auto blankAxes = [&] {
325 for (const auto& d : draws)
326 Check(d.text.empty() || d.y != 13 || !((d.x >= 90 && d.x < 118) || (d.x >= 151 && d.x < 179)),
327 "released DOR attitude leaves both lower guidance cells blank");
328 };
329 auto align = [&] {
330 Check(TextAt(91, 13, L"ALIGN") && TextAt(153, 13, L"ALIGN"), "DOR attitude ownership shows ALIGN on both axes");
331 Check(91 + 25 <= 118 && 153 + 25 <= 179, "ALIGN fits both existing guidance cells");
332 };
333 frame(); Check(TextAt(56, 1, L"A/F") && TextAt(56, 13, L"A/T") && TextAt(181,25,L"0.000"), "lamp test retains normal labels and zero altitude");
334 frame(11); Check(!HasText(L"ALT") && !TextAt(181,25,L"0.000"), "unused zero altitude label and value are hidden");
335 bus.AFCS.TvmOn = true; frame();
336 Check(TextAt(56,1,L"TVM") && TextAt(96,13,L"TVM"), "TVM displays normally before DOR selection");
337 bus.AFCS.TvmOn = false; bus.AFCS.DorOn = true;
338 bus.AFCS.AutothrottleEngaged = true;
339 auto& g = bus.orbit.guidance;
340 g.valid = g.ascentWaiting = g.ascentControl = true; g.phase = Phase::Wait;
341 bus.OnGround = true; frame(); phase(L"WAIT"); blankAxes();
342 Check(!HasText(L"TVM"), "switch from TVM clears cached label");
343 Check(ColorAt(55,13) == 0xff000000, "phase changes start highlight");
344 frame(4); Check(ColorAt(55,13) == 0xff00ff00, "phase highlight expires");
345 frame(); Check(ColorAt(55,13) == 0xff00ff00, "stable phase does not retrigger highlight");
346 g.ascentWaiting = false; g.ascentLiftoff = true; g.attitude = g.thrust = true;
347 g.phase = Phase::Depart; g.ascentNormal = .8;
348 bus.OnGround = false; playerships[0].mslKm = .02f; frame(); phase(L"VTOL"); align();
349 g.ascentLiftoff = false; g.ascentMain = 1;
350 bus.AFCS.AutopilotEngaged = bus.AFCS.DorAircraft = true;
351 bus.AFCS.CurrentLateralMode = Afcs::Heading; bus.AFCS.CurrentVerticalMode = Afcs::Pitch;
352 playerships[0].mslKm = 5; frame(); phase(L"BURN");
353 Check(TextAt(96,13,L"HDG") && TextAt(158,13,L"PIT") && !HasText(L"A/F"), "DOR source remains visible during AFCS HDG/PIT ascent");
354 bus.AFCS.CurrentVerticalMode = Afcs::FlightPathAngle; bus.AFCS.DesiredFpaRadians = .1f; frame();
355 Check(TextAt(158,13,L"FPA") && TextAt(151,25,L"+5.7"), "DOR aircraft FPA retains its angle readout");
357 bus.AFCS.CurrentLateralMode = Afcs::Navigation; bus.AFCS.DesiredCourseRadians = 1.2f; frame();
358 Check(TextAt(91,13,L"ALIGN") && bus.AFCS.DesiredRadians == 1.2f, "assigned navigation remains attitude-controlled without replacing selected course");
359 bus.AFCS.DorAircraft = bus.AFCS.AutopilotEngaged = false;
360 bus.AFCS.CurrentLateralMode = Afcs::LateralMode_Off; bus.AFCS.CurrentVerticalMode = Afcs::VerticalMode_Off;
361 g = {}; g.valid = true;
362 AttitudeController controller; RotationState rotation; rotation.effort = 1; rotation.acceleration = {.1,.1,.1};
363 for (float altitude : {50.f,150.f,563.6f,80.f}) for (auto coast : {Phase::Wait,Phase::Coast}) {
364 playerships[0].mslKm = altitude;
365 g = {}; g.valid = true; g.phase = coast; g.pointing = {0,0,-1};
366 Check(controller.Step(g,rotation,{0,1,0},.1), "real controller accepts wait/coast attitude release");
367 frame(); phase(coast == Phase::Wait ? L"WAIT" : L"COAST"); blankAxes();
368 Check(!g.attitude && !ManualAttitudeDisconnect(g), "blank axes agree with real controller's pilot attitude freedom");
369 }
370 g = {}; g.valid = g.thrust = true; g.phase = Phase::Depart; g.pointing = {1,0,0}; g.remainingDeltaV = 1;
371 Check(controller.Step(g,rotation,{0,1,0},.1), "real controller produces initial alignment");
372 frame(); phase(L"RCS"); align();
373 Check(ManualAttitudeDisconnect(g), "manual attitude input takes over during ALIGN");
374 controller.Reset();
375 for (int n=0;n<10;++n) {
376 g = {}; g.valid = g.thrust = true; g.phase = Phase::Depart; g.pointing = {0,0,1}; g.remainingDeltaV = 1;
377 controller.Step(g,rotation,{0,1,0},.1);
378 }
379 Check(g.thrust && g.attitude && g.phase == Phase::Depart, "real controller captures and holds burn attitude");
380 frame(); phase(L"BURN"); align();
381 Check(ManualAttitudeDisconnect(g), "ALIGN stays visible while a captured burn still owns attitude");
382 g = {}; g.valid = true; g.phase = Phase::Coast;
383 auto& a = bus.orbit.actuation; a.dor = a.valid = true; a.rotationEffort = {.2,0,0};
384 bus.ProgramTime = bus.orbit.sourceTime = 10; a.programTime = 9.8;
385 frame(); phase(L"RCS"); blankAxes();
386 a.rotationEffort={};a.programTime=10;bus.ProgramTime=bus.orbit.sourceTime=10.2;frame();phase(L"RCS");
387 bus.ProgramTime=bus.orbit.sourceTime=10.8; a.programTime = 9.4; frame(); phase(L"COAST");
388 a.programTime = 10.1; frame(); phase(L"COAST");
389 a.programTime = 10; a.dor = false; frame(); phase(L"COAST");
390 bus.ProgramTime=bus.orbit.sourceTime=11;a.programTime=11;a.dor=true;a.rotationEffort={.001,0,0};
391 frame();phase(L"COAST"); // negligible residual stabilization is not a burn phase
392 a = {};
393 g.poweredRendezvous=g.attitude=g.thrust=true;g.pointing={0,0,1};g.phase=Phase::Depart;
395 g.accelerationCommand={0,-.005,.024};frame();phase(L"BURN");align();
396 g.accelerationCommand={0,-.005,0};frame();phase(L"RCS");align();
397 g.accelerationCommand={0,-.005,-.024};frame();phase(L"BRAKE");align();
398 g.poweredRendezvous=false;
399 g.entryControl = g.attitude = g.thrust = true; g.phase = Phase::Arrive;
400 g.pointing = {0,0,1}; g.accelerationCommand = {0,.002,-.01};
401 frame(); phase(L"BRAKE"); align();
402 g.accelerationCommand = {0,.002,.01}; frame(); phase(L"BURN");
403 g.accelerationCommand = {}; frame(); phase(L"COAST"); align();
404 bus.FlightFreeze = true; frame(); phase(L"WAIT"); blankAxes();
405 bus.FlightFreeze = false; bus.ProgramTime = 10.6; frame(); phase(L"WAIT"); blankAxes();
406 bus.ProgramTime = bus.orbit.sourceTime = 10;
407 g.valid = false; frame(); phase(L"WAIT"); blankAxes();
408 g.valid = true; g.entryLimited = true; g.accelerationCommand = {0,.002,.01}; frame(); phase(L"BRAKE");
409 bus.AFCS.StandbyLateralMode = Afcs::Localizer; bus.AFCS.StandbyVerticalMode = Afcs::Glideslope;
410 frame(); Check(TextAt(96,1,L"LOC") && TextAt(158,1,L"G/S"), "upper row keeps armed modes during DOR");
411 bus.AFCS.DorOn = false; bus.AFCS.TvmOn = true; frame();
412 Check(TextAt(56,1,L"TVM") && TextAt(56,13,L"A/T") && TextAt(96,13,L"TVM") && !HasText(L"BRAKE") && !HasText(L"ALIGN"), "DOR-to-TVM handoff clears phases and restores A/T");
413 bus.AFCS.TvmOn = false; bus.AFCS.AutopilotEngaged = true;
415 frame();Check(TextAt(151,25,L"-2.5"),"selected PIT angle is visible below the active vertical cell");
416 bus.ProgramTime=bus.orbit.sourceTime=10;
417 bus.AFCS.CurrentLateralMode = Afcs::Heading; bus.AFCS.CurrentVerticalMode = Afcs::AltitudeMsl;
418 frame(); Check(TextAt(56,1,L"A/F") && TextAt(56,13,L"A/T") && TextAt(96,13,L"HDG") && TextAt(184,13,L"ALT") && TextAt(181,25,L"0.000"), "active sea-level altitude hold remains visible at entry handoff");
419 bus.AFCS.CurrentVerticalMode = Afcs::AltitudeAgl; frame();
420 Check(TextAt(198,17,L"A") && TextAt(181,25,L"0.000"), "active zero AGL hold remains visible");
421 bus.AFCS.CurrentVerticalMode = Afcs::VerticalMode_Off; bus.AFCS.DesiredAltitudeKm = 30; frame();
422 Check(TextAt(184,1,L"ALT") && TextAt(181,25,L"30.00"), "nonzero selected altitude remains visible outside altitude hold");
423 bus.AFCS.DesiredAltitudeKm = 0; frame();
424 Check(!HasText(L"ALT") && !TextAt(181,25,L"0.000"), "clearing unused altitude hides label and value together");
425 bus.AFCS.StandbyVerticalMode = Afcs::AltitudeMsl; frame();
426 Check(TextAt(184,1,L"ALT") && TextAt(181,25,L"0.000"), "armed zero altitude remains a meaningful selection");
427 bus.AFCS.AutothrottleEngaged = false; frame();
428 Check(!HasText(L"A/T") && !HasText(L"BURN"), "inactive throttle and DOR show no thrust indication");
429}
430
431int main() {
432 GroundStateTests();
433 AxisDefaultTests();
434 HeadingOwnershipTests();
435 VerticalCycleTests();
436 DorPanelTests();
437 std::cout << "PASS " << checks << " FMA rendered-text and transition checks\n";
438}
SCRIPT_CONTROL SCRIPT_STATE const void int
SCRIPT_CONTROL SCRIPT_STATE const void DWORD
@ REF_ONGROUND
Definition ServerTypes.h:43
Definition Bus.h:20
float RollAttitudeRadians
Definition Bus.h:48
float GroundSpeedKms
Definition Bus.h:179
float PitchAttitudeRadians
Definition Bus.h:47
bool OnGround
Definition Bus.h:173
float IndicatedAirspeedKms
Definition Bus.h:34
struct Bus::Afcs AFCS
bool FlightFreeze
Definition Bus.h:474
double ProgramTime
Definition Bus.h:473
float VerticalSpeedKms
Definition Bus.h:451
float TargetBearingDeg
Definition Bus.h:503
Orbital::BusState orbit
Definition Bus.h:481
Definition Font.h:7
Bus * bus
Definition Instrument.h:22
void DrawText(const WCHAR *str, int relativeX, int relativeY, float prmZ, int flags, RiseMath::Color color, int font=-1, std::string elementName="", int width=0, int height=0) const
Definition Instrument.h:49
virtual void FrameMove(float fElapsed)
Definition Instrument.h:92
Instrument(int prmX, int prmY, float prmXScale, float prmYScale, Bus *prmBus, Logger *prmLogger, DeviceObject *prmDevice, std::vector< Font * > prmFonts)
Definition Instrument.h:36
Logger * logger
Definition Instrument.h:23
virtual void Render()=0
DeviceObject * pDevice
Definition Instrument.h:21
UINT defaultFont
Definition Instrument.h:24
void AddToCallStack(const char *msg)
Definition Logger.cpp:355
bool Step(Guidance &g, const RotationState &in, Vec radial, double dt)
Sprite(Logger *prmLogger, DeviceObject *prmpDevice, std::string prmPathAndFilename, int prmX, int prmY, float prmZ, int prmTop, int prmLeft, int prmWidth, int prmHeight, DWORD prmColor, float scaleX=1.0f, float scaleY=1.0f)
Definition Sprite.cpp:5
void Draw(RiseMath::Color prmColor)
Definition Sprite.cpp:75
float f_AGL
Definition globals.cpp:9
s_network_objects playerships[MAX_SCAN]
Definition globals.cpp:112
#define cloudTopsMslC
Definition globals.h:110
constexpr double Pi
Definition OrbitMath.h:10
bool ManualAttitudeDisconnect(const Guidance &g)
Definition OrbitState.h:355
auto ToRadian(T value)
Definition ClientMath.h:13
constexpr float Tau
Definition ClientMath.h:12
auto ToDegree(T value)
Definition ClientMath.h:14
HRESULT Draw(Rendering::RenderDevice *device, Rendering::RenderTexture *texture, Rendering::RenderBuffer *vertices, const RiseMath::Matrix &world, UINT segments, Rendering::RenderMaterial *volumeEffect=nullptr, float physicalScale=1)
(25) Automatic Flight Control System (AFCS) modes and engagement status, including autothrottle;
Definition Bus.h:86
float DesiredPitchRadians
Definition Bus.h:141
float DesiredRollRadians
Definition Bus.h:140
float DesiredAltitudeKm
Definition Bus.h:122
float DesiredHeadingRadians
Definition Bus.h:133
float DesiredRadians
Definition Bus.h:138
bool DorOn
Definition Bus.h:148
bool AutothrottleEngaged
Definition Bus.h:88
bool TvmOn
Definition Bus.h:151
enum Bus::Afcs::LateralModes CurrentLateralMode
float DesiredVsiKms
Definition Bus.h:129
float DesiredCourseRadians
Definition Bus.h:136
bool AutopilotEngaged
Definition Bus.h:87
bool DorAircraft
Definition Bus.h:149
float DesiredFpaRadians
Definition Bus.h:130
enum Bus::Afcs::VerticalModes StandbyVerticalMode
enum Bus::Afcs::LateralModes StandbyLateralMode
float DesiredIasKms
Definition Bus.h:126
enum Bus::Afcs::VerticalModes CurrentVerticalMode
double entryForwardAcceleration
Definition OrbitState.h:352
ActuationTelemetry actuation
Definition OrbitState.h:349
double ascentOrbitHeading
Definition OrbitState.h:293
bool ascentOrbitSteering
Definition OrbitState.h:52