GDK Common Interface Documentation (C++)¶
Overview¶
The Common module provides the G02 robot with initialization and release functionality for the GDK system. Through the C++ interface, developers can conveniently manage the lifecycle of the GDK system, ensuring the system starts correctly and resources are released correctly.
Interface Description¶
Global Functions¶
1. GDKInit()¶
- Function: Initialize the GDK system
- Parameters: None
- Return Value:
GDKRes, the operation result status code GDKRes::kSuccess: Initialization succeeded-
Other values: Initialization failed
-
Description:
- This function must be called before calling any other GDK functionality
- Initializes the GDK internal system, DDS connection, configuration management, etc.
-
It is recommended to call this once at program startup
-
Example:
#include <iostream>
#include "gdk/gdk.h"
int main() {
// Initialize the GDK system
agibot::gdk::GDKRes init_result = agibot::gdk::GDKInit();
if (init_result != agibot::gdk::GDKRes::kSuccess) {
std::cout << "GDK initialization failed: " << static_cast<int>(init_result) << std::endl;
return -1;
}
std::cout << "GDK initialized successfully" << std::endl;
// Use GDK functionality...
return 0;
}
2. GDKRelease()¶
- Function: Release GDK system resources
- Parameters: None
- Return Value:
GDKRes, the operation result status code GDKRes::kSuccess: Release succeeded-
Other values: Release failed
-
Description:
- Call this function before the program ends to release GDK system resources
- Cleans up the DDS connection, closes file handles, releases memory, etc.
-
It is recommended to call this once before the program exits
-
Example:
#include <iostream>
#include "gdk/gdk.h"
int main() {
// Initialize the GDK system
agibot::gdk::GDKRes init_result = agibot::gdk::GDKInit();
if (init_result != agibot::gdk::GDKRes::kSuccess) {
std::cout << "GDK initialization failed" << std::endl;
return -1;
}
std::cout << "GDK initialized successfully" << std::endl;
// Use GDK functionality...
// Release GDK system resources
agibot::gdk::GDKRes release_result = agibot::gdk::GDKRelease();
if (release_result != agibot::gdk::GDKRes::kSuccess) {
std::cout << "GDK release failed: " << static_cast<int>(release_result) << std::endl;
return -1;
}
std::cout << "GDK released successfully" << std::endl;
return 0;
}
Complete Usage Example¶
#include <iostream>
#include <thread>
#include "gdk/gdk.h"
int main() {
std::cout << "GDK Common example program" << std::endl;
// 1. Initialize the GDK system
std::cout << "Initializing GDK system..." << std::endl;
agibot::gdk::GDKRes init_result = agibot::gdk::GDKInit();
if (init_result != agibot::gdk::GDKRes::kSuccess) {
std::cout << "❌ GDK initialization failed: " << static_cast<int>(init_result) << std::endl;
return -1;
}
std::cout << "✅ GDK initialized successfully" << std::endl;
// 2. Use GDK functionality
std::cout << "Starting to use GDK functionality..." << std::endl;
// Create a camera object
agibot::gdk::Camera camera;
std::this_thread::sleep_for(std::chrono::seconds(1));
// Create an IMU object
agibot::gdk::Imu imu;
std::this_thread::sleep_for(std::chrono::seconds(1));
std::cout << "Finished using GDK functionality" << std::endl;
// 3. Release GDK system resources
std::cout << "Releasing GDK system resources..." << std::endl;
agibot::gdk::GDKRes release_result = agibot::gdk::GDKRelease();
if (release_result != agibot::gdk::GDKRes::kSuccess) {
std::cout << "❌ GDK release failed: " << static_cast<int>(release_result) << std::endl;
return -1;
}
std::cout << "✅ GDK released successfully" << std::endl;
std::cout << "Program ended normally" << std::endl;
return 0;
}
Usage Notes¶
- Initialization order:
GDKInit()must be called before calling any other GDK functionality - Release order: Call
GDKRelease()to release resources before the program ends - Error handling: Always check the return value to ensure the operation succeeded
- Single call: Typically you only need to call
GDKInit()once at program start andGDKRelease()once at the end - Exception safety: Ensure
GDKRelease()is called to release resources even in exceptional situations - Multithreading: GDK initialization is global; in a multithreaded environment, only one thread needs to call it
Error Code Description¶
| Error Code | Description | Possible Cause |
|---|---|---|
GDKRes::kSuccess |
Operation succeeded | - |
GDKRes::kInvalidInput |
Invalid input | Parameter error |
GDKRes::kInvalidOutput |
Invalid output | Output parameter error |
GDKRes::kTimeout |
Timeout | Operation timed out |
GDKRes::kNotInitialized |
Not initialized | System not properly initialized |
GDKRes::kAlreadyInitialized |
Already initialized | Duplicate initialization |
GDKRes::kInternalError |
Internal error | System internal error |
Application Scenarios¶
- System startup: Initialize GDK when the robot system starts up
- Resource management: Ensure GDK system resources are released correctly