refactor(navigation): 重构Navigation类继承unitree::robot::Client

移除不必要的client_成员变量,直接继承unitree::robot::Client类
简化初始化逻辑,更新相关文档说明
This commit is contained in:
2025-09-21 15:15:09 +08:00
parent 61d206e948
commit 1a9fc5f7e1
3 changed files with 6 additions and 13 deletions

View File

@@ -7,14 +7,13 @@ const std::string SLAM_SERVICE_NAME = "slam_operate";
namespace custom {
Navigation::Navigation() : client_(nullptr) {}
Navigation::Navigation() : unitree::robot::Client(SLAM_SERVICE_NAME) {}
Navigation::~Navigation() {}
void Navigation::Init() {
try {
client_ = std::make_unique<unitree::robot::Client>(SLAM_SERVICE_NAME);
client_->Init();
unitree::robot::Client::Init();
LOG_INFO("Navigation client for service '" + SLAM_SERVICE_NAME + "' initialized.");
} catch (const std::exception& e) {
LOG_ERROR("Failed to initialize navigation client: " + std::string(e.what()));
@@ -22,11 +21,6 @@ void Navigation::Init() {
}
bool Navigation::callSlamService(int api_id, const nlohmann::json& data) {
if (!client_) {
LOG_ERROR("Navigation client not initialized.");
return false;
}
nlohmann::json request_json;
request_json["data"] = data;
std::string request_str = request_json.dump();
@@ -34,7 +28,7 @@ bool Navigation::callSlamService(int api_id, const nlohmann::json& data) {
LOG_INFO("Calling slam service api_id: " + std::to_string(api_id) + ", request: " + request_str);
int ret = client_->Call(api_id, request_str, response_str);
int ret = this->Call(api_id, request_str, response_str);
if (ret != 0) {
LOG_ERROR("Slam service request failed with SDK error code: " + std::to_string(ret));