Ejemplo n.º 1
0
        public void TestDoubleSolenoid()
        {
            using (DoubleSolenoid solenoid = new DoubleSolenoid(0, 1))
            {
                NotifyCallback solenoid1Callback = null;
                NotifyCallback solenoid2Callback = null;

                int callback1Id = -1;
                int callback2Id = -1;

                if (RobotBase.IsSimulation)
                {
                    solenoid1Callback = (s, o) =>
                    {
                        SimData.DIO[12].SetValue(!o.GetBoolean());
                    };
                    callback1Id = SimData.PCM[0].RegisterSolenoidOutputCallback(0, solenoid1Callback);

                    solenoid2Callback = (s, o) =>
                    {
                        SimData.DIO[13].SetValue(!o.GetBoolean());
                    };
                    callback2Id = SimData.PCM[0].RegisterSolenoidOutputCallback(1, solenoid2Callback);
                }

                solenoid.Set(DoubleSolenoid.Value.Off);
                Timer.Delay(SolenoidDelayTime);
                Assert.That(fakeSolenoid1.Get());
                Assert.That(fakeSolenoid2.Get());
                Assert.That(solenoid.Get(), Is.EqualTo(DoubleSolenoid.Value.Off));

                solenoid.Set(DoubleSolenoid.Value.Forward);
                Timer.Delay(SolenoidDelayTime);
                Assert.That(!fakeSolenoid1.Get());
                Assert.That(fakeSolenoid2.Get());
                Assert.That(solenoid.Get(), Is.EqualTo(DoubleSolenoid.Value.Forward));

                solenoid.Set(DoubleSolenoid.Value.Reverse);
                Timer.Delay(SolenoidDelayTime);
                Assert.That(fakeSolenoid1.Get());
                Assert.That(!fakeSolenoid2.Get());
                Assert.That(solenoid.Get(), Is.EqualTo(DoubleSolenoid.Value.Reverse));

                if (RobotBase.IsSimulation)
                {
                    SimData.PCM[0].CancelSolenoidOutputCallback(0, callback1Id);
                    SimData.PCM[0].CancelSolenoidOutputCallback(1, callback2Id);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Gets the current position that the solenoid is supposed to be in
        /// </summary>
        /// <returns></returns>
        public DoubleSolenoid.Value GetCurrentPosition()
        {
#if USE_LOCKING
            lock (solenoid)
#endif
            {
                return(solenoid.Get());
            }
        }
Ejemplo n.º 3
0
        public void TestSolenoidGetOff()
        {
            using (DoubleSolenoid ds = NewDoubleSolenoid())
            {
                GetSolenoids().SetSolenoidOutput(0, false);
                GetSolenoids().SetSolenoidOutput(1, false);

                Assert.AreEqual(DoubleSolenoid.Value.Off, ds.Get());
            }
        }
Ejemplo n.º 4
0
        public void TestSolenoidGetReverse()
        {
            using (DoubleSolenoid ds = NewDoubleSolenoid())
            {
                GetSolenoids().SetSolenoidOutput(1, true);
                GetSolenoids().SetSolenoidOutput(0, false);

                Assert.AreEqual(DoubleSolenoid.Value.Reverse, ds.Get());
            }
        }
Ejemplo n.º 5
0
 public void TestValueChanged()
 {
     using (DoubleSolenoid s = NewDoubleSolenoid())
     {
         s.Set(DoubleSolenoid.Value.Forward);
         Assert.That(s.Get(), Is.EqualTo(Value.Forward));
         s.ValueChanged(null, null, NetworkTables.Value.MakeString("Reverse"), NetworkTables.NotifyFlags.NotifyLocal);
         Assert.That(s.Get, Is.EqualTo(Value.Reverse));
         s.ValueChanged(null, null, NetworkTables.Value.MakeString("Garbage"), NetworkTables.NotifyFlags.NotifyLocal);
         Assert.That(s.Get, Is.EqualTo(Value.Off));
         s.ValueChanged(null, null, NetworkTables.Value.MakeString("Forward"), NetworkTables.NotifyFlags.NotifyLocal);
         Assert.That(s.Get, Is.EqualTo(Value.Forward));
     }
 }
Ejemplo n.º 6
0
        public void TestDoubleSolenoid()
        {
            using (DoubleSolenoid solenoid = new DoubleSolenoid(0, 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);
                }

                solenoid.Set(DoubleSolenoid.Value.Off);
                Timer.Delay(SolenoidDelayTime);
                Assert.That(fakeSolenoid1.Get());
                Assert.That(fakeSolenoid2.Get());
                Assert.That(solenoid.Get(), Is.EqualTo(DoubleSolenoid.Value.Off));

                solenoid.Set(DoubleSolenoid.Value.Forward);
                Timer.Delay(SolenoidDelayTime);
                Assert.That(!fakeSolenoid1.Get());
                Assert.That(fakeSolenoid2.Get());
                Assert.That(solenoid.Get(), Is.EqualTo(DoubleSolenoid.Value.Forward));

                solenoid.Set(DoubleSolenoid.Value.Reverse);
                Timer.Delay(SolenoidDelayTime);
                Assert.That(fakeSolenoid1.Get());
                Assert.That(!fakeSolenoid2.Get());
                Assert.That(solenoid.Get(), Is.EqualTo(DoubleSolenoid.Value.Reverse));

                if (RobotBase.IsSimulation)
                {
                    SimData.GetPCM(0).Solenoids[0].Cancel("Value", solenoid1Callback);
                    SimData.GetPCM(0).Solenoids[1].Cancel("Value", solenoid2Callback);
                }
            }
        }