Skip to content

Commit

Permalink
set_payload with single cog argument not work (#46)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
Cosmoflips and lebai authored May 17, 2023
1 parent 8ee9bae commit 373b15f
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 10 deletions.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down
2 changes: 1 addition & 1 deletion Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion sdk/include/lebai/robot.hh
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ namespace lebai
*
*/
using CartesianPose = std::map<std::string, double>;
using DoubleVector = std::vector<double>;
/**
* @brief 运动学正解的返回值数据结构.
*
Expand All @@ -53,7 +54,7 @@ namespace lebai
*/
struct KinematicsInverseResp
{
std::vector<double> joint_positions; /*!< 机械臂关节位置的map数据,应当包括'j1','j2','j3','j4','j5','j6'六个关节的角度值. */
DoubleVector joint_positions; /*!< 机械臂关节位置的map数据,应当包括'j1','j2','j3','j4','j5','j6'六个关节的角度值. */
bool ok = false; /*!< 计算是否成功 */
};

Expand Down
39 changes: 39 additions & 0 deletions sdk/src/protos/dynamic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<rapidjson::StringBuffer> *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;
Expand Down
17 changes: 17 additions & 0 deletions sdk/src/protos/dynamic.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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<rapidjson::StringBuffer> *writer) const;
virtual bool IsNullJSONData() const;
};

class SetMassRequest : public JSONBase
{
public:
Expand Down
12 changes: 7 additions & 5 deletions sdk/src/robot.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1328,10 +1328,12 @@ void Robot::set_payload(double mass)
}
void Robot::set_payload(std::map<std::string, double> 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);
}

Expand All @@ -1341,7 +1343,7 @@ std::map<std::string, double> Robot::get_payload()
std::map<std::string,double> 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;
}
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/robot_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/robot_impl.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 373b15f

Please sign in to comment.