Go2 Controller#
This module provides the primary public API for controlling the Unitree Go2 robot.
Users should interact exclusively with Go2Controller, which exposes
high-level functionality such as movement, video, audio, OCR, input, and LIDAR through properties.
- class go2.core.controller.Go2Controller(hardware_type: HardwareType, execution_mode: ExecutionMode = ExecutionMode.BASIC)[source]#
Bases:
objectPrimary control interface for the Unitree Go2 robot.
This class is the main entry point that users interact with. It manages hardware initialization, module lifecycles, safety checks, and shutdown.
Modules are accessed via properties rather than direct instantiation.
Notes
All hardware access is routed through this controller.
Modules creation, initialization, and shutdown is handled automatically.
Supports both SDK-backed hardware and a Mujoco simulation.
See also
DogModule,ModuleRegistry- add_module(module_type: ModuleType, **kwargs) None[source]#
Add a module to the controller. Modules are initialized immediately upon addition. Manual module initialization is discouraged and should not be attempted. Duplicate module addition is prevented explicitly.
Modules are identified using
ModuleTypeenums.- Parameters:
module_type (ModuleType) – The type of module to add.
**kwargs – Constructor arguments passed to the module implementation.
- Raises:
ValueError – If the module type is not registered.
ValueError – If the module type depends on native hardware support, but the controller is not set up to provide it.
- property audio: AudioModule#
Access the audio control module.
- Raises:
RuntimeError – If the module is not loaded or shutdown has been requested.
- has_module(module_type: ModuleType) bool[source]#
Check whether a module is currently loaded.
- property input: InputModule#
Access the input control module.
- Raises:
RuntimeError – If the module is not loaded or shutdown has been requested.
- property lidar: LIDARModule#
Access the lidar control module.
- Raises:
RuntimeError – If the module is not loaded or shutdown has been requested.
- property movement: MovementModule#
Access the movement control module.
- Raises:
RuntimeError – If the module is not loaded or shutdown has been requested.
- property ocr: OCRModule#
Access the ocr control module.
- Raises:
RuntimeError – If the module is not loaded or shutdown has been requested.
- register_cleanup_callback_post_module_shutdown(callback: Callable[[], None])[source]#
Register a cleanup callback to be executed during safe shutdown after modules are stopped, but before hardware is released.
- Parameters:
callback (callable) – Zero-argument function to execute during shutdown.
- register_cleanup_callback_pre_module_shutdown(callback: Callable[[], None])[source]#
Register a cleanup callback to be executed during safe shutdown before modules are stopped and before hardware is released.
- Parameters:
callback (callable) – Zero-argument function to execute during shutdown.
- safe_shutdown()[source]#
Perform a coordinated and safe shutdown.
- This method:
Stops movement immediately
Signals shutdown to all subsystems
Shuts down all modules
Executes registered cleanup callbacks
Releases hardware resources
Important
Select modules depend on ROS2 nodes. These lifetime of these nodes must handled cleanly on process termination. Therefore, it is critical that students ALWAYS call
safe_shutdown()to ensure proper shutdown of ROS2. This called automatically on process crash (via SIGINT or SIGTERM). However, it is fully the user’s responsibility to call this method upon normal (error free) script exit. Failing to follow this can (and probably will) result in zombie ROS2 processes, unreleased resources, and UB.Notes
This method is idempotent and may be safely called multiple times.
- property video: VideoModule#
Access the video capture module.
- Raises:
RuntimeError – If the module is not loaded or shutdown has been requested.
Hardware Support Types#
- class go2.hardware.hardware_type.HardwareType(value)[source]#
Bases:
EnumEnumeration passed upon creation of a
Go2Controllerinstance.- NATIVE = 1#
Commands should act upon an actual Unitree-Go2 robot.
- VIRTUAL = 2#
Commands should act upon the simulator (launched on controller creation in ‘VIRTUAL’ mode).
Module Management#
- class go2.core.registry.ExecutionMode(value)[source]#
Bases:
EnumEnumeration passed upon creation of a
Go2Controllerinstance. Dicates the available modules based on system installed packages.Installation for all dependencies can be found here: https://github.com/7Swaize/go2-control/blob/main/docs/public/install/installation.md
- ADVANCED = 2#
Allows access to ALL modules.
- BASIC = 1#
Restricts access to the
LIDARmodule.
- class go2.core.registry.ModuleType(value)[source]#
Bases:
EnumEnumeration of all supported default module categories.
This enum is used by the module registry to identify and construct modules dynamically.
- AUDIO = 5#
- INPUT = 3#
- LIDAR = 6#
- MOVEMENT = 2#
- OCR = 4#
- VIDEO = 1#
- class go2.core.registry.ModuleRegistry[source]#
Bases:
objectCentral registry for all available modules.
The registry maps
ModuleTypevalues to their corresponding implementations and metadata. It is responsible for controlling which modules are available based on system configuration.Notes
This is an internal system component.
Modules are registered at startup.
- classmethod get_class(module_type: ModuleType) Type[DogModule] | None[source]#
Retrieve the implementation class for a module type.
- classmethod get_descriptor(module_type: ModuleType) ModuleDescriptor | None[source]#
Retrieve the descriptor for a module type.
- classmethod is_registered(module_type: ModuleType) bool[source]#
Check whether a module type is registered.
Go2ControllerGo2Controller.add_module()Go2Controller.audioGo2Controller.has_module()Go2Controller.inputGo2Controller.is_shutdown_requested()Go2Controller.lidarGo2Controller.movementGo2Controller.ocrGo2Controller.register_cleanup_callback_post_module_shutdown()Go2Controller.register_cleanup_callback_pre_module_shutdown()Go2Controller.safe_shutdown()Go2Controller.video