Skip to content

Commit

Permalink
interface optimization and rpc unify (#45)
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

---------

Co-authored-by: lebai <[email protected]>
  • Loading branch information
Cosmoflips and lebai authored May 17, 2023
1 parent 028c2de commit 48ce7b3
Show file tree
Hide file tree
Showing 10 changed files with 142 additions and 72 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

option(CMAKE_EXPORT_COMPILE_COMMANDS "Export compile command" TRUE)

project(lebai VERSION 1.1.0 LANGUAGES CXX)
project(lebai VERSION 1.1.1 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.0
PROJECT_NUMBER = 1.1.1

# 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
27 changes: 16 additions & 11 deletions sdk/include/lebai/robot.hh
Original file line number Diff line number Diff line change
Expand Up @@ -693,16 +693,7 @@ namespace lebai
* @param dir: 调用场景所在的文件夹名
* @param params: 其他参数
*/
unsigned int start_task(const std::string &name,bool is_main,unsigned int loop_to,const std::string &dir,const std::vector<std::string> & params);
/**
* @brief 调用场景
*
* @param name: 调用场景的名字
* @param is_main: 是否以主任务方式运行(主任务会排队执行,子任务会并发执行)
* @param loop_to: 循环次数(默认0永久循环)
* @param dir: 调用场景所在的文件夹名
*/
unsigned int start_task(const std::string &name,bool is_main,unsigned int loop_to,const std::string &dir);
unsigned int start_task(const std::string &name,const std::vector<std::string> & params,const std::string & dir, bool is_parallel,unsigned int loop_to);
/**
* @brief 调用场景
*
Expand All @@ -721,6 +712,7 @@ namespace lebai
* @param wait: 是否等待
*/
void pause_task(unsigned int id,unsigned long time,bool wait);
void pause_task(unsigned int id);
/**
* @brief 恢复任务与运动
*
Expand Down Expand Up @@ -896,12 +888,25 @@ namespace lebai
* @param cog 质心相对于TCP坐标系的偏移.
*/
void set_payload(double mass, std::map<std::string, double> cog);
/**
* @brief 设置机器人末端负载.
*
* @param mass 末端负载的质量(kg).
*/
void set_payload(double mass);
/**
* @brief 设置机器人末端负载.
*
* @param mass 末端负载的质量(kg).
* @param cog 质心相对于TCP坐标系的偏移.
*/
void set_payload(std::map<std::string, double> cog);
/**
* @brief 获取末端负载设置.
*
* @return 由负载质量mass和负载偏移组成的元组.
*/
std::tuple<double, std::map<std::string, double>> get_payload();
std::map<std::string, double> get_payload();
/**
* @brief 设置机器人重力加速度方向.
*
Expand Down
2 changes: 1 addition & 1 deletion sdk/python/jsonbase.i
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
%template(StrVector) std::vector<std::string>;
%template(IntVector) std::vector<int>;
%template(BVector) std::vector<bool>;
// %template(DoubleVector) std::vector<double>;
%template(DoubleVector) std::vector<double>;
%template(BSVector) std::vector<std::tuple<bool,std::string>>;
%std_tuple(TupleDDB, double, double, bool);
%std_tuple(TupleIntStr, int, std::string);
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/protos/control.cc
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ namespace lebai
bool TaskIndex::Serialize(rapidjson::Writer<rapidjson::StringBuffer> *writer) const
{
writer->StartObject();
writer->Key("ids");
writer->Key("id");
writer->Uint(id_);
writer->EndObject();
return true;
Expand Down
81 changes: 53 additions & 28 deletions sdk/src/protos/dynamic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,41 @@ namespace lebai
{
namespace dynamic
{
void SetMassRequest::set_mass(double mass)
{
mass_ = mass;
}
double SetMassRequest::mass() const
{
return mass_;
}
double *SetMassRequest::mutable_mass()
{
return &mass_;
}
bool SetMassRequest::Deserialize(const rapidjson::Value &obj)
{
if(obj.HasMember("mass"))
{
double mass = (double)(obj["mass"].GetDouble());
mass_ = mass;
}
return true;
}
bool SetMassRequest::Serialize(rapidjson::Writer<rapidjson::StringBuffer> *writer) const
{
writer->StartObject();
writer->Key("mass");
writer->Double(mass_);
writer->EndObject();
return true;
}
bool SetMassRequest::IsNullJSONData() const
{
return false;
}


void SetPayloadRequest::set_mass(double mass)
{
mass_ = mass;
Expand All @@ -19,15 +54,15 @@ namespace lebai
return &mass_;
}

void SetPayloadRequest::set_cog(std::vector<double> cog)
void SetPayloadRequest::set_cog(posture::Position cog)
{
cog_ = cog;
}
std::vector<double> SetPayloadRequest::cog() const
posture::Position SetPayloadRequest::cog() const
{
return cog_;
}
std::vector<double> *SetPayloadRequest::mutable_cog()
posture::Position *SetPayloadRequest::mutable_cog()
{
return &cog_;
}
Expand All @@ -41,11 +76,10 @@ namespace lebai
}
if(obj.HasMember("cog"))
{
std::vector<double> cog;
for(auto c = obj["cog"].GetArray().Begin();c != obj["cog"].GetArray().End();c++)
{
cog.push_back(c->GetDouble());
}
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;
Expand All @@ -56,19 +90,16 @@ namespace lebai
writer->Key("mass");
writer->Double(mass_);
writer->Key("cog");
writer->StartArray();
for(auto c:cog_)
{
writer->Double(c);
}
writer->EndArray();
cog_.Serialize(writer);
writer->EndObject();
return true;
}
bool SetPayloadRequest::IsNullJSONData() const
{
return false;
}


void Payload::set_mass(double mass)
{
mass_ = mass;
Expand All @@ -82,15 +113,15 @@ namespace lebai
return &mass_;
}

void Payload::set_cog(std::vector<double> cog)
void Payload::set_cog(posture::Position cog)
{
cog_ = cog;
}
std::vector<double> Payload::cog() const
posture::Position Payload::cog() const
{
return cog_;
}
std::vector<double> *Payload::mutable_cog()
posture::Position *Payload::mutable_cog()
{
return &cog_;
}
Expand All @@ -104,11 +135,10 @@ namespace lebai
}
if(obj.HasMember("cog"))
{
std::vector<double> cog;
for(auto c = obj["cog"].GetArray().Begin();c != obj["cog"].GetArray().End();c++)
{
cog.push_back(c->GetDouble());
}
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;
Expand All @@ -119,12 +149,7 @@ namespace lebai
writer->Key("mass");
writer->Double(mass_);
writer->Key("cog");
writer->StartArray();
for(auto c:cog_)
{
writer->Double(c);
}
writer->EndArray();
cog_.Serialize(writer);
writer->EndObject();
return true;
}
Expand Down
34 changes: 26 additions & 8 deletions sdk/src/protos/dynamic.hh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <vector>
#include <memory>
#include <string>
#include "posture.hh"

namespace lebai
{
Expand All @@ -16,13 +17,30 @@ namespace lebai
double mass() const;
double *mutable_mass();

void set_cog(std::vector<double> cog);
std::vector<double> cog() const;
std::vector<double> * mutable_cog();
void set_cog(posture::Position cog);
posture::Position cog() const;
posture::Position * mutable_cog();

protected:
double mass_;
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:
void set_mass(double mass);
double mass() const;
double *mutable_mass();

protected:
double mass_;
std::vector<double> cog_;
// These methods are used to serialize and deserialize the class.
// They will not be wrapped in the SDK.
public:
Expand All @@ -38,13 +56,13 @@ namespace lebai
double mass() const;
double *mutable_mass();

void set_cog(std::vector<double> cog);
std::vector<double> cog() const;
std::vector<double> * mutable_cog();
void set_cog(posture::Position cog);
posture::Position cog() const;
posture::Position * mutable_cog();

protected:
double mass_;
std::vector<double> cog_;
posture::Position cog_;
// These methods are used to serialize and deserialize the class.
// They will not be wrapped in the SDK.
public:
Expand Down
54 changes: 33 additions & 21 deletions sdk/src/robot.cc
Original file line number Diff line number Diff line change
Expand Up @@ -921,7 +921,7 @@ void Robot::add_signal(unsigned int index,int value)
impl_->addSignal(req);
}

unsigned int Robot::start_task(const std::string &name,bool is_parallel,unsigned int loop_to,const std::string & dir,const std::vector<std::string> & params)
unsigned int Robot::start_task(const std::string &name,const std::vector<std::string> & params,const std::string & dir, bool is_parallel,unsigned int loop_to)
{
control::StartTaskRequest req;
req.set_name(name);
Expand All @@ -932,16 +932,6 @@ unsigned int Robot::start_task(const std::string &name,bool is_parallel,unsigned
control::TaskIndex resp = impl_->scene(req);
return resp.id();
}
unsigned int Robot::start_task(const std::string &name,bool is_parallel,unsigned int loop_to,const std::string & dir)
{
control::StartTaskRequest req;
req.set_name(name);
req.set_is_parallel(is_parallel);
req.set_loop_to(loop_to);
req.set_dir(dir);
control::TaskIndex resp = impl_->scene(req);
return resp.id();
}
unsigned int Robot::start_task(const std::string &name)
{
control::StartTaskRequest req;
Expand All @@ -956,6 +946,14 @@ std::vector<unsigned int> Robot::load_task_list()
control::TaskIds resp = impl_->loadTaskList();
return resp.ids();
}
void Robot::pause_task(unsigned int id)
{
control::PauseRequest req;
req.set_id(id);
req.set_time(0);
req.set_wait(false);
impl_->pauseTask(req);
}
void Robot::pause_task(unsigned int id,unsigned long time,bool wait)
{
control::PauseRequest req;
Expand Down Expand Up @@ -1315,23 +1313,37 @@ void Robot::set_payload(double mass, std::map<std::string, double> cog)
{
dynamic::SetPayloadRequest req;
req.set_mass(mass);
std::vector<double> c;
c.push_back(cog.at("x"));
c.push_back(cog.at("y"));
c.push_back(cog.at("z"));
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);
}
void Robot::set_payload(double mass)
{
dynamic::SetMassRequest req;
req.set_mass(mass);
impl_->setPayload(req);
}
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"));
impl_->setPayload(req);
}

std::tuple<double, std::map<std::string, double>> Robot::get_payload()
std::map<std::string, double> Robot::get_payload()
{
dynamic::Payload resp = impl_->getPayload();
std::map<std::string,double> cog;
cog["x"] = resp.cog()[0];
cog["y"] = resp.cog()[1];
cog["Z"] = resp.cog()[2];
std::tuple<double, std::map<std::string, double>> ret = std::make_tuple(resp.mass(),cog);
return ret;
cog["x"] = resp.cog().x();
cog["y"] = resp.cog().y();
cog["Z"] = resp.cog().z();
cog["mass"] = resp.mass();
return cog;
}

void Robot::set_gravity(std::map<std::string,double> gravity)
Expand Down
Loading

0 comments on commit 48ce7b3

Please sign in to comment.