Beispiel #1
0
        void initTurret()
        {
            /* first choose the sensor */
            _turret.SetFeedbackDevice(TalonSrx.FeedbackDevice.CtreMagEncoder_Relative);
            _turret.SetSensorDirection(false);
            _turret.ConfigEncoderCodesPerRev(4096); // if using CTRE.TalonSrx.FeedbackDevice.QuadEncoder

            _turret.SetP(0, TURRET_P);              /* tweak this first, a little bit of overshoot is okay */
            _turret.SetI(0, TURRET_I);
            _turret.SetD(0, TURRET_D);
            _turret.SetF(0, TURRET_F);

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

            /* set the peak and nominal outputs, 12V means full */
            _turret.ConfigNominalOutputVoltage(MINIMUM_TURRET_VOLTAGE, -1 * MINIMUM_TURRET_VOLTAGE); //The minimum voltage that will be applied to the turret.
            _turret.ConfigPeakOutputVoltage(+3.0f, -3.0f);                                           //THe maximum voltage that will be applied to the turret.

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

            _turret.SetPosition(0);        /* start our position at zero, this example uses relative positions */
            _turret.SetVoltageRampRate(0); /* V per sec */

            _turret.SetControlMode(ControlMode.kPosition);
            _turret.Set(angleSetpoint);

            _turret.SetEncPosition(0);
        }
Beispiel #2
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);
            }
        }
        private void SetupPositionServo()
        {
            TalonSrx armTalon = (TalonSrx)_gearBox.GetMaster();

            armTalon.ConfigNominalOutputVoltage(0, 0);
            armTalon.ConfigPeakOutputVoltage(Constants.MAX_VOLTAGE, -Constants.MAX_VOLTAGE);
            armTalon.SetAllowableClosedLoopErr(0, Constants.TOLERANCE);

            armTalon.SetPID(0, Constants.KPARM, Constants.KIARM, Constants.KDARM);

            _controlMode = ControlMode.kPosition;

            armTalon.SelectProfileSlot(0);
            armTalon.SetMotionMagicAcceleration(60.0f);
            armTalon.SetMotionMagicCruiseVelocity(22.0f);

            armTalon.SetVoltageRampRate(0f);
        }