arcor2
arcor2 copied to clipboard
Support for loops
- User-defined function can be passed as a parameter to the “for_loop” action (this can be probably made in a generic way, not just for the purpose of cycles).
- Loop itself is action calling given function, with provided parameters.
- Depends on #430.
The code will approximately be like:
def function_1(obj: Generic, idx: int, *, an: Optional[str] = None) -> None:
obj.hooray(idx, an="action_name_2")
def main():
...
obj.nop() # just to show that it is there
...
cycles.for_loop(function_1, 0, 10, 1, {"action_name": "a1_for_body", "obj": obj}, an="a1_for")
class Cycles(Generic):
def for_loop(start: float = 0, stop: float = 10, step: float = 1, loop_body: Callable, loop_body_params: List[ActionParameter], *, an: Optional[str] = None) -> None:
params_dict = loop_body_params_to_dict(loop_body_params)
for idx in range(start, stop, step):
params_dict["idx"] = idx
loop_body(**params_dict)
Current state: prepared data structures, no support at all.