Control¶
- class component_model.utils.controls.Control(name: str, limits: tuple[tuple[float | None, float | None] | float | None, ...], rw: RW)¶
Bases:
objectKeep track of the changes of a single float variable, avoiding discontinuities and abrupt changes.
Based on the ranges of value, speed, acceleration, the following rules are used:
Instantaneous acceleration changes (within the limits set for acceleration) are allowed
When a goal is reached, the goal value (variable value, first or second derivation) is kept ‘forever’
Derivatives above 2nd order are not considered.
The goal shall be reached in as short time as possible.
Store and check possible float variable changes, including first and second derivatives
Set control goals as list of goals, one goal per control variable.
A single goal is either None (currently inactive) or a tuple 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:
name (str) – Name of control variable. Unique within Controls. 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)
rw (RW) – getter/setter function for the variable related to the control. The function shall have a single optional (float or None) argument and return the value of the variable. If omittet, or None, only the current value is returned. If not None, the new value is set and returned.
Methods
__init__(name, limits, rw)check_limit(order, value)limit(order, minmax[, value])Get/Set the limit for the Control, 'order', 'minmax'.
limits(order[, value])Get/Set the min/max limit for 'idx', 'order'.
setgoal(order, value[, speed, acc])Set a new goal for the control, i.e. set the required time-acceleration sequence to reach value with all derivatives = 0.0.
step(time, dt)Step towards the goal (if goal is set).
Attributes
Return the tuple of current value, speed and acceleration.
Read-only property to access the read/write function.
- check_limit(order: int, value: float) float¶
- limit(order: int, minmax: int, value: float | None = None) float¶
Get/Set the limit for the Control, ‘order’, ‘minmax’.
- limits(order: int, value: tuple[float, float] | None = None) tuple[float, float]¶
Get/Set the min/max limit for ‘idx’, ‘order’.
- setgoal(order: int, value: float | None, speed: float | None = None, acc: float | None = None)¶
Set a new goal for the control, i.e. set the required time-acceleration sequence to reach value with all derivatives = 0.0.
Note
Initially the start-time for the goal sequence is unknown and is set to zero. At the first step the current time is added to these times
- Parameters:
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.
speed (float) – Optional possibility to set a start-speed != 0.0. None: keep the internally stored value
acc (float) – Optional possibility to set a start-acceleration != 0.0. None: keep the internally stored value
- step(time: float, dt: float)¶
Step towards the goal (if goal is set).
- property current¶
Return the tuple of current value, speed and acceleration.