GDK Common Interface Documentation (Python)¶
Overview¶
The GDK (Genie Development Kit) common interface provides the core functionality for system initialization and resource release. Through the Python interface, developers can conveniently manage the lifecycle of the GDK system, ensuring that all GDK functionality is used correctly.
Interface Description¶
1. gdk_init()¶
- Function: Initialize the GDK system
- Parameters: None
- Return value:
GDKRes, the operation result status code
GDKRes Status Code Description¶
| Status code | Description |
|---|---|
kSuccess |
Operation succeeded |
kInvalidInput |
Invalid input parameter |
kInvalidOutput |
Invalid output parameter |
kRuntimeError |
Runtime error |
kUnknown |
Unknown error |
- Example:
import agibot_gdk
# Initialize the GDK system
result = agibot_gdk.gdk_init()
if result == agibot_gdk.GDKRes.kSuccess:
print("GDK initialized successfully")
else:
print(f"GDK initialization failed, error code: {result}")
exit(1)
2. gdk_release()¶
- Function: Release GDK system resources
- Parameters: None
-
Return value:
GDKRes, the operation result status code -
Example:
import agibot_gdk
# Use GDK functionality...
# Release GDK system resources
result = agibot_gdk.gdk_release()
if result == agibot_gdk.GDKRes.kSuccess:
print("GDK released successfully")
else:
print(f"GDK release failed, error code: {result}")
Complete Usage Example¶
import agibot_gdk
import time
def main():
# 1. Initialize the GDK system
print("Initializing the GDK system...")
init_result = agibot_gdk.gdk_init()
if init_result != agibot_gdk.GDKRes.kSuccess:
print(f"GDK initialization failed, error code: {init_result}")
return -1
print("GDK initialized successfully")
try:
# 2. Use GDK functionality
print("Starting to use GDK functionality...")
# Create a camera object
camera = agibot_gdk.Camera()
time.sleep(1) # Wait for the camera to initialize
# Get an image
image = camera.get_latest_image(agibot_gdk.CameraType.kHeadStereoLeft, 1000.0)
if image is not None:
print(f"Successfully obtained image: {image.width}x{image.height}")
else:
print("No image obtained")
# Close the camera
camera.close_camera()
print("Finished using GDK functionality")
except Exception as e:
print(f"An error occurred while using GDK functionality: {e}")
return -1
finally:
# 3. Release GDK system resources
print("Releasing GDK system resources...")
release_result = agibot_gdk.gdk_release()
if release_result != agibot_gdk.GDKRes.kSuccess:
print(f"GDK release failed, error code: {release_result}")
return -1
print("GDK released successfully")
return 0
if __name__ == "__main__":
exit(main())
Usage Notes¶
- Initialization required: You must call
gdk_init()to initialize the system before using any GDK functionality - Release required: You must call
gdk_release()to release system resources before the program ends - Resource management: Ensure resources can be released correctly even in exceptional situations
- Error handling: Always check the return value to ensure the operation succeeded
- Initialization order: Initialize GDK first, then create specific functional objects (such as Camera, Robot, etc.)
- Release order: Close specific functional objects first, then release the GDK system
Application Scenarios¶
- System management: Managing the complete lifecycle of the GDK system
- Resource control: Ensuring correct allocation and release of system resources
- Exception handling: Guaranteeing cleanup of system resources in exceptional situations
- Multi-module development: Providing a unified initialization entry point for multiple GDK modules