Controls

class component_model.utils.controls.Controls(names: tuple[str, ...] = (), limits: tuple[tuple[tuple[float | None, float | None] | float | None, ...], ...] | None = None, limit_err: int = logging.WARNING)

Bases: object

Keep track of float variable changes.

  • Store and check possible float variable changes, including first and second derivatives

  • Set control goals. A goal is either None or a sequence of (time, acceleration) tuples. In this way an acceleration can be set or the velocity or position can be changed through the step function.

Parameters:
  • names (tuple[str]) – Tuple of name strings for the control variables to use. The names are only used internally an do not need to correlate with outside names and objects

  • limits – None or tuple of limits one per name. None means ‘no limit’ for variable(s), order or min/max. In general the (min,max) is provided for all orders, i.e. 3 tuples of 2-tuples of float per name. A given order can be fixed through min==max or by providing a single float instead of the tuple. The sub-orders of a fixed order do not need to be provided and are internally set to (0.0, 0,0)

  • limit_err – Determines how limit errors are dealt with. Anything below critical sets the value to the limit and provides a logger message. Critical leads to a program run error.

__init__(names: tuple[str, ...] = (), limits: tuple[tuple[tuple[float | None, float | None] | float | None, ...], ...] | None = None, limit_err: int = logging.WARNING)

Methods

__init__([names, limits, limit_err])

append(name, limits)

check_limit(ident, order, value)

getgoal(ident)

idx(name)

Find index from name.

limit(ident, order, minmax[, value])

Get/Set the single limit for 'idx', 'order', 'minmax'.

limits(ident, order[, value])

Get/Set the min/max limit for 'idx', 'order'.

setgoal(ident, order, value[, t0])

Set a new goal for 'ident', i.e. set the required time-acceleration sequence to reach value with all derivatives = 0.0.

step(time, dt)

Step towards the goals (if goals are set).

append(name: str, limits: tuple[tuple[float | None, float | None] | float | None, ...])
check_limit(ident: int | str, order: int, value: float) float | None
getgoal(ident: int | str) tuple
idx(name: str) int

Find index from name.

limit(ident: int | str, order: int, minmax: int, value: float | None = None) float

Get/Set the single limit for ‘idx’, ‘order’, ‘minmax’.

limits(ident: int | str, order: int, value: tuple | None = None) tuple[float, float]

Get/Set the min/max limit for ‘idx’, ‘order’.

setgoal(ident: int | str, order: int, value: float | None, t0: float = 0.0)

Set a new goal for ‘ident’, i.e. set the required time-acceleration sequence to reach value with all derivatives = 0.0.

Parameters:
  • ident (int|str) – the identificator of the control element (as integer or name)

  • order (int) – the order 0,1,2 of the goal to be set

  • value (float|None) – the goal value (acceleration, velocity or position) to be reached. None to unset the goal.

  • t0 (float) – the current time

step(time: float, dt: float)

Step towards the goals (if goals are set).