コード例 #1
0
        public void Lib_Cos()
        {
            float stepDelta = FPGATrigonometryConstants.TwoPI / Steps;

            var posError = double.MinValue;
            var negError = double.MaxValue;
            var absError = 0d;

            // able to achieve about this accuracy
            var eps = 2.5e-5;

            for (var step = 0; step < Steps; step++)
            {
                var rad = step * stepDelta;

                // calculate cos
                var taylorCos     = FPGATrigonometry.Cos(rad);
                var calculatedCos = Math.Cos(rad);
                var cosDelta      = taylorCos - calculatedCos;

                absError = Math.Max(absError, Math.Abs(cosDelta));
                posError = Math.Max(cosDelta, posError);
                negError = Math.Min(cosDelta, negError);

                Assert.IsTrue(absError < eps, $"Failed for cos({rad})");
            }
        }
コード例 #2
0
        public static float DeltaVInclinationOrbit(float mass, float innerRadius, float outerRadius, float inclination)
        {
            var vApogee  = SequentialMath.Sqrt(2 * FPGAOrbitalCalcConstants.G * mass * (innerRadius / outerRadius) * (1 / (innerRadius + outerRadius)));
            var vOrbital = VOrbit(mass, outerRadius);
            var cosInc   = FPGATrigonometry.Cos(inclination);
            var deltaV   = SequentialMath.Sqrt(vApogee * vApogee + vOrbital * vOrbital - 2 * vApogee * vOrbital * cosInc);

            return(deltaV);
        }
コード例 #3
0
        public static float DeltaVInclinationOrbitOptimized(float mass, float innerRadius, float outerRadius, float inclination)
        {
            var vApogeeSquared  = 2 * FPGAOrbitalCalcConstants.G * mass * (innerRadius / outerRadius) * (1 / (innerRadius + outerRadius));
            var vOrbitalSquared = VOrbitSquared(mass, outerRadius);
            var cosInc          = FPGATrigonometry.Cos(inclination);

            var vCos   = SequentialMath.Sqrt(vApogeeSquared * vOrbitalSquared * cosInc * cosInc);
            var deltaV = SequentialMath.Sqrt(vApogeeSquared + vOrbitalSquared - 2 * vCos);

            return(deltaV);
        }
コード例 #4
0
        public void Cos()
        {
            using (var port = new QuokkaPort())
            {
                var rnd = new Random(Environment.TickCount);

                foreach (var idx in Enumerable.Range(-5000, 10000))
                {
                    var value = (float)(idx * rnd.NextDouble() * FPGATrigonometryConstants.TwoPI);
                    port.WriteFloat(value);

                    var expected    = FPGATrigonometry.Cos(value);
                    var actualBytes = port.Read(4, true, port.DefaultTimeout);
                    var actual      = TestConverters.FloatFromByteArray(actualBytes);

                    Assert.AreEqual(expected, actual, $"Failed for {value}");
                }
            }
        }
コード例 #5
0
        public static async Task Aggregator(
            FPGA.InputSignal <bool> RXD,
            FPGA.OutputSignal <bool> TXD
            )
        {
            Sequential handler = () =>
            {
                FPU.FPUScopeNoSync();

                while (true)
                {
                    float data = 0;
                    UART.ReadFloat(115200, RXD, out data);

                    data = FPGATrigonometry.Cos(data);

                    UART.WriteFloat(115200, data, TXD);
                }
            };

            FPGA.Config.OnStartup(handler);
        }