Skip to content

Commit

Permalink
Merge pull request #57 from liufang-robot/master
Browse files Browse the repository at this point in the history
修正future数据不能返回的问题
  • Loading branch information
liufang-robot authored Nov 10, 2023
2 parents c8b0cea + 13b536c commit db7430d
Show file tree
Hide file tree
Showing 9 changed files with 221 additions and 169 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,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.8 LANGUAGES CXX)
project(lebai VERSION 1.1.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.1.8
PROJECT_NUMBER = 1.1.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
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.1.9

添加接口连接抛出异常的处理

## 1.1.8

speedl添加参考坐标系
Expand Down
84 changes: 52 additions & 32 deletions examples/example.cc
Original file line number Diff line number Diff line change
@@ -1,76 +1,96 @@
/**
* Copyright 2022 lebai.ltd
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
*/

#include <iostream>
#include <chrono>
#include <thread>
#include <cmath>
#include <lebai/robot.hh>


int main(int argc, char ** argv)
int main(int argc, char **argv)
{
if(argc < 2)
if (argc < 2)
{
std::cerr<<"You must specify the IP address of the robot"<<std::endl;
std::cerr<<"Execute example as follow:"<<std::endl;
std::cerr<<"./example 192.168.1.200 sim"<<std::endl;
std::cerr << "You must specify the IP address of the robot" << std::endl;
std::cerr << "Execute example as follow:" << std::endl;
std::cerr << "./example 192.168.1.200 sim" << std::endl;
return 0;
}
std::string ip = argv[1];
bool sim = false;
if(argc > 2)
if (argc > 2)
{
std::string sim_str = argv[2];
if(sim_str == "sim")
if (sim_str == "sim")
{
sim = true;
}
}
std::cout<<"Connecting to robot at "<<ip<<std::endl;
std::cout<<"Connecting for simulation mode is "<<sim<<std::endl;
std::cout << "Connecting to robot at " << ip << std::endl;
std::cout << "Connecting for simulation mode is " << sim << std::endl;
// Create robot instance
lebai::l_master::Robot robot(ip, sim);
std::this_thread::sleep_for(std::chrono::seconds(1));
robot.movej({13.0/ 180.0 * M_PI, -52.0/ 180.0 * M_PI, 86.0/ 180.0 * M_PI, 8.0/ 180.0 * M_PI, -59.0/ 180.0 * M_PI, -11.0/ 180.0 * M_PI}, 1.0, 0.5, 0.0, 0.0);
std::this_thread::sleep_for(std::chrono::seconds(1));
robot.movej({13.0 / 180.0 * M_PI, -52.0 / 180.0 * M_PI, 86.0 / 180.0 * M_PI, 8.0 / 180.0 * M_PI, -59.0 / 180.0 * M_PI, -11.0 / 180.0 * M_PI}, 1.0, 0.5, 0.0, 0.0);
robot.movej({0.0 / 180.0 * M_PI, -52.0 / 180.0 * M_PI, 86.0 / 180.0 * M_PI,
8.0 / 180.0 * M_PI, -59.0 / 180.0 * M_PI, -11.0 / 180.0 * M_PI},
1.0, 0.5, 0.0, 0.0);
robot.wait_move();
auto id = robot.start_task("10052");
std::cout << "id " << id << "\n";
for (size_t i = 0; i < 30; ++i)
{
std::this_thread::sleep_for(std::chrono::seconds(1));
try {
robot.get_robot_mode();
}
catch(std::runtime_error & ex)
{
std::cout<<"get_robot_mode error: "<<ex.what()<<std::endl;
}

}

// std::cout << "after sleep" << std::endl;
// bool is_network_connected = robot.is_network_connected();
// std::cout << "is connected "
// << "\n";
// if (!is_network_connected)
// {
// std::cout << "exit....\n";
// return 0;
// }

// robot.wait_move();
// robot.movec({{"x", -0.282541}, {"y", -0.168246}, {"z", 0.265824}, {"rz", 1.27256}, {"ry", -0.206353}, {"rx", 0.937445}},
// {{"x", -0.255832}, {"y", 0.00270435}, {"z", 0.266642}, {"rz", 1.27293}, {"ry", -0.20805}, {"rx", 0.94485}},
// 0.0, 1.0, 0.5, 0.0, 0.0);
// kinematics_forward: -0.282541, -0.168246, 0.265824, 1.27256, -0.206353, 0.937445
// kinematics_forward: -0.255832, 0.00270435, 0.266642, 1.27293, -0.20805, 0.94485
// kinematics_forward: -0.282541, -0.168246, 0.265824, 1.27256, -0.206353, 0.937445
// kinematics_forward: -0.255832, 0.00270435, 0.266642, 1.27293, -0.20805, 0.94485

//auto fk_resp = robot.kinematics_forward({3.0/ 180.0 * M_PI, -48.0/ 180.0 * M_PI, 78.0/ 180.0 * M_PI, 9.0/ 180.0 * M_PI, -67.0/ 180.0 * M_PI, -3.0/ 180.0 * M_PI});
//std::vector<double> jp = {3.0/ 180.0 * M_PI, -48.0/ 180.0 * M_PI, 78.0/ 180.0 * M_PI, 9.0/ 180.0 * M_PI, -67.0/ 180.0 * M_PI, -3.0/ 180.0 * M_PI};
//std::cout<<"jp "<<jp[0]<<", "<<jp[1]<<", "<<jp[2]<<", "<<jp[3]<<", "<<jp[4]<<", "<<jp[5]<<std::endl;
//std::cout<<"kinematics_forward: "<<fk_resp.pose["x"]<<", "<<fk_resp.pose["y"]<<", "<<fk_resp.pose["z"]<<", "<<fk_resp.pose["rx"]<<", "<<fk_resp.pose["ry"]<<", "<<fk_resp.pose["rz"]<<std::endl;
//auto ik_resp = robot.kinematics_inverse(fk_resp.pose);
//if(ik_resp.ok)
// auto fk_resp = robot.kinematics_forward({3.0/ 180.0 * M_PI, -48.0/ 180.0 * M_PI, 78.0/ 180.0 * M_PI, 9.0/ 180.0 * M_PI, -67.0/ 180.0 * M_PI, -3.0/ 180.0 * M_PI});
// std::vector<double> jp = {3.0/ 180.0 * M_PI, -48.0/ 180.0 * M_PI, 78.0/ 180.0 * M_PI, 9.0/ 180.0 * M_PI, -67.0/ 180.0 * M_PI, -3.0/ 180.0 * M_PI};
// std::cout<<"jp "<<jp[0]<<", "<<jp[1]<<", "<<jp[2]<<", "<<jp[3]<<", "<<jp[4]<<", "<<jp[5]<<std::endl;
// std::cout<<"kinematics_forward: "<<fk_resp.pose["x"]<<", "<<fk_resp.pose["y"]<<", "<<fk_resp.pose["z"]<<", "<<fk_resp.pose["rx"]<<", "<<fk_resp.pose["ry"]<<", "<<fk_resp.pose["rz"]<<std::endl;
// auto ik_resp = robot.kinematics_inverse(fk_resp.pose);
// if(ik_resp.ok)
//{
// std::cout<<"kinematics_inverse: "<<ik_resp.joint_positions[0]<<", "<<ik_resp.joint_positions[1]<<", "<<ik_resp.joint_positions[2]<<", "<<ik_resp.joint_positions[3]<<", "<<ik_resp.joint_positions[4]<<", "<<ik_resp.joint_positions[5]<<std::endl;
//}
//jp = {-28/ 180.0 * M_PI, -59.0/ 180.0 * M_PI, 96.0/ 180.0 * M_PI, -2.0/ 180.0 * M_PI, -92.0/ 180.0 * M_PI, 16.0/ 180.0 * M_PI};
//std::cout<<"jp "<<jp[0]<<", "<<jp[1]<<", "<<jp[2]<<", "<<jp[3]<<", "<<jp[4]<<", "<<jp[5]<<std::endl;
//fk_resp = robot.kinematics_forward(jp);
//std::cout<<"kinematics_forward: "<<fk_resp.pose["x"]<<", "<<fk_resp.pose["y"]<<", "<<fk_resp.pose["z"]<<", "<<fk_resp.pose["rx"]<<", "<<fk_resp.pose["ry"]<<", "<<fk_resp.pose["rz"]<<std::endl;
// std::cout<<"kinematics_inverse: "<<ik_resp.joint_positions[0]<<", "<<ik_resp.joint_positions[1]<<", "<<ik_resp.joint_positions[2]<<", "<<ik_resp.joint_positions[3]<<", "<<ik_resp.joint_positions[4]<<", "<<ik_resp.joint_positions[5]<<std::endl;
// }
// jp = {-28/ 180.0 * M_PI, -59.0/ 180.0 * M_PI, 96.0/ 180.0 * M_PI, -2.0/ 180.0 * M_PI, -92.0/ 180.0 * M_PI, 16.0/ 180.0 * M_PI};
// std::cout<<"jp "<<jp[0]<<", "<<jp[1]<<", "<<jp[2]<<", "<<jp[3]<<", "<<jp[4]<<", "<<jp[5]<<std::endl;
// fk_resp = robot.kinematics_forward(jp);
// std::cout<<"kinematics_forward: "<<fk_resp.pose["x"]<<", "<<fk_resp.pose["y"]<<", "<<fk_resp.pose["z"]<<", "<<fk_resp.pose["rx"]<<", "<<fk_resp.pose["ry"]<<", "<<fk_resp.pose["rz"]<<std::endl;
return 0;
}
10 changes: 4 additions & 6 deletions sdk/include/lebai/robot.hh
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ namespace lebai
/**
* @brief 机械臂的主要接口对象,通过本对象的方法与机械臂进行数据交互.
* @note 使用该数据结构和机械臂交互要求机械臂软件版本>=3.1.5。
* @note 接口的每一个函数都可能抛出异常std::runtime_error, 这是因为网络连接丢失或者调用的逻辑错误等。
*
*
*/
class Robot
Expand All @@ -71,6 +73,7 @@ namespace lebai
/**
* @brief 内部实现.
* @note 用户无需使用.
*
*/
class RobotImpl;

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

/**
* @brief 返回是否和机械臂的网络连接正常,如果网络连接异常,调用和机械臂交互的接口会抛出异常std::runtime_error。
*
* @note 不建议使用,直接catch接口调用获取网络异常。
* @return true 表示网络连接正常,false表示网络连接异常.
*/
bool is_network_connected();
Expand Down
Loading

0 comments on commit db7430d

Please sign in to comment.