@@ -19,62 +19,6 @@ class RW(Protocol):
1919 def __call__ (self , val : float | None = None , / ) -> float : ...
2020
2121
22- class Controls (object ):
23- """Keep track of float variable changes.
24-
25- limit_err: Determines how limit errors are dealt with.
26- Anything below critical sets the value to the limit and provides a logger message.
27- Critical leads to a program run error.
28- """
29-
30- limit_err : int = logging .WARNING
31-
32- def __init__ (
33- self ,
34- limit_err : int = logging .WARNING ,
35- ):
36- Controls .limit_err = limit_err
37- self .controls : list ["Control" ] = []
38-
39- @property
40- def nogoals (self ):
41- for crl in self .controls :
42- if len (crl .goal ):
43- return False
44- return True
45-
46- def extend (self , crls : tuple ["Control" , ...]):
47- for crl in crls :
48- self .append (crl )
49-
50- def append (self , crl : "Control" ):
51- """Append one or several Control object(s)."""
52- for c in self .controls :
53- if c .name == crl .name :
54- raise KeyError (f"Control with name { c .name } already exists. Choose a unique name." ) from None
55- self .controls .append (crl )
56-
57- def __getitem__ (self , ident : int | str ):
58- """Get the control object identified by ident (index within .controls or valid name)."""
59- if isinstance (ident , str ):
60- for crl in self .controls :
61- if crl .name == ident :
62- return crl
63- raise KeyError (f"Control with name { ident } not found." ) from None
64- elif isinstance (ident , int ):
65- if ident < 0 or ident >= len (self .controls ):
66- raise ValueError (f"Control { ident } does not exist within set of controls." ) from None
67- return self .controls [ident ]
68- else :
69- raise TypeError (f"Integer expected as subscript. Found { ident } " ) from None
70-
71- def step (self , time : float , dt : float ):
72- """Step towards the goals (if goals are set)."""
73- if not self .nogoals :
74- for crl in self .controls :
75- crl .step (time , dt )
76-
77-
7822class Control (object ):
7923 """Keep track of the changes of a single float variable, avoiding discontinuities and abrupt changes.
8024
@@ -194,7 +138,7 @@ def check_limit(self, order: int, value: float) -> float:
194138 return lim
195139 return value
196140
197- def setgoal (self , order : int , value : float | None , speed : float | None = 0.0 , acc : float | None = 0.0 ):
141+ def setgoal (self , order : int , value : float | None , speed : float | None = None , acc : float | None = None ):
198142 """Set a new goal for the control, i.e. set the required time-acceleration sequence
199143 to reach value with all derivatives = 0.0.
200144
@@ -285,7 +229,6 @@ def setgoal(self, order: int, value: float | None, speed: float | None = 0.0, ac
285229 (t0 + dt1 + dt2 + dt3 , acc2 ),
286230 (float ("inf" ), 0.0 ),
287231 ]
288- logger .info (f"New goal({ self .name } ): { self .goal } " )
289232 self .started = False
290233
291234 @property
@@ -299,6 +242,7 @@ def step(self, time: float, dt: float):
299242 if not self .started : # not yet started. Need to add current time.
300243 for i , (t , a ) in enumerate (self .goal ):
301244 self .goal [i ] = (t + time , a )
245+ logger .info (f"@{ time } . New goal({ self .name } ): { self .goal } " )
302246 self .started = True
303247 _t , self .acc = self .goal [0 ]
304248 if time > _t : # move to correct goal entry
@@ -317,4 +261,61 @@ def step(self, time: float, dt: float):
317261 _t , self .acc = self .goal [0 ]
318262
319263 if np .isinf (_t ) and abs (self .acc ) < 1e-12 and abs (self .speed ) < 1e-12 :
264+ logger .info (f"@{ time } . Goal { self .name } finalized." )
320265 self .goal = []
266+
267+
268+ class Controls (object ):
269+ """Keep track of float variable changes.
270+
271+ limit_err: Determines how limit errors are dealt with.
272+ Anything below critical sets the value to the limit and provides a logger message.
273+ Critical leads to a program run error.
274+ """
275+
276+ limit_err : int = logging .WARNING
277+
278+ def __init__ (
279+ self ,
280+ limit_err : int = logging .WARNING ,
281+ ):
282+ Controls .limit_err = limit_err
283+ self .controls : list [Control ] = []
284+
285+ @property
286+ def nogoals (self ):
287+ for crl in self .controls :
288+ if len (crl .goal ):
289+ return False
290+ return True
291+
292+ def append (self , crl : "Control" ):
293+ """Append one or several Control object(s)."""
294+ for c in self .controls :
295+ if c .name == crl .name :
296+ raise KeyError (f"Control with name { c .name } already exists. Choose a unique name." ) from None
297+ self .controls .append (crl )
298+
299+ def extend (self , crls : tuple [Control , ...]):
300+ for crl in crls :
301+ self .append (crl )
302+
303+ def __getitem__ (self , ident : int | str ):
304+ """Get the control object identified by ident (index within .controls or valid name)."""
305+ if isinstance (ident , str ):
306+ for crl in self .controls :
307+ if crl .name == ident :
308+ return crl
309+ raise KeyError (f"Control with name { ident } not found." ) from None
310+ elif isinstance (ident , int ):
311+ if ident < 0 or ident >= len (self .controls ):
312+ raise ValueError (f"Control { ident } does not exist within set of controls." ) from None
313+ return self .controls [ident ]
314+ else :
315+ raise TypeError (f"Integer expected as subscript. Found { ident } " ) from None
316+
317+ def step (self , time : float , dt : float ):
318+ """Step towards the goals (if goals are set)."""
319+ if not self .nogoals :
320+ for crl in self .controls :
321+ crl .step (time , dt )
0 commit comments