Skip to content

Commit

Permalink
Merge pull request #16 from liufang-robot/master
Browse files Browse the repository at this point in the history
修正一个rpc可能会卡死的bug,修正文档错误。
  • Loading branch information
liufang-robot authored Dec 21, 2022
2 parents e54ab8e + 6444259 commit c0db4fe
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 46 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.0.8 LANGUAGES CXX)
project(lebai VERSION 1.0.9 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.8
PROJECT_NUMBER = 1.0.9

# 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
2 changes: 1 addition & 1 deletion TODO.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# TODO

## v1.0.8
## v1.0.9

- [x] SDK版本
- [x] 系统控制-reboot
Expand Down
6 changes: 6 additions & 0 deletions doc/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# ChangeLog

## 1.0.9

修正文档错误

修正rpc的逻辑错误,该逻辑错误导致rpc调用可能卡死的问题。

## 1.0.8

添加关节跟随运动的接口towardj
Expand Down
90 changes: 52 additions & 38 deletions sdk/include/lebai/robot.hh
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ namespace lebai
* \brief 机械臂状态相关的接口.
*/

/** \addtogroup IO Input and Output
* \brief IO相关的接口
/** \addtogroup IO 通用输入输出
* \brief 通用输入输出相关的接口
*/

/** \defgroup CLAW 夹爪.
Expand Down Expand Up @@ -394,7 +394,7 @@ namespace lebai
* 11 | 示教中 | 机器人处于示教模式中
* 12 | 已停止 | 机器人处于停止状态,非急停状态
*
* @note See state <a href="https://help.lebai.ltd/guide/basic.html#%E6%9C%BA%E5%99%A8%E4%BA%BA%E7%8A%B6%E6%80%81">here</a>.
* @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();
/**
Expand Down Expand Up @@ -447,13 +447,13 @@ namespace lebai
/**
* @brief 获取机械臂关节当前反馈力矩
*
* @return * std::vector<double>
* @return 关节当前反馈力矩
*/
std::vector<double> get_actual_joint_torques();
/**
* @brief 获取机械臂关节当前控制力矩
*
* @return * std::vector<double>
* @return 关节当前控制力矩
*/
std::vector<double> get_target_joint_torques();

Expand All @@ -462,74 +462,88 @@ namespace lebai
* @{
*/
/**
* @brief 设置控制箱数字输出
*
* @brief 设置数字输出
* @param device 设备类型,以字符串形式传入,包括 `ROBOT`, `FLANGE`, `EXTRA`, `SHOULDER`, `FLANGE_BTN`
* 查看 <a href="https://help.lebai.ltd/sdk/io.html#io-%E8%AE%BE%E5%A4%87%E7%B1%BB%E5%9E%8B">详细信息</a>.
* @param pin 端口,从 0 开始
* @param value 待设置的值
*/
void set_do(std::string device, unsigned int pin, unsigned int value);
/**
* @brief 获取控制箱数字输出
*
* @brief 获取数字输出
* @param device 设备类型,以字符串形式传入,包括 `ROBOT`, `FLANGE`, `EXTRA`, `SHOULDER`, `FLANGE_BTN`
* 查看 <a href="https://help.lebai.ltd/sdk/io.html#io-%E8%AE%BE%E5%A4%87%E7%B1%BB%E5%9E%8B">详细信息</a>.
* @param pin 端口,从 0 开始
* @return 返回输入数值
* @return 返回数字输出数值
*/
unsigned int get_do(std::string device, unsigned int pin);
/**
* @brief 获取控制箱数字输出
*
* @param pin 端口,从 0 开始
* @return 返回输入数值
* @brief 获取多个数字输出
* @param device 设备类型,以字符串形式传入,包括 `ROBOT`, `FLANGE`, `EXTRA`, `SHOULDER`, `FLANGE_BTN`
* 查看 <a href="https://help.lebai.ltd/sdk/io.html#io-%E8%AE%BE%E5%A4%87%E7%B1%BB%E5%9E%8B">详细信息</a>.
* @param pin 起始数字输出端口,从 0 开始
* @param num 连续的数字输出个数
* @return 返回多个数字输出数值
*/
std::vector<unsigned int> get_dos(std::string device, unsigned int pin, unsigned int num);
/**
* @brief 获取控制箱数字输入
*
* @brief 获取数字输入
* @param device 设备类型,以字符串形式传入,包括 `ROBOT`, `FLANGE`, `EXTRA`, `SHOULDER`, `FLANGE_BTN`
* 查看 <a href="https://help.lebai.ltd/sdk/io.html#io-%E8%AE%BE%E5%A4%87%E7%B1%BB%E5%9E%8B">详细信息</a>.
* @param pin 端口,从 0 开始
* @return 返回输入数值
*/
unsigned int get_di(std::string device, unsigned int pin);
/**
* @brief 获取控制箱数字输入
*
* @param pin 端口,从 0 开始
* @return 返回输入数值
* @brief 获取多个数字输入
* @param device 设备类型,以字符串形式传入,包括 `ROBOT`, `FLANGE`, `EXTRA`, `SHOULDER`, `FLANGE_BTN`
* 查看 <a href="https://help.lebai.ltd/sdk/io.html#io-%E8%AE%BE%E5%A4%87%E7%B1%BB%E5%9E%8B">详细信息</a>.
* @param pin 起始数字输入端口,从 0 开始
* @param num 连续的数字输入个数
* @return 返回多个数字输入
*/
std::vector<unsigned int> get_dis(std::string device, unsigned int pin, unsigned int num);

/**
* @brief 设置控制箱数字输出
*
* @param pin: 端口,从 0 开始
* @param value: 待设置的值
* @brief 设置模拟输出
* @param device 设备类型,以字符串形式传入,包括 `ROBOT`, `FLANGE`, `EXTRA`, `SHOULDER`, `FLANGE_BTN`
* 查看 <a href="https://help.lebai.ltd/sdk/io.html#io-%E8%AE%BE%E5%A4%87%E7%B1%BB%E5%9E%8B">详细信息</a>.
* @param pin: 模拟输出端口,从 0 开始
* @param value: 待设置的模拟输出值
*/
void set_ao(std::string device, unsigned int pin, double value);
/**
* @brief 获取控制箱模拟输入
*
* @brief 获取模拟输出
* @param device 设备类型,以字符串形式传入,包括 `ROBOT`, `FLANGE`, `EXTRA`, `SHOULDER`, `FLANGE_BTN`
* 查看 <a href="https://help.lebai.ltd/sdk/io.html#io-%E8%AE%BE%E5%A4%87%E7%B1%BB%E5%9E%8B">详细信息</a>.
* @param pin: 端口,从 0 开始
* @return 返回输入数值
* @return 返回模拟输入数值
*/
double get_ao(std::string device, unsigned int pin);
/**
* @brief 获取控制箱模拟输入
*
* @param pin: 端口,从 0 开始
* @return 返回输入数值
* @brief 获取多个模拟输出
* @param device 设备类型,以字符串形式传入,包括 `ROBOT`, `FLANGE`, `EXTRA`, `SHOULDER`, `FLANGE_BTN`
* 查看 <a href="https://help.lebai.ltd/sdk/io.html#io-%E8%AE%BE%E5%A4%87%E7%B1%BB%E5%9E%8B">详细信息</a>.
* @param pin: 起始模拟输出端口,从 0 开始
* @param num 连续的模拟输出个数
* @return 返回模拟输出数值
*/
std::vector<double> get_aos(std::string device, unsigned int pin, unsigned int num);
/**
* @brief 获取控制箱模拟输入
*
* @brief 获取模拟输入
* @param device 设备类型,以字符串形式传入,包括 `ROBOT`, `FLANGE`, `EXTRA`, `SHOULDER`, `FLANGE_BTN`
* 查看 <a href="https://help.lebai.ltd/sdk/io.html#io-%E8%AE%BE%E5%A4%87%E7%B1%BB%E5%9E%8B">详细信息</a>.
* @param pin: 端口,从 0 开始
* @return 返回输入数值
* @return 返回模拟输入数值
*/
double get_ai(std::string device, unsigned int pin);
/**
* @brief 获取控制箱模拟输入
*
* @param pin: 端口,从 0 开始
* @return 返回输入数值
* @brief 获取多个模拟输入
* @param device 设备类型,以字符串形式传入,包括 `ROBOT`, `FLANGE`, `EXTRA`, `SHOULDER`, `FLANGE_BTN`
* 查看 <a href="https://help.lebai.ltd/sdk/io.html#io-%E8%AE%BE%E5%A4%87%E7%B1%BB%E5%9E%8B">详细信息</a>.
* @param pin: 起始模拟输入端口,从 0 开始
* @param num 连续的模拟输入个数
* @return 返回多个模拟输入数值
*/
std::vector<double> get_ais(std::string device, unsigned int pin, unsigned int num);
/** @}*/
Expand Down
4 changes: 2 additions & 2 deletions sdk/src/jsonrpc_connector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,11 @@ int JSONRpcConnector::CallRpc(const std::string & method, const std::string & re
std::string jsonrpc_resp;
jsonrpc_req = ToJSONRpcReqString(call_jsonrpc_id, method, req_data_str);
// std::cout<<"jsonrpc_req id:"<<call_jsonrpc_id<<" "<<method<<"\n";
auto future = endpoint_.createFuture(id_, call_jsonrpc_id);
if(!endpoint_.send(id_, jsonrpc_req))
{
throw std::runtime_error("Send Jsonrpc request failed!");
}
auto future = endpoint_.createFuture(id_, call_jsonrpc_id);
}
auto resq_data = future.get();
if(resp_data_str)
{
Expand Down
9 changes: 7 additions & 2 deletions sdk/src/websocket.hh
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ namespace lebai

void onMessage(websocketpp::connection_hdl, WSClient::message_ptr msg)
{
std::lock_guard<std::mutex> guard(promises_map_mutex_);
std::string message_str = msg->get_payload();
int callback_jsonrpc_id;
int error_code;
Expand All @@ -90,7 +91,7 @@ namespace lebai
return;
}
else
{
{
if(promises_.find(callback_jsonrpc_id) != promises_.end())
{
if(ret == JSONRpcRespParseResult::kResult)
Expand All @@ -103,7 +104,9 @@ namespace lebai
promises_[callback_jsonrpc_id]->set_value(std::make_tuple(error_code, resp_data_str));
promises_.erase(callback_jsonrpc_id);
}

}
else{
// Should not happen
}
}
}
Expand All @@ -120,6 +123,7 @@ namespace lebai

std::future<std::tuple<int, std::string>> createPromise(int rpc_id)
{
std::lock_guard<std::mutex> guard(promises_map_mutex_);
promises_[rpc_id] = std::make_unique<std::promise<std::tuple<int, std::string>>>();
return promises_[rpc_id]->get_future();;
}
Expand All @@ -137,6 +141,7 @@ namespace lebai
std::string uri_;
std::string server_;
std::string error_reason_;
std::mutex promises_map_mutex_;
};

// std::ostream& operator<<(std::ostream& out, ConnectionMetadata const& data) {
Expand Down
6 changes: 5 additions & 1 deletion sdk/test/test_robot.cc
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,11 @@ namespace lebai
robot_.get_di("EXTRA", 0);
robot_.set_do("EXTRA", 0, static_cast<unsigned int>(1));
robot_.get_ai("EXTRA", 0);
robot_.set_ao("EXTRA", 0, 0.0);
robot_.set_ao("EXTRA", 0, 0.0);
for(unsigned int i = 0; i < 100; ++i)
{
robot_.get_di("EXTRA", 0);
}
}
TEST_F(RobotTest, TestClaw)
{
Expand Down

0 comments on commit c0db4fe

Please sign in to comment.