CANifier
- class phoenix5.CANifier(deviceNumber: int)
Bases:
CANBusAddressable
CTRE CANifier
Device for interfacing common devices to the CAN bus.
Constructor.
- Parameters:
deviceNumber – The CAN Device ID of the CANifier.
- class GeneralPin(value: int)
Bases:
pybind11_object
General IO Pins on the CANifier
Members:
QUAD_IDX : Quadrature Idx pin
QUAD_B : Quadrature B pin
QUAD_A : Quadrature A pin
LIMR : Reverse limit pin
LIMF : Forward limit pin
SDA : SDA pin
SCL : SCL pin
SPI_CS : SPI_CS pin
SPI_MISO_PWM2P : SPI_MISO_PWM2 pin
SPI_MOSI_PWM1P : SPI_MOSI_PWM1 pin
SPI_CLK_PWM0P : SPI_CLK_PWM0 pin
- LIMF = <GeneralPin.LIMF: 4>
- LIMR = <GeneralPin.LIMR: 3>
- QUAD_A = <GeneralPin.QUAD_A: 2>
- QUAD_B = <GeneralPin.QUAD_B: 1>
- QUAD_IDX = <GeneralPin.QUAD_IDX: 0>
- SCL = <GeneralPin.SCL: 6>
- SDA = <GeneralPin.SDA: 5>
- SPI_CLK_PWM0P = <GeneralPin.SPI_CLK_PWM0P: 10>
- SPI_CS = <GeneralPin.SPI_CS: 7>
- SPI_MISO_PWM2P = <GeneralPin.SPI_MISO_PWM2P: 8>
- SPI_MOSI_PWM1P = <GeneralPin.SPI_MOSI_PWM1P: 9>
- property name
- property value
- class LEDChannel(value: int)
Bases:
pybind11_object
Enum for the LED Output Channels
Members:
A : LED Channel A
B : LED Channel B
C : LED Channel C
- A = <LEDChannel.A: 0>
- B = <LEDChannel.B: 1>
- C = <LEDChannel.C: 2>
- property name
- property value
- class PWMChannel(value: int)
Bases:
pybind11_object
Enum for the PWM Input Channels
Members:
PWMChannel0 : PWM Channel 0
PWMChannel1 : PWM Channel 1
PWMChannel2 : PWM Channel 2
PWMChannel3 : PWM Channel 3
- PWMChannel0 = <PWMChannel.PWMChannel0: 0>
- PWMChannel1 = <PWMChannel.PWMChannel1: 1>
- PWMChannel2 = <PWMChannel.PWMChannel2: 2>
- PWMChannel3 = <PWMChannel.PWMChannel3: 3>
- property name
- property value
- property PWMChannelCount
Number of PWM channels available to CANifier
- class PinValues
Bases:
pybind11_object
Structure to hold the pin values.
- property LIMF
Forward limit pin
- property LIMR
Reverse limit pin
- property QUAD_A
Quadrature A pin
- property QUAD_B
Quadrature B pin
- property QUAD_IDX
Quadrature Idx pin
- property SCL
SCL pin
- property SDA
SDA pin
- property SPI_CLK_PWM0
SPI_CLK_PWM0 pin
- property SPI_CS_PWM3
SPI_CS_PWM3 pin
- property SPI_MISO_PWM2
SPI_MISO_PWM2 pin
- property SPI_MOSI_PWM1
SPI_MOSI_PWM1 pin
- clearStickyFaults(timeoutMs: int = 0) phoenix5._ctre.ErrorCode
Clears the Sticky Faults
- Parameters:
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.
- configAllSettings(allConfigs: phoenix5._ctre.CANifierConfiguration, 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.
- configClearPositionOnLimitF(clearPositionOnLimitF: bool, timeoutMs: int = 0) phoenix5._ctre.ErrorCode
Enables clearing the position of the feedback sensor when the forward limit switch is triggered
- Parameters:
clearPositionOnLimitF – Whether clearing is enabled, defaults false
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.
- configClearPositionOnLimitR(clearPositionOnLimitR: bool, timeoutMs: int = 0) phoenix5._ctre.ErrorCode
Enables clearing the position of the feedback sensor when the reverse limit switch is triggered
- Parameters:
clearPositionOnLimitR – Whether clearing is enabled, defaults false
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.
- configClearPositionOnQuadIdx(clearPositionOnQuadIdx: bool, timeoutMs: int = 0) phoenix5._ctre.ErrorCode
Enables clearing the position of the feedback sensor when the quadrature index signal is detected
- Parameters:
clearPositionOnQuadIdx – Whether clearing is enabled, defaults false
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.
- configFactoryDefault(timeoutMs: int = 50) phoenix5._ctre.ErrorCode
Configures all persistent settings to defaults (overloaded so timeoutMs is 50 ms).
- Parameters:
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.
- configGetCustomParam(paramIndex: int, timeoutMs: int = 0) int
Gets the value of a custom parameter. This is for arbitrary use.
Sometimes it is necessary to save calibration/duty cycle/output information in the device. Particularly if the device is part of a subsystem that can be replaced.
- Parameters:
paramIndex – Index of custom parameter. [0-1]
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:
Value of the custom param.
- configGetParameter(*args, **kwargs)
Overloaded function.
configGetParameter(self: phoenix5._ctre.CANifier, param: phoenix5._ctre.ParamEnum, ordinal: int, timeoutMs: int = 0) -> float
Gets a parameter. Generally this is not used. This can be utilized in - Using new features without updating API installation. - Errata workarounds to circumvent API implementation. - Allows for rapid testing / unit testing of firmware.
- Parameters:
param – Parameter enumeration.
ordinal – Ordinal of parameter.
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:
Value of parameter.
configGetParameter(self: phoenix5._ctre.CANifier, param: phoenix5._ctre.ParamEnum, valueToSend: int, ordinal: int, timeoutMs: int) -> tuple[phoenix5._ctre.ErrorCode, int, int]
Gets a parameter by passing an int by reference
- Parameters:
param – Parameter enumeration
valueToSend – Value to send to parameter
valueReceived – Reference to integer to receive
subValue – SubValue of parameter
ordinal – Ordinal of parameter
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.
- configSetCustomParam(newValue: int, paramIndex: int, timeoutMs: int = 0) phoenix5._ctre.ErrorCode
Sets the value of a custom parameter. This is for arbitrary use.
Sometimes it is necessary to save calibration/duty cycle/output information in the device. Particularly if the device is part of a subsystem that can be replaced.
- Parameters:
newValue – Value for custom parameter.
paramIndex – Index of custom parameter. [0-1]
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.
- configSetParameter(param: phoenix5._ctre.ParamEnum, value: float, subValue: int, ordinal: int, timeoutMs: int = 0) phoenix5._ctre.ErrorCode
Sets a parameter. Generally this is not used. This can be utilized in - Using new features without updating API installation. - Errata workarounds to circumvent API implementation. - Allows for rapid testing / unit testing of firmware.
- Parameters:
param – Parameter enumeration.
value – Value of parameter.
subValue – Subvalue for parameter. Maximum value of 255.
ordinal – Ordinal of parameter.
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.
- configVelocityMeasurementPeriod(period: phoenix5._ctre.sensors.SensorVelocityMeasPeriod, timeoutMs: int = 0) phoenix5._ctre.ErrorCode
Configures the period of each velocity sample. Every 1ms a position value is sampled, and the delta between that sample and the position sampled kPeriod ms ago is inserted into a filter. kPeriod is configured with this function.
- Parameters:
period – Desired period for the velocity measurement.
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.
- configVelocityMeasurementWindow(windowSize: int, timeoutMs: int = 0) phoenix5._ctre.ErrorCode
Sets the number of velocity samples used in the rolling average velocity measurement.
- Parameters:
windowSize – Number of samples in the rolling average of velocity measurement. Valid values are 1,2,4,8,16,32. If another value is specified, it will truncate to nearest support value.
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.
- static destroyAllCANifiers() None
Destructs all CANifier objects
- enablePWMOutput(pwmChannel: int, bEnable: bool) phoenix5._ctre.ErrorCode
Enables PWM Outputs Currently supports PWM 0, PWM 1, and PWM 2
- Parameters:
pwmChannel – Index of the PWM channel to enable.
bEnable – True” enables output on the pwm channel.
- getAllConfigs(allConfigs: phoenix5._ctre.CANifierConfiguration, 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.
- getBusVoltage() float
Gets the bus voltage seen by the device.
- Returns:
The bus voltage value (in volts).
- getFaults(toFill: phoenix5._ctre.CANifierFaults) phoenix5._ctre.ErrorCode
Gets the CANifier fault status
- Parameters:
toFill – Container for fault statuses.
- Returns:
Error Code generated by function. 0 indicates no error.
- getFirmwareVersion() int
Gets the firmware version of the device.
- Returns:
Firmware version of device.
- getGeneralInput(inputPin: phoenix5._ctre.CANifier.GeneralPin) bool
Gets the state of the specified pin
- Parameters:
inputPin – The index of the pin.
- Returns:
The state of the pin.
- getGeneralInputs(allPins: phoenix5._ctre.CANifier.PinValues) phoenix5._ctre.ErrorCode
Gets the state of all General Pins
- Parameters:
allPins – A structure to fill with the current state of all pins.
- getLastError() phoenix5._ctre.ErrorCode
Call GetLastError() generated by this object. Not all functions return an error code but can potentially report errors.
This function can be used to retrieve those error codes.
- Returns:
The last ErrorCode generated.
- getPWMInput(pwmChannel: phoenix5._ctre.CANifier.PWMChannel) tuple[phoenix5._ctre.ErrorCode, Annotated[list[float], FixedSize(2)]]
Gets the PWM Input
- Parameters:
pwmChannel – PWM channel to get.
pulseWidthAndPeriod – Double array to hold Duty Cycle [0] and Period [1].
- getQuadraturePosition() int
Gets the quadrature encoder’s position
- Returns:
Position of encoder
- getQuadratureVelocity() int
Gets the quadrature encoder’s velocity
- Returns:
Velocity of encoder
- getStatusFramePeriod(frame: phoenix5._ctre.CANifierStatusFrame, timeoutMs: int = 0) int
Gets the period of the given status frame.
- Parameters:
frame – Frame to get the period of.
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:
Period of the given status frame.
- getStickyFaults(toFill: phoenix5._ctre.CANifierStickyFaults) phoenix5._ctre.ErrorCode
Gets the CANifier sticky fault status
- Parameters:
toFill – Container for sticky fault statuses.
- Returns:
Error Code generated by function. 0 indicates no error.
- hasResetOccurred() bool
Returns true if the device has reset since last call.
- Returns:
Has a Device Reset Occurred?
- setControlFramePeriod(frame: phoenix5._ctre.CANifierControlFrame, periodMs: int) phoenix5._ctre.ErrorCode
Sets the period of the given control frame.
- Parameters:
frame – Frame whose period is to be changed.
periodMs – Period in ms for the given frame.
- Returns:
Error Code generated by function. 0 indicates no error.
- setGeneralOutput(outputPin: phoenix5._ctre.CANifier.GeneralPin, outputValue: bool, outputEnable: bool) phoenix5._ctre.ErrorCode
Sets the output of a General Pin
- Parameters:
outputPin – The pin to use as output.
outputValue – The desired output state.
outputEnable – Whether this pin is an output. “True” enables output.
- setGeneralOutputs(outputBits: int, isOutputBits: int) phoenix5._ctre.ErrorCode
Sets the output of all General Pins
- Parameters:
outputBits – A bit mask of all the output states. LSB->MSB is in the order of the #GeneralPin enum.
isOutputBits – A boolean bit mask that sets the pins to be outputs or inputs. A bit of 1 enables output.
- setLEDOutput(percentOutput: float, ledChannel: phoenix5._ctre.CANifier.LEDChannel) phoenix5._ctre.ErrorCode
Sets the LED Output
- Parameters:
percentOutput – Output duty cycle expressed as percentage.
ledChannel – Channel to set the output of.
- setPWMOutput(pwmChannel: int, dutyCycle: float) phoenix5._ctre.ErrorCode
Sets the PWM Output Currently supports PWM 0, PWM 1, and PWM 2
- Parameters:
pwmChannel – Index of the PWM channel to output.
dutyCycle – Duty Cycle (0 to 1) to output. Default period of the signal is 4.2 ms.
- setQuadraturePosition(newPosition: int, timeoutMs: int = 0) phoenix5._ctre.ErrorCode
Sets the quadrature encoder’s position
- Parameters:
newPosition – Position to set
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.
- setStatusFramePeriod(statusFrame: phoenix5._ctre.CANifierStatusFrame, periodMs: int, timeoutMs: int = 0) phoenix5._ctre.ErrorCode
Sets the period of the given status frame.
- Parameters:
statusFrame – Frame whose period is to be changed.
periodMs – Period in ms for the given frame.
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.