unienv_interface.utils.control_util¶
Functions:
| Name | Description |
|---|---|
find_best_timestep |
Compute the simulation timestep dt such that every sensor period is an |
is_integer_multiple |
Return whether |
Attributes:
| Name | Type | Description |
|---|---|---|
Number |
|
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. |
is_integer_multiple
¶
Return whether value is a positive integer multiple (k >= 1) of base.
Uses a relative tolerance on value / base instead of float %, which
is unreliable for decimal periods (e.g. 0.1 % 0.02 != 0).