示例#1
0
        public void init()
        {
            /* first choose the sensor */
            _talon.SetFeedbackDevice(CTRE.TalonSrx.FeedbackDevice.CtreMagEncoder_Absolute);
            _talon.SetSensorDirection(false);

            /* set closed loop gains in slot0 */
            _talon.SetP(0, 0.5f); /* 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 target to the current position */
            ResetTargetPosition();
        }
示例#2
0
        public static void Main()
        {
            CTRE.TalonSrx talon = new CTRE.TalonSrx(0);
            talon.SetControlMode(TalonSrx.ControlMode.kVoltage);
            talon.SetFeedbackDevice(TalonSrx.FeedbackDevice.CtreMagEncoder_Relative);
            talon.SetSensorDirection(false);
            talon.SetVoltageRampRate(0.0f);
            talon.EnableCurrentLimit(false);
            talon.ConfigLimitMode(TalonSrx.LimitMode.kLimitMode_SrxDisableSwitchInputs);

            double time_per_voltage = 20;

            double[] voltages = new double[] { 0, 7 };

            bool time_out = false;

            bool continuous = false;

            /* simple counter to print and watch using the debugger */
            int counter = 0;
            /* loop forever */
            double time_last = DateTime.Now.Hour * 3600 + DateTime.Now.Minute * 60 + DateTime.Now.Second + DateTime.Now.Millisecond / 1000.0;

            while (true)
            {
                /* print the three analog inputs as three columns */
                //Debug.Print("Counter Value: " + counter);
                CTRE.Watchdog.Feed();



                /* increment counter */
                ++counter; /* try to land a breakpoint here and hover over 'counter' to see it's current value.  Or add it to the Watch Tab */

                /* wait a bit */
                //using(System.IO.StreamWriter file = new System.IO.StreamWriter(@"C:\Users\Public\TestFolder\data.srv"))
                //{
                double seconds = DateTime.Now.Hour * 3600 + DateTime.Now.Minute * 60 + DateTime.Now.Second + DateTime.Now.Millisecond / 1000.0;
                UInt64 index   = (UInt64)System.Math.Floor((seconds - time_last) / time_per_voltage);
                double voltage = 0;
                if (continuous)
                {
                    if (index < (UInt64)voltages.Length - 1)
                    {
                        double value = (seconds - time_last) / time_per_voltage;
                        voltage = (voltages[index + 1] - voltages[index]) * (value - index) + voltages[index];
                    }
                    else if (!time_out)
                    {
                        voltage = voltages[voltages.Length - 1];
                    }
                }
                else
                {
                    if (index < (UInt64)voltages.Length)
                    {
                        voltage = voltages[index];
                    }
                    else if (!time_out)
                    {
                        voltage = voltages[voltages.Length - 1];
                    }
                }

                talon.Set((float)voltage);                 //low ish voltage

                //CTRE.TalonSrx.VelocityMeasurementPeriod.Period_100Ms period;
                Debug.Print(seconds.ToString() + "," + talon.GetPosition().ToString() + "," + talon.GetSpeed().ToString() + "," + talon.GetOutputVoltage().ToString()
                            + "," + talon.GetOutputCurrent().ToString() + "," + talon.GetBusVoltage().ToString() + "," + talon.GetTemperature().ToString());


                //talon.SetVelocityMeasurementPeriod(CTRE.TalonSrx.VelocityMeasurementPeriod.Period_10Ms);
                //  file.WriteLine(seconds.ToString() + "," + talon.GetPosition().ToString() + "," + talon.GetSpeed().ToString());
                //}
                System.Threading.Thread.Sleep(10);
            }
        }