From 373b15fe884408042baed39df915418ef5f08fbb Mon Sep 17 00:00:00 2001 From: Cosmoslip <37982167+Cosmoflips@users.noreply.github.com> Date: Wed, 17 May 2023 14:45:09 +0800 Subject: [PATCH] set_payload with single cog argument not work (#46) * fix: get_payload invalid object * feat: unify pause_task arguments * fix: bugfix and overload * fix:bugfix * fix:bugfix * fix:bugfix * doc: version update * fix:bugfix * fix: set_payload with cog not work * doc: update version --------- Co-authored-by: lebai --- CMakeLists.txt | 3 ++- Doxyfile | 2 +- sdk/include/lebai/robot.hh | 3 ++- sdk/src/protos/dynamic.cc | 39 ++++++++++++++++++++++++++++++++++++++ sdk/src/protos/dynamic.hh | 17 +++++++++++++++++ sdk/src/robot.cc | 12 +++++++----- sdk/src/robot_impl.cc | 2 +- sdk/src/robot_impl.hh | 2 +- 8 files changed, 70 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 709fe7f..4e9092d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,8 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") option(CMAKE_EXPORT_COMPILE_COMMANDS "Export compile command" TRUE) -project(lebai VERSION 1.1.1 LANGUAGES CXX) + +project(lebai VERSION 1.1.2 LANGUAGES CXX) set(PROJECT_NAMESPACE lebai) message(STATUS "${PROJECT_NAME} version: ${PROJECT_VERSION}") # message(STATUS "major: ${PROJECT_VERSION_MAJOR}") diff --git a/Doxyfile b/Doxyfile index 8509d09..ea2314a 100644 --- a/Doxyfile +++ b/Doxyfile @@ -38,7 +38,7 @@ PROJECT_NAME = "lebai sdk" # could be handy for archiving the generated documentation or if some version # control system is used. -PROJECT_NUMBER = 1.1.1 +PROJECT_NUMBER = 1.1.2 # Using the PROJECT_BRIEF tag one can provide an optional one line description # for a project that appears at the top of each page and should give viewer a diff --git a/sdk/include/lebai/robot.hh b/sdk/include/lebai/robot.hh index 1f6ae57..d265bba 100644 --- a/sdk/include/lebai/robot.hh +++ b/sdk/include/lebai/robot.hh @@ -38,6 +38,7 @@ namespace lebai * */ using CartesianPose = std::map; + using DoubleVector = std::vector; /** * @brief 运动学正解的返回值数据结构. * @@ -53,7 +54,7 @@ namespace lebai */ struct KinematicsInverseResp { - std::vector joint_positions; /*!< 机械臂关节位置的map数据,应当包括'j1','j2','j3','j4','j5','j6'六个关节的角度值. */ + DoubleVector joint_positions; /*!< 机械臂关节位置的map数据,应当包括'j1','j2','j3','j4','j5','j6'六个关节的角度值. */ bool ok = false; /*!< 计算是否成功 */ }; diff --git a/sdk/src/protos/dynamic.cc b/sdk/src/protos/dynamic.cc index 10f31f7..a6275a2 100644 --- a/sdk/src/protos/dynamic.cc +++ b/sdk/src/protos/dynamic.cc @@ -41,6 +41,45 @@ namespace lebai } + void SetCogRequest::set_cog(posture::Position cog) + { + cog_ = cog; + } + posture::Position SetCogRequest::cog() const + { + return cog_; + } + posture::Position *SetCogRequest::mutable_cog() + { + return &cog_; + } + + bool SetCogRequest::Deserialize(const rapidjson::Value &obj) + { + if(obj.HasMember("cog")) + { + posture::Position cog; + cog.set_x(obj["cog"].GetObject()["x"].GetDouble()); + cog.set_y(obj["cog"].GetObject()["y"].GetDouble()); + cog.set_z(obj["cog"].GetObject()["z"].GetDouble()); + cog_ = cog; + } + return true; + } + bool SetCogRequest::Serialize(rapidjson::Writer *writer) const + { + writer->StartObject(); + writer->Key("cog"); + cog_.Serialize(writer); + writer->EndObject(); + return true; + } + bool SetCogRequest::IsNullJSONData() const + { + return false; + } + + void SetPayloadRequest::set_mass(double mass) { mass_ = mass; diff --git a/sdk/src/protos/dynamic.hh b/sdk/src/protos/dynamic.hh index 4733bd1..4e8bed7 100644 --- a/sdk/src/protos/dynamic.hh +++ b/sdk/src/protos/dynamic.hh @@ -32,6 +32,23 @@ namespace lebai virtual bool IsNullJSONData() const; }; + class SetCogRequest : public JSONBase + { + public: + void set_cog(posture::Position cog); + posture::Position cog() const; + posture::Position * mutable_cog(); + + protected: + posture::Position cog_; + // These methods are used to serialize and deserialize the class. + // They will not be wrapped in the SDK. + public: + virtual bool Deserialize(const rapidjson::Value &obj); + virtual bool Serialize(rapidjson::Writer *writer) const; + virtual bool IsNullJSONData() const; + }; + class SetMassRequest : public JSONBase { public: diff --git a/sdk/src/robot.cc b/sdk/src/robot.cc index a68f670..d4d997d 100644 --- a/sdk/src/robot.cc +++ b/sdk/src/robot.cc @@ -1328,10 +1328,12 @@ void Robot::set_payload(double mass) } void Robot::set_payload(std::map cog) { - posture::Position req; - req.set_x(cog.at("x")); - req.set_y(cog.at("y")); - req.set_z(cog.at("z")); + dynamic::SetCogRequest req; + posture::Position c; + c.set_x(cog.at("x")); + c.set_y(cog.at("y")); + c.set_z(cog.at("z")); + req.set_cog(c); impl_->setPayload(req); } @@ -1341,7 +1343,7 @@ std::map Robot::get_payload() std::map cog; cog["x"] = resp.cog().x(); cog["y"] = resp.cog().y(); - cog["Z"] = resp.cog().z(); + cog["z"] = resp.cog().z(); cog["mass"] = resp.mass(); return cog; } diff --git a/sdk/src/robot_impl.cc b/sdk/src/robot_impl.cc index b20a602..29baf28 100644 --- a/sdk/src/robot_impl.cc +++ b/sdk/src/robot_impl.cc @@ -495,7 +495,7 @@ namespace lebai { json_rpc_connector_->CallRpc("set_payload",req.ToJSONString(),nullptr); } - void Robot::RobotImpl::setPayload(const posture::Position &req) + void Robot::RobotImpl::setPayload(const dynamic::SetCogRequest &req) { json_rpc_connector_->CallRpc("set_payload",req.ToJSONString(),nullptr); } diff --git a/sdk/src/robot_impl.hh b/sdk/src/robot_impl.hh index fea8c3e..c95ad36 100644 --- a/sdk/src/robot_impl.hh +++ b/sdk/src/robot_impl.hh @@ -108,7 +108,7 @@ namespace lebai void unzip(const file::UnzipRequest & req); file::LoadZipListResponse loadZipList(const file::LoadZipListRequest & req); void setPayload(const dynamic::SetPayloadRequest & req); - void setPayload(const posture::Position & req); + void setPayload(const dynamic::SetCogRequest & req); void setPayload(const dynamic::SetMassRequest & req); dynamic::Payload getPayload(); void setGravity(const posture::Position & req);