State Machine Approach#

Derive from an abstract state that automatically handles shutdown checks.

State Machine Approach for User Use#

Abstract base class for all robot behavior states.

Users create custom states by inheriting from this class and implementing the execute() method. This approach is completely optional. It is solely available for those who are comfortable with a more advanced approach.

This framework provides:
  • Automatic loop cancellation

  • Safe shutdown handling

  • Consistent state lifecycle hooks

class go2.states.robot_state.Go2StateAbstract(unitree_controller: Go2Controller)[source]#

Bases: ABC

Abstract base class for robot behavior states.

cancel() None[source]#

Request cancellation of the current state.

Notes

  • This flag can be checked manually by user logic

  • Loop-based logic is already auto-cancellable

final check_shutdown()[source]#

Check whether the system is shutting down.

Raises:

KeyboardInterrupt – If the controller shutdown event is set

abstract execute(*args, **kwargs) Any[source]#

Main execution logic for the state.

This method is automatically instrumented to support safe shutdown. Any for or while loop inside this method will automatically check for system shutdown.

Notes

  • Long-running logic is safe by default

on_enter()[source]#

Called when the state becomes active.

Sets internal running flags.

on_exit()[source]#

Called when the state exits.

Cleans up internal state.