Skip to content

Commit

Permalink
feat:Dio and Hook (#32)
Browse files Browse the repository at this point in the history
* fix:bugfix

* fix:bugfix

* Update build.yml

* Update build.yml

* Update build.yml

* Update build.yml

* Update build.yml

* Update build.yml

* Update build.yml

* Update build.yml

* Update build.yml

* Update build.yml

* update ci

* feat:Dio features for arm

* fix:bugfix

* fix:bugfix

* fix:bugfix

* fix:bugfix

* fix:bugfix

* add python-setup in windows_python_build

* merge master from liufang-robot:master

* Update windows_python_build.yml

* Update windows_python_build.yml

* Update windows_python_build.yml

* Update windows_python_build.yml

* fix:aach64 cpp build

* Update linux_aarch64_cpp_build.yml

* Update linux_aarch64_cpp_build.yml

* Update linux_aarch64_cpp_build.yml

* Update linux_aarch64_cpp_build.yml

* Update linux_aarch64_cpp_build.yml

* Delete linux_aarch64_cpp_build.yml

* Update linux_python_build.yml

* Update linux_python_build.yml

* fix:Cartesian rx rz wrong swap

* fix:bugfix

* chore:dio fields change

* Update linux_python_build.yml

[skip ci]

* fix:bugfix

* fix:bugfix

* fix:bugfix

* feat:hook exec

* fix:bugfix

* fix:get_task_state undefine

* Update robot.cc

* Update robot.hh

* Update CMakeLists.txt

* Update Doxyfile

---------

Co-authored-by: liufang <liufang_robot@outlook.com>
  • Loading branch information
Cosmoflips and liufang-robot authored Mar 2, 2023
1 parent 36b2170 commit 39eb1d6
Show file tree
Hide file tree
Showing 12 changed files with 353 additions and 198 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/linux_python_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ run-name: ${{ github.actor }} Linux python build
on:
workflow_dispatch:
pull_request:
push:
branches:
- master
jobs:
linux_python_build:
runs-on: ubuntu-latest
Expand Down
9 changes: 8 additions & 1 deletion .github/workflows/windows_python_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,14 @@ jobs:
python-version: '3.10'
- name: Check cmake
run: cmake --version
- run: pip install python-dev-tools
# - uses: msys2/setup-msys2@v2
# with:
# update: true
# install: >-
# base-devel
# mingw-w64-x86_64-python3
- name: Configure
run: cmake -S. -Bbuild -G "Visual Studio 17 2022" -DBUILD_PYTHON=ON -DBUILD_DOCUMENTATION=OFF
- name: Build
run: cmake --build build
run: cmake --build build
2 changes: 1 addition & 1 deletion CMakeLists.txt
100644 → 100755
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.0.17 LANGUAGES CXX)
project(lebai VERSION 1.0.18 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.0.17
PROJECT_NUMBER = 1.0.18

# 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
34 changes: 18 additions & 16 deletions sdk/include/lebai/robot.hh
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,12 @@ namespace lebai
* @note 查看 <a href="https://help.lebai.ltd/guide/basic.html#%E6%9C%BA%E5%99%A8%E4%BA%BA%E7%8A%B6%E6%80%81">具体信息</a>.
*/
int get_robot_mode();
/**
* @brief 是否已与手臂断开连接
*
* @return 是否已断开连接
*/
bool is_disconnected();
/**
* @brief 获取机械臂关节当前反馈位置
*
Expand Down Expand Up @@ -550,34 +556,20 @@ namespace lebai
* @return 返回多个模拟输入数值
*/
std::vector<double> get_ais(std::string device, unsigned int pin, unsigned int num);
/**
* @brief 设置数字端口输出值
* @param pin: 端口号,从 0 开始
* @param value: 待设置的模拟输出值
* @return 若设置成功为true,若当前此端口为输入模式则为false
*/
bool set_dio(unsigned int pin, bool value);
/**
* @brief 设置数字端口模式
* @param pin 端口号,从 0 开始
* @param value 设置的值,false为输入模式,true为输出模式
* @return 返回是否成功
*/
bool set_dio_mode(unsigned int pin, bool value);
/**
* @brief 获取数字端口输出值
* @param pin: 端口号,从 0 开始
* @param count: 查询的连续端口数
* @return 从pin开始的连续count个端口的当前值
*/
std::vector<bool> get_dios(unsigned int pin, unsigned int count);
void set_dio_mode(std::string device,unsigned int pin, bool value);
/**
* @brief 获取数字端口模式
* @param pin 端口号,从 0 开始
* @param count 查询的连续端口数
* @return 从pin开始的连续count个端口的当前模式
*/
std::vector<bool> get_dios_mode(unsigned int pin, unsigned int count);
std::vector<bool> get_dios_mode(std::string device,unsigned int pin, unsigned int count);
/** @}*/


Expand Down Expand Up @@ -707,6 +699,16 @@ namespace lebai
* @param id 任务的ID.
*/
void cancel_task(unsigned int id);
/**
* @brief 根据已设置的Hook执行对应场景
*
* @param id 任务的ID.
*/
unsigned int exec_hook(unsigned int id);
/**
* @brief 获取任务状态.
*/
std::string get_task_state();
/**
* @brief 获取任务状态.
*
Expand Down
85 changes: 85 additions & 0 deletions sdk/src/protos/control.cc
Original file line number Diff line number Diff line change
Expand Up @@ -665,5 +665,90 @@ namespace lebai
{
return false;
}

void Exec::set_id(unsigned int id)
{
id_ = id;
}
unsigned int Exec::id()
{
return id_;
}
unsigned int *Exec::mutable_id()
{
return &id_;
}
bool Exec::Deserialize(const rapidjson::Value &obj)
{
if(obj.HasMember("id"))
{
id_ = (unsigned int)(obj["id"].GetUint());
}
return true;
}
bool Exec::Serialize(rapidjson::Writer<rapidjson::StringBuffer> *writer) const
{
writer->StartObject();
writer->Key("id");
writer->Uint(id_);
writer->EndObject();
return true;
}
bool Exec::IsNullJSONData() const
{
return false;
}

void HookResponse::set_success(unsigned int success)
{
success_ = success;
}
unsigned int HookResponse::success()
{
return success_;
}
unsigned int *HookResponse::mutable_success()
{
return &success_;
}

void HookResponse::set_error(std::string error)
{
error_ = error;
}
std::string HookResponse::error()
{
return error_;
}
std::string *HookResponse::mutable_error()
{
return &error_;
}
bool HookResponse::Deserialize(const rapidjson::Value &obj)
{
if(obj.HasMember("success"))
{
success_ = bool(obj["success"].GetBool());
}
if(obj.HasMember("error"))
{
error_ = (std::string)(obj["error"].GetString());
}
return true;
}
bool HookResponse::Serialize(rapidjson::Writer<rapidjson::StringBuffer> *writer) const
{
writer->StartObject();
writer->Key("success");
writer->Bool(success_);
writer->Key("error");
writer->String(error_.c_str());
writer->EndObject();
return true;
}
bool HookResponse::IsNullJSONData() const
{
return false;
}
}
}
35 changes: 35 additions & 0 deletions sdk/src/protos/control.hh
Original file line number Diff line number Diff line change
Expand Up @@ -211,5 +211,40 @@ namespace lebai
virtual bool Serialize(rapidjson::Writer<rapidjson::StringBuffer> *writer) const;
virtual bool IsNullJSONData() const;
};

class Exec : public JSONBase
{
public:
void set_id(unsigned int id);
unsigned int id();
unsigned int * mutable_id();

protected:
unsigned int id_;
public:
virtual bool Deserialize(const rapidjson::Value &obj);
virtual bool Serialize(rapidjson::Writer<rapidjson::StringBuffer> *writer) const;
virtual bool IsNullJSONData() const;
};

class HookResponse : public JSONBase
{
public:
void set_success(unsigned int success);
unsigned int success();
unsigned int * mutable_success();

void set_error(std::string error);
std::string error();
std::string * mutable_error();

protected:
unsigned int success_;
std::string error_;
public:
virtual bool Deserialize(const rapidjson::Value &obj);
virtual bool Serialize(rapidjson::Writer<rapidjson::StringBuffer> *writer) const;
virtual bool IsNullJSONData() const;
};
}
}
91 changes: 91 additions & 0 deletions sdk/src/protos/io.cc
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,19 @@ namespace lebai
return false;
}

void SetDioModeRequest::set_device(IoDevice device)
{
device_ = device;
}
IoDevice SetDioModeRequest::device()
{
return device_;
}
IoDevice* SetDioModeRequest::mutable_device()
{
return &device_;
}

void SetDioModeRequest::set_pin(unsigned int pin)
{
pin_ = pin;
Expand Down Expand Up @@ -855,6 +868,22 @@ namespace lebai

bool SetDioModeRequest::Deserialize(const rapidjson::Value &obj)
{
if(obj.HasMember("device"))
{
std::string device_str = std::string(obj["device"].GetString());
if(device_str == "ROBOT")
{
device_ = ROBOT;
}
else if(device_str == "FLANGE")
{
device_ = FLANGE;
}
else if(device_str == "EXTRA")
{
device_ = EXTRA;
}
}
if(obj.HasMember("pin"))
{
pin_ = obj["pin"].GetUint();
Expand All @@ -868,6 +897,8 @@ namespace lebai
bool SetDioModeRequest::Serialize(rapidjson::Writer<rapidjson::StringBuffer> *writer) const
{
writer->StartObject();
writer->Key("device");
writer->Int(device_);
writer->Key("pin");
writer->Uint(pin_);
writer->Key("value");
Expand Down Expand Up @@ -913,6 +944,18 @@ namespace lebai
return false;
}

void SetDioRequest::set_device(IoDevice device)
{
device_ = device;
}
IoDevice SetDioRequest::device()
{
return device_;
}
IoDevice* SetDioRequest::mutable_device()
{
return &device_;
}
void SetDioRequest::set_pin(unsigned int pin)
{
pin_ = pin;
Expand Down Expand Up @@ -941,6 +984,22 @@ namespace lebai

bool SetDioRequest::Deserialize(const rapidjson::Value &obj)
{
if(obj.HasMember("device"))
{
std::string device_str = std::string(obj["device"].GetString());
if(device_str == "ROBOT")
{
device_ = ROBOT;
}
else if(device_str == "FLANGE")
{
device_ = FLANGE;
}
else if(device_str == "EXTRA")
{
device_ = EXTRA;
}
}
if(obj.HasMember("pin"))
{
pin_ = obj["pin"].GetUint();
Expand All @@ -954,6 +1013,8 @@ namespace lebai
bool SetDioRequest::Serialize(rapidjson::Writer<rapidjson::StringBuffer> *writer) const
{
writer->StartObject();
writer->Key("device");
writer->Int(device_);
writer->Key("pin");
writer->Uint(pin_);
writer->Key("value");
Expand Down Expand Up @@ -1095,6 +1156,18 @@ namespace lebai
return false;
}

void GetDiosModeRequest::set_device(IoDevice device)
{
device_ = device;
}
IoDevice GetDiosModeRequest::device()
{
return device_;
}
IoDevice* GetDiosModeRequest::mutable_device()
{
return &device_;
}
void GetDiosModeRequest::set_pin(unsigned int pin)
{
pin_ = pin;
Expand Down Expand Up @@ -1123,6 +1196,22 @@ namespace lebai

bool GetDiosModeRequest::Deserialize(const rapidjson::Value &obj)
{
if(obj.HasMember("device"))
{
std::string device_str = std::string(obj["device"].GetString());
if(device_str == "ROBOT")
{
device_ = ROBOT;
}
else if(device_str == "FLANGE")
{
device_ = FLANGE;
}
else if(device_str == "EXTRA")
{
device_ = EXTRA;
}
}
if(obj.HasMember("pin"))
{
pin_ = obj["pin"].GetUint();
Expand All @@ -1136,6 +1225,8 @@ namespace lebai
bool GetDiosModeRequest::Serialize(rapidjson::Writer<rapidjson::StringBuffer> *writer) const
{
writer->StartObject();
writer->Key("device");
writer->Int(device_);
writer->Key("pin");
writer->Uint(pin_);
writer->Key("count");
Expand Down
Loading

0 comments on commit 39eb1d6

Please sign in to comment.