Ejemplo n.º 1
0
        /**
         * Setup all of the configuration parameters.
         */
        public int SetupConfig()
        {
            /* binary OR all the return values so we can make a quick decision if our init was successful */
            int status = 0;

            /* specify sensor characteristics */
            _talon.SetFeedbackDevice(CTRE.TalonSrx.FeedbackDevice.CtreMagEncoder_Relative);
            _talon.SetSensorDirection(false); /* make sure positive motor output means sensor moves in position direction */
            // call ConfigEncoderCodesPerRev or ConfigPotentiometerTurns for Quadrature or Analog sensor types.

            /* brake or coast during neutral */
            status |= _talon.ConfigNeutralMode(CTRE.TalonSrx.NeutralMode.Brake);

            /* closed-loop and motion-magic parameters */
            status |= _talon.SetF(kSlotIdx, 0.1153f, kTimeoutMs); // 1300RPM (8874 native sensor units per 100ms) at full motor output (+1023)
            status |= _talon.SetP(kSlotIdx, 2.00f, kTimeoutMs);
            status |= _talon.SetI(kSlotIdx, 0f, kTimeoutMs);
            status |= _talon.SetD(kSlotIdx, 20f, kTimeoutMs);
            status |= _talon.SetIzone(kSlotIdx, 0, kTimeoutMs);
            status |= _talon.SelectProfileSlot(kSlotIdx); /* select this slot */
            status |= _talon.ConfigNominalOutputVoltage(0f, 0f, kTimeoutMs);
            status |= _talon.ConfigPeakOutputVoltage(+12f, -12f, kTimeoutMs);
            status |= _talon.SetMotionMagicCruiseVelocity(1000f, kTimeoutMs); // 1000 RPM
            status |= _talon.SetMotionMagicAcceleration(2000f, kTimeoutMs);   // 2000 RPM per sec, (0.5s to reach cruise velocity).

            /* Home the relative sensor,
             *  alternatively you can throttle until limit switch,
             *  use an absolute signal like CtreMagEncoder_Absolute or analog sensor.
             */
            status |= _talon.SetPosition(0, kTimeoutMs);

            return(status);
        }
Ejemplo n.º 2
0
        public void Run()
        {
            _talon.SetControlMode(CTRE.TalonSrx.ControlMode.kVoltage);

            _talon.SetFeedbackDevice(CTRE.TalonSrx.FeedbackDevice.CtreMagEncoder_Relative);
            _talon.SetSensorDirection(false);

            _talon.SetVoltageRampRate(0.0f);

            _talon.SetP(0, 0.80f);
            _talon.SetI(0, 0f);
            _talon.SetD(0, 0f);
            _talon.SetF(0, 0.09724488664269079041176191004297f);
            _talon.SelectProfileSlot(0);
            _talon.ConfigNominalOutputVoltage(0f, 0f);
            _talon.ConfigPeakOutputVoltage(+12.0f, -12.0f);
            _talon.ChangeMotionControlFramePeriod(5);

            /* loop forever */
            while (true)
            {
                _talon.GetMotionProfileStatus(out _motionProfileStatus);

                Drive();

                CTRE.Watchdog.Feed();

                Instrument();

                Thread.Sleep(5);
            }
        }
Ejemplo n.º 3
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(CTRE.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);
            }
        }