Exemplo n.º 1
0
        /** spin in this routine forever */
        public void RunForever()
        {
            /* config our talon, don't continue until it's successful */
            int initStatus = SetupConfig(); /* configuration */

            while (initStatus != 0)
            {
                Instrument.PrintConfigError();
                initStatus = SetupConfig(); /* (re)config*/
            }
            /* robot loop */
            while (true)
            {
                /* get joystick params */
                float leftY = -1f * _gamepad.GetAxis(1);
                bool  btnTopLeftShoulder = _gamepad.GetButton(5);
                bool  btnBtmLeftShoulder = _gamepad.GetButton(7);
                Deadband(ref leftY);

                /* keep robot enabled if gamepad is connected and in 'D' mode */
                if (_gamepad.GetConnectionStatus() == CTRE.UsbDeviceConnection.Connected)
                {
                    CTRE.Watchdog.Feed();
                }

                /* set the control mode based on button pressed */
                if (btnTopLeftShoulder)
                {
                    _mode = ControlMode.kPercentVbus;
                }
                if (btnBtmLeftShoulder)
                {
                    _mode = ControlMode.kMotionMagic;
                }

                /* calc the Talon output based on mode */
                if (_mode == ControlMode.kPercentVbus)
                {
                    float output = leftY; // [-1, +1] percent duty cycle
                    _talon.SetControlMode(_mode);
                    _talon.Set(output);
                }
                else if (_mode == ControlMode.kMotionMagic)
                {
                    float servoToRotation = leftY * 10;// [-10, +10] rotations
                    _talon.SetControlMode(_mode);
                    _talon.Set(servoToRotation);
                }
                /* instrumentation */
                Instrument.Process(_talon);

                /* wait a bit */
                System.Threading.Thread.Sleep(5);
            }
        }
Exemplo n.º 2
0
        public void run()
        {
            Loop10Ms();

            //if (_gamepad.GetConnectionStatus() == CTRE.UsbDeviceConnection.Connected) // check if gamepad is plugged in OR....
            if (_gamepad.GetButton(kEnableButton)) // check if bottom left shoulder buttom is held down.
            {
                /* then enable motor outputs*/
                CTRE.Watchdog.Feed();
            }
        }
Exemplo n.º 3
0
        public static void Main()
        {
            float turn = 0;

            timer.Start();

            bool leftLast  = false;
            bool rightLast = false;

            while (true)
            {
                ds.update();
                ds.SendBattery(12.34f);
                float t = deltaTime();
                CTRE.FRC.DriverStation.State s = ds.GetState();
                if (ds.IsEnabled())
                {
                    float x     = controller.GetAxis(0);
                    float y     = controller.GetAxis(1);
                    float twist = -controller.GetAxis(4);
                    if (twist * twist < 0.005)
                    {
                        twist = 0;
                    }
                    turn += twist * t * 180;

                    if (controller.GetButton(6) && !leftLast)
                    {
                        turn -= 90;
                    }
                    if (controller.GetButton(5) && !rightLast)
                    {
                        turn += 90;
                    }
                    leftLast  = controller.GetButton(6);
                    rightLast = controller.GetButton(5);

                    drive(x, y, turn);
                }
                else
                {
                    float[] ypr = new float[3];
                    pigeon.GetYawPitchRoll(ypr);
                    turn = ypr[0];
                }

                byte[] b = new byte[] { (byte)'h', (byte)'e', (byte)'l', (byte)'l', (byte)'o' };
                ds.SendUDP(2550, b);
            }
        }
Exemplo n.º 4
0
 void FillBtns(ref bool[] btns)
 {
     for (uint i = 1; i < btns.Length; ++i)
     {
         btns[i] = _gamepad.GetButton(i);
     }
 }
Exemplo n.º 5
0
        public static void Main()
        {
            //Gamepad for input
            CTRE.Controller.GameController _gamepad = new CTRE.Controller.GameController(CTRE.UsbHostDevice.GetInstance(0), 0);

            //Create the DriverModule object by giving it the port you plugged it in to.
            CTRE.HERO.Module.DriverModule driver = new CTRE.HERO.Module.DriverModule(CTRE.HERO.IO.Port5);

            //these just act as shorter names for the driveLow and pullUp states
            bool driveLow = CTRE.HERO.Module.DriverModule.OutputState.driveLow;
            bool pullUp   = CTRE.HERO.Module.DriverModule.OutputState.pullUp;

            while (true)
            {
                //When the 'X' button is pressed, enable outputs
                if (_gamepad.GetButton(1) == true)
                {
                    driver.Set(1, driveLow);
                    driver.Set(2, driveLow);
                }
                else
                {
                    driver.Set(1, pullUp);
                    driver.Set(2, pullUp);
                }

                System.Threading.Thread.Sleep(10);
            }
        }
Exemplo n.º 6
0
        public static void Main()
        {
            /* enable compressor closed loop.  Compressor output will turn automatically
             *  if pressure switch signals low-pressure. */
            _pcm.StartCompressor();

            /* loop forever */
            while (true)
            {
                /* Check our gamepad inputs */
                bool bActivateSolenoid = _gamepad.GetButton(0);

                /* turn on channel 0 if button is held */
                _pcm.SetSolenoidOutput(0, bActivateSolenoid);
                /* turn on channel 1 if button is NOT held */
                _pcm.SetSolenoidOutput(1, !bActivateSolenoid);

                /* only enable actuators (PCM/Talons/etc.) if gamepad is present */
                if (_gamepad.GetConnectionStatus() == CTRE.UsbDeviceConnection.Connected)
                {
                    CTRE.Watchdog.Feed();
                }

                /* yield for a while */
                System.Threading.Thread.Sleep(10);
            }
        }
Exemplo n.º 7
0
        uint [] _debLeftY = { 0, 0 }; // _debLeftY[0] is how many times leftY is zero, _debLeftY[1] is how many times leftY is not zeero.

        public void Run()
        {
            /* first choose the sensor */
            _talon.SetFeedbackDevice(TalonSrx.FeedbackDevice.CtreMagEncoder_Relative);
            _talon.SetSensorDirection(false);
            //_talon.ConfigEncoderCodesPerRev(XXX), // if using CTRE.TalonSrx.FeedbackDevice.QuadEncoder
            //_talon.ConfigPotentiometerTurns(XXX), // if using CTRE.TalonSrx.FeedbackDevice.AnalogEncoder or CTRE.TalonSrx.FeedbackDevice.AnalogPot

            /* set closed loop gains in slot0 */
            _talon.SetP(0, 0.2f); /* tweak this first, a little bit of overshoot is okay */
            _talon.SetI(0, 0f);
            _talon.SetD(0, 0f);
            _talon.SetF(0, 0f); /* For position servo kF is rarely used. Leave zero */

            /* use slot0 for closed-looping */
            _talon.SelectProfileSlot(0);

            /* set the peak and nominal outputs, 12V means full */
            _talon.ConfigNominalOutputVoltage(+0.0f, -0.0f);
            _talon.ConfigPeakOutputVoltage(+3.0f, -3.0f);

            /* how much error is allowed?  This defaults to 0. */
            _talon.SetAllowableClosedLoopErr(0, 0);

            /* zero the sensor and throttle */
            ZeroSensorAndThrottle();

            /* loop forever */
            while (true)
            {
                Loop10Ms();

                //if (_gamepad.GetConnectionStatus() == CTRE.UsbDeviceConnection.Connected) // check if gamepad is plugged in OR....
                if (_gamepad.GetButton(kEnableButton)) // check if bottom left shoulder buttom is held down.
                {
                    /* then enable motor outputs*/
                    CTRE.Watchdog.Feed();
                }

                /* print signals to Output window */
                Instrument();

                /* 10ms loop */
                Thread.Sleep(10);
            }
        }
Exemplo n.º 8
0
 public int GetFirstButton(CTRE.Controller.GameController gamepad)
 {
     for (uint i = 0; i < 16; ++i)
     {
         if (gamepad.GetButton(i))
         {
             return((int)i);
         }
     }
     return(-1);
 }
Exemplo n.º 9
0
        public static void Main()
        {
            //Gamepad for input
            CTRE.Controller.GameController _gamepad = new CTRE.Controller.GameController(CTRE.UsbHostDevice.GetInstance(0), 0);

            //simple PWM for fine control of pulse width, period, timing...
            uint period   = 50000; //period between pulses
            uint duration = 1500;  //duration of pulse
            PWM  pwm_9    = new PWM(CTRE.HERO.IO.Port3.PWM_Pin9, period, duration, PWM.ScaleFactor.Microseconds, false);

            pwm_9.Start(); //starts the signal

            // ...and just a PWM SpeedController for motor controller (Victor SP, Talon SR, Victor 888, etc.)...
            PWMSpeedController pwmSpeedController = new PWMSpeedController(CTRE.HERO.IO.Port3.PWM_Pin4);

            while (true)
            {
                /* only enable motor control (PWM/CAN) if gamepad is connected.  Logitech gamepads may be disabled using the X/D switch */
                if (_gamepad.GetConnectionStatus() == CTRE.UsbDeviceConnection.Connected)
                {
                    CTRE.Watchdog.Feed();
                }

                /* let axis control the pwm speed controller */
                pwmSpeedController.Set(0.10f); /* 10% */

                /* let button1 control the explicit PWM pin duration*/
                if (_gamepad.GetButton(1) == true)
                {
                    pwm_9.Duration = 2000; /* 2.0ms */
                }
                else
                {
                    pwm_9.Duration = 1000; /* 1.0ms */
                }

                /* yield for a bit, this controls this task's frequency */
                System.Threading.Thread.Sleep(10);
            }
        }
Exemplo n.º 10
0
        public void RunForever()
        {
            while (true)
            {
                if (_gamepad.GetConnectionStatus() == CTRE.UsbDeviceConnection.Connected)
                {
                    CTRE.Watchdog.Feed();
                }

                /* get buttons */
                for (uint i = 1; i < 20; ++i)
                {
                    _buttons[i].last = _buttons[i].now;
                    _buttons[i].now  = _gamepad.GetButton(i);
                }

                /* yield for a bit, and track timeouts */
                System.Threading.Thread.Sleep(10);

                /* pigeon related tasks */
                PidgyTask();
            }
        }