refactor(navigation): 重构Navigation类继承unitree::robot::Client
移除不必要的client_成员变量,直接继承unitree::robot::Client类 简化初始化逻辑,更新相关文档说明
This commit is contained in:
@@ -429,7 +429,7 @@ unitree-go2/
|
||||
│ ├── custom_robot.hpp # Main orchestrator
|
||||
│ ├── logger.hpp # Logging system
|
||||
│ ├── mqtt.hpp # MQTT client
|
||||
│ ├── navigation.hpp # Navigation and SLAM
|
||||
│ ├── navigation.hpp # Navigation and SLAM (inherits from unitree::robot::Client)
|
||||
│ └── nlohmann/ # JSON library
|
||||
├── src/ # Source files
|
||||
│ ├── config.cpp # Configuration implementation
|
||||
@@ -438,7 +438,7 @@ unitree-go2/
|
||||
│ ├── logger.cpp # Logging system implementation
|
||||
│ ├── main.cpp # Entry point
|
||||
│ ├── mqtt.cpp # MQTT client implementation
|
||||
│ └── navigation.cpp # Navigation and SLAM implementation
|
||||
│ └── navigation.cpp # Navigation and SLAM implementation (inherits from unitree::robot::Client)
|
||||
├── scripts/ # Utility scripts
|
||||
│ ├── install_deps.sh # Install dependencies
|
||||
│ └── run_robot.sh # Run with optimal settings
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
namespace custom {
|
||||
|
||||
class Navigation {
|
||||
class Navigation : public unitree::robot::Client {
|
||||
public:
|
||||
Navigation();
|
||||
~Navigation();
|
||||
@@ -24,7 +24,6 @@ public:
|
||||
bool closeSlam();
|
||||
|
||||
private:
|
||||
std::unique_ptr<unitree::robot::Client> client_;
|
||||
bool callSlamService(int api_id, const nlohmann::json& data);
|
||||
};
|
||||
|
||||
|
||||
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user