State Validation (Internal)#

Warning

This section documents internal robot state management. Users should not use these classes directly.

Internal infrastructure for safely cancelling long-running state execution loops by injecting shutdown checks into user-defined code.

This system automatically modifies the AST (Abstract Syntax Tree) of state execute() methods at class creation time, inserting cancellation checks inside all for and while loops.

Purpose#

  • Prevent infinite or blocking loops in user-written state logic

  • Allow graceful shutdown when the robot or controller exits

  • Avoid requiring users to manually check shutdown flags

This is an internal system and should not be directly used or modified by user code.

class go2.states.validation.CancellableMeta(name, bases, attrs)[source]#

Bases: ABCMeta

Metaclass that injects loop cancellation logic into execute() methods.

If a class defines an execute method: - Its source code is retrieved - Parsed into an AST - All loops are instrumented with shutdown checks - The modified function replaces the original

If any step fails, the original method is preserved.

class go2.states.validation.LoopCancellationInjector[source]#

Bases: NodeTransformer

AST transformer that injects shutdown checks into loop bodies.

This transformer modifies: - while loops - for loops

by inserting a call to self.check_shutdown() as the first statement in each loop body.

Notes

  • Assumes the transformed method belongs to a class defining check_shutdown()

  • Used exclusively by CancellableMeta