Skip to content

Commit

Permalink
添加is_network_connected方法 (#38)
Browse files Browse the repository at this point in the history
* fix: 完善文档,添加dotnet的文档。

* fix: 修正linux_python_build.yml重复编译的问题,以及没有指定PYTHONPATH的问题。

* fix: 修正文档错误

* feat: 添加python2的构建选项 修正旋转部分数据表示x和z反了的问题 完善文档

* 修正websocket在windows平台的问题。

* cmake require 版本3.18.2

* 修正rx,ry,rz的问题

* feat: 添加is_network_connected方法
  • Loading branch information
liufang-robot authored May 4, 2023
1 parent 18bd157 commit af5b391
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 4 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.20 LANGUAGES CXX)
project(lebai VERSION 1.0.21 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.20
PROJECT_NUMBER = 1.0.21

# 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
4 changes: 4 additions & 0 deletions doc/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# ChangeLog

## 1.0.21

添加is_network_connected方法。

## 1.0.20

修正windows平台编译WebSocket的问题。
Expand Down
18 changes: 16 additions & 2 deletions sdk/include/lebai/robot.hh
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,16 @@ namespace lebai

/**
* @brief 构造Robot对象.
* @note 当你尝试创建Robot对象时,会根据传入的ip参数尝试去连接机械臂,但是可能会连接失败,当连接不成功时,对象依然会创建。
*
* 但是如果网络没有连接成功而你调用和机械臂交互的接口时,会抛出std::runtime_error异常,表示网络连接异常.
*
* 你可以通过@ref is_network_connected()方法来判断是否连接成功,如果连接不成功,你可以尝试重新创建Robot对象,或者等待网络恢复.
*
*
*
* @param ip: 机械臂IP地址.
* @param simulator: 用于表示机械臂是否为仿真机械臂(docker仿真或控制器运行在仿真模式下)的标志.True表示仿真模式,False表示实物机械臂.
* @param simulator: 用于表示机械臂是否为仿真机械臂(docker仿真或控制器运行在仿真模式下)的macs标志.True表示仿真模式,False表示实物机械臂.
*/
explicit Robot(std::string ip, bool simulator = false);
/**
Expand All @@ -101,6 +108,13 @@ namespace lebai
*/
std::tuple<int, std::string> call(const std::string & method, const std::string & params);

/**
* @brief 返回是否和机械臂的网络连接正常,如果网络连接异常,调用和机械臂交互的接口会抛出异常std::runtime_error。
*
* @return true 表示网络连接正常,false表示网络连接异常.
*/
bool is_network_connected();

/** \defgroup STARTSTOP 启动停止.
* \brief 启动停止相关的接口.
*/
Expand Down Expand Up @@ -364,7 +378,7 @@ namespace lebai
/**
* @brief 查询指定MotionId的运动状态.
*
* @param id 指定的运动id.
* @return id 指定的运动id.
*/
std::string get_motion_state(unsigned int id);
/**
Expand Down
4 changes: 4 additions & 0 deletions sdk/src/robot.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ std::tuple<int, std::string> Robot::call(const std::string & method, const std::
{
return impl_->call(method, params);
}
bool Robot::is_network_connected()
{
return impl_->isNetworkConnected();
}

void Robot::start_sys()
{
Expand Down
5 changes: 5 additions & 0 deletions sdk/src/robot_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ namespace lebai
return std::make_tuple(ret, resp_data_str);
}

bool Robot::RobotImpl::isNetworkConnected()
{
return json_rpc_connector_->GetConnectionStatus() == JSONRpcConnector::kOpen;
}

int Robot::RobotImpl::startSys()
{
return json_rpc_connector_->CallRpc("start_sys", "{}", nullptr);
Expand Down
1 change: 1 addition & 0 deletions sdk/src/robot_impl.hh
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ namespace lebai
RobotImpl(const::std::string &ip, bool simulator);
virtual ~RobotImpl();
std::tuple<int, std::string> call(const std::string & method, const std::string & params);
bool isNetworkConnected();
int startSys();
int stopSys();
int powerdown();
Expand Down
4 changes: 4 additions & 0 deletions sdk/test/test_robot.cc
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,10 @@ namespace lebai
kf_resp.pose = robot_.pose_times(kf_resp.pose, kf_resp.pose);
kf_resp.pose = robot_.pose_inverse(kf_resp.pose);
}
TEST_F(RobotTest, TestNetworkConnection)
{
EXPECT_TRUE(robot_.is_network_connected());
}
}

int main(int argc, char **argv)
Expand Down

0 comments on commit af5b391

Please sign in to comment.