示例#1
0
        public void TestEnableDisable()
        {
            TestablePWMOutput TestPWMOutput      = new TestablePWMOutput();
            float             SteadyStateEpsilon = 0.001f;
            LowPass <float>   TestLPF            = new LowPass <float>(SteadyStateEpsilon: SteadyStateEpsilon);

            TestPWMOutput.SetOutput(0.3f);
            TalonMC TestMotor = new TalonMC(TestPWMOutput, 0.4f, TestLPF);

            TestMotor.SetSpeed(0.5f);

            Thread.Sleep(500);

            Assert.AreEqual(0.5f, TestMotor.TargetSpeed);
            // Assert.AreNotEqual(TestMotor.OngoingSpeedThread, TestLPF.IsSteadyState());
            Assert.AreNotEqual(SteadyStateEpsilon == 0.0f, TestLPF.IsSteadyState());

            TestMotor.SetEnabled(false);

            Assert.AreEqual(0.5f, TestMotor.TargetSpeed);
            Assert.AreEqual(0.5f, TestPWMOutput.DutyCycle);

            TestMotor.SetEnabled(true);

            Assert.AreEqual(0.5f, TestMotor.TargetSpeed);
            Thread.Sleep(500);
            Assert.AreNotEqual(0.5f, TestPWMOutput.DutyCycle);
        }
示例#2
0
        public void TestInitialization()
        {
            LowPass <double> Test0 = new LowPass <double>();
            LowPass <double> Test1 = new LowPass <double>(-3);
            LowPass <double> Test2 = new LowPass <double>(3);

            Assert.ThrowsException <ArgumentException>(() => new LowPass <string>());
        }
示例#3
0
        public ArmMotorController()
        {
            Scarlet.Utilities.StateStore.Start("ARM");

            BBBPinManager.AddMappingPWM(ShoulderPin);
            BBBPinManager.AddMappingPWM(ElbowPin);
            BBBPinManager.AddMappingPWM(WristPin1);
            BBBPinManager.AddMappingPWM(WristPin2);
            BBBPinManager.AddMappingGPIO(WristDirectionPin1, true, ResistorState.PULL_UP);
            BBBPinManager.AddMappingGPIO(WristDirectionPin2, true, ResistorState.PULL_UP);

            BBBPinManager.AddMappingADC(ShoulderPotPin);
            BBBPinManager.AddMappingADC(ElbowPotPin);
            BBBPinManager.AddMappingADC(WristPotPin);
            BBBPinManager.ApplyPinSettings(BBBPinManager.ApplicationMode.APPLY_IF_NONE);
            BeagleBone.Initialize(SystemMode.DEFAULT, true);

            const double DegToRad = Math.PI / 180.0;

            a = new Arm((0, 0, Math.PI / 2, Math.PI / 2, 0, 0, 6.8),
                        (0, 0, -76 * DegToRad, 100 * DegToRad, 0, 0, 28.0),
                        (0, 0, -168.51 * DegToRad, -10 * DegToRad, 0, 0, 28.0),
                        (-2 * Math.PI, 2 * Math.PI, -Math.PI / 2, Math.PI / 2, 0, 0, 12.75));
            //(0, 12.75, -Math.PI / 2, Math.PI / 2));

            LowPass <float> ShoulderFilter = new LowPass <float>();
            LowPass <float> ElbowFilter    = new LowPass <float>();

            ShoulderPWM = PWMBBB.PWMDevice1.OutputB;
            ElbowPWM    = PWMBBB.PWMDevice1.OutputA;
            IPWMOutput WristPWM1 = PWMBBB.PWMDevice2.OutputB;
            IPWMOutput WristPWM2 = PWMBBB.PWMDevice2.OutputA;

            IDigitalOut WristDirectionGPIO1 = new DigitalOutBBB(WristDirectionPin1);
            IDigitalOut WristDirectionGPIO2 = new DigitalOutBBB(WristDirectionPin2);
            IAnalogueIn ShoulderADC         = new AnalogueInBBB(ShoulderPotPin);
            IAnalogueIn ElbowADC            = new AnalogueInBBB(ElbowPotPin);
            IAnalogueIn WristADC            = new AnalogueInBBB(WristPotPin);

            Shoulder = new TalonMC(ShoulderPWM, 0.2f, ShoulderFilter);
            Elbow    = new TalonMC(ElbowPWM, 0.2f, ElbowFilter);
            Wrist1   = new CytronMD30C(WristPWM1, WristDirectionGPIO1, 0.3f);
            Wrist2   = new CytronMD30C(WristPWM2, WristDirectionGPIO2, 0.3f);

            ShoulderPot = new Potentiometer(ShoulderADC, 300);
            ElbowPot    = new Potentiometer(ElbowADC, 300);
            WristPot    = new Potentiometer(WristADC, 300);
        }
示例#4
0
        public void TestThreadValidity()
        {
            TestablePWMOutput TestPWMOutput = new TestablePWMOutput();
            LowPass <float>   TestFilter    = new LowPass <float>(SteadyStateEpsilon: 0.1);
            TalonMC           TestTalon     = new TalonMC(TestPWMOutput, 0.5f, TestFilter);

            // Low Pass should run continuously because it was not given an epsilon above
            // Here we will make sure it doesn't block
            Stopwatch Watch = new Stopwatch();

            Watch.Reset();
            Watch.Start();
            TestTalon.SetSpeed(1.0f);
            Watch.Stop();
            // Allow 150ms delay for setting talon speed
            Assert.IsTrue(Watch.ElapsedMilliseconds < 150);
            // Test to ensure that output duty cycle rises
            // (Which is controlled on another thread)
            float LastDC = TestPWMOutput.DutyCycle;

            Watch.Reset();
            Watch.Start();
            while (Watch.ElapsedMilliseconds < 2000)
            {
                float DC = TestPWMOutput.DutyCycle;
                if (TestFilter.IsSteadyState())
                {
                    Assert.AreEqual(DC, LastDC);

                    // Tested these conditions by setting OngoingSpeedThread to public
                    // then set it back.
                    // Assert.IsFalse(TestTalon.OngoingSpeedThread);
                }
                else
                {
                    // Tested these conditions by setting OngoingSpeedThread to public
                    // then set it back.
                    // Assert.IsTrue(TestTalon.OngoingSpeedThread);
                    Assert.IsTrue(DC > LastDC);
                }
                LastDC = DC;
            }
        }
示例#5
0
        public void SetUp()
        {
            _out = new ConstantSignal <double>(() => 0.0);
            if (_midiManager != null)
            {
                _plugin.MidiProcessor.NoteOff -= _midiManager.NoteOff;
                _plugin.MidiProcessor.NoteOn  -= _midiManager.NoteOn;
            }
            _midiManager = new MidiManager(NoteChannels);
            _plugin.MidiProcessor.NoteOff += _midiManager.NoteOff;
            _plugin.MidiProcessor.NoteOn  += _midiManager.NoteOn;

            _scratchBuffer1 = new double[this.BlockSize, 1];
            _scratchBuffer2 = new double[this.BlockSize, 1];
            _scratchBuffer3 = new double[this.BlockSize, 1];
            _scratchBuffer4 = new double[this.BlockSize, 1];
            _scratchBuffer5 = new double[this.BlockSize, 1];
            _scratchBuffer6 = new double[this.BlockSize, 1];

            _scratchBufferChannels1 = new double[this.BlockSize, NoteChannels];
            _scratchBufferChannels2 = new double[this.BlockSize, NoteChannels];
            _scratchBufferChannels3 = new double[this.BlockSize, NoteChannels];

            _scratchBufferChannels4 = new double[this.BlockSize, NoteChannels];
            _scratchBufferChannels5 = new double[this.BlockSize, NoteChannels];
            _scratchBufferChannels6 = new double[this.BlockSize, NoteChannels];

            _blockSize  = BlockSize;
            _sampleRate = SampleRate;



            var sine1 = new Oscillator(NoteChannels, this.SampleRate)
            {
                Shape       = Oscillator.WaveShape.Sine,
                Frequency   = _midiManager.ChannelFrequencies,
                OctaveShift = new ConstantSignal <int>(() => _plugin.Model.Path1OctaveShift),
                Amplitude   = new ConstantSignal <double>(() => _plugin.Model.Sine)
            };

            sine1.Out.Buffer = _scratchBufferChannels1;

            var square1 = new Oscillator(NoteChannels, this.SampleRate)
            {
                Shape       = Oscillator.WaveShape.Square,
                Frequency   = _midiManager.ChannelFrequencies,
                OctaveShift = new ConstantSignal <int>(() => _plugin.Model.Path1OctaveShift),
                Amplitude   = new ConstantSignal <double>(() => _plugin.Model.Square)
            };

            square1.Out.Buffer = _scratchBufferChannels2;

            var triangle1 = new Oscillator(NoteChannels, this.SampleRate)
            {
                Shape       = Oscillator.WaveShape.Triangle,
                Frequency   = _midiManager.ChannelFrequencies,
                OctaveShift = new ConstantSignal <int>(() => _plugin.Model.Path1OctaveShift),
                Amplitude   = new ConstantSignal <double>(() => _plugin.Model.Triangle)
            };

            triangle1.Out.Buffer = _scratchBufferChannels3;


            var sine2 = new Oscillator(NoteChannels, this.SampleRate)
            {
                Shape       = Oscillator.WaveShape.Sine,
                Frequency   = _midiManager.ChannelFrequencies,
                OctaveShift = new ConstantSignal <int>(() => _plugin.Model.Path2OctaveShift),
                Amplitude   = new ConstantSignal <double>(() => _plugin.Model.Sine)
            };

            sine2.Out.Buffer = _scratchBufferChannels4;

            var square2 = new Oscillator(NoteChannels, this.SampleRate)
            {
                Shape       = Oscillator.WaveShape.Square,
                Frequency   = _midiManager.ChannelFrequencies,
                OctaveShift = new ConstantSignal <int>(() => _plugin.Model.Path2OctaveShift),
                Amplitude   = new ConstantSignal <double>(() => _plugin.Model.Square)
            };

            square2.Out.Buffer = _scratchBufferChannels5;

            var triangle2 = new Oscillator(NoteChannels, this.SampleRate)
            {
                Shape       = Oscillator.WaveShape.Triangle,
                Frequency   = _midiManager.ChannelFrequencies,
                OctaveShift = new ConstantSignal <int>(() => _plugin.Model.Path2OctaveShift),
                Amplitude   = new ConstantSignal <double>(() => _plugin.Model.Triangle)
            };

            triangle2.Out.Buffer = _scratchBufferChannels6;

            var sourceSum1 = new Sum("sourceSum");

            sourceSum1.Inputs.Add(sine1.Out);
            sourceSum1.Inputs.Add(square1.Out);
            sourceSum1.Inputs.Add(triangle1.Out);
            sourceSum1.Buffer = _scratchBufferChannels1;

            var sourceSum2 = new Sum("sourceSum2");

            sourceSum2.Inputs.Add(sine2.Out);
            sourceSum2.Inputs.Add(square2.Out);
            sourceSum2.Inputs.Add(triangle2.Out);
            sourceSum2.Buffer = _scratchBufferChannels4;

            var adsr1 = new Adsr(NoteChannels, this.SampleRate)
            {
                ReleaseDuration = new ConstantSignal <double>(() => _plugin.Model.ReleaseDuration / 5),
                AttackDuration  = new ConstantSignal <double>(() => _plugin.Model.AttackDuration / 10),
                DecayDuration   = new ConstantSignal <double>(() => _plugin.Model.DecayDuration / 10),
                Attack          = new ConstantSignal <double>(() => _plugin.Model.AttackStrength),
                Sustain         = new ConstantSignal <double>(() => _plugin.Model.SustainStrength),
                Triggers        = _midiManager.ChannelTriggers,
                Input           = sourceSum1
            };

            adsr1.Out.Buffer = _scratchBufferChannels1;

            var adsr2 = new Adsr(NoteChannels, this.SampleRate)
            {
                ReleaseDuration = new ConstantSignal <double>(() => _plugin.Model.ReleaseDuration / 5),
                AttackDuration  = new ConstantSignal <double>(() => _plugin.Model.AttackDuration / 10),
                DecayDuration   = new ConstantSignal <double>(() => _plugin.Model.DecayDuration / 10),
                Attack          = new ConstantSignal <double>(() => _plugin.Model.AttackStrength),
                Sustain         = new ConstantSignal <double>(() => _plugin.Model.SustainStrength),
                Triggers        = _midiManager.ChannelTriggers,
                Input           = sourceSum2
            };

            adsr2.Out.Buffer = _scratchBufferChannels4;



            var delayOsc = new Oscillator(1, SampleRate)
            {
                Shape     = Oscillator.WaveShape.Triangle,
                Frequency = new ConstantSignal <double>(() => _plugin.Model.Delay1PlaybackSpeedFreq),
                Amplitude = new ConstantSignal <double>(() => Math.Pow(_plugin.Model.Delay1PlaybackSpeedMod, 3) / 2),
                Base      = new ConstantSignal <double>(() => 1)
            };

            delayOsc.Out.Buffer = _scratchBuffer1;



            var delay1 = new Delay()
            {
                DelayLength   = new ConstantSignal <int>(() => _plugin.Model.Delay1Length),
                PlaybackSpeed = delayOsc.Out,
                Gain          = new ConstantSignal <double>(() => _plugin.Model.Delay1Gain)
            };

            delay1.Out.Buffer = _scratchBuffer2;

            var combine1 = new Mix("Combine");

            combine1.Inputs.Add(delay1.Out);
            combine1.Inputs.Add(adsr1.Out.Flat((sum, cur) => sum + cur, 0d));
            combine1.Strengths.Add(new ConstantSignal <double>(() => _plugin.Model.Wet1));
            combine1.Strengths.Add(new ConstantSignal <double>(() => 1 - _plugin.Model.Wet1));
            combine1.Buffer = _scratchBuffer3;

            var lowPass1 = new LowPass("lowpass1")
            {
                Scale = new ConstantSignal <int>(() => _plugin.Model.Filter1),
                Input = combine1
            };

            lowPass1.Buffer = _scratchBuffer4;
            delay1.Input    = lowPass1;


            var combine2 = new Mix("Combine2");

            combine2.Inputs.Add(delay1.Out);
            combine2.Inputs.Add(adsr2.Out.Flat((sum, cur) => sum + cur, 0d));
            combine2.Strengths.Add(new ConstantSignal <double>(() => _plugin.Model.Gain1));
            combine2.Strengths.Add(new ConstantSignal <double>(() => _plugin.Model.Gain2));
            combine2.Buffer = _scratchBuffer6;


            var softClip = new ApplyFunction(sample => sample / (1 + Math.Abs(sample)), "SoftClip")
            {
                Buffer = _scratchBuffer6,
                Input  = combine2
            };



            _out = softClip;
        }
示例#6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LowPassComb"/> class.
 /// </summary>
 /// <param name="initMaxDelay">The initial max delay.</param>
 /// <param name="initDelay">The initial delay.</param>
 /// <param name="initFeedBack">The initial feedback.</param>
 /// <param name="cutOffFreq">The initial cutoff frequency.</param>
 public LowPassComb(float initMaxDelay = 1000, float initDelay = 1, float initFeedBack = 0.9f, float cutOffFreq = 1000) : base(initMaxDelay, initDelay, initFeedBack)
 {
     this.Frequency = cutOffFreq;
     this.lpf       = new LowPass(this.Frequency);
 }
示例#7
0
        public static void Start(string[] args)
        {
            if (args.Length < 2)
            {
                TestMain.ErrorExit("perf command requires functionality to test.");
            }
            switch (args[1].ToLower())
            {
            case "dataunit":
            {
                if (args.Length < 3)
                {
                    TestMain.ErrorExit("perf dataunit command requires # of elements to test.");
                }
                int TestLength = int.Parse(args[2]);
                Log.Output(Log.Severity.INFO, Log.Source.OTHER, "Testing DataUnit performance, " + TestLength.ToString("N0", CultureInfo.InvariantCulture) + " iterations.");
                Log.Output(Log.Severity.INFO, Log.Source.OTHER, "Generating keyset...");
                string[] Values = { "Erza", "Homura", "Reika", "Jibril", "Aqua", "Kurisu" };
                byte[]   IDs    = new byte[TestLength];
                Random   Random = new Random();
                for (int i = 0; i < IDs.Length; i++)
                {
                    IDs[i] = (byte)Random.Next(Values.Length);
                }
                DataUnit DUT = new DataUnit("Testing Structure");         // DataUnit under Test

                Log.Output(Log.Severity.INFO, Log.Source.OTHER, "Writing to DataUnit...");
                Stopwatch Stopwatch = Stopwatch.StartNew();
                for (int i = 0; i < IDs.Length; i++)
                {
                    DUT.Add(i.ToString(), Values[IDs[i]]);
                }
                Stopwatch.Stop();
                Log.Output(Log.Severity.INFO, Log.Source.OTHER, "  Took " + Math.Round(Stopwatch.ElapsedTicks * 1000F / Stopwatch.Frequency, 5) + "ms.");

                Log.Output(Log.Severity.INFO, Log.Source.OTHER, "Reading from DataUnit...");
                Stopwatch = Stopwatch.StartNew();
                for (int i = 0; i < IDs.Length; i++)
                {
                    DUT.GetValue <string>(i.ToString());
                }
                Stopwatch.Stop();
                Log.Output(Log.Severity.INFO, Log.Source.OTHER, "  Took " + Math.Round(Stopwatch.ElapsedTicks * 1000F / Stopwatch.Frequency, 5) + "ms.");
                break;
            }

            case "filter":
            {
                if (args.Length < 3)
                {
                    TestMain.ErrorExit("perf filter command requires filter type to test.");
                }
                if (args[2] != "lowpass" && args[2] != "average")
                {
                    TestMain.ErrorExit("Invalid filter type supplied.");
                }
                if (args.Length < 4)
                {
                    TestMain.ErrorExit("perf filter command requires # of cycles to test.");
                }

                IFilter <double> FUT = null;
                switch (args[2].ToLower())
                {
                case "lowpass": { FUT = new LowPass <double>(); break; }

                case "average": { FUT = new Average <double>(); break; }
                }
                int TestLength = int.Parse(args[3]);

                Log.Output(Log.Severity.INFO, Log.Source.OTHER, "Testing Filter performance, " + TestLength.ToString("N0", CultureInfo.InvariantCulture) + " iterations.");
                Log.Output(Log.Severity.INFO, Log.Source.OTHER, "Generating inputs...");
                double[] Inputs = new double[TestLength];
                Random   Random = new Random();
                for (int i = 0; i < Inputs.Length; i++)
                {
                    Inputs[i] = Random.NextDouble();
                }

                Log.Output(Log.Severity.INFO, Log.Source.OTHER, "Cycling Filter...");
                Stopwatch Stopwatch = Stopwatch.StartNew();
                for (int i = 0; i < Inputs.Length; i++)
                {
                    FUT.Feed(Inputs[i]);
                    double Output = FUT.GetOutput();
                }
                Stopwatch.Stop();
                Log.Output(Log.Severity.INFO, Log.Source.OTHER, "  Took " + Math.Round(Stopwatch.ElapsedTicks * 1000F / Stopwatch.Frequency, 5) + "ms.");

                break;
            }
            }
        }