From 6b9ad807576311d8de435ad4b24fa3fc0a67724a Mon Sep 17 00:00:00 2001 From: Sucan126 <632190820@qq.com> Date: Mon, 22 Sep 2025 14:46:18 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E5=91=BD=E5=90=8D=E7=A9=BA=E9=97=B4):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8DUnitree=20SDK=E7=B1=BB=E5=9E=8B=E5=91=BD?= =?UTF-8?q?=E5=90=8D=E7=A9=BA=E9=97=B4=E9=97=AE=E9=A2=98=E5=B9=B6=E9=87=8D?= =?UTF-8?q?=E6=9E=84PoseData?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将ChannelSubscriberPtr改为unitree::robot::ChannelSubscriberPtr - 重构PoseData结构为poseDate类,增加JSON序列化功能 - 更新相关代码以使用新的poseDate类 --- README.md | 6 +++++ include/navigation.hpp | 52 ++++++++++++++++++++++++++++++------------ src/navigation.cpp | 4 ++-- 3 files changed, 45 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index da02954..e9c52a2 100644 --- a/README.md +++ b/README.md @@ -390,6 +390,12 @@ When the service list is retrieved (either through the `list` command or interna 2. Update JSON parsing and validation 3. Add corresponding response handling +### Fixing Namespace Issues + +When working with Unitree SDK types, ensure proper namespace qualification: +- Use `unitree::robot::ChannelSubscriberPtr` instead of just `ChannelSubscriberPtr` +- Check all SDK type references for correct namespace usage + ### Custom Configurations The robot's configuration is defined at compile time in `include/config.hpp`. To customize the configuration: diff --git a/include/navigation.hpp b/include/navigation.hpp index a25a1c1..420ff83 100644 --- a/include/navigation.hpp +++ b/include/navigation.hpp @@ -26,6 +26,39 @@ const int32_t ROBOT_API_ID_RESUME_NAV = 1202; namespace custom { +class poseDate +{ +public: + float x = 0.0f; + float y = 0.0f; + float z = 0.0f; + float q_x = 0.0f; + float q_y = 0.0f; + float q_z = 0.0f; + float q_w = 1.0f; + int mode = 1; + float speed = 0.8f; + std::string toJsonStr() const + { + nlohmann::json j; + j["data"]["targetPose"]["x"] = x; + j["data"]["targetPose"]["y"] = y; + j["data"]["targetPose"]["z"] = z; + j["data"]["targetPose"]["q_x"] = q_x; + j["data"]["targetPose"]["q_y"] = q_y; + j["data"]["targetPose"]["q_z"] = q_z; + j["data"]["targetPose"]["q_w"] = q_w; + j["data"]["mode"] = mode; + j["data"]["speed"] = speed; + return j.dump(4); + } + void printInfo() const + { + std::cout << "x:" << x << " y:" << y << " z:" << z << " q_x:" + << q_x << " q_y:" << q_y << " q_z:" << q_z << " q_w:" << q_w << std::endl; + } +}; + class Navigation : public unitree::robot::Client { public: Navigation(); @@ -41,7 +74,7 @@ public: bool resumeNavigation(); bool closeSlam(); - PoseData getCurrentPose() const { return currentPose; } + poseDate getCurrentPose() const { return currentPose; } bool hasArrived() const { return is_arrived; } @@ -50,21 +83,10 @@ private: void slamInfoHandler(const void *message); void slamKeyInfoHandler(const void *message); - ChannelSubscriberPtr subSlamInfo; - ChannelSubscriberPtr subSlamKeyInfo; + unitree::robot::ChannelSubscriberPtr subSlamInfo; + unitree::robot::ChannelSubscriberPtr subSlamKeyInfo; - // Structure to hold pose data - struct PoseData { - double x = 0.0; - double y = 0.0; - double z = 0.0; - double q_x = 0.0; - double q_y = 0.0; - double q_z = 0.0; - double q_w = 0.0; - }; - - PoseData currentPose; + poseDate currentPose; bool is_arrived = false; }; diff --git a/src/navigation.cpp b/src/navigation.cpp index 8ff1e1b..179f615 100644 --- a/src/navigation.cpp +++ b/src/navigation.cpp @@ -4,12 +4,12 @@ namespace custom { Navigation::Navigation() : unitree::robot::Client(SLAM_SERVICE_NAME) { - subSlamInfo = ChannelSubscriberPtr( + subSlamInfo = unitree::robot::ChannelSubscriberPtr( new unitree::robot::ChannelSubscriber(SlamInfoTopic)); subSlamInfo->InitChannel( std::bind(&Navigation::slamInfoHandler, this, std::placeholders::_1), 1); - subSlamKeyInfo = ChannelSubscriberPtr( + subSlamKeyInfo = unitree::robot::ChannelSubscriberPtr( new unitree::robot::ChannelSubscriber(SlamKeyInfoTopic)); subSlamKeyInfo->InitChannel( std::bind(&Navigation::slamKeyInfoHandler, this, std::placeholders::_1), 1);