EncoderSim

class wpilib.simulation.EncoderSim(encoder: wpilib._wpilib.Encoder)

Bases: pybind11_object

Class to control a simulated encoder.

Constructs from an Encoder object.

Parameters:

encoder – Encoder to simulate

static create_for_channel(channel: SupportsInt | SupportsIndex) wpilib.simulation._simulation.EncoderSim

Creates an EncoderSim for a digital input channel. Encoders take two channels, so either one may be specified.

Parameters:

channel – digital input channel

Returns:

Simulated object @throws NoSuchElementException if no Encoder is configured for that channel

static create_for_index(index: SupportsInt | SupportsIndex) wpilib.simulation._simulation.EncoderSim

Creates an EncoderSim for a simulated index. The index is incremented for each simulated Encoder.

Parameters:

index – simulator index

Returns:

Simulated object

get_count() int

Read the count of the encoder.

Returns:

the count

get_direction() bool

Get the direction of the encoder.

Returns:

the direction of the encoder

get_distance() float

Read the distance of the encoder.

Returns:

the encoder distance

get_distance_per_pulse() float

Read the distance per pulse of the encoder.

Returns:

the encoder distance per pulse

get_initialized() bool

Read the Initialized value of the encoder.

Returns:

true if initialized

get_max_period() float

Get the max period of the encoder.

Returns:

the max period of the encoder

get_period() float

Read the period of the encoder.

Returns:

the encoder period

get_rate() float

Get the rate of the encoder.

Returns:

the rate of change

get_reset() bool

Check if the encoder has been reset.

Returns:

true if reset

get_reverse_direction() bool

Get the reverse direction of the encoder.

Returns:

the reverse direction of the encoder

get_samples_to_average() int

Get the samples-to-average value.

Returns:

the samples-to-average value

register_count_callback(callback: collections.abc.Callable[[str, hal._wpi_hal.Value], None], initial_notify: bool) wpilib.simulation._simulation.CallbackStore

Register a callback on the count property of the encoder.

Parameters:
  • callback – the callback that will be called whenever the count property is changed

  • initial_notify – if true, the callback will be run on the initial value

Returns:

the CallbackStore object associated with this callback

register_direction_callback(callback: collections.abc.Callable[[str, hal._wpi_hal.Value], None], initial_notify: bool) wpilib.simulation._simulation.CallbackStore

Register a callback on the direction of the encoder.

Parameters:
  • callback – the callback that will be called whenever the direction is changed

  • initial_notify – if true, the callback will be run on the initial value

Returns:

the CallbackStore object associated with this callback

register_distance_per_pulse_callback(callback: collections.abc.Callable[[str, hal._wpi_hal.Value], None], initial_notify: bool) wpilib.simulation._simulation.CallbackStore

Register a callback on the distance per pulse value of this encoder.

Parameters:
  • callback – the callback that will be called whenever the distance per pulse is changed

  • initial_notify – if true, the callback will be run on the initial value

Returns:

the CallbackStore object associated with this callback

register_initialized_callback(callback: collections.abc.Callable[[str, hal._wpi_hal.Value], None], initial_notify: bool) wpilib.simulation._simulation.CallbackStore

Register a callback on the Initialized property of the encoder.

Parameters:
  • callback – the callback that will be called whenever the Initialized property is changed

  • initial_notify – if true, the callback will be run on the initial value

Returns:

the CallbackStore object associated with this callback

register_max_period_callback(callback: collections.abc.Callable[[str, hal._wpi_hal.Value], None], initial_notify: bool) wpilib.simulation._simulation.CallbackStore

Register a callback to be run whenever the max period of the encoder is changed.

Parameters:
  • callback – the callback

  • initial_notify – whether to run the callback on the initial value

Returns:

the CallbackStore object associated with this callback

register_period_callback(callback: collections.abc.Callable[[str, hal._wpi_hal.Value], None], initial_notify: bool) wpilib.simulation._simulation.CallbackStore

Register a callback on the period of the encoder.

Parameters:
  • callback – the callback that will be called whenever the period is changed

  • initial_notify – if true, the callback will be run on the initial value

Returns:

the CallbackStore object associated with this callback

register_reset_callback(callback: collections.abc.Callable[[str, hal._wpi_hal.Value], None], initial_notify: bool) wpilib.simulation._simulation.CallbackStore

Register a callback to be called whenever the encoder is reset.

Parameters:
  • callback – the callback

  • initial_notify – whether to run the callback on the initial value

Returns:

the CallbackStore object associated with this callback

register_reverse_direction_callback(callback: collections.abc.Callable[[str, hal._wpi_hal.Value], None], initial_notify: bool) wpilib.simulation._simulation.CallbackStore

Register a callback on the reverse direction.

Parameters:
  • callback – the callback that will be called whenever the reverse direction is changed

  • initial_notify – if true, the callback will be run on the initial value

Returns:

the CallbackStore object associated with this callback

register_samples_to_average_callback(callback: collections.abc.Callable[[str, hal._wpi_hal.Value], None], initial_notify: bool) wpilib.simulation._simulation.CallbackStore

Register a callback on the samples-to-average value of this encoder.

Parameters:
  • callback – the callback that will be called whenever the samples-to-average is changed

  • initial_notify – if true, the callback will be run on the initial value

Returns:

the CallbackStore object associated with this callback

reset_data() None

Resets all simulation data for this encoder.

set_count(count: SupportsInt | SupportsIndex) None

Change the count of the encoder.

Parameters:

count – the new count

set_direction(direction: bool) None

Set the direction of the encoder.

Parameters:

direction – the new direction

set_distance(distance: SupportsFloat | SupportsIndex) None

Change the encoder distance.

Parameters:

distance – the new distance

set_distance_per_pulse(distance_per_pulse: SupportsFloat | SupportsIndex) None

Change the encoder distance per pulse.

Parameters:

distance_per_pulse – the new distance per pulse

set_initialized(initialized: bool) None

Change the Initialized value of the encoder.

Parameters:

initialized – the new value

set_max_period(max_period: SupportsFloat | SupportsIndex) None

Change the max period of the encoder.

Parameters:

max_period – the new value

set_period(period: SupportsFloat | SupportsIndex) None

Change the encoder period.

Parameters:

period – the new period

set_rate(rate: SupportsFloat | SupportsIndex) None

Change the rate of the encoder.

Parameters:

rate – the new rate

set_reset(reset: bool) None

Change the reset property of the encoder.

Parameters:

reset – the new value

set_reverse_direction(reverse_direction: bool) None

Set the reverse direction.

Parameters:

reverse_direction – the new value

set_samples_to_average(samples_to_average: SupportsInt | SupportsIndex) None

Set the samples-to-average value.

Parameters:

samples_to_average – the new value