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);