13. 其他接口

13.1. 获取机器人DH参数补偿值

在 C++SDK-v2.1.1.0 版本加入.

1/**
2* @brief 获取机器人DH参数补偿值
3* @param [out] dhCompensation 机器人DH参数补偿值(mm) [cmpstD1,cmpstA2,cmpstA3,cmpstD4,cmpstD5,cmpstD6]
4* @return 错误码
5*/
6errno_t GetDHCompensation(double dhCompensation[6]);

13.2. 下载点位表数据库

在 C++SDK-v2.1.1.0 版本加入.

1/**
2* @brief 下载点位表数据库
3* @param [in] pointTableName 要下载的点位表名称    pointTable1.db
4* @param [in] saveFilePath 下载点位表的存储路径   C://test/
5* @return 错误码
6*/
7errno_t PointTableDownLoad(const std::string &pointTableName, const std::string &saveFilePath);

13.3. 上传点位表数据库

在 C++SDK-v2.1.1.0 版本加入.

1/**
2* @brief 上传点位表数据库
3* @param [in] pointTableFilePath 上传点位表的全路径名   C://test/pointTable1.db
4* @return 错误码
5*/
6errno_t PointTableUpLoad(const std::string &pointTableFilePath);

13.4. 点位表更新lua文件

在 C++SDK-v2.1.1.0 版本加入.

1/**
2* @brief 点位表更新lua文件
3* @param [in] pointTableName 要切换的点位表名称   "pointTable1.db",当点位表为空,即""时,表示将lua程序更新为未应用点位表的初始程序
4* @param [in] luaFileName 要更新的lua文件名称   "testPointTable.lua"
5* @param [out] errorStr 切换点位表错误信息
6* @return 错误码
7*/
8errno_t PointTableUpdateLua(const std::string &pointTableName, const std::string &luaFileName);

13.5. 初始化日志参数

在 C++SDK-v2.1.2.0 版本加入.

1/**
2* @brief 初始化日志参数;
3* @param output_model:输出模式,0-直接输出;1-缓冲输出;2-异步输出;
4* @param file_path: 文件保存路径+名称,,长度上限256,名称必须是xxx.log的形式,比如/home/fr/linux/fairino.log;
5* @param file_num:滚动存储的文件数量,1~20个.单个文件上限50M;
6* @return errno_t 错误码;
7*/
8    errno_t LoggerInit(int output_model = 0, std::string file_path = "", int file_num = 5);

13.6. 设置日志过滤等级

在 C++SDK-v2.1.2.0 版本加入.

1/**
2* @brief 设置日志过滤等级;
3* @param lvl: 过滤等级值,值越小输出日志越少,默认值是1. 1-error, 2-warnning, 3-inform, 4-debug;
4*/
5void SetLoggerLevel(int lvl = 1);

13.7. 代码示例

在 C++SDK-v2.1.2.0 版本加入.

 1#include "libfairino/robot.h"
 2
 3//如果使用Windows,包含下面的头文件
 4#include <string.h>
 5#include <windows.h>
 6//如果使用linux,包含下面的头文件
 7/*
 8#include <cstdlib>
 9#include <iostream>
10#include <stdio.h>
11#include <cstring>
12#include <unistd.h>
13*/
14#include <chrono>
15#include <thread>
16#include <string>
17
18using namespace std;
19
20int main(void)
21{
22    FRRobot robot;
23    robot.LoggerInit(2, "C:/Users/fr/Desktop/c++sdk//sdk_with_log/abcd.log", 2);
24    // robot.LoggerInit();
25    robot.SetLoggerLevel(3);
26    // robot.SetLoggerLevel();
27    robot.RPC("192.168.58.2");
28
29    double dh[6] = {0};
30    int retval = 0;
31    retval = robot.GetDHCompensation(dh);
32    cout << "retval is: " << retval << endl;
33    cout << "dh is: " << dh[0] << " " << dh[1] << " " << dh[2] << " " << dh[3] << " " << dh[4] << " " << dh[5] << endl;
34
35    string save_path = "D://sharkLog/";
36    string point_table_name = "point_table_a.db";
37    retval = robot.PointTableDownLoad(point_table_name, save_path);
38    cout<<"download : "<<point_table_name<<" fail: "<<retval<< endl;
39
40    string upload_path = "D://sharkLog/0.db";
41    retval = robot.PointTableUpLoad(upload_path);
42    cout << "retval is: "<<retval<<endl;
43
44    string point_tablename = "point_table_test.db";
45    string lua_name = "testPoint.lua";
46    retval = robot.PointTableUpdateLua(point_tablename, lua_name);
47    cout << "retval is: " << retval << endl;
48}

13.8. 获取机器人外设协议

在 C++SDK-v2.1.3.0 版本加入.

1/**
2* @brief 获取机器人外设协议
3* @param [out] protocol 机器人外设协议号 4096-扩展轴控制卡;4097-ModbusSlave;4098-ModbusMaster
4* @return 错误码
5*/
6errno_t GetExDevProtocol(int *protocol);

13.9. 设置机器人外设协议

在 C++SDK-v2.1.3.0 版本加入.

1/**
2* @brief 设置机器人外设协议
3* @param [in] protocol 机器人外设协议号 4096-扩展轴控制卡;4097-ModbusSlave;4098-ModbusMaster
4* @return 错误码
5*/
6errno_t SetExDevProtocol(int protocol);

13.10. 代码示例

在 C++SDK-v2.1.3.0 版本加入.

 1#include "libfairino/robot.h"
 2//如果使用Windows,包含下面的头文件
 3#include <string.h>
 4#include <windows.h>
 5//如果使用linux,包含下面的头文件
 6/*
 7#include <cstdlib>
 8#include <iostream>
 9#include <stdio.h>
10#include <cstring>
11#include <unistd.h>
12*/
13#include <chrono>
14#include <thread>
15#include <string>
16
17using namespace std;
18
19int main(void)
20{
21    FRRobot robot;
22    robot.LoggerInit();
23    robot.SetLoggerLevel();
24    robot.RPC("192.168.58.2");
25    int retval = 0;
26
27    ROBOT_STATE_PKG robot_pkg;
28    int i = 0;
29    while (i < 5)
30    {
31        std::this_thread::sleep_for(std::chrono::seconds(1));
32        memset(&robot_pkg, 0, sizeof(ROBOT_STATE_PKG));
33        retval = robot.GetRobotRealTimeState(&robot_pkg);
34        std::cout << "program_state " << (int)robot_pkg.program_state<< "\n"
35            << "data_len " << (int)robot_pkg.data_len << "\n"
36            << "robot_state " << (int)robot_pkg.robot_state << "\n"
37            << "robot_mode " << (int)robot_pkg.robot_mode << std::endl;
38        i++;
39    }
40
41    int protocol = 4096;
42    retval = robot.SetExDevProtocol(protocol);
43    std::cout << "SetExDevProtocol retval " << retval << std::endl;
44    retval = robot.GetExDevProtocol(&protocol);
45    std::cout << "GetExDevProtocol retval " << retval <<" protocol is: " << protocol << std::endl;
46
47    return 0;
48}