GDK C++ Usage Guide¶
In hybrid deployment, you can carry out secondary development on the x86 platform based on the GDK C++ interface. This document describes how to use GDK in a C++ project.
Please make sure the dynamic library version linked at build time matches the one linked at run time. If the linked dynamic library versions do not match between build and run time, GDK will output an error log, for example: "Version mismatch, runtime version: 2.2.0, build version: 2.2.1";
Basic development (using motion control as an example)¶
Include the header file¶
Initialize GDK¶
if (agibot::gdk::GDKInit() != agibot::gdk::GDKRes::kSuccess) {
std::cout << "GDK initialization failed" << std::endl;
return -1;
}
Initialize the robot object¶
agibot::gdk::Robot robot;
std::cout << "Robot init" << std::endl;
std::this_thread::sleep_for(std::chrono::seconds(1));
Set the joints to control along with their target joint positions and execution speed¶
agibot::gdk::JointControlReq joint_control;
joint_control.life_time = 5.0;
joint_control.joint_names = {"arm_l_joint1", "arm_l_joint2", "arm_l_joint3"};
joint_control.joint_positions = {0.5, -0.3, 0.8};
joint_control.joint_velocities = {0.3, 0.3, 0.3};
Send the joint control command¶
if (robot.JointControl(joint_control) != agibot::gdk::GDKRes::kSuccess) {
std::cout << "Failed to control joints" << std::endl;
} else {
std::cout << "Joint control command sent successfully" << std::endl;
}
Building¶
CMake build configuration¶
GDK's header files and dynamic libraries are deployed under the GDK_HOME directory; in hybrid deployment, GDK_HOME defaults to ~/.cache/agibot. Add the following to your CMakeLists.txt to link your program against the gdk library and its headers, and use this approach to create the build target:
if(NOT DEFINED ENV{GDK_HOME})
set(GDK_HOME_PATH ~/.cache/agibot)
else()
set(GDK_HOME_PATH $ENV{GDK_HOME})
endif()
function(add_adapter name)
add_executable(${name} src/${name}.cpp)
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
target_include_directories(${name} PRIVATE ${GDK_HOME_PATH}/app/gdk/build_dep/cpp/x86_64/include)
target_link_libraries(${name} PRIVATE ${GDK_HOME_PATH}/app/gdk/build_dep/cpp/x86_64/lib/libgdk_adapter.so)
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64")
target_include_directories(${name} PRIVATE ${GDK_HOME_PATH}/app/gdk/build_dep/cpp/aarch64/include)
target_link_libraries(${name} PRIVATE ${GDK_HOME_PATH}/app/gdk/build_dep/cpp/aarch64/lib/libgdk_adapter.so)
endif()
endfunction()
add_adapter(your_program)