pub struct CANifier { /* private fields */ }
Expand description
CTRE CANifier
Device for interfacing common devices to the CAN bus.
Implementations§
source§impl CANifier
impl CANifier
sourcepub fn new(device_number: i32) -> CANifier
pub fn new(device_number: i32) -> CANifier
Constructor.
device_number
- The CAN Device ID of the CANifier.
pub fn _set_led_output(
&self,
duty_cycle: u32,
led_channel: LEDChannel
) -> ErrorCode
pub fn set_led_output(
&self,
percent_output: f64,
led_channel: LEDChannel
) -> ErrorCode
sourcepub fn set_general_outputs(
&self,
outputs_bits: u32,
is_output_bits: u32
) -> ErrorCode
pub fn set_general_outputs(
&self,
outputs_bits: u32,
is_output_bits: u32
) -> ErrorCode
Sets the output of all General Pins
output_bits
- A bit mask of all the output states. LSB->MSB is in the order of the GeneralPin enum.is_output_bits
- A boolean bit mask that sets the pins to be outputs or inputs. A bit of 1 enables output.
pub fn set_general_output(
&self,
output_pin: GeneralPin,
output_value: bool,
output_enable: bool
) -> ErrorCode
pub fn _set_pwm_output(&self, pwm_channel: u32, duty_cycle: u32) -> ErrorCode
sourcepub fn set_pwm_output(
&self,
pwm_channel: PWMChannel,
duty_cycle: f64
) -> ErrorCode
pub fn set_pwm_output(
&self,
pwm_channel: PWMChannel,
duty_cycle: f64
) -> ErrorCode
Sets the PWM Output Currently supports PWM 0, PWM 1, and PWM 2
pwm_channel
- Index of the PWM channel to output.duty_cycle
- Duty Cycle (0 to 1) to output. Default period of the signal is 4.2 ms.
pub fn _enable_pwm_output(&self, pwm_channel: u32, b_enable: bool) -> ErrorCode
sourcepub fn enable_pwm_output(
&self,
pwm_channel: PWMChannel,
enable: bool
) -> ErrorCode
pub fn enable_pwm_output(
&self,
pwm_channel: PWMChannel,
enable: bool
) -> ErrorCode
Enables PWM Outputs Currently supports PWM 0, PWM 1, and PWM 2
pub fn _get_general_inputs(&self, all_pins: &mut [bool]) -> ErrorCode
sourcepub fn get_general_inputs(&self) -> Result<PinValues>
pub fn get_general_inputs(&self) -> Result<PinValues>
Gets the state of all General Pins
sourcepub fn get_general_input(&self, input_pin: GeneralPin) -> Result<bool>
pub fn get_general_input(&self, input_pin: GeneralPin) -> Result<bool>
Gets the state of the specified pin
sourcepub fn get_pwm_input(&self, pwm_channel: PWMChannel) -> Result<[f64; 2]>
pub fn get_pwm_input(&self, pwm_channel: PWMChannel) -> Result<[f64; 2]>
Gets the PWM Input. Returns a 2-array holding the Pulse Width (microseconds) [0] and Period (microseconds) [1].
pub fn get_last_error(&self) -> ErrorCode
pub fn get_bus_voltage(&self) -> Result<f64>
pub fn get_quadrature_position(&self) -> Result<i32>
pub fn set_quadrature_position(&self, pos: i32, timeout_ms: i32) -> ErrorCode
pub fn get_quadrature_velocity(&self) -> Result<i32>
sourcepub fn config_velocity_measurement_period(
&self,
period: VelocityMeasPeriod,
timeout_ms: i32
) -> ErrorCode
pub fn config_velocity_measurement_period(
&self,
period: VelocityMeasPeriod,
timeout_ms: i32
) -> 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.
pub fn config_velocity_measurement_window(
&self,
window: i32,
timeout_ms: i32
) -> ErrorCode
sourcepub fn config_set_parameter(
&self,
param: ParamEnum,
value: f64,
sub_value: i32,
ordinal: i32,
timeout_ms: i32
) -> ErrorCode
pub fn config_set_parameter(
&self,
param: ParamEnum,
value: f64,
sub_value: i32,
ordinal: i32,
timeout_ms: i32
) -> 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.
pub fn config_get_parameter(
&self,
param: ParamEnum,
ordinal: i32,
timeout_ms: i32
) -> Result<f64>
sourcepub fn config_set_custom_param(
&self,
new_value: i32,
param_index: i32,
timeout_ms: i32
) -> ErrorCode
pub fn config_set_custom_param(
&self,
new_value: i32,
param_index: i32,
timeout_ms: i32
) -> 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.
new_value
- Value for custom parameter.param_index
- Index of custom parameter [0,1]timeout_ms
- 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.
sourcepub fn config_get_custom_param(
&self,
param_index: i32,
timout_ms: i32
) -> Result<i32>
pub fn config_get_custom_param(
&self,
param_index: i32,
timout_ms: i32
) -> Result<i32>
Gets the value of a custom parameter. This is for arbitrary use.
param_index
- Index of custom parameter [0,1].timeout_ms
- 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.