Table of Contents

Class ParentDevice

Namespace
CTRE.Phoenix6.Hardware
Assembly
Phoenix6.Hardware.dll

Base class of Phoenix devices. This holds the base information for the devices, and can be used as a generic type to hold onto a collection of multiple devices.

public abstract class ParentDevice : CommonDevice
Inheritance
ParentDevice
Implements
Derived
Inherited Members

Constructors

ParentDevice(int, string, CANBus)

Constructor for a device

public ParentDevice(int deviceID, string model, CANBus canbus)

Parameters

deviceID int

ID of the device

model string

Model of the device

canbus CANBus

CANbus the device is on

Fields

deviceIdentifier

The unique deviceIdentifier for this device.

protected readonly DeviceIdentifier deviceIdentifier

Field Value

DeviceIdentifier

Properties

AppliedControl

The latest applied control request. Caller can cast this to the derived class if they know its type. Otherwise, use GetControlInfo() to get info out of it.

public ControlRequest AppliedControl { get; }

Property Value

ControlRequest

DeviceHash

Hash of this device.

public uint DeviceHash { get; }

Property Value

uint

DeviceID

ID of this device.

public int DeviceID { get; }

Property Value

int

HasResetOccurred

Returns true if device has reset since the previous call of this routine.

public bool HasResetOccurred { get; }

Property Value

bool

Network

Network this device is on.

public CANBus Network { get; }

Property Value

CANBus

Methods

GetResetOccurredChecker()

Return a lambda that checks for device resets

public Func<bool> GetResetOccurredChecker()

Returns

Func<bool>

IsConnected(double)

Returns whether the device is still connected to the robot. This is equivalent to refreshing and checking the latency of the Version status signal.

public bool IsConnected(double maxLatencySeconds = 0.5)

Parameters

maxLatencySeconds double

The maximum latency of the Version status signal before the device is reported as disconnected

Returns

bool

true if the device is connected

LookupStatusSignal<T>(ushort, string, bool, bool)

Looks up a status signal and inserts it into the local dictionary if not found

protected StatusSignal<T> LookupStatusSignal<T>(ushort spn, string signalName, bool reportOnConstruction, bool refresh)

Parameters

spn ushort

SPN index to lookup

signalName string

Name of signal

reportOnConstruction bool

Whether to report errors on construction

refresh bool

Whether to refresh the status signal before returning

Returns

StatusSignal<T>

Status code of the lookup

Type Parameters

T

Generic type of StatusSignal to get

LookupStatusSignal<T>(ushort, string, Func<Dictionary<ushort, string>>, bool, bool)

Looks up a status signal and inserts it into the local dictionary if not found

protected StatusSignal<T> LookupStatusSignal<T>(ushort spn, string signalName, Func<Dictionary<ushort, string>> generator, bool reportOnConstruction, bool refresh)

Parameters

spn ushort

SPN index to lookup

signalName string

Name of signal

generator Func<Dictionary<ushort, string>>

The generator for a map

reportOnConstruction bool

Whether to report errors on construction

refresh bool

Whether to refresh the status signal before returning

Returns

StatusSignal<T>

Status code of the lookup

Type Parameters

T

Generic type of StatusSignal to get

OptimizeBusUtilization(double, double)

Optimizes the device's bus utilization by reducing the update frequencies of its status signals.

All status signals that have not been explicitly given an update frequency using SetUpdateFrequency(double, double) will be slowed down. Note that if other status signals in the same status frame have been given an update frequency, the update frequency will be honored for the entire frame.

This function only needs to be called once on this device in the robot program. Additionally, this method does not necessarily need to be called after setting the update frequencies of other signals.

To restore the default status update frequencies, call ResetSignalFrequencies(double). Alternatively, remove this method call, redeploy the robot application, and power-cycle the device on the bus. The user can also override individual status update frequencies using SetUpdateFrequency(double, double).
public StatusCode OptimizeBusUtilization(double optimizedFreqHz = 4, double timeoutSeconds = 0.1)

Parameters

optimizedFreqHz double

The update frequency to apply to the optimized status signals. A frequency of 0 Hz will turn off the signals. Otherwise, the minimum supported signal frequency is 4 Hz (default).

timeoutSeconds double

Maximum amount of time to wait for each status frame when performing the action

Returns

StatusCode

Status code of the first failed update frequency set call, or OK if all succeeded

OptimizeBusUtilizationForAll(params IEnumerable<CommonDevice>)

Optimizes the bus utilization of the provided devices by reducing the update frequencies of their status signals. This API defaults to an optimized update frequency of 4 Hz to preserve log data.

All status signals that have not been explicitly given an update frequency using SetUpdateFrequency(double, double) will be slowed down. Note that if other status signals in the same status frame have been given an update frequency, the update frequency will be honored for the entire frame.

This function only needs to be called once in the robot program for the provided devices. Additionally, this method does not necessarily need to be called after setting the update frequencies of other signals.

To restore the default status update frequencies, call ResetSignalFrequenciesForAll(params IEnumerable<CommonDevice>). Alternatively, remove this method call, redeploy the robot application, and power-cycle the devices on the bus. The user can also override individual status update frequencies using SetUpdateFrequency(double, double).

This will wait up to 0.100 seconds (100ms) for each status frame.
public static StatusCode OptimizeBusUtilizationForAll(params IEnumerable<CommonDevice> devices)

Parameters

devices IEnumerable<CommonDevice>

Devices for which to opimize bus utilization

Returns

StatusCode

Status code of the first failed optimize call, or OK if all succeeded

OptimizeBusUtilizationForAll(double, params IEnumerable<CommonDevice>)

Optimizes the bus utilization of the provided devices by reducing the update frequencies of their status signals.

All status signals that have not been explicitly given an update frequency using SetUpdateFrequency(double, double) will be slowed down. Note that if other status signals in the same status frame have been given an update frequency, the update frequency will be honored for the entire frame.

This function only needs to be called once in the robot program for the provided devices. Additionally, this method does not necessarily need to be called after setting the update frequencies of other signals.

To restore the default status update frequencies, call ResetSignalFrequenciesForAll(params IEnumerable<CommonDevice>). Alternatively, remove this method call, redeploy the robot application, and power-cycle the devices on the bus. The user can also override individual status update frequencies using SetUpdateFrequency(double, double).

This will wait up to 0.100 seconds (100ms) for each status frame.
public static StatusCode OptimizeBusUtilizationForAll(double optimizedFreqHz, params IEnumerable<CommonDevice> devices)

Parameters

optimizedFreqHz double

The update frequency to apply to the optimized status signals. A frequency of 0 Hz will turn off the signals. Otherwise, the minimum supported signal frequency is 4 Hz (default).

devices IEnumerable<CommonDevice>

Devices for which to opimize bus utilization

Returns

StatusCode

Status code of the first failed optimize call, or OK if all succeeded

ResetSignalFrequencies(double)

Resets the update frequencies of all the device's status signals to the defaults.

This restores the default update frequency of all status signals, including status signals explicitly given an update frequency using SetUpdateFrequency(double, double) and status signals optimized out using OptimizeBusUtilization(double, double).
public StatusCode ResetSignalFrequencies(double timeoutSeconds = 0.1)

Parameters

timeoutSeconds double

Maximum amount of time to wait for each status frame when performing the action

Returns

StatusCode

Status code of the first failed update frequency set call, or OK if all succeeded

ResetSignalFrequenciesForAll(params IEnumerable<CommonDevice>)

Resets the update frequencies of all the devices' status signals to the defaults.

This restores the default update frequency of all status signals, including status signals explicitly given an update frequency using SetUpdateFrequency(double, double) and status signals optimized out using OptimizeBusUtilizationForAll(double, params IEnumerable<CommonDevice>).

This will wait up to 0.100 seconds (100ms) for each status frame.
public static StatusCode ResetSignalFrequenciesForAll(params IEnumerable<CommonDevice> devices)

Parameters

devices IEnumerable<CommonDevice>

Devices for which to restore default update frequencies

Returns

StatusCode

Status code of the first failed restore call, or OK if all succeeded

SetControlPrivate(ControlRequest)

Sets the control request to this device

protected StatusCode SetControlPrivate(ControlRequest request)

Parameters

request ControlRequest

Control request to set

Returns

StatusCode

Status code of control set