internal override InterruptableSensorBase GiveInterruptableSensorBase() { m_interruptTrigger = new AnalogTrigger(s_analogIo.GetInput()); m_interruptTrigger.SetLimitsVoltage(2.0f, 3.0f); m_interruptTriggerOutput = new AnalogTriggerOutput(m_interruptTrigger, AnalogTriggerType.State); return(m_interruptTriggerOutput); }
public void TestAnalogTriggerNullInput() { Assert.Throws<ArgumentNullException>(() => { AnalogTrigger trigger = new AnalogTrigger(null); }); }
internal override void FreeInterruptableSensorBase() { m_interruptTriggerOutput.CancelInterrupts(); m_interruptTriggerOutput.Dispose(); m_interruptTriggerOutput = null; m_interruptTrigger.Dispose(); m_interruptTrigger = null; }
public void TestSetFiltered() { using (AnalogTrigger at = new AnalogTrigger(2)) { at.Averaged = false; at.Filtered = true; Assert.AreEqual(TrigerType.Filtered, GetData(at.Index).TrigType); } }
public void TestAnalogTriggerOutputCreation() { using (AnalogTrigger trigger = new AnalogTrigger(0)) { using (AnalogTriggerOutput output = new AnalogTriggerOutput(trigger, AnalogTriggerType.State)) { Assert.That(SimData.Reports.ContainsKey((byte)ResourceType.kResourceType_AnalogTriggerOutput)); Assert.That(SimData.Reports[(byte)ResourceType.kResourceType_AnalogTriggerOutput].Contains((byte)trigger.Index)); } } }
public void TestAnalogTriggerInitFree([Range(0, 7)]int pin) { int index; using (AnalogTrigger trigger = new AnalogTrigger(pin)) { index = trigger.Index; Assert.IsTrue(GetData(index).Initialized); Assert.AreEqual(pin, GetData(index).AnalogPin); } Assert.IsFalse(GetData(index).Initialized); }
public void TestSetFilteredThenAverage() { using (AnalogTrigger at = new AnalogTrigger(2)) { SimData.DriverStation.ControlData.DsAttached = true; SimData.ErrorData = null; at.Averaged = true; at.Filtered = true; Assert.That(SimData.ErrorData, Is.Not.Null); SimData.ErrorData = null; } }
/// <summary> /// Get the position of the analog triggers /// </summary> /// <param name="trigger">Trigger to retrieve the position of</param> /// <returns>Position of the trigger button</returns> public byte GetAnalogT(AnalogTrigger trigger) { if (!IsConnected || XBoxJoystickData == null) { return(0); } lock (XBoxJoystickData) { return((byte)(XBoxJoystickData[(uint)trigger])); } }
public void TestAnalogTriggerAboveWindow() { AnalogTrigger trigger = new AnalogTrigger(s_analogIo.GetInput()); trigger.SetLimitsVoltage(2.0f, 3.0f); s_analogIo.GetOutput().SetVoltage(4.0f); Timer.Delay(DelayTime); Assert.IsFalse(trigger.GetInWindow(), "Analog Trigger is in the window (2V, 3V)"); Assert.IsTrue(trigger.GetTriggerState(), "Analog trigger is not on"); trigger.Dispose(); }
public void TestAnalogTriggerInWindow() { AnalogTrigger trigger = new AnalogTrigger(s_analogIo.GetInput()); trigger.SetLimitsVoltage(2.0f, 3.0f); s_analogIo.GetOutput().SetVoltage(2.5f); Timer.Delay(DelayTime); Assert.IsTrue(trigger.GetInWindow(), "Analog Trigger is not in the window (2V, 3V)"); //Not checking for state, because state will be whichever state it was in last. trigger.Dispose(); }
public void TestAnalogTriggerInWindow() { AnalogTrigger trigger = new AnalogTrigger(analogIO.GetInput()); trigger.SetLimitsVoltage(2.0f, 3.0f); analogIO.GetOutput().SetVoltage(2.5f); Timer.Delay(DelayTime); Assert.IsTrue(trigger.InWindow, "Analog Trigger is not in the window (2V, 3V)"); Assert.IsFalse(trigger.TriggerState, "Analog trigger is on"); trigger.Dispose(); }
public void TestAnalogTriggerOutputRoutings(AnalogTriggerType type) { using (AnalogTrigger trigger = new AnalogTrigger(0)) { using (AnalogTriggerOutput output = new AnalogTriggerOutput(trigger, type)) { Assert.That(output.AnalogTriggerForRouting, Is.True); int routingChannel = (trigger.Index << 2) + (int)type; byte routingModule = (byte)(trigger.Index >> 2); Assert.That(output.ChannelForRouting, Is.EqualTo(routingChannel)); Assert.That(output.ModuleForRouting, Is.EqualTo(routingModule)); } } }
public void TestAnalogTriggerTakeAnalogInput() { using (AnalogInput aIn = new AnalogInput(0)) { Assert.That(SimData.AnalogIn[0].Initialized, Is.True); int index = 0; using (AnalogTrigger trigger = new AnalogTrigger(aIn)) { index = trigger.Index; Assert.That(GetData(index).Initialized, Is.True); } Assert.That(GetData(index).Initialized, Is.False); Assert.That(SimData.AnalogIn[0].Initialized, Is.True); } Assert.That(SimData.AnalogIn[0].Initialized, Is.False); }
public void TestAnalogTriggerCounter() { AnalogTrigger trigger = new AnalogTrigger(s_analogIo.GetInput()); trigger.SetLimitsVoltage(2.0f, 3.0f); Counter counter = new Counter(trigger); for (int i = 0; i < 50; i++) { s_analogIo.GetOutput().SetVoltage(1.0); Timer.Delay(DelayTime); s_analogIo.GetOutput().SetVoltage(4.0); Timer.Delay(DelayTime); } Assert.AreEqual(50, counter.Get(), "Analog trigger counter did not count 50 ticks"); counter.Dispose(); trigger.Dispose(); }
public void TestSetLimitsVoltageInvalid() { using (AnalogTrigger at = new AnalogTrigger(2)) { Assert.Throws<BoundaryException>(() => { at.SetLimitsVoltage(4.0, 2.0); }); } }
public void TestAnalogTriggerOutputGetInvalidType() { using (AnalogTrigger trigger = new AnalogTrigger(0)) { using (AnalogTriggerOutput output = new AnalogTriggerOutput(trigger, AnalogTriggerType.FallingPulse)) { Assert.Throws<UncleanStatusException>(() => { output.Get(); }); } } }
public void TestAnalogTriggerOutputGetInWindow() { using (AnalogTrigger trigger = new AnalogTrigger(0)) { using (AnalogTriggerOutput output = new AnalogTriggerOutput(trigger, AnalogTriggerType.InWindow)) { HALAnalog.GetAnalogTriggerInWindow = (IntPtr pointer, ref int status) => { status = 0; return false; }; Assert.That(output.Get(), Is.False); HALAnalog.GetAnalogTriggerInWindow = (IntPtr pointer, ref int status) => { status = 0; return true; }; Assert.That(output.Get(), Is.True); HALAnalog.GetAnalogTriggerInWindow = global::HAL.SimulatorHAL.HALAnalog.getAnalogTriggerInWindow; } } }
public void TestCounterInit5() { using (AnalogTrigger at = new AnalogTrigger(2)) { using (Counter ctr = new Counter(at)) { TestInit(0, 2, 0, true, false, false, false, true); } } }
public void TestCounterSetDownAnalogSource() { using (Counter c = new Counter()) { TestInit(0, 0, 0, false, false, false, false); using (AnalogTrigger at = new AnalogTrigger(2)) { c.SetDownSource(at, AnalogTriggerType.State); TestInit(0, 0, 2, false, false, false, false, false, true); } } }
//public static List<ErrorData> ErrorList { get; } = new List<ErrorData>(); /* * /// <summary> * /// Gets the can talon. * /// </summary> * /// <param name="id">The identifier.</param> * /// <returns></returns> * public static CanTalonData GetCanTalon(int id) * { * CanTalonData data; * bool retVal = s_canTalon.TryGetValue(id, out data); * if (retVal) * { * //Contains key. Just return it * return data; * } * else * { * //CAN Talon does not exist yet. Return null. * return null; * } * } * * /// <summary> * /// Initializes the can talon. * /// </summary> * /// <param name="id">The identifier.</param> * /// <returns></returns> * public static bool InitializeCanTalon(int id) * { * CanTalonData data; * bool retVal = s_canTalon.TryGetValue(id, out data); * if (retVal) * { * //Contains key. return false saying we did not initialize a new one. * return false; * } * else * { * //Create a new Can Talon data and return true. * data = new CanTalonData(); * s_canTalon.Add(id, data); * OnTalonSRXAddedOrRemoved?.Invoke(id, new TalonSRXEventArgs(true)); * return true; * } * } * * /// <summary> * /// Removes the can talon. * /// </summary> * /// <param name="id">The identifier.</param> * public static void RemoveCanTalon(int id) * { * s_canTalon.Remove(id); * OnTalonSRXAddedOrRemoved?.Invoke(id, new TalonSRXEventArgs(false)); * } * * /// <summary> * /// Gets the PCM. * /// </summary> * /// <param name="id">The identifier.</param> * /// <returns></returns> * public static PCMData GetPCM(int id) * { * PCMData data; * bool retVal = s_pcm.TryGetValue(id, out data); * if (retVal) * { * //Contains key. Just return it * return data; * } * else * { * data = new PCMData(); * s_pcm.Add(id, data); * OnPCMAdded?.Invoke(data, null); * return data; * } * } * * /// <summary> * /// Initializes the PCM. * /// </summary> * /// <param name="id">The identifier.</param> * /// <returns></returns> * public static bool InitializePCM(int id) * { * PCMData data; * bool retVal = s_pcm.TryGetValue(id, out data); * if (retVal) * { * //Contains key. return false saying we did not initialize a new one. * return false; * } * else * { * //Create a new PCM data and return true. * data = new PCMData(); * s_pcm.Add(id, data); * OnPCMAdded?.Invoke(data, null); * return true; * } * } * * /// <summary> * /// Gets the PDP. * /// </summary> * /// <param name="id">The identifier.</param> * /// <returns></returns> * public static PDPData GetPDP(int id) * { * PDPData data; * bool retVal = s_pdp.TryGetValue(id, out data); * if (retVal) * { * //Contains key. Just return it * return data; * } * else * { * data = new PDPData(); * s_pdp.Add(id, data); * OnPDPAdded?.Invoke(data, null); * return data; * } * } * * /// <summary> * /// Initializes a new PDP. * /// </summary> * /// <param name="id">The identifier.</param> * /// <returns>True if new PDP was created, otherwise false</returns> * public static bool InitializePDP(int id) * { * PDPData data; * bool retVal = s_pdp.TryGetValue(id, out data); * if (retVal) * { * //Contains key. return false saying we did not initialize a new one. * return false; * } * else * { * //Create a new PCM data and return true. * data = new PDPData(); * s_pdp.Add(id, data); * OnPDPAdded?.Invoke(data, null); * return true; * } * } * * /// <summary> * /// Occurs on talon SRX added or removed. * /// </summary> * public static event EventHandler<TalonSRXEventArgs> OnTalonSRXAddedOrRemoved; * /// <summary> * /// Occurs when a PCM is added. * /// </summary> * public static event EventHandler OnPCMAdded; * /// <summary> * /// Occurs when a PDP is added. * /// </summary> * public static event EventHandler OnPDPAdded; * */ static SimData() { for (int i = 0; i < HAL_GetNumPCMModules(); i++) { PCM.Add(new HALSimPCMData(i)); } for (int i = 0; i < HAL_GetNumPDPModules(); i++) { PDP.Add(new HALSimPDPData(i)); } for (int i = 0; i < HAL_GetNumAccumulators(); i++) { AnalogGyro.Add(new HALSimAnalogGyroData(i)); } for (int i = 0; i < HAL_GetNumAnalogOutputs(); i++) { AnalogOut.Add(new HALSimAnalogOutData(i)); } for (int i = 0; i < HAL_GetNumAnalogInputs(); i++) { AnalogIn.Add(new HALSimAnalogInData(i)); } for (int i = 0; i < HAL_GetNumAnalogTriggers(); i++) { AnalogTrigger.Add(new HALSimAnalogTriggerData(i)); } for (int i = 0; i < HAL_GetNumDigitalChannels(); i++) { DIO.Add(new HALSimDIOData(i)); } for (int i = 0; i < HAL_GetNumDigitalPWMOutputs(); i++) { DigitalPWM.Add(new HALSimDigitalPWMData(i)); } for (int i = 0; i < 4; i++) { //DigitalGlitchFilter.Add(new DigitalGlitchFilterData()); } for (int i = 0; i < HAL_GetNumPWMChannels(); i++) { PWM.Add(new HALSimPWMData(i)); } for (int i = 0; i < 4; i++) { Relay.Add(new HALSimRelayData(i)); } for (int i = 0; i < 8; i++) { //Counter.Add(new CounterData()); } for (int i = 0; i < 8; i++) { Encoder.Add(new HALSimEncoderData(i)); } for (int i = 0; i < 5; i++) { SPIAccelerometer.Add(new HALSimSPIAccelerometerData(i)); } for (int i = 0; i < 5; i++) { //SPIAccumulator.Add(new SPIAccumulatorData()); } //InitializePDP(0); //ErrorList.Clear(); }
public void TestCounterInit5() { //Assert.Pass(); //return; using (AnalogTrigger at = new AnalogTrigger(2)) { using (Counter ctr = new Counter(at)) { TestInit(0, 1, 0, true, false, false, false, true); } } }
public void TestSetLimitsRawValid() { using (AnalogTrigger at = new AnalogTrigger(2)) { at.SetLimitsRaw(50, 150); Assert.That(GetAnalogVoltageToValue(2, GetData(at.Index).TrigLower), Is.EqualTo(50)); Assert.That(GetAnalogVoltageToValue(2, GetData(at.Index).TrigUpper), Is.EqualTo(150)); } }
public void TestSetLimitsRawInvalid() { using (AnalogTrigger at = new AnalogTrigger(2)) { Assert.Throws<BoundaryException>(() => { at.SetLimitsRaw(150, 50); }); } }
public void TestAnalogTriggerGetInWindow() { using (AnalogTrigger trigger = new AnalogTrigger(0)) { HALAnalog.GetAnalogTriggerInWindow = (IntPtr pointer, ref int status) => { status = 0; return false; }; Assert.That(trigger.GetInWindow(), Is.False); HALAnalog.GetAnalogTriggerInWindow = (IntPtr pointer, ref int status) => { status = 0; return true; }; Assert.That(trigger.GetInWindow(), Is.True); HALAnalog.GetAnalogTriggerInWindow = HAL.SimulatorHAL.HALAnalog.getAnalogTriggerInWindow; } }
internal override InterruptableSensorBase GiveInterruptableSensorBase() { m_interruptTrigger = new AnalogTrigger(s_analogIo.GetInput()); m_interruptTrigger.SetLimitsVoltage(2.0f, 3.0f); m_interruptTriggerOutput = new AnalogTriggerOutput(m_interruptTrigger, AnalogTriggerType.State); return m_interruptTriggerOutput; }
public void TestSetLimitsVoltageValid() { using (AnalogTrigger at = new AnalogTrigger(2)) { at.SetLimitsVoltage(2.2, 4.4); Assert.That(GetData(at.Index).TrigLower, Is.EqualTo(2.2)); Assert.That(GetData(at.Index).TrigUpper, Is.EqualTo(4.4)); } }