コード例 #1
0
 public void TestPWMSpeedControllerStarts0()
 {
     using (PWMSpeedController t = (PWMSpeedController)Activator.CreateInstance(m_type, 2))
     {
         Assert.AreEqual(t.Get(), 0);
     }
 }
コード例 #2
0
 public void TestPWMHelpers([Range(-1.0, 1.0, 0.2)] double range)
 {
     using (PWMSpeedController t = (PWMSpeedController)Activator.CreateInstance(m_type, 2))
     {
         t.Set(range);
         Assert.That(SimData.PWM[2].GetSpeed(), Is.EqualTo(range).Within(.01));
     }
 }
コード例 #3
0
        public void TestPIDWrite([Range(-1.0, 1.0, 0.2)] double range)
        {
            using (PWMSpeedController t = (PWMSpeedController)Activator.CreateInstance(m_type, 2))
            {
                t.PidWrite(range);

                Assert.That(t.Get(), Is.EqualTo(range).Within(.01));
            }
        }
コード例 #4
0
ファイル: VictorItem.cs プロジェクト: Dylan-Watson/FRC-2017
        /// <summary>
        ///     Constructor
        /// </summary>
        /// <param name="type">type of victor</param>
        /// <param name="channel">pwm channel the victor is plugged into</param>
        /// <param name="commonName">CommonName the component will have</param>
        /// <param name="isReversed">if the controller output should be reversed</param>
        public VictorItem(VictorType type, int channel, string commonName, bool isReversed = false)
        {
            VictorType = type;
            if (type == VictorType.Sp)
            {
                victor = new VictorSP(channel);
            }
            else
            {
                victor = new Victor(channel);
            }

            Name       = commonName;
            IsReversed = isReversed;
        }
コード例 #5
0
ファイル: VictorItem.cs プロジェクト: Dylan-Watson/FRC-2017
        /// <summary>
        ///     Constructor
        /// </summary>
        /// <param name="type">type of victor</param>
        /// <param name="channel">pwm channel the victor is plugged into</param>
        /// <param name="commonName">CommonName the component will have</param>
        /// <param name="side">side of the drive train the cotnroller is on</param>
        /// <param name="isReversed">if the controller output should be reversed</param>
        public VictorItem(VictorType type, int channel, string commonName, Side side, bool isReversed = false)
        {
            VictorType = type;
            if (type == VictorType.Sp)
            {
                victor = new VictorSP(channel);
            }
            else
            {
                victor = new Victor(channel);
            }

            Name              = commonName;
            IsReversed        = isReversed;
            IsDrivetrainMotor = true;
            DriveSide         = side;
        }
コード例 #6
0
ファイル: Program.cs プロジェクト: CoryNessCTR/HERO-Examples
        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);
            }
        }
コード例 #7
0
 public void TestPWMSpeedControllerInitialized()
 {
     using (PWMSpeedController t = (PWMSpeedController)Activator.CreateInstance(m_type, 2))
     {
         /*
          * ControllerType controllerType = ControllerType.None;
          * if (m_type == typeof(Jaguar))
          * {
          *  controllerType = ControllerType.Jaguar;
          * }
          * else if (m_type == typeof(Talon))
          * {
          *  controllerType = ControllerType.Talon;
          * }
          * else if (m_type == typeof(TalonSRX))
          * {
          *  controllerType = ControllerType.TalonSRX;
          * }
          * else if (m_type == typeof(VictorSP))
          * {
          *  controllerType = ControllerType.VictorSP;
          * }
          * else if (m_type == typeof(Victor))
          * {
          *  controllerType = ControllerType.Victor;
          * }
          * else if (m_type == typeof(Spark))
          * {
          *  controllerType = ControllerType.Spark;
          * }
          * else if (m_type == typeof(SD540))
          * {
          *  controllerType = ControllerType.SD540;
          * }
          * Assert.AreEqual(SimData.PWM[2].Type, controllerType);
          */
     }
 }
コード例 #8
0
        static void Initialize()
        {
            // Serial port
            _uart = new System.IO.Ports.SerialPort(CTRE.HERO.IO.Port1.UART, 115200);
            _uart.Open();

            // Victor SPX Slaves
            // Left Slave
            victor1.Set(ControlMode.Follower, 0);
            // Right Slave
            victor3.Set(ControlMode.Follower, 2);

            // Talon SRX Slaves
            // Feeder Slave
            feederL.Set(ControlMode.Follower, 0);
            feederL.SetInverted(true);
            // Intake Slave
            intakeLft.Set(ControlMode.Follower, 2);
            intakeLft.SetInverted(true);

            // Hood
            hood.ConfigSelectedFeedbackSensor(FeedbackDevice.Analog, 0, kTimeoutMs);
            hood.SetSensorPhase(false);
            hood.Config_kP(0, 30f, kTimeoutMs); /* tweak this first, a little bit of overshoot is okay */
            hood.Config_kI(0, 0.0005f, kTimeoutMs);
            hood.Config_kD(0, 0f, kTimeoutMs);
            hood.Config_kF(0, 0f, kTimeoutMs);
            /* use slot0 for closed-looping */
            hood.SelectProfileSlot(0, 0);

            /* set the peak and nominal outputs, 1.0 means full */
            hood.ConfigNominalOutputForward(0.0f, kTimeoutMs);
            hood.ConfigNominalOutputReverse(0.0f, kTimeoutMs);
            hood.ConfigPeakOutputForward(+1.0f, kTimeoutMs);
            hood.ConfigPeakOutputReverse(-1.0f, kTimeoutMs);
            hood.ConfigForwardSoftLimitThreshold(HOOD_LOWER_BOUND_ANALOG, kTimeoutMs);
            hood.ConfigReverseSoftLimitThreshold(HOOD_UPPER_BOUND_ANALOG, kTimeoutMs);
            hood.ConfigForwardSoftLimitEnable(true, kTimeoutMs);
            hood.ConfigReverseSoftLimitEnable(true, kTimeoutMs);

            /* how much error is allowed?  This defaults to 0. */
            hood.ConfigAllowableClosedloopError(0, 5, kTimeoutMs);

            //***********************
            // MAY NEED TUNING
            //***********************
            // Turret
            turret.ConfigSelectedFeedbackSensor(FeedbackDevice.CTRE_MagEncoder_Absolute, 1, kTimeoutMs);
            int absPos = turret.GetSelectedSensorPosition(1);

            turret.ConfigSelectedFeedbackSensor(FeedbackDevice.CTRE_MagEncoder_Relative, 0, kTimeoutMs);
            turret.SetSelectedSensorPosition(0, 0, kTimeoutMs);
            turret.SetSensorPhase(true);
            turret.Config_IntegralZone(20);
            turret.Config_kP(0, 2f, kTimeoutMs); // tweak this first, a little bit of overshoot is okay
            turret.Config_kI(0, 0f, kTimeoutMs);
            turret.Config_kD(0, 0f, kTimeoutMs);
            turret.Config_kF(0, 0f, kTimeoutMs);
            // use slot0 for closed-looping
            turret.SelectProfileSlot(0, 0);

            // set the peak and nominal outputs, 1.0 means full
            turret.ConfigNominalOutputForward(0.0f, kTimeoutMs);
            turret.ConfigNominalOutputReverse(0.0f, kTimeoutMs);
            turret.ConfigPeakOutputForward(+0.5f, kTimeoutMs);
            turret.ConfigPeakOutputReverse(-0.5f, kTimeoutMs);
            turret.ConfigReverseSoftLimitThreshold(TURRET_UPPER_BOUND_ANALOG, kTimeoutMs);
            turret.ConfigForwardSoftLimitThreshold(TURRET_LOWER_BOUND_ANALOG, kTimeoutMs);
            turret.ConfigReverseSoftLimitEnable(true, kTimeoutMs);
            turret.ConfigForwardSoftLimitEnable(true, kTimeoutMs);

            // how much error is allowed?  This defaults to 0.
            turret.ConfigAllowableClosedloopError(0, 5, kTimeoutMs);

            // Shooter
            shooterSensorTalon.ConfigSelectedFeedbackSensor(FeedbackDevice.CTRE_MagEncoder_Relative, 0, kTimeoutMs);
            shooterSensorTalon.SetSensorPhase(false);
            shooterSensorTalon.ConfigPeakOutputReverse(0.0f, kTimeoutMs);
            shooterSensorTalon.ConfigPeakOutputForward(1.0f, kTimeoutMs);

            shooterVESC = new PWMSpeedController(CTRE.HERO.IO.Port3.PWM_Pin7);
            shooterVESC.Set(0);

            pcm.SetSolenoidOutput(shooterFeedbackLEDPort, false);
        }