CTRE Phoenix Pro C++ 23.0.12
ctre::phoenixpro::hardware::core::CoreCANcoder Class Reference

Class for CANcoder, a CAN based magnetic encoder that provides absolute and relative position along with filtered velocity. More...

#include <ctre/phoenixpro/core/CoreCANcoder.hpp>

Inheritance diagram for ctre::phoenixpro::hardware::core::CoreCANcoder:
ctre::phoenixpro::hardware::ParentDevice ctre::phoenixpro::hardware::CANcoder

Public Member Functions

 CoreCANcoder (int deviceId, std::string canbus="")
 Constructs a new CANcoder object. More...
 
 CoreCANcoder (CoreCANcoder const &)=delete
 
CoreCANcoderoperator= (CoreCANcoder const &)=delete
 
bool HasResetOccurred ()
 
configs::CANcoderConfiguratorGetConfigurator ()
 Gets the configurator for this CANcoder. More...
 
configs::CANcoderConfigurator const & GetConfigurator () const
 Gets the configurator for this CANcoder. More...
 
sim::CANcoderSimStateGetSimState ()
 Get the simulation state for this device. More...
 
StatusSignalValue< int > & GetVersionMajor ()
 App Major Version number. More...
 
StatusSignalValue< int > & GetVersionMinor ()
 App Minor Version number. More...
 
StatusSignalValue< int > & GetVersionBugfix ()
 App Bugfix Version number. More...
 
StatusSignalValue< int > & GetVersionBuild ()
 App Build Version number. More...
 
StatusSignalValue< int > & GetVersion ()
 Full Version. More...
 
StatusSignalValue< int > & GetFaultField ()
 Integer representing all faults. More...
 
StatusSignalValue< int > & GetStickyFaultField ()
 Integer representing all sticky faults. More...
 
StatusSignalValue< units::angular_velocity::turns_per_second_t > & GetVelocity ()
 Velocity of device. More...
 
StatusSignalValue< units::angle::turn_t > & GetPosition ()
 Position of device. More...
 
StatusSignalValue< units::angle::turn_t > & GetAbsolutePosition ()
 Absolute Position of device. More...
 
StatusSignalValue< units::angular_velocity::turns_per_second_t > & GetUnfilteredVelocity ()
 The unfiltered velocity reported by CANcoder. More...
 
StatusSignalValue< units::angle::turn_t > & GetPositionSinceBoot ()
 The relative position reported by the CANcoder since boot. More...
 
StatusSignalValue< units::voltage::volt_t > & GetSupplyVoltage ()
 Measured supply voltage to the CANcoder. More...
 
StatusSignalValue< signals::MagnetHealthValue > & GetMagnetHealth ()
 Magnet health as measured by CANcoder. More...
 
StatusSignalValue< bool > & GetFault_Hardware ()
 Hardware fault occurred. More...
 
StatusSignalValue< bool > & GetStickyFault_Hardware ()
 Hardware fault occurred. More...
 
StatusSignalValue< bool > & GetFault_Undervoltage ()
 Device supply voltage dropped to near brownout levels. More...
 
StatusSignalValue< bool > & GetStickyFault_Undervoltage ()
 Device supply voltage dropped to near brownout levels. More...
 
StatusSignalValue< bool > & GetFault_BootDuringEnable ()
 Device boot while detecting the enable signal. More...
 
StatusSignalValue< bool > & GetStickyFault_BootDuringEnable ()
 Device boot while detecting the enable signal. More...
 
StatusSignalValue< bool > & GetFault_BadMagnet ()
 The magnet distance is not correct or magnet is missing. More...
 
StatusSignalValue< bool > & GetStickyFault_BadMagnet ()
 The magnet distance is not correct or magnet is missing. More...
 
ctre::phoenix::StatusCode SetControl (controls::ControlRequest &request)
 Control motor with generic control request object. More...
 
ctre::phoenix::StatusCode SetControl (controls::ControlRequest &&request)
 Control motor with generic control request object. More...
 
ctre::phoenix::StatusCode SetPosition (units::angle::turn_t newValue, units::time::second_t timeoutSeconds)
 The position to set the sensor position to right now. More...
 
ctre::phoenix::StatusCode SetPosition (units::angle::turn_t newValue)
 The position to set the sensor position to right now. More...
 
ctre::phoenix::StatusCode ClearStickyFaults (units::time::second_t timeoutSeconds)
 Clear the sticky faults in the device. More...
 
ctre::phoenix::StatusCode ClearStickyFaults ()
 Clear the sticky faults in the device. More...
 
- Public Member Functions inherited from ctre::phoenixpro::hardware::ParentDevice
 ParentDevice (int deviceID, std::string model, std::string canbus)
 
int GetDeviceID () const
 
const std::string & GetCANBus () const
 
std::shared_ptr< const controls::ControlRequestGetAppliedControl () const
 Get the latest applied control. More...
 
std::shared_ptr< controls::ControlRequestGetAppliedControl ()
 Get the latest applied control. More...
 

Additional Inherited Members

- Static Public Attributes inherited from ctre::phoenixpro::hardware::ParentDevice
static constexpr double kDefaultControlRatePeriodsSec = 0.010
 
- Protected Member Functions inherited from ctre::phoenixpro::hardware::ParentDevice
virtual void ReportIfTooOld ()=0
 
virtual ctre::phoenix::StatusCode SetControlPrivate (controls::ControlRequest &request)
 
template<typename T >
StatusSignalValue< T > & LookupStatusSignalValue (uint16_t spn, std::string signalName, bool reportOnConstruction)
 
template<typename T >
StatusSignalValue< T > & LookupStatusSignalValue (uint16_t spn, uint16_t mapper_iter, std::function< std::map< int, StatusSignalValue< T > >()> map_filler, std::string signalName, bool reportOnConstruction)
 
template<typename T , typename U >
StatusSignalValue< T > LookupDimensionlessStatusSignalValue (uint16_t spn, std::string signalName)
 Returns a unitless version of the StatusSignalValue by value. More...
 
void ReportIfTooOld (int minMajor, int minMinor, int minBugfix, int minBuild)
 
- Protected Attributes inherited from ctre::phoenixpro::hardware::ParentDevice
DeviceIdentifier deviceIdentifier
 

Detailed Description

Class for CANcoder, a CAN based magnetic encoder that provides absolute and relative position along with filtered velocity.

Constructor & Destructor Documentation

◆ CoreCANcoder() [1/2]

ctre::phoenixpro::hardware::core::CoreCANcoder::CoreCANcoder ( int  deviceId,
std::string  canbus = "" 
)

Constructs a new CANcoder object.

Parameters
deviceIdID of the device, as configured in Phoenix Tuner.
canbusName of the CAN bus this device is on. Possible CAN bus strings are:
  • "rio" for the native roboRIO CAN bus
  • CANivore name or serial number
  • SocketCAN interface (non-FRC Linux only)
  • "*" for any CANivore seen by the program
  • empty string (default) to select the default for the system:
    • "rio" on roboRIO
    • "can0" on Linux
    • "*" on Windows

◆ CoreCANcoder() [2/2]

ctre::phoenixpro::hardware::core::CoreCANcoder::CoreCANcoder ( CoreCANcoder const &  )
delete

Member Function Documentation

◆ ClearStickyFaults() [1/2]

ctre::phoenix::StatusCode ctre::phoenixpro::hardware::core::CoreCANcoder::ClearStickyFaults ( )
inline

Clear the sticky faults in the device.

This typically has no impact on the device functionality. Instead, it just clears telemetry faults that are accessible via API and Tuner Self-Test.

This will wait up to 0.050 seconds (50ms) by default.

Returns
StatusCode of the set command

◆ ClearStickyFaults() [2/2]

ctre::phoenix::StatusCode ctre::phoenixpro::hardware::core::CoreCANcoder::ClearStickyFaults ( units::time::second_t  timeoutSeconds)
inline

Clear the sticky faults in the device.

This typically has no impact on the device functionality. Instead, it just clears telemetry faults that are accessible via API and Tuner Self-Test.

Parameters
timeoutSecondsMaximum time to wait up to in seconds.
Returns
StatusCode of the set command

◆ GetAbsolutePosition()

StatusSignalValue< units::angle::turn_t > & ctre::phoenixpro::hardware::core::CoreCANcoder::GetAbsolutePosition ( )

Absolute Position of device.

The possible range is documented below, however the exact expected range is determined by the AbsoluteSensorRange.

Minimum Value: -0.5 Maximum Value: 0.999755859375 Default Value: 0 Units: rotations

Default Rates: CAN: 100.0 Hz

Returns
AbsolutePosition Status Signal Value object

◆ GetConfigurator() [1/2]

configs::CANcoderConfigurator & ctre::phoenixpro::hardware::core::CoreCANcoder::GetConfigurator ( )
inline

Gets the configurator for this CANcoder.

Gets the configurator for this CANcoder

Returns
Configurator for this CANcoder

◆ GetConfigurator() [2/2]

configs::CANcoderConfigurator const & ctre::phoenixpro::hardware::core::CoreCANcoder::GetConfigurator ( ) const
inline

Gets the configurator for this CANcoder.

Gets the configurator for this CANcoder

Returns
Configurator for this CANcoder

◆ GetFault_BadMagnet()

StatusSignalValue< bool > & ctre::phoenixpro::hardware::core::CoreCANcoder::GetFault_BadMagnet ( )

The magnet distance is not correct or magnet is missing.

Default Value: False

Default Rates: CAN: 4.0 Hz

Returns
Fault_BadMagnet Status Signal Value object

◆ GetFault_BootDuringEnable()

StatusSignalValue< bool > & ctre::phoenixpro::hardware::core::CoreCANcoder::GetFault_BootDuringEnable ( )

Device boot while detecting the enable signal.

Default Value: False

Default Rates: CAN: 4.0 Hz

Returns
Fault_BootDuringEnable Status Signal Value object

◆ GetFault_Hardware()

StatusSignalValue< bool > & ctre::phoenixpro::hardware::core::CoreCANcoder::GetFault_Hardware ( )

Hardware fault occurred.

Default Value: False

Default Rates: CAN: 4.0 Hz

Returns
Fault_Hardware Status Signal Value object

◆ GetFault_Undervoltage()

StatusSignalValue< bool > & ctre::phoenixpro::hardware::core::CoreCANcoder::GetFault_Undervoltage ( )

Device supply voltage dropped to near brownout levels.

Default Value: False

Default Rates: CAN: 4.0 Hz

Returns
Fault_Undervoltage Status Signal Value object

◆ GetFaultField()

StatusSignalValue< int > & ctre::phoenixpro::hardware::core::CoreCANcoder::GetFaultField ( )

Integer representing all faults.

This returns the fault flags reported by the device. These are device specific and are not used directly in typical applications. Use the signal specific GetFault_*() methods instead.

Minimum Value: 0 Maximum Value: 1048575 Default Value: 0 Units:

Default Rates: CAN: 4.0 Hz

Returns
FaultField Status Signal Value object

◆ GetMagnetHealth()

StatusSignalValue< signals::MagnetHealthValue > & ctre::phoenixpro::hardware::core::CoreCANcoder::GetMagnetHealth ( )

Magnet health as measured by CANcoder.

Magnet health as measured by CANcoder. Red indicates too close or too far, Orange is adequate but with reduced accuracy, green is ideal. Invalid means the accuracy cannot be determined.

Default Rates: CAN 2.0: 10.0 Hz CAN FD: 100.0 Hz

Returns
MagnetHealth Status Signal Value object

◆ GetPosition()

StatusSignalValue< units::angle::turn_t > & ctre::phoenixpro::hardware::core::CoreCANcoder::GetPosition ( )

Position of device.

Minimum Value: -16384.0 Maximum Value: 16383.999755859375 Default Value: 0 Units: rotations

Default Rates: CAN: 100.0 Hz

Returns
Position Status Signal Value object

◆ GetPositionSinceBoot()

StatusSignalValue< units::angle::turn_t > & ctre::phoenixpro::hardware::core::CoreCANcoder::GetPositionSinceBoot ( )

The relative position reported by the CANcoder since boot.

This is the total displacement reported by CANcoder since power up. This signal is relative and is not influenced by the fusing algorithm. It is also not timesynced. If you wish to use a signal with timesync, use Position.

Minimum Value: -16384.0 Maximum Value: 16383.999755859375 Default Value: 0 Units: rotations

Default Rates: CAN 2.0: 10.0 Hz CAN FD: 100.0 Hz

Returns
PositionSinceBoot Status Signal Value object

◆ GetSimState()

sim::CANcoderSimState & ctre::phoenixpro::hardware::core::CoreCANcoder::GetSimState ( )
inline

Get the simulation state for this device.

This function reuses an allocated simulation state object, so it is safe to call this function multiple times in a robot loop.

Returns
Simulation state

◆ GetStickyFault_BadMagnet()

StatusSignalValue< bool > & ctre::phoenixpro::hardware::core::CoreCANcoder::GetStickyFault_BadMagnet ( )

The magnet distance is not correct or magnet is missing.

Default Value: False

Default Rates: CAN: 4.0 Hz

Returns
StickyFault_BadMagnet Status Signal Value object

◆ GetStickyFault_BootDuringEnable()

StatusSignalValue< bool > & ctre::phoenixpro::hardware::core::CoreCANcoder::GetStickyFault_BootDuringEnable ( )

Device boot while detecting the enable signal.

Default Value: False

Default Rates: CAN: 4.0 Hz

Returns
StickyFault_BootDuringEnable Status Signal Value object

◆ GetStickyFault_Hardware()

StatusSignalValue< bool > & ctre::phoenixpro::hardware::core::CoreCANcoder::GetStickyFault_Hardware ( )

Hardware fault occurred.

Default Value: False

Default Rates: CAN: 4.0 Hz

Returns
StickyFault_Hardware Status Signal Value object

◆ GetStickyFault_Undervoltage()

StatusSignalValue< bool > & ctre::phoenixpro::hardware::core::CoreCANcoder::GetStickyFault_Undervoltage ( )

Device supply voltage dropped to near brownout levels.

Default Value: False

Default Rates: CAN: 4.0 Hz

Returns
StickyFault_Undervoltage Status Signal Value object

◆ GetStickyFaultField()

StatusSignalValue< int > & ctre::phoenixpro::hardware::core::CoreCANcoder::GetStickyFaultField ( )

Integer representing all sticky faults.

This returns the persistent "sticky" fault flags reported by the device. These are device specific and are not used directly in typical applications. Use the signal specific GetStickyFault_*() methods instead.

Minimum Value: 0 Maximum Value: 1048575 Default Value: 0 Units:

Default Rates: CAN: 4.0 Hz

Returns
StickyFaultField Status Signal Value object

◆ GetSupplyVoltage()

StatusSignalValue< units::voltage::volt_t > & ctre::phoenixpro::hardware::core::CoreCANcoder::GetSupplyVoltage ( )

Measured supply voltage to the CANcoder.

Minimum Value: 4 Maximum Value: 16.75 Default Value: 4 Units: V

Default Rates: CAN 2.0: 10.0 Hz CAN FD: 100.0 Hz

Returns
SupplyVoltage Status Signal Value object

◆ GetUnfilteredVelocity()

StatusSignalValue< units::angular_velocity::turns_per_second_t > & ctre::phoenixpro::hardware::core::CoreCANcoder::GetUnfilteredVelocity ( )

The unfiltered velocity reported by CANcoder.

This is the unfiltered velocity reported by CANcoder. This signal does not use the fusing algorithm. It is also not timesynced. If you wish to use a signal with timesync, use Velocity.

Minimum Value: -8000.0 Maximum Value: 7999.755859375 Default Value: 0 Units: rotations per second

Default Rates: CAN 2.0: 10.0 Hz CAN FD: 100.0 Hz

Returns
UnfilteredVelocity Status Signal Value object

◆ GetVelocity()

StatusSignalValue< units::angular_velocity::turns_per_second_t > & ctre::phoenixpro::hardware::core::CoreCANcoder::GetVelocity ( )

Velocity of device.

Minimum Value: -512.0 Maximum Value: 511.998046875 Default Value: 0 Units: rotations per second

Default Rates: CAN: 100.0 Hz

Returns
Velocity Status Signal Value object

◆ GetVersion()

StatusSignalValue< int > & ctre::phoenixpro::hardware::core::CoreCANcoder::GetVersion ( )

Full Version.

The format is a four byte value.

Full Version of firmware in device. The format is a four byte value.

Minimum Value: 0 Maximum Value: 4294967295 Default Value: 0 Units:

Default Rates: CAN: 4.0 Hz

Returns
Version Status Signal Value object

◆ GetVersionBugfix()

StatusSignalValue< int > & ctre::phoenixpro::hardware::core::CoreCANcoder::GetVersionBugfix ( )

App Bugfix Version number.

Minimum Value: 0 Maximum Value: 255 Default Value: 0 Units:

Default Rates: CAN: 4.0 Hz

Returns
VersionBugfix Status Signal Value object

◆ GetVersionBuild()

StatusSignalValue< int > & ctre::phoenixpro::hardware::core::CoreCANcoder::GetVersionBuild ( )

App Build Version number.

Minimum Value: 0 Maximum Value: 255 Default Value: 0 Units:

Default Rates: CAN: 4.0 Hz

Returns
VersionBuild Status Signal Value object

◆ GetVersionMajor()

StatusSignalValue< int > & ctre::phoenixpro::hardware::core::CoreCANcoder::GetVersionMajor ( )

App Major Version number.

Minimum Value: 0 Maximum Value: 255 Default Value: 0 Units:

Default Rates: CAN: 4.0 Hz

Returns
VersionMajor Status Signal Value object

◆ GetVersionMinor()

StatusSignalValue< int > & ctre::phoenixpro::hardware::core::CoreCANcoder::GetVersionMinor ( )

App Minor Version number.

Minimum Value: 0 Maximum Value: 255 Default Value: 0 Units:

Default Rates: CAN: 4.0 Hz

Returns
VersionMinor Status Signal Value object

◆ HasResetOccurred()

bool ctre::phoenixpro::hardware::core::CoreCANcoder::HasResetOccurred ( )
Returns
true if device has reset since the previous call of this routine.

◆ operator=()

CoreCANcoder & ctre::phoenixpro::hardware::core::CoreCANcoder::operator= ( CoreCANcoder const &  )
delete

◆ SetControl() [1/2]

ctre::phoenix::StatusCode ctre::phoenixpro::hardware::core::CoreCANcoder::SetControl ( controls::ControlRequest &&  request)
inline

Control motor with generic control request object.

User must make sure the specified object is castable to a valid control request, otherwise this function will fail at run-time and return the corresponding StatusCode

Parameters
requestControl object to request of the device
Returns
Status Code of the request, 0 is OK

◆ SetControl() [2/2]

ctre::phoenix::StatusCode ctre::phoenixpro::hardware::core::CoreCANcoder::SetControl ( controls::ControlRequest request)
inline

Control motor with generic control request object.

User must make sure the specified object is castable to a valid control request, otherwise this function will fail at run-time and return the NotSupported StatusCode

Parameters
requestControl object to request of the device
Returns
Status Code of the request, 0 is OK

◆ SetPosition() [1/2]

ctre::phoenix::StatusCode ctre::phoenixpro::hardware::core::CoreCANcoder::SetPosition ( units::angle::turn_t  newValue)
inline

The position to set the sensor position to right now.

This will wait up to 0.050 seconds (50ms) by default.

Parameters
newValueValue to set to.
Returns
StatusCode of the set command

◆ SetPosition() [2/2]

ctre::phoenix::StatusCode ctre::phoenixpro::hardware::core::CoreCANcoder::SetPosition ( units::angle::turn_t  newValue,
units::time::second_t  timeoutSeconds 
)
inline

The position to set the sensor position to right now.

Parameters
newValueValue to set to.
timeoutSecondsMaximum time to wait up to in seconds.
Returns
StatusCode of the set command

The documentation for this class was generated from the following file: