Skip to content

unienv_interface.utils.control_util

Number module-attribute

Number = Union[int, float]

find_best_timestep

find_best_timestep(timesteps: Iterable[Number], *, max_denominator: int = 10000, return_fraction: bool = False) -> Tuple[Union[float, Fraction], List[int]]

Compute the simulation timestep dt such that every sensor period is an integer multiple of dt (i.e., dt is the GCD of the periods). Works with floats.

Parameters:

Name Type Description Default
timesteps Iterable[Number]

Iterable of sensor periods (seconds, ms, etc.). Must be > 0.

required
max_denominator int

Max denominator when rational-approximating floats. Increase if your periods are very fine-grained.

10000
return_fraction bool

If True, returns dt as a Fraction; otherwise a float.

False

Returns:

Name Type Description
dt Union[float, Fraction]

The best simulation timestep (float or Fraction).

steps_per_sensor List[int]

For each input period T_i, the integer k_i = T_i / dt.

Raises:

Type Description
ValueError

If list is empty or contains non-positive values.