TalonSRX

class phoenix5.TalonSRX(*args, **kwargs)

Bases: BaseTalon

CTRE Talon SRX Motor Controller when used on CAN Bus.

{@code
// Example usage of a TalonSRX motor controller
TalonSRX motor{0}; // creates a new TalonSRX with ID 0

TalonSRXConfiguration config;
config.peakCurrentLimit = 40; // the peak current, in amps
config.peakCurrentDuration = 1500; // the time at the peak current before the limit triggers, in ms
config.continuousCurrentLimit = 30; // the current to maintain if the peak limit is triggered
motor.ConfigAllSettings(config); // apply the config settings; this selects the quadrature encoder

motor.Set(TalonSRXControlMode::PercentOutput, 0.5); // runs the motor at 50% power

std::cout << motor.GetSelectedSensorPosition() << std::endl; // prints the position of the selected sensor
std::cout << motor.GetSelectedSensorVelocity() << std::endl; // prints the velocity recorded by the selected sensor
std::cout << motor.GetMotorOutputPercent() << std::endl; // prints the percent output of the motor (0.5)
std::cout << motor.GetStatorCurrent() << std::endl; // prints the output current of the motor

ErrorCode error = motor.GetLastError(); // gets the last error generated by the motor controller
Faults faults;
ErrorCode faultsError = motor.GetFaults(faults); // fills faults with the current motor controller faults; returns the last error generated

motor.SetStatusFramePeriod(StatusFrameEnhanced::Status_2_Feedback0, 10); // changes the period of the Status 2 frame (GetSelectedSensor*()) to 10ms
}

See also

WPI_TalonSRX

Overloaded function.

  1. __init__(self: phoenix5._ctre.TalonSRX, deviceNumber: int) -> None

Constructor for a Talon

Parameters:

deviceNumber – CAN Device ID of TalonSRX

  1. __init__(self: phoenix5._ctre.TalonSRX, deviceNumber: int, canbus: str) -> None

Constructor so non-FRC platforms can specify a CAN 2.0 socketcan bus

Parameters:
  • deviceNumber – CAN Device ID of TalonSRX

  • canbus – String specifying the bus

configAllSettings(allConfigs: phoenix5._ctre.TalonSRXConfiguration, timeoutMs: int = 50) phoenix5._ctre.ErrorCode

Configures all persistent settings.

Parameters:
  • allConfigs – Object with all of the persistant settings

  • timeoutMs – Timeout value in ms. If nonzero, function will wait for config success and report an error if it times out. If zero, no blocking or checking is performed.

Returns:

Error Code generated by function. 0 indicates no error.

configContinuousCurrentLimit(amps: int, timeoutMs: int = 0) phoenix5._ctre.ErrorCode

Configure the continuous allowable current-draw (when current limit is enabled).

Supply current limiting is also available via ConfigSupplyCurrentLimit(), which is a common routine with Talon FX.

Current limit is activated when current exceeds the peak limit for longer than the peak duration. Then software will limit to the continuous limit. This ensures current limiting while allowing for momentary excess current events.

For simpler current-limiting (single threshold) use ConfigContinuousCurrentLimit() and set the peak to zero: ConfigPeakCurrentLimit(0).

Parameters:
  • amps – Amperes to limit.

  • timeoutMs – Timeout value in ms. If nonzero, function will wait for config success and report an error if it times out. If zero, no blocking or checking is performed.

configPeakCurrentDuration(milliseconds: int, timeoutMs: int = 0) phoenix5._ctre.ErrorCode

Configure the peak allowable duration (when current limit is enabled).

Supply current limiting is also available via ConfigSupplyCurrentLimit(), which is a common routine with Talon FX.

Current limit is activated when current exceeds the peak limit for longer than the peak duration. Then software will limit to the continuous limit. This ensures current limiting while allowing for momentary excess current events.

For simpler current-limiting (single threshold) use ConfigContinuousCurrentLimit() and set the peak to zero: ConfigPeakCurrentLimit(0).

Parameters:
  • milliseconds – How long to allow current-draw past peak limit.

  • timeoutMs – Timeout value in ms. If nonzero, function will wait for config success and report an error if it times out. If zero, no blocking or checking is performed.

configPeakCurrentLimit(amps: int, timeoutMs: int = 0) phoenix5._ctre.ErrorCode

Configure the peak allowable current (when current limit is enabled).

Supply current limiting is also available via ConfigSupplyCurrentLimit(), which is a common routine with Talon FX.

Current limit is activated when current exceeds the peak limit for longer than the peak duration. Then software will limit to the continuous limit. This ensures current limiting while allowing for momentary excess current events.

For simpler current-limiting (single threshold) use ConfigContinuousCurrentLimit() and set the peak to zero: ConfigPeakCurrentLimit(0).

Parameters:
  • amps – Amperes to limit.

  • timeoutMs – Timeout value in ms. If nonzero, function will wait for config success and report an error if it times out. If zero, no blocking or checking is performed.

configSelectedFeedbackSensor(*args, **kwargs)

Overloaded function.

  1. configSelectedFeedbackSensor(self: phoenix5._ctre.TalonSRX, feedbackDevice: phoenix5._ctre.TalonSRXFeedbackDevice, pidIdx: int = 0, timeoutMs: int = 0) -> phoenix5._ctre.ErrorCode

Select the feedback device for the motor controller.

Parameters:
  • feedbackDevice – Talon SRX Feedback Device to select.

  • pidIdx – 0 for Primary closed-loop. 1 for auxiliary closed-loop.

  • timeoutMs – Timeout value in ms. If nonzero, function will wait for config success and report an error if it times out. If zero, no blocking or checking is performed.

Returns:

Error Code generated by function. 0 indicates no error.

  1. configSelectedFeedbackSensor(self: phoenix5._ctre.TalonSRX, feedbackDevice: phoenix5._ctre.FeedbackDevice, pidIdx: int, timeoutMs: int = 0) -> phoenix5._ctre.ErrorCode

Select the feedback device for the motor controller.

Parameters:
  • feedbackDevice – Feedback Device to select.

  • pidIdx – 0 for Primary closed-loop. 1 for auxiliary closed-loop.

  • timeoutMs – Timeout value in ms. If nonzero, function will wait for config success and report an error if it times out. If zero, no blocking or checking is performed.

Returns:

Error Code generated by function. 0 indicates no error.

  1. configSelectedFeedbackSensor(self: phoenix5._ctre.TalonSRX, feedbackDevice: phoenix5._ctre.RemoteFeedbackDevice, pidIdx: int, timeoutMs: int) -> phoenix5._ctre.ErrorCode

Select the remote feedback device for the motor controller. Most CTRE CAN motor controllers will support remote sensors over CAN.

Parameters:
  • feedbackDevice – Remote Feedback Device to select.

  • pidIdx – 0 for Primary closed-loop. 1 for auxiliary closed-loop.

  • timeoutMs – Timeout value in ms. If nonzero, function will wait for config success and report an error if it times out. If zero, no blocking or checking is performed.

Returns:

Error Code generated by function. 0 indicates no error.

configSupplyCurrentLimit(currLimitConfigs: phoenix5._ctre.SupplyCurrentLimitConfiguration, timeoutMs: int = 50) phoenix5._ctre.ErrorCode

Configures the supply (input) current limit.

Parameters:
  • currLimitConfigs – Current limit configuration

  • timeoutMs – Timeout value in ms. If nonzero, function will wait for config success and report an error if it times out. If zero, no blocking or checking is performed.

Returns:

Error Code generated by function. 0 indicates no error.

configurePID(pid: phoenix5._ctre.TalonSRXPIDSetConfiguration, pidIdx: int = 0, timeoutMs: int = 50) phoenix5._ctre.ErrorCode

Sets all PID persistant settings.

Parameters:
  • pid – Object with all of the PID set persistant settings

  • pidIdx – 0 for Primary closed-loop. 1 for auxiliary closed-loop.

  • timeoutMs – Timeout value in ms. If nonzero, function will wait for config success and report an error if it times out. If zero, no blocking or checking is performed.

enableCurrentLimit(enable: bool) None

Enable or disable Current Limit.

Supply current limiting is also available via ConfigSupplyCurrentLimit(), which is a common routine with Talon FX.

Parameters:

enable – Enable state of current limit. @see configPeakCurrentLimit() @see configPeakCurrentDuration() @see configContinuousCurrentLimit()

getAllConfigs(allConfigs: phoenix5._ctre.TalonSRXConfiguration, timeoutMs: int = 50) None

Gets all persistant settings.

Parameters:
  • allConfigs – Object with all of the persistant settings

  • timeoutMs – Timeout value in ms. If nonzero, function will wait for config success and report an error if it times out. If zero, no blocking or checking is performed.

getPIDConfigs(pid: phoenix5._ctre.TalonSRXPIDSetConfiguration, pidIdx: int = 0, timeoutMs: int = 50) None

Gets all PID set persistant settings.

Parameters:
  • pid – Object with all of the PID set persistant settings

  • pidIdx – 0 for Primary closed-loop. 1 for auxiliary closed-loop.

  • timeoutMs – Timeout value in ms. If nonzero, function will wait for config success and report an error if it times out. If zero, no blocking or checking is performed.

getSensorCollection() phoenix5._ctre.SensorCollection
Returns:

object that can get/set individual RAW sensor values.

getSimCollection() phoenix5._ctre.TalonSRXSimCollection
Returns:

object that can set simulation inputs.

set(*args, **kwargs)

Overloaded function.

  1. set(self: phoenix5._ctre.TalonSRX, mode: phoenix5._ctre.TalonSRXControlMode, value: float) -> None

Sets the appropriate output on the talon, depending on the mode.

  • Standard Driving Example:

  • _talonLeft.set(ControlMode.PercentOutput, leftJoy);

  • _talonRght.set(ControlMode.PercentOutput, rghtJoy);

Parameters:
  • mode – The output mode to apply. In PercentOutput, the output is between -1.0 and 1.0, with 0.0 as stopped. In Current mode, output value is in amperes. In Velocity mode, output value is in position change / 100ms. In Position mode, output value is in encoder ticks or an analog value, depending on the sensor. In Follower mode, the output value is the integer device ID of the talon to duplicate.

  • value – The setpoint value, as described above.

  1. set(self: phoenix5._ctre.TalonSRX, mode: phoenix5._ctre.TalonSRXControlMode, demand0: float, demand1Type: phoenix5._ctre.DemandType, demand1: float) -> None

Arcade Drive Example: * _talonLeft.set(ControlMode.PercentOutput, joyForward, DemandType.ArbitraryFeedForward, +joyTurn); * _talonRght.set(ControlMode.PercentOutput, joyForward, DemandType.ArbitraryFeedForward, -joyTurn);

  • Drive Straight Example:

  • Note: Selected Sensor Configuration is necessary for both PID0 and PID1.

  • _talonLeft.follow(_talonRght, FollwerType.AuxOutput1);

  • _talonRght.set(ControlMode.PercentOutput, joyForward, DemandType.AuxPID, desiredRobotHeading);

  • Drive Straight to a Distance Example:

  • Note: Other configurations (sensor selection, PID gains, etc.) need to be set.

  • _talonLeft.follow(_talonRght, FollwerType.AuxOutput1);

  • _talonRght.set(ControlMode.MotionMagic, targetDistance, DemandType.AuxPID, desiredRobotHeading);

Parameters:
  • mode – Sets the appropriate output on the talon, depending on the mode.

  • demand0 – The output value to apply. such as advanced feed forward and/or auxiliary close-looping in firmware. In PercentOutput, the output is between -1.0 and 1.0, with 0.0 as stopped. In Current mode, output value is in amperes. In Velocity mode, output value is in position change / 100ms. In Position mode, output value is in encoder ticks or an analog value, depending on the sensor. See In Follower mode, the output value is the integer device ID of the talon to duplicate.

  • demand1Type – The demand type for demand1. Neutral: Ignore demand1 and apply no change to the demand0 output. AuxPID: Use demand1 to set the target for the auxiliary PID 1. Auxiliary PID is always executed as standard Position PID control. ArbitraryFeedForward: Use demand1 as an arbitrary additive value to the * demand0 output. In PercentOutput the demand0 output is the motor output, and in closed-loop modes the demand0 output is the output of PID0.

  • demand1 – Supplmental output value. AuxPID: Target position in Sensor Units ArbitraryFeedForward: Percent Output between -1.0 and 1.0

  1. set(self: phoenix5._ctre.TalonSRX, mode: phoenix5._ctre.ControlMode, value: float) -> None

  2. set(self: phoenix5._ctre.TalonSRX, mode: phoenix5._ctre.ControlMode, demand0: float, demand1Type: phoenix5._ctre.DemandType, demand1: float) -> None