com.ctre.phoenix.motorcontrol.can.TalonSRX Java Examples
The following examples show how to use
com.ctre.phoenix.motorcontrol.can.TalonSRX.
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: SubsystemMast.java From PowerUp-2018 with GNU General Public License v3.0 | 6 votes |
/** gives birth to the CANTalons */ public SubsystemMast(){ /** Does it make sense to move the limit switch IDs to Constants? **/ //no because they could be moved due to various electrical reasons-nate lowerPinionLimit = new DigitalInput(6); upperPinionLimit = new DigitalInput(7); lowerScrewLimit = new DigitalInput(3); upperScrewLimit = new DigitalInput(4); leftPinion = new TalonSRX(Constants.LEFT_PINION_MOTOR); rightPinion = new TalonSRX(Constants.RIGHT_PINION_MOTOR); screw = new TalonSRX(Constants.SCREW_MOTOR); voltage(leftPinion); voltage(rightPinion); voltage(screw); override = false; }
Example #2
Source File: SubsystemDrive.java From PowerUp-2018 with GNU General Public License v3.0 | 6 votes |
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: Drive.java From FRC-2018-Public with MIT License | 6 votes |
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 #4
Source File: Arm.java From FRC-2019-Public with MIT License | 6 votes |
@Override public boolean checkSystem() { return TalonSRXChecker.checkMotors(this, new ArrayList<MotorChecker.MotorConfig<TalonSRX>>() { private static final long serialVersionUID = 3069865439600365807L; { add(new MotorChecker.MotorConfig<>("master", mMaster)); } }, new MotorChecker.CheckerConfig() { { mRunOutputPercentage = 0.5; mRunTimeSec = 0.5; mCurrentFloor = 0.1; mRPMFloor = 90; mCurrentEpsilon = 2.0; mRPMEpsilon = 200; mRPMSupplier = () -> mMaster.getSelectedSensorVelocity(); } }); }
Example #5
Source File: Wrist.java From FRC-2019-Public with MIT License | 6 votes |
@Override public boolean checkSystem() { return TalonSRXChecker.checkMotors(this, new ArrayList<MotorChecker.MotorConfig<TalonSRX>>() { private static final long serialVersionUID = -716113039054569446L; { add(new MotorChecker.MotorConfig<>("master", mMaster)); } }, new MotorChecker.CheckerConfig() { { mRunOutputPercentage = 0.5; mRunTimeSec = 1.0; mCurrentFloor = 0.1; mRPMFloor = 90; mCurrentEpsilon = 2.0; mRPMEpsilon = 200; mRPMSupplier = () -> mMaster.getSelectedSensorVelocity(); } }); }
Example #6
Source File: Elevator.java From FRC-2019-Public with MIT License | 6 votes |
@Override public boolean checkSystem() { return TalonSRXChecker.checkMotors(this, new ArrayList<MotorChecker.MotorConfig<TalonSRX>>() { private static final long serialVersionUID = 2555581143886197844L; { add(new MotorChecker.MotorConfig<>("master", mMaster)); add(new MotorChecker.MotorConfig<>("slave 1", mSlaves[0])); add(new MotorChecker.MotorConfig<>("slave 2", mSlaves[1])); } }, new MotorChecker.CheckerConfig() { { mRunOutputPercentage = 0.5; mRunTimeSec = 1.0; mCurrentFloor = 0.1; mRPMFloor = 90; mCurrentEpsilon = 2.0; mRPMEpsilon = 200; mRPMSupplier = () -> mMaster.getSelectedSensorVelocity(); } }); }
Example #7
Source File: Turret.java From FRC-2019-Public with MIT License | 6 votes |
@Override public boolean checkSystem() { return TalonSRXChecker.checkMotors(this, new ArrayList<MotorChecker.MotorConfig<TalonSRX>>() { private static final long serialVersionUID = 1636612675181038895L; { add(new MotorChecker.MotorConfig<>("master", mMaster)); } }, new MotorChecker.CheckerConfig() { { mRunOutputPercentage = 0.1; mRunTimeSec = 1.0; mCurrentFloor = 0.1; mRPMFloor = 90; mCurrentEpsilon = 2.0; mRPMEpsilon = 200; mRPMSupplier = mMaster::getSelectedSensorVelocity; } }); }
Example #8
Source File: SubsystemMast.java From PowerUp-2018 with GNU General Public License v3.0 | 5 votes |
/** configures the voltage of each CANTalon */ private void voltage(TalonSRX talon) { // talon.configNominalOutputVoltage(0f, 0f); // talon.configPeakOutputVoltage(12.0f, -12.0f); talon.enableCurrentLimit(true); talon.configContinuousCurrentLimit(60, 300); talon.configPeakCurrentDuration(500, 10); }
Example #9
Source File: SubsystemDrive.java From PowerUp-2018 with GNU General Public License v3.0 | 5 votes |
/** * gives birth to the talons and instantiates variables (including the Bot enum) */ public SubsystemDrive() { accel = new BuiltInAccelerometer(); drivetrain = Drivetrain.ROCKET_LEAGUE; reversing = false; docking = false; dockInhibitor = 0.5d; pid = new PID(); // masters leftMaster = new TalonSRX(Constants.LEFT_MASTER); leftMaster.configSelectedFeedbackSensor(FeedbackDevice.CTRE_MagEncoder_Relative, Constants.LEFT_PID, Constants.TIMEOUT_PID); rightMaster = new TalonSRX(Constants.RIGHT_MASTER); rightMaster.configSelectedFeedbackSensor(FeedbackDevice.CTRE_MagEncoder_Relative, Constants.RIGHT_PID, Constants.TIMEOUT_PID); // slaves leftSlave = new TalonSRX(Constants.LEFT_SLAVE); leftSlave.follow(leftMaster); rightSlave = new TalonSRX(Constants.RIGHT_SLAVE); rightSlave.follow(rightMaster); switch (Robot.bot){ case TEUFELSKIND: PID.setPIDF(Constants.TEUFELSKIND.P, Constants.TEUFELSKIND.I, Constants.TEUFELSKIND.D, Constants.TEUFELSKIND.F); break; case OOF: PID.setPIDF(Constants.OOF.P, Constants.OOF.I, Constants.OOF.D, Constants.OOF.F); break; } }
Example #10
Source File: TalonSRXChecker.java From FRC-2019-Public with MIT License | 5 votes |
@Override protected void storeConfiguration() { // record previous configuration for all talons for (MotorConfig<TalonSRX> config : mMotorsToCheck) { LazyTalonSRX talon = (LazyTalonSRX) config.mMotor; StoredTalonSRXConfiguration configuration = new StoredTalonSRXConfiguration(); configuration.mMode = talon.getControlMode(); configuration.mSetValue = talon.getLastSet(); mStoredConfigurations.add(configuration); } }
Example #11
Source File: TalonSRXFactory.java From FRC-2019-Public with MIT License | 4 votes |
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 #12
Source File: TalonSRXFactory.java From FRC-2019-Public with MIT License | 4 votes |
public static TalonSRX createPermanentSlaveTalon(int id, int master_id) { final TalonSRX talon = createTalon(id, kSlaveConfiguration); talon.set(ControlMode.Follower, master_id); return talon; }
Example #13
Source File: TalonSRXFactory.java From FRC-2019-Public with MIT License | 4 votes |
public static TalonSRX createDefaultTalon(int id) { return createTalon(id, kDefaultConfiguration); }
Example #14
Source File: TalonSRXChecker.java From FRC-2018-Public with MIT License | 4 votes |
public TalonSRXConfig(String name, TalonSRX talon) { mName = name; mTalon = talon; }
Example #15
Source File: TalonSRXFactory.java From FRC-2018-Public with MIT License | 4 votes |
public static TalonSRX createDefaultTalon(int id) { return createTalon(id, kDefaultConfiguration); }
Example #16
Source File: TalonSRXFactory.java From FRC-2018-Public with MIT License | 4 votes |
public static TalonSRX createPermanentSlaveTalon(int id, int master_id) { final TalonSRX talon = createTalon(id, kSlaveConfiguration); talon.set(ControlMode.Follower, master_id); return talon; }
Example #17
Source File: TalonSRXFactory.java From FRC-2018-Public with MIT License | 4 votes |
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; }
Example #18
Source File: TalonSRXChecker.java From FRC-2019-Public with MIT License | 4 votes |
@Override protected double getMotorCurrent(TalonSRX motor) { return motor.getOutputCurrent(); }
Example #19
Source File: TalonSRXChecker.java From FRC-2019-Public with MIT License | 4 votes |
@Override protected void setMotorOutput(TalonSRX motor, double output) { motor.set(ControlMode.PercentOutput, output); }
Example #20
Source File: SubsystemManipulator.java From PowerUp-2018 with GNU General Public License v3.0 | 4 votes |
/** gives birth to the CANTalons */ public SubsystemManipulator(){ armLeft = new TalonSRX(Constants.LEFT_FLYWHEEL); armRight = new TalonSRX(Constants.RIGHT_FLYWHEEL); }
Example #21
Source File: TalonSRXChecker.java From FRC-2019-Public with MIT License | 4 votes |
public static boolean checkMotors(Subsystem subsystem, ArrayList<MotorConfig<TalonSRX>> motorsToCheck, CheckerConfig checkerConfig) { TalonSRXChecker checker = new TalonSRXChecker(); return checker.checkMotorsImpl(subsystem, motorsToCheck, checkerConfig); }