Java Code Examples for com.ctre.phoenix.motorcontrol.can.TalonSRX#setSensorPhase()

The following examples show how to use com.ctre.phoenix.motorcontrol.can.TalonSRX#setSensorPhase() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Drive.java    From FRC-2018-Public with MIT License 6 votes vote down vote up
private void configureMaster(TalonSRX talon, boolean left) {
    talon.setStatusFramePeriod(StatusFrameEnhanced.Status_2_Feedback0, 5, 100);
    final ErrorCode sensorPresent = talon.configSelectedFeedbackSensor(FeedbackDevice
            .CTRE_MagEncoder_Relative, 0, 100); //primary closed-loop, 100 ms timeout
    if (sensorPresent != ErrorCode.OK) {
        DriverStation.reportError("Could not detect " + (left ? "left" : "right") + " encoder: " + sensorPresent, false);
    }
    talon.setInverted(!left);
    talon.setSensorPhase(true);
    talon.enableVoltageCompensation(true);
    talon.configVoltageCompSaturation(12.0, Constants.kLongCANTimeoutMs);
    talon.configVelocityMeasurementPeriod(VelocityMeasPeriod.Period_50Ms, Constants.kLongCANTimeoutMs);
    talon.configVelocityMeasurementWindow(1, Constants.kLongCANTimeoutMs);
    talon.configClosedloopRamp(Constants.kDriveVoltageRampRate, Constants.kLongCANTimeoutMs);
    talon.configNeutralDeadband(0.04, 0);
}
 
Example 2
Source File: SubsystemDrive.java    From PowerUp-2018 with GNU General Public License v3.0 6 votes vote down vote up
public static void setPIDF(TalonSRX _talon, Boolean invert, double p, double i, double d, double f) {
    /* first choose the sensor */
    _talon.configSelectedFeedbackSensor(FeedbackDevice.CTRE_MagEncoder_Relative,
            0, Constants.TIMEOUT_PID);
    _talon.setSensorPhase(true);
    _talon.setInverted(invert);
    /* Set relevant frame periods to be at least as fast as periodic rate*/
    _talon.setStatusFramePeriod(StatusFrameEnhanced.Status_13_Base_PIDF0, 10,
            Constants.TIMEOUT_PID);
    _talon.setStatusFramePeriod(StatusFrameEnhanced.Status_10_MotionMagic, 10,
            Constants.TIMEOUT_PID);
    /* set the peak and nominal outputs */
    _talon.configNominalOutputForward(0, Constants.TIMEOUT_PID);
    _talon.configNominalOutputReverse(0, Constants.TIMEOUT_PID);
    _talon.configPeakOutputForward(1, Constants.TIMEOUT_PID);
    _talon.configPeakOutputReverse(-1, Constants.TIMEOUT_PID);
    /* set closed loop gains in slot0 - see documentation */
    _talon.selectProfileSlot(0, Constants.RIGHT_PID);
    _talon.config_kP(0, p, Constants.TIMEOUT_PID);
    _talon.config_kI(0, i, Constants.TIMEOUT_PID);
    _talon.config_kD(0, d, Constants.TIMEOUT_PID);
    _talon.config_kF(0, f, Constants.TIMEOUT_PID);
    /* set acceleration and vcruise velocity - see documentation */
    _talon.configMotionCruiseVelocity(15000, Constants.TIMEOUT_PID);
    _talon.configMotionAcceleration(6000, Constants.TIMEOUT_PID);
}
 
Example 3
Source File: TalonSRXFactory.java    From FRC-2019-Public with MIT License 4 votes vote down vote up
public static TalonSRX createTalon(int id, Configuration config) {
    TalonSRX talon = new LazyTalonSRX(id);
    talon.set(ControlMode.PercentOutput, 0.0);

    talon.changeMotionControlFramePeriod(config.MOTION_CONTROL_FRAME_PERIOD_MS);
    talon.clearMotionProfileHasUnderrun(kTimeoutMs);
    talon.clearMotionProfileTrajectories();

    talon.clearStickyFaults(kTimeoutMs);

    talon.configForwardLimitSwitchSource(LimitSwitchSource.FeedbackConnector,
            LimitSwitchNormal.Disabled, kTimeoutMs);
    talon.configReverseLimitSwitchSource(LimitSwitchSource.FeedbackConnector,
            LimitSwitchNormal.Disabled, kTimeoutMs);
    talon.overrideLimitSwitchesEnable(config.ENABLE_LIMIT_SWITCH);

    // Turn off re-zeroing by default.
    talon.configSetParameter(
            ParamEnum.eClearPositionOnLimitF, 0, 0, 0, kTimeoutMs);
    talon.configSetParameter(
            ParamEnum.eClearPositionOnLimitR, 0, 0, 0, kTimeoutMs);

    talon.configNominalOutputForward(0, kTimeoutMs);
    talon.configNominalOutputReverse(0, kTimeoutMs);
    talon.configNeutralDeadband(config.NEUTRAL_DEADBAND, kTimeoutMs);

    talon.configPeakOutputForward(1.0, kTimeoutMs);
    talon.configPeakOutputReverse(-1.0, kTimeoutMs);

    talon.setNeutralMode(config.NEUTRAL_MODE);

    talon.configForwardSoftLimitThreshold(config.FORWARD_SOFT_LIMIT, kTimeoutMs);
    talon.configForwardSoftLimitEnable(config.ENABLE_SOFT_LIMIT, kTimeoutMs);

    talon.configReverseSoftLimitThreshold(config.REVERSE_SOFT_LIMIT, kTimeoutMs);
    talon.configReverseSoftLimitEnable(config.ENABLE_SOFT_LIMIT, kTimeoutMs);
    talon.overrideSoftLimitsEnable(config.ENABLE_SOFT_LIMIT);

    talon.setInverted(config.INVERTED);
    talon.setSensorPhase(config.SENSOR_PHASE);

    talon.selectProfileSlot(0, 0);

    talon.configVelocityMeasurementPeriod(config.VELOCITY_MEASUREMENT_PERIOD, kTimeoutMs);
    talon.configVelocityMeasurementWindow(config.VELOCITY_MEASUREMENT_ROLLING_AVERAGE_WINDOW,
            kTimeoutMs);

    talon.configOpenloopRamp(config.OPEN_LOOP_RAMP_RATE, kTimeoutMs);
    talon.configClosedloopRamp(config.CLOSED_LOOP_RAMP_RATE, kTimeoutMs);

    talon.configVoltageCompSaturation(0.0, kTimeoutMs);
    talon.configVoltageMeasurementFilter(32, kTimeoutMs);
    talon.enableVoltageCompensation(false);

    talon.enableCurrentLimit(config.ENABLE_CURRENT_LIMIT);

    talon.setStatusFramePeriod(StatusFrameEnhanced.Status_1_General,
            config.GENERAL_STATUS_FRAME_RATE_MS, kTimeoutMs);
    talon.setStatusFramePeriod(StatusFrameEnhanced.Status_2_Feedback0,
            config.FEEDBACK_STATUS_FRAME_RATE_MS, kTimeoutMs);

    talon.setStatusFramePeriod(StatusFrameEnhanced.Status_3_Quadrature,
            config.QUAD_ENCODER_STATUS_FRAME_RATE_MS, kTimeoutMs);
    talon.setStatusFramePeriod(StatusFrameEnhanced.Status_4_AinTempVbat,
            config.ANALOG_TEMP_VBAT_STATUS_FRAME_RATE_MS, kTimeoutMs);
    talon.setStatusFramePeriod(StatusFrameEnhanced.Status_8_PulseWidth,
            config.PULSE_WIDTH_STATUS_FRAME_RATE_MS, kTimeoutMs);

    talon.setControlFramePeriod(ControlFrame.Control_3_General, config.CONTROL_FRAME_PERIOD_MS);

    return talon;
}
 
Example 4
Source File: TalonSRXFactory.java    From FRC-2018-Public with MIT License 4 votes vote down vote up
public static TalonSRX createTalon(int id, Configuration config) {
    TalonSRX talon = new LazyTalonSRX(id);
    talon.set(ControlMode.PercentOutput, 0.0);

    talon.changeMotionControlFramePeriod(config.MOTION_CONTROL_FRAME_PERIOD_MS);
    talon.clearMotionProfileHasUnderrun(kTimeoutMs);
    talon.clearMotionProfileTrajectories();

    talon.clearStickyFaults(kTimeoutMs);

    talon.configForwardLimitSwitchSource(LimitSwitchSource.FeedbackConnector,
            LimitSwitchNormal.NormallyOpen, kTimeoutMs);
    talon.configReverseLimitSwitchSource(LimitSwitchSource.FeedbackConnector,
            LimitSwitchNormal.NormallyOpen, kTimeoutMs);
    talon.overrideLimitSwitchesEnable(config.ENABLE_LIMIT_SWITCH);

    // Turn off re-zeroing by default.
    talon.configSetParameter(
            ParamEnum.eClearPositionOnLimitF, 0, 0, 0, kTimeoutMs);
    talon.configSetParameter(
            ParamEnum.eClearPositionOnLimitR, 0, 0, 0, kTimeoutMs);

    talon.configNominalOutputForward(0, kTimeoutMs);
    talon.configNominalOutputReverse(0, kTimeoutMs);
    talon.configNeutralDeadband(config.NEUTRAL_DEADBAND, kTimeoutMs);

    talon.configPeakOutputForward(1.0, kTimeoutMs);
    talon.configPeakOutputReverse(-1.0, kTimeoutMs);

    talon.setNeutralMode(config.NEUTRAL_MODE);

    talon.configForwardSoftLimitThreshold(config.FORWARD_SOFT_LIMIT, kTimeoutMs);
    talon.configForwardSoftLimitEnable(config.ENABLE_SOFT_LIMIT, kTimeoutMs);

    talon.configReverseSoftLimitThreshold(config.REVERSE_SOFT_LIMIT, kTimeoutMs);
    talon.configReverseSoftLimitEnable(config.ENABLE_SOFT_LIMIT, kTimeoutMs);
    talon.overrideSoftLimitsEnable(config.ENABLE_SOFT_LIMIT);

    talon.setInverted(config.INVERTED);
    talon.setSensorPhase(config.SENSOR_PHASE);

    talon.selectProfileSlot(0, 0);

    talon.configVelocityMeasurementPeriod(config.VELOCITY_MEASUREMENT_PERIOD, kTimeoutMs);
    talon.configVelocityMeasurementWindow(config.VELOCITY_MEASUREMENT_ROLLING_AVERAGE_WINDOW,
            kTimeoutMs);

    talon.configOpenloopRamp(config.OPEN_LOOP_RAMP_RATE, kTimeoutMs);
    talon.configClosedloopRamp(config.CLOSED_LOOP_RAMP_RATE, kTimeoutMs);

    talon.configVoltageCompSaturation(0.0, kTimeoutMs);
    talon.configVoltageMeasurementFilter(32, kTimeoutMs);
    talon.enableVoltageCompensation(false);

    talon.enableCurrentLimit(config.ENABLE_CURRENT_LIMIT);

    talon.setStatusFramePeriod(StatusFrameEnhanced.Status_1_General,
            config.GENERAL_STATUS_FRAME_RATE_MS, kTimeoutMs);
    talon.setStatusFramePeriod(StatusFrameEnhanced.Status_2_Feedback0,
            config.FEEDBACK_STATUS_FRAME_RATE_MS, kTimeoutMs);

    talon.setStatusFramePeriod(StatusFrameEnhanced.Status_3_Quadrature,
            config.QUAD_ENCODER_STATUS_FRAME_RATE_MS, kTimeoutMs);
    talon.setStatusFramePeriod(StatusFrameEnhanced.Status_4_AinTempVbat,
            config.ANALOG_TEMP_VBAT_STATUS_FRAME_RATE_MS, kTimeoutMs);
    talon.setStatusFramePeriod(StatusFrameEnhanced.Status_8_PulseWidth,
            config.PULSE_WIDTH_STATUS_FRAME_RATE_MS, kTimeoutMs);

    talon.setControlFramePeriod(ControlFrame.Control_3_General, config.CONTROL_FRAME_PERIOD_MS);

    return talon;
}