pyrcf.utils.filters

Attributes

QuatType

Numpy array representating quaternion in format [x,y,z,w]

Functions

bounded_derivative_filter(→ float)

Filter signal so that its output and output derivative stay within bounds.

abs_bounded_derivative_filter(→ float)

Filter signal so that the absolute values of its output and output

first_order_filter(→ float | numpy.ndarray)

First order filter.

second_order_filter(→ float | numpy.ndarray)

Second-order filter for data stream, interpolating from current to desired value.

low_pass_filter(→ float | numpy.ndarray)

Low-pass filter.

quaternion_slerp(→ QuatType)

Get the slerp smoothed quaternion value between quat1 and quat2 at the time

Module Contents

pyrcf.utils.filters.QuatType: TypeAlias = np.ndarray

Numpy array representating quaternion in format [x,y,z,w]

pyrcf.utils.filters.bounded_derivative_filter(prev_output: float, new_input: float, dt: float, output_bounds: Tuple[float, float], derivative_bounds: Tuple[float, float]) float

Filter signal so that its output and output derivative stay within bounds.

Parameters:
  • prev_output (float) – Previous filter output, or initial value.

  • new_input (float) – New filter input.

  • dt (float) – Sampling period in [s].

  • output_bounds (Tuple[float, float]) – Min and max value for the output.

  • derivative_bounds (Tuple[float, float]) – Min and max value for the output derivative.

Returns:

New filter output.

Return type:

float

pyrcf.utils.filters.abs_bounded_derivative_filter(prev_output: float, new_input: float, dt: float, max_output: float, max_derivative: float) float

Filter signal so that the absolute values of its output and output derivative stay within bounds.

Parameters:
  • prev_output (float) – Previous filter output, or initial value.

  • new_input (float) – New filter input.

  • dt (float) – Sampling period in [s].

  • max_output (float) – Maximum absolute value of the output.

  • max_derivative (float) – Maximum absolute value of the output derivative.

Returns:

New filter output.

Return type:

float

pyrcf.utils.filters.first_order_filter(current_value: float | numpy.ndarray, desired_value: float | numpy.ndarray, gain: float) float | numpy.ndarray

First order filter.

Parameters:
  • current_value (float | np.ndarray) – Current value.

  • desired_value (float | np.ndarray) – Target value.

  • gain (float) – Filter gain (applied to target during interpolation).

Returns:

Output from filter.

Return type:

float | np.ndarray

pyrcf.utils.filters.second_order_filter(current_value: float | numpy.ndarray, desired_value: float | numpy.ndarray, gain: float) float | numpy.ndarray

Second-order filter for data stream, interpolating from current to desired value.

Parameters:
  • current_value (float | np.ndarray) – Current value.

  • desired_value (float | np.ndarray) – Target value.

  • gain (float) – Filter gain (applied to first-order filtered target during interpolation)

Returns:

Output from filter.

Return type:

float | np.ndarray

pyrcf.utils.filters.low_pass_filter(prev_output: float | numpy.ndarray, new_input: float | numpy.ndarray, dt: float = None, cutoff_period: float = None) float | numpy.ndarray

Low-pass filter.

Parameters:
  • prev_output (float|np.ndarray) – Previous filter output, or initial value.

  • new_input (float|np.ndarray) – New filter input.

  • dt (float) – Sampling period in [s]. Defaults to None (will select based on Nyquist-Shannon limit to avoid aliasing).

  • cutoff_period (float, optional) – Time constant of the filter in [s]. Defaults to None (will select based on Nyquist-Shannon limit to avoid aliasing).

  • NOTE – dt/cutoff_period should be < 0.5 to respect Nyquist-Shannon sampling theorem.

Returns:

New filter output.

Return type:

float|np.ndarray

pyrcf.utils.filters.quaternion_slerp(quat1: QuatType, quat2: QuatType, interpolation_param: float) QuatType

Get the slerp smoothed quaternion value between quat1 and quat2 at the time ratio given by interpolation_param.

Parameters:
  • quat1 (QuatType) – Starting quaternion

  • quat2 (QuatType) – Target quaternion

  • interpolation_param (float) – Value between 0 and 1. 0 = quat1, 1 = quat2.

Returns:

Numpy array representing a quaternion in order (x,y,z,w)

Return type:

QuatType