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); }
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; } }