public static async Task Aggregator( FPGA.InputSignal <bool> RXD, FPGA.OutputSignal <bool> TXD ) { Sequential handler = () => { FPU.FPUScopeNoSync(); while (true) { FPGA.Optimizations.AddOptimizer <DefaultOptimizer>(); const uint baud = 115200; UART.ReadFloat(baud, RXD, out float mass); UART.ReadFloat(baud, RXD, out float radius); var vOrbit = FPGAOrbitalCalc.TOrbit(mass, radius); UART.WriteFloat(baud, vOrbit, TXD); } }; FPGA.Config.OnStartup(handler); }
public void Quokka_TOrbit() { using (var port = new QuokkaPort()) { var r0 = 6371e+3f; // orbit periods around the earth var cases = new[] { // low orbit new { R = r0 + 200e+3f, M = 5.972e+24f, T = 5301.04f }, // ISS orbit new { R = r0 + 409e+3f, M = 5.972e+24f, T = 5555.96f }, // geostationary orbit new { R = r0 + 35786e+3f, M = 5.972e+24f, T = 86142.8f }, // moon orbit new { R = r0 + 399000e+3f, M = 5.972e+24f, T = 2.56858e+6f }, }; foreach (var testCase in cases) { float calculated = FPGAOrbitalCalc.TOrbit(testCase.M, testCase.R); var err = Math.Abs((calculated - testCase.T) / testCase.T); Assert.IsTrue(err < 0.01); port.WriteFloat(testCase.M); port.WriteFloat(testCase.R); var actualBytes = port.Read(4, true, port.DefaultTimeout); var actual = TestConverters.FloatFromByteArray(actualBytes); Assert.AreEqual(calculated, actual, $"Failed for {testCase}"); } } }