public void TestClearFaults() { using (Solenoid s = NewSolenoid()) { s.ClearAllPCMStickyFaults(); } }
public void TestSmartDashboardType() { using (Solenoid s = NewSolenoid()) { Assert.That(s.SmartDashboardType, Is.EqualTo("Solenoid")); } }
public void TestSolenoidGetAll() { using (Solenoid s = NewSolenoid()) { GetSolenoids().SetSolenoidOutput(0, true); GetSolenoids().SetSolenoidOutput(1, true); GetSolenoids().SetSolenoidOutput(2, false); GetSolenoids().SetSolenoidOutput(3, false); GetSolenoids().SetSolenoidOutput(4, false); GetSolenoids().SetSolenoidOutput(5, true); GetSolenoids().SetSolenoidOutput(6, false); GetSolenoids().SetSolenoidOutput(7, false); byte allSolenoids = s.GetAll(); bool solenoid0 = ((0x1 << 0) & allSolenoids) != 0; bool solenoid1 = ((0x1 << 1) & allSolenoids) != 0; bool solenoid2 = ((0x1 << 2) & allSolenoids) != 0; bool solenoid3 = ((0x1 << 3) & allSolenoids) != 0; bool solenoid4 = ((0x1 << 4) & allSolenoids) != 0; bool solenoid5 = ((0x1 << 5) & allSolenoids) != 0; bool solenoid6 = ((0x1 << 6) & allSolenoids) != 0; bool solenoid7 = ((0x1 << 7) & allSolenoids) != 0; Assert.That(solenoid0); Assert.That(solenoid1); Assert.That(!solenoid2); Assert.That(!solenoid3); Assert.That(!solenoid4); Assert.That(solenoid5); Assert.That(!solenoid6); Assert.That(!solenoid7); } }
public void TestBlackList() { using (Solenoid s = NewSolenoid()) { Assert.IsFalse(s.IsBlackListed()); } }
public void TestSolenoidModuleOverLimit() { Assert.Throws <ArgumentOutOfRangeException>(() => { var s = new Solenoid(SolenoidModules, 0); }); }
public void TestCreateLowerLimit() { Assert.Throws <ArgumentOutOfRangeException>(() => { var p = new Solenoid(m_module, -1); }); }
public void TestCreateUpperLimit() { Assert.Throws <ArgumentOutOfRangeException>(() => { var p = new Solenoid(m_module, SolenoidChannels); }); }
public void TestSolenoidCreate() { using (Solenoid s = NewSolenoid()) { Assert.IsTrue(GetSolenoids().GetSolenoidInitialized(0)); } }
public ISolenoid CreateSolenoid(Solenoid s) { log.DebugFormat("HardwareService.CreateSolenoid()"); ISolenoid sol; switch (s.HardwareType) { case "GPIO": log.DebugFormat("{0}", s.Address); ConnectorPin pin = GetGPIOPin(s.Address); log.DebugFormat("Got pin {0}", pin.ToString()); sol = new GPIOSolenoid(pin, s.Name, gpio); break; case "Distributed": //return new DistributedSolenoid(s.Name, s.Address); sol = new BEM106EthernetSolenoid(s.Name, s.Address); break; case "SPI": sol = new SPISolenoid(s.Name, s.Address); break; default: throw new Exception("Unknown Solenoid type"); } Solenoids.Add(sol); return(sol); }
public void TestSolenoidModuleOverLimit() { Assert.Throws<ArgumentOutOfRangeException>(() => { var s = new Solenoid(SolenoidModules, 0); }); }
public void TestVoltageFault() { using (Solenoid s = NewSolenoid()) { Assert.That(!s.GetPCMSolenoidVoltageFault()); } }
public void TestSolenoidCreateDefaultModule() { using (Solenoid s = new Solenoid(0)) { Assert.IsTrue(SimData.PCM[0].GetSolenoidInitialized(0)); } Assert.That(SimData.PCM[0].GetSolenoidInitialized(0), Is.False); }
public void TestSolenoidCreateDefaultModule() { using (Solenoid s = new Solenoid(0)) { Assert.IsTrue(SimData.GetPCM(0).Solenoids[0].Initialized); } Assert.That(SimData.GetPCM(0).Solenoids[0].Initialized, Is.False); }
public void TestMultipleAllocation() { using (Solenoid ds = NewSolenoid()) { Assert.Throws(typeof(AllocationException), () => { var p = NewSolenoid(); }); } }
public void TestStopLiveWindowModeTableNull() { using (Solenoid s = NewSolenoid()) { s.Set(true); Assert.That(s.Get, Is.True); s.StopLiveWindowMode(); Assert.That(s.Get, Is.False); } }
public void TestUpdateTableNull() { using (Solenoid s = NewSolenoid()) { Assert.DoesNotThrow(() => { s.UpdateTable(); }); } }
public void TestSolenoidSet() { using (Solenoid s = NewSolenoid()) { s.Set(true); Assert.IsTrue(GetSolenoids().GetSolenoidOutput(0)); s.Set(false); Assert.IsFalse(GetSolenoids().GetSolenoidOutput(0)); } }
public void TestSolenoidGet() { using (Solenoid s = NewSolenoid()) { s.Set(true); Assert.IsTrue(s.Get()); s.Set(false); Assert.IsFalse(s.Get()); } }
public void TestValueChanged() { using (Solenoid s = NewSolenoid()) { s.Set(false); Assert.That(s.Get, Is.False); s.ValueChanged(null, null, Value.MakeBoolean(true), NetworkTables.NotifyFlags.NotifyLocal); Assert.That(s.Get, Is.True); s.ValueChanged(null, null, Value.MakeBoolean(false), NetworkTables.NotifyFlags.NotifyLocal); Assert.That(s.Get, Is.False); } }
public void TestStopLiveWindowModeTable() { using (Solenoid s = NewSolenoid()) { ITable table = new MockNetworkTable(); s.InitTable(table); s.Set(true); Assert.That(s.Get, Is.True); s.StopLiveWindowMode(); Assert.That(s.Get, Is.False); } }
public void LoadConfig() { try { if (Spis != null) { Spis.Clear(); } Spis = dataServer.GetSpis(device.Id); if (Solenoids != null) { Solenoids.Clear(); } Solenoids = dataServer.GetSolenoids(device.Id); PumpSolenoid = Solenoids.AsQueryable <Solenoid>().Where(s => s.Id == device.PumpSolenoid).First <Solenoid>(); if (Alarms != null) { Alarms.Clear(); } Alarms = dataServer.GetAlarms(device.Id); if (Analogs != null) { Analogs.Clear(); } Analogs = dataServer.GetAnalogs(device.Id); if (Schedules != null) { Schedules.Clear(); } Schedules = dataServer.GetSchedules(device.Id); CreateEvent(EventTypes.Application, "DeviceController configuration complete"); log.InfoFormat("InterfaceManager.LoadConfig(): Configuration complete."); } catch (Exception ex) { log.ErrorFormat("LoadConfig(): {0}", ex.Message); } }
public IrrigationProgram(int id, string name, DateTime start, int duration, int solenoidId, HardwareService hw, DataService data) { Id = id; Name = name; Start = start; Duration = duration; SolenoidId = solenoidId; hardwareService = hw; dataService = data; DataSolenoid = dataService.Solenoids.AsQueryable <Solenoid>().Where(s => s.Id == solenoidId).First <Solenoid>(); HardwareSolenoid = hardwareService.Solenoids.AsQueryable <ISolenoid>().Where(s => s.Id == solenoidId).First <ISolenoid>(); HardwarePumpSolenoid = hardwareService.PumpSolenoid; DataPumpSolenoid = dataService.Solenoids RequiresPump = DataSolenoid.RequiresPump; Data.IrrigationProgram program = new Data.IrrigationProgram() { Name = Name, Start = Start, Duration = Duration, DeviceId = data.device.Id, SolenoidName = DataSolenoid.Name, SolenoidId = DataSolenoid.Id, RequiresPump = DataSolenoid.RequiresPump }; dataService.dataServer.PutIrrigationProgram(program); //start irrigating HardwareSolenoid.On(); DataSolenoid.Value = 1; dataService.dataServer.PutSolenoid(DataSolenoid); if (RequiresPump) { hardwareService.PumpSolenoid.On(); } //report to the server DataSolenoid.Value = 1; dataService.dataServer.PutSolenoid(DataSolenoid); }
public ISolenoid CreateSolenoid(Solenoid s) { switch (s.HardwareType) { case "GPIO": GPIOSolenoid sol = new GPIOSolenoid(s, dataServer, gpio); return(sol); case "Distributed": return(new DistributedSolenoid(s, dataServer)); case "SPI": return(new SPISolenoid(s, dataServer)); default: break; } throw new Exception("Unknown Solenoid type"); }
public void Dump(Position pos, Solenoid state) { //pin.write() needs a bool bool sol = !(state == Solenoid.Open); switch (pos) { case Position.LeftFront: LFDump.Write(sol); break; case Position.RightFront: RFDump.Write(sol); break; case Position.LeftRear: LRDump.Write(sol); break; case Position.RightRear: RRDump.Write(sol); break; } }
public DeviceSolenoid(Solenoid s) { dataSolenoid = s; log.DebugFormat("DeviceSolenoid() {0}", s.Name); switch (s.HardwareType) { case "GPIO": log.DebugFormat("{0}", s.Address); hardwareSolenoid = new GPIOSolenoid(dataSolenoid.Id, dataSolenoid.Name, dataSolenoid.Address); break; case "Distributed": //return new DistributedSolenoid(s.Name, s.Address); hardwareSolenoid = new BEM106EthernetSolenoid(dataSolenoid.Id, dataSolenoid.Name, dataSolenoid.Address); break; case "SPI": hardwareSolenoid = new SPISolenoid(dataSolenoid.Id, dataSolenoid.Name, dataSolenoid.Address); break; default: throw new Exception("Unknown Solenoid type"); } }
public void TestCreateUpperLimit() { Assert.Throws<ArgumentOutOfRangeException>(() => { var p = new Solenoid(m_module, TestBase.SolenoidChannels); }); }
public void TestCreateLowerLimit() { Assert.Throws<ArgumentOutOfRangeException>(() => { var p = new Solenoid(m_module, -1); }); }
public void TestSolenoid() { Reset(); using (Solenoid solenoid1 = new Solenoid(0)) using (Solenoid solenoid2 = new Solenoid(1)) { NotifyCallback solenoid1Callback = null; NotifyCallback solenoid2Callback = null; int callback1Id = -1; int callback2Id = -1; if (RobotBase.IsSimulation) { solenoid1Callback = (string s, HAL_Value val) => { SimData.DIO[12].SetValue(!val.GetBoolean()); }; callback1Id = SimData.PCM[0].RegisterSolenoidOutputCallback(0, solenoid1Callback, false); solenoid2Callback = (s, o) => { SimData.DIO[13].SetValue(!o.GetBoolean()); }; callback2Id = SimData.PCM[0].RegisterSolenoidOutputCallback(1, solenoid2Callback); } solenoid1.Set(false); solenoid2.Set(false); Timer.Delay(SolenoidDelayTime); Assert.That(fakeSolenoid1.Get()); Assert.That(fakeSolenoid2.Get()); Assert.That(!solenoid1.Get()); Assert.That(!solenoid2.Get()); solenoid1.Set(true); solenoid2.Set(false); Timer.Delay(SolenoidDelayTime); Assert.That(!fakeSolenoid1.Get()); Assert.That(fakeSolenoid2.Get()); Assert.That(solenoid1.Get()); Assert.That(!solenoid2.Get()); solenoid1.Set(false); solenoid2.Set(true); Timer.Delay(SolenoidDelayTime); Assert.That(fakeSolenoid1.Get()); Assert.That(!fakeSolenoid2.Get()); Assert.That(!solenoid1.Get()); Assert.That(solenoid2.Get()); solenoid1.Set(true); solenoid2.Set(true); Timer.Delay(SolenoidDelayTime); Assert.That(!fakeSolenoid1.Get()); Assert.That(!fakeSolenoid2.Get()); Assert.That(solenoid1.Get()); Assert.That(solenoid2.Get()); if (RobotBase.IsSimulation) { SimData.PCM[0].CancelSolenoidOutputCallback(0, callback1Id); SimData.PCM[0].CancelSolenoidOutputCallback(1, callback2Id); } } }
/// <summary> /// Initialize the controllers. /// </summary> public static void Init() { // Instantiates all the hardware devices with the respective ports. #region InstantiateDevices can_01 = new CANTalon(1); can_02 = new CANTalon(2); //can_02.MotorControlMode = ControlMode.Follower; //can_02.Set(can_01.DeviceId); //can_02.ReverseOutput(true); can_03 = new CANTalon(3); can_04 = new CANTalon(4); //can_04.MotorControlMode = ControlMode.Follower; //can_04.Set(can_03.DeviceId); can_05 = new CANTalon(5); can_06 = new CANTalon(6); can_07 = new CANTalon(7); can_08 = new CANTalon(8); can_09 = new CANTalon(9); can_10 = new CANTalon(10); can_11 = new Compressor(11); can_12 = new PowerDistributionPanel(12); pcm_11_0 = new Solenoid(11, 0); pcm_11_1 = new Solenoid(11, 1); pcm_11_2 = new Solenoid(11, 2); usb_0 = new Joystick(0); usb_1 = new Joystick(1); usb_2 = new Joystick(2); sw_0 = new DriveTrainObject(Left1, Left2, Right1, Right2); #endregion // Clears the sticky faults on all CAN devices. #region ClearCANStickyFaults can_01.ClearStickyFaults(); can_02.ClearStickyFaults(); can_03.ClearStickyFaults(); can_04.ClearStickyFaults(); can_05.ClearStickyFaults(); can_06.ClearStickyFaults(); can_07.ClearStickyFaults(); can_08.ClearStickyFaults(); can_09.ClearStickyFaults(); can_10.ClearStickyFaults(); can_11.ClearAllPCMStickyFaults(); can_12.ClearStickyFaults(); #endregion // Disable motor safety so that it doesn't stop motors from being output to. #region DisableSafety can_01.SafetyEnabled = false; can_02.SafetyEnabled = false; can_03.SafetyEnabled = false; can_04.SafetyEnabled = false; can_05.SafetyEnabled = false; can_06.SafetyEnabled = false; can_07.SafetyEnabled = false; can_08.SafetyEnabled = false; can_09.SafetyEnabled = false; can_10.SafetyEnabled = false; sw_0.SafetyEnabled = false; #endregion Intake2.Inverted = true; Shooter_Pivot.Inverted = true; Intake1.Inverted = true; Agitator.Inverted = true; // Initializes the camera server with the default options. CameraServer.Instance.StartAutomaticCapture(); //UsbCamera cam = new UsbCamera("cam0", 0); //cam.SetResolution(320, 240); //CameraServer.Instance.StartAutomaticCapture(cam); // Instantiates the NavX. NavX = new AHRS(SPI.Port.MXP); // Creates a new copy of the turntable. TurntableEncoder = new Encoder(8, 9); #region PID Controllers // Handles moving forwards and backwards for the shooter using the Pixy as the sensor. CamForward = new CamForwardPID(3.00, 0.00, 0.00, 0.00); // Handles the setpoint needed for the shooter using Pixy data. ShooterPos = new ShooterPosPID(3.00, 0.00, 0.00, 0.00); // Creates a new instance of the turn controller. TurnController = new TurningPID(new PIDF { kP = 0.0465, // 0.054 kI = 0.00, kD = 0.00, kF = 0.00 }); // Sets the tolerance of the PID controller to 0.02. // Cancels the turning if the error is within 0.02. TurnController.Controller.SetAbsoluteTolerance(0.2); // Adds the PID controller to the Live Window for easier testing. LiveWindow.AddActuator("PID Controllers", "Turn Control", TurnController.Controller); #endregion }
public void TestSolenoid() { Reset(); using (Solenoid solenoid1 = new Solenoid(0)) using (Solenoid solenoid2 = new Solenoid(1)) { Action<string, dynamic> solenoid1Callback = null; Action<string, dynamic> solenoid2Callback = null; if (RobotBase.IsSimulation) { solenoid1Callback = (s, o) => { SimData.DIO[12].Value = !o; }; SimData.GetPCM(0).Solenoids[0].Register("Value", solenoid1Callback); solenoid2Callback = (s, o) => { SimData.DIO[13].Value = !o; }; SimData.GetPCM(0).Solenoids[1].Register("Value", solenoid2Callback); } solenoid1.Set(false); solenoid2.Set(false); Timer.Delay(SolenoidDelayTime); Assert.That(fakeSolenoid1.Get()); Assert.That(fakeSolenoid2.Get()); Assert.That(!solenoid1.Get()); Assert.That(!solenoid2.Get()); solenoid1.Set(true); solenoid2.Set(false); Timer.Delay(SolenoidDelayTime); Assert.That(!fakeSolenoid1.Get()); Assert.That(fakeSolenoid2.Get()); Assert.That(solenoid1.Get()); Assert.That(!solenoid2.Get()); solenoid1.Set(false); solenoid2.Set(true); Timer.Delay(SolenoidDelayTime); Assert.That(fakeSolenoid1.Get()); Assert.That(!fakeSolenoid2.Get()); Assert.That(!solenoid1.Get()); Assert.That(solenoid2.Get()); solenoid1.Set(true); solenoid2.Set(true); Timer.Delay(SolenoidDelayTime); Assert.That(!fakeSolenoid1.Get()); Assert.That(!fakeSolenoid2.Get()); Assert.That(solenoid1.Get()); Assert.That(solenoid2.Get()); if (RobotBase.IsSimulation) { SimData.GetPCM(0).Solenoids[0].Cancel("Value", solenoid1Callback); SimData.GetPCM(0).Solenoids[1].Cancel("Value", solenoid2Callback); } } }