ARCS SDK API  0.24.0
robot_algorithm.h
浏览该文件的文档.
1 /** @file robot_algorithm.h
2  * @brief 机器人算法相关的对外接口
3  */
4 #ifndef AUBO_SDK_ROBOT_ALGORITHM_INTERFACE_H
5 #define AUBO_SDK_ROBOT_ALGORITHM_INTERFACE_H
6 
7 #include <string>
8 #include <vector>
9 #include <memory>
10 #include <functional>
11 
12 #include <aubo/global_config.h>
13 #include <aubo/type_def.h>
14 
15 namespace arcs {
16 namespace common_interface {
17 
18 /**
19  * 机器人算法相关的对外接口
20  */
21 class ARCS_ABI_EXPORT RobotAlgorithm
22 {
23 public:
25  virtual ~RobotAlgorithm();
26 
27  /**
28  * 力传感器标定算法(三点标定法)
29  *
30  * @param force
31  * @param q
32  * @return
33  *
34  * @throws arcs::common_interface::AuboException
35  *
36  * @par Python函数原型
37  * calibrateTcpForceSensor(self: pyaubo_sdk.RobotAlgorithm, arg0:
38  * List[List[float]], arg1: List[List[float]]) -> Tuple[List[float],
39  * List[float], float, List[float]]
40  *
41  * @par Lua函数原型
42  * calibrateTcpForceSensor(force: table, q: table) -> table
43  *
44  */
45  ForceSensorCalibResult calibrateTcpForceSensor(
46  const std::vector<std::vector<double>> &forces,
47  const std::vector<std::vector<double>> &poses);
48 
49  /**
50  * 力传感器标定算法(三点标定法)
51  * @param forces
52  * @param poses
53  * @return force_offset, com, mass, angle error
54  *
55  * @throws arcs::common_interface::AuboException
56  *
57  */
58  ForceSensorCalibResultWithError calibrateTcpForceSensor2(
59  const std::vector<std::vector<double>> &forces,
60  const std::vector<std::vector<double>> &poses);
61 
62  /**
63  * 基于电流的负载辨识算法接口
64  *
65  * 需要采集空载时运行激励轨迹的位置、速度、电流以及带负载时运行激励轨迹的位置、速度、电流
66  *
67  * @param data_file_no_payload
68  * 空载时运行激励轨迹各关节数据的文件路径(.csv格式),共18列,依次为6个关节位置、6个关节速度、6个关节电流
69  * @param data_file_with_payload
70  * 带负载运行激励轨迹各关节数据的文件路径(.csv格式),共18列,依次为6个关节位置、6个关节速度、6个关节电流
71  * @return 辨识的结果
72  *
73  * @throws arcs::common_interface::AuboException
74  *
75  * @par Python函数原型
76  * payloadIdentify(self: pyaubo_sdk.RobotAlgorithm, arg0: List[List[float]],
77  * arg1: List[List[float]]) -> Tuple[List[float], List[float], float,
78  * List[float]]
79  *
80  * @par Lua函数原型
81  * payloadIdentify(data_with_payload: table, data_with_payload: table) ->
82  * table
83  *
84  */
85  int payloadIdentify(const std::string &data_file_no_payload,
86  const std::string &data_file_with_payload);
87 
88  /**
89  * 新版基于电流的负载辨识算法接口
90  *
91  * 需要采集带载时运行最少三个点的位置、速度、加速度、电流、温度、末端传感器数据、底座数据
92  *
93  * @param data
94  * 带负载的各关节数据的文件路径(.csv格式),共42列,末端传感器数据、底座数据默认为0
95  * @return 辨识的结果
96  *
97  */
98  int payloadIdentify1(const std::string &file_name);
99 
100  /**
101  * 负载辨识是否计算完成
102  * @return 完成返回0; 正在进行中返回1; 计算失败返回<0;
103  *
104  * @throws arcs::common_interface::AuboException
105  *
106  */
107  int payloadCalculateFinished();
108 
109  /**
110  * 获取负载辨识结果
111  * @return
112  *
113  * @throws arcs::common_interface::AuboException
114  *
115  */
116  Payload getPayloadIdentifyResult();
117 
118  /**
119  * 关节摩擦力模型辨识算法接口
120  *
121  * @param q
122  * @param qd
123  * @param qdd
124  * @param temp
125  * @return
126  *
127  * @throws arcs::common_interface::AuboException
128  *
129  * @par Python函数原型
130  * frictionModelIdentify(self: pyaubo_sdk.RobotAlgorithm, arg0:
131  * List[List[float]], arg1: List[List[float]], arg2: List[List[float]],
132  * arg3: List[List[float]]) -> bool
133  *
134  * @par Lua函数原型
135  * frictionModelIdentify(q: table, qd: table, qdd: table, temp: table) ->
136  * boolean
137  *
138  */
139  bool frictionModelIdentify(const std::vector<std::vector<double>> &q,
140  const std::vector<std::vector<double>> &qd,
141  const std::vector<std::vector<double>> &qdd,
142  const std::vector<std::vector<double>> &temp);
143 
144  /**
145  * 工件坐标系标定算法接口(需要在调用之前正确的设置机器人的TCP偏移)
146  * 输入多组关节角度和标定类型,输出工件坐标系位姿(相对于机器人基坐标系)
147  *
148  * @param q 关节角度
149  * @param type 标定类型
150  * @return 计算结果(工件坐标系位姿)以及错误代码
151  *
152  * @throws arcs::common_interface::AuboException
153  *
154  * @par Python函数原型
155  * calibWorkpieceCoordinatePara(self: pyaubo_sdk.RobotAlgorithm, arg0:
156  * List[List[float]], arg1: int) -> Tuple[List[float], int]
157  *
158  * @par Lua函数原型
159  * calibWorkpieceCoordinatePara(q: table, type: number) -> table, number
160  *
161  */
162  ResultWithErrno calibWorkpieceCoordinatePara(
163  const std::vector<std::vector<double>> &q, int type);
164 
165  /**
166  * 动力学正解
167  *
168  * @param q 关节角
169  * @param torqs
170  * @return 计算结果以及错误代码
171  *
172  * @throws arcs::common_interface::AuboException
173  *
174  * @par Python函数原型
175  * forwardDynamics(self: pyaubo_sdk.RobotAlgorithm, arg0: List[float], arg1:
176  * List[float]) -> Tuple[List[float], int]
177  *
178  * @par Lua函数原型
179  * forwardDynamics(q: table, torqs: table) -> table, number
180  *
181  */
182  ResultWithErrno forwardDynamics(const std::vector<double> &q,
183  const std::vector<double> &torqs);
184 
185  /**
186  * 动力学正解,基于给定的TCP偏移
187  *
188  * @param q 关节角
189  * @param torqs
190  * @return 计算结果以及错误代码,同forwardDynamics
191  *
192  * @throws arcs::common_interface::AuboException
193  *
194  * @par Python函数原型
195  * forwardDynamics(self: pyaubo_sdk.RobotAlgorithm, arg0: List[float], arg1:
196  * List[float]) -> Tuple[List[float], int]
197  *
198  * @par Lua函数原型
199  * forwardDynamics(q: table, torqs: table) -> table, number
200  *
201  */
202  ResultWithErrno forwardDynamics1(const std::vector<double> &q,
203  const std::vector<double> &torqs,
204  const std::vector<double> &tcp_offset);
205 
206  /**
207  * 运动学正解, 基于激活的TCP偏移(最近的通过 setTcpOffset 设置的参数)
208  * 输入关节角度,输出TCP位姿
209  *
210  * @param q 关节角
211  * @return TCP位姿和正解结果是否有效
212  *
213  * @throws arcs::common_interface::AuboException
214  *
215  * @par Python函数原型
216  * forwardKinematics(self: pyaubo_sdk.RobotAlgorithm, arg0: List[float]) ->
217  * Tuple[List[float], int]
218  *
219  * @par Lua函数原型
220  * forwardKinematics(q: table) -> table, number
221  *
222  */
223  ResultWithErrno forwardKinematics(const std::vector<double> &q);
224 
225  /**
226  * 运动学正解
227  * 输入关节角度,输出TCP位姿
228  *
229  * @param q 关节角
230  * @param tcp_offset tcp偏移
231  * @return TCP位姿和正解结果是否有效
232  *
233  * @throws arcs::common_interface::AuboException
234  *
235  * @par Python函数原型
236  * forwardKinematics(self: pyaubo_sdk.RobotAlgorithm, arg0: List[float],
237  * arg1: List[float]) -> Tuple[List[float], int]
238  *
239  * @par Lua函数原型
240  * forwardKinematics1(q: table, tcp_offset: table) -> table, number
241  *
242  * @since 0.24.1
243  *
244  */
245  ResultWithErrno forwardKinematics1(const std::vector<double> &q,
246  const std::vector<double> &tcp_offset);
247 
248  /**
249  * 运动学正解(忽略 TCP 偏移值)
250  *
251  * @param q 关节角
252  * @return 法兰盘中心位姿和正解结果是否有效
253  *
254  * @throws arcs::common_interface::AuboException
255  *
256  */
257  ResultWithErrno forwardToolKinematics(const std::vector<double> &q);
258 
259  /**
260  * 运动学逆解
261  * 输入TCP位姿和参考关节角度,输出关节角度
262  *
263  * @param qnear 参考关节角
264  * @param pose TCP位姿
265  * @return 关节角和逆解结果是否有效
266  * 返回值的第一个参数为逆解结果,第二个为逆解错误码,错误码返回列表如下
267  * 0 - 成功
268  * -23 - 逆解计算不收敛,计算出错
269  * -24 - 逆解计算超出机器人最大限制
270  * -25 - 逆解输入配置存在错误
271  * -26 - 逆解雅可比矩阵计算失败
272  * -27 - 目标点存在解析解,但均不满足选解条件
273  * -28 - 逆解返回未知类型错误
274  * 若错误码非0,则返回值的第一个参数为输入参考关节角qnear
275  *
276  * @throws arcs::common_interface::AuboException
277  *
278  * @par Python函数原型
279  * inverseKinematics(self: pyaubo_sdk.RobotAlgorithm, arg0: List[float],
280  * arg1: List[float]) -> Tuple[List[float], int]
281  *
282  * @par Lua函数原型
283  * inverseKinematics(qnear: table, pose: table) -> table, int
284  *
285  */
286  ResultWithErrno inverseKinematics(const std::vector<double> &qnear,
287  const std::vector<double> &pose);
288 
289  /**
290  * 运动学逆解
291  * 输入TCP位姿和参考关节角度,输出关节角度
292  *
293  * @param qnear 参考关节角
294  * @param pose TCP位姿
295  * @param tcp_offset TCP偏移
296  * @return 关节角和逆解结果是否有效,同 inverseKinematics
297  * @throws arcs::common_interface::AuboException
298  *
299  * @par Python函数原型
300  * inverseKinematics(self: pyaubo_sdk.RobotAlgorithm, arg0: List[float],
301  * arg1: List[float]) -> Tuple[List[float], int]
302  *
303  * @par Lua函数原型
304  * inverseKinematics(qnear: table, pose: table) -> table, int
305  *
306  */
307  ResultWithErrno inverseKinematics1(const std::vector<double> &qnear,
308  const std::vector<double> &pose,
309  const std::vector<double> &tcp_offset);
310 
311  /**
312  * 求出所有的逆解, 基于激活的 TCP 偏移
313  *
314  * @param pose TCP位姿
315  * @return 关节角和逆解结果是否有效
316  * 返回的错误码同inverseKinematics
317  *
318  * @throws arcs::common_interface::AuboException
319  *
320  */
321  ResultWithErrno1 inverseKinematicsAll(const std::vector<double> &pose);
322 
323  /**
324  * 求出所有的逆解, 基于提供的 TCP 偏移
325  *
326  * @param pose TCP位姿
327  * @param tcp_offset TCP偏移
328  * @return 关节角和逆解结果是否有效,同 inverseKinematicsAll
329  * 返回的错误码同inverseKinematics
330  *
331  * @throws arcs::common_interface::AuboException
332  *
333  */
334  ResultWithErrno1 inverseKinematicsAll1(
335  const std::vector<double> &pose, const std::vector<double> &tcp_offset);
336 
337  /**
338  * 运动学逆解(忽略 TCP 偏移值)
339  *
340  * @param qnear 参考关节角
341  * @param pose 法兰盘中心的位姿
342  * @return 关节角和逆解结果是否有效
343  *
344  * @throws arcs::common_interface::AuboException
345  *
346  */
347  ResultWithErrno inverseToolKinematics(const std::vector<double> &qnear,
348  const std::vector<double> &pose);
349 
350  /**
351  * 运动学逆解(忽略 TCP 偏移值)
352  *
353  * @param qnear 参考关节角
354  * @param pose 法兰盘中心的位姿
355  * @return 关节角和逆解结果是否有效
356  *
357  * @throws arcs::common_interface::AuboException
358  *
359  */
360  ResultWithErrno1 inverseToolKinematicsAll(const std::vector<double> &pose);
361 
362  /**
363  * 求解movej之间的轨迹点
364  *
365  * @param q1 movej的起点
366  * @param r1 在q1处的交融半径
367  * @param q2 movej的终点
368  * @param r2 在q2处的交融半径
369  * @param d 采样距离
370  * @return q1~q2 之间笛卡尔空间离散轨迹点(x,y,z,rx,ry,rz)集合
371  *
372  * @throws arcs::common_interface::AuboException
373  *
374  * @par Python函数原型
375  * pathMovej(self: pyaubo_sdk.RobotAlgorithm, arg0: List[float], arg1:
376  * float, arg2: List[float], arg3: float, arg4: float) -> List[List[float]]
377  *
378  * @par Lua函数原型
379  * pathMovej(q1: table, r1: number, q2: table, r2: number, d: number) ->
380  * table, number
381  */
382  std::vector<std::vector<double>> pathMovej(const std::vector<double> &q1,
383  double r1,
384  const std::vector<double> &q2,
385  double r2, double d);
386  /**
387  * 计算机械臂末端的雅克比矩阵
388  *
389  * @param q 关节角
390  * @param base_or_end 参考坐标系为基坐标系(或者末端坐标系)
391  * true: 在 base 下描述
392  * false: 在 末端坐标系 下描述
393  * @return 雅克比矩阵是否有效
394  * 返回值的第一个参数为该构型下对应的雅克比矩阵,第二个为逆解错误码
395  * 此接口的错误码返回值在0.28.1-rc.21 0.29.0-alpha.25版本之后做了修改。
396  * 此前逆解错误时返回 30082 ,修改后错误码返回列表如下
397  * 0 - 成功
398  * -23 - 逆解计算不收敛,计算出错
399  * -24 - 逆解计算超出机器人最大限制
400  * -25 - 逆解输入配置存在错误
401  * -26 - 逆解雅可比矩阵计算失败
402  * -27 - 目标点存在解析解,但均不满足选解条件
403  * -28 - 逆解返回未知类型错误
404  * 若错误码非0,则返回值的第一个参数为输入参考关节角qnear
405  *
406  * @throws arcs::common_interface::AuboException
407  *
408  * @par Python函数原型
409  * calJacobian(self: pyaubo_sdk.RobotAlgorithm, arg0: List[float],
410  * arg1: bool) -> Tuple[List[float], int]
411  *
412  * @par Lua函数原型
413  * calJacobian(q: table, base_or_end: boolean) -> table
414  *
415  */
416  ResultWithErrno calcJacobian(const std::vector<double> &q,
417  bool base_or_end);
418 
419  /**
420  * 求解交融的轨迹点
421  *
422  * @param type
423  * 0-movej and movej
424  * 1-movej and movel
425  * 2-movel and movej
426  * 3-movel and movel
427  * @param q_start 交融前路径的起点
428  * @param q_via 在q1处的交融半径
429  * @param q_to 交融后路径的终点
430  * @param r 在q_via处的交融半径
431  * @param d 采样距离
432  * @return q_via处的交融段笛卡尔空间离散轨迹点(x,y,z)集合
433  *
434  * @throws arcs::common_interface::AuboException
435  *
436  * @par Python函数原型
437  * pathBlend3Points(self: pyaubo_sdk.RobotAlgorithm, arg0: int, arg1:
438  * List[float], arg2: List[float], arg3: List[float], arg4: float, arg5:
439  * float) -> List[List[float]]
440  *
441  *
442  * @par Lua函数原型
443  * pathBlend3Points(type: number, q_start: table, q_via: table, q_to: table,
444  * r: number, d: number) -> table, number
445  */
446  std::vector<std::vector<double>> pathBlend3Points(
447  int type, const std::vector<double> &q_start,
448  const std::vector<double> &q_via, const std::vector<double> &q_to,
449  double r, double d);
450 
451  /**
452  * 生成用于负载辨识的激励轨迹
453  * 此接口内部调用pathBufferAppend
454  * 将离线轨迹存入buffer中,后续可通过movePathBuffer运行离线轨迹
455  * @param name 轨迹名字
456  * @param traj_conf 各关节轨迹的限制条件
457  * traj_conf.move_axis: 运动的轴
458  * 由于实际用户现场可能不希望在负载辨识时控制机械臂多关节大幅度运动,故最好选用traj_conf.move_axis=LoadIdentifyMoveAxis::Joint_4_6;
459  * traj_conf.init_joint:
460  * 运动初始关节角,为了避免关节5接近零位时的奇异问题,应设置traj_conf.init_joint[4]的绝对值不小于0.3(rad),接近1.57(rad)为宜。其余关节的关节角可任意设置
461  * traj_conf.lower_joint_bound, traj_conf.upper_joint_bound:
462  * 关节角上下限,维度应与config.move_axis维度保持一致,推荐设置upper_joint_bound为2,lower_joint_bound为-2
463  * config.max_velocity, config.max_acceleration:
464  * 关节角速度角加速度限制,维度应与config.move_axis维度保持一致,出于安全和驱动器跟随性能的考虑,推荐设置max_velocity=3,max_acceleration=5
465  *
466  * @return 成功返回0;失败返回错误码
467  * AUBO_BUSY
468  * AUBO_BAD_STATE
469  * -AUBO_INVL_ARGUMENT
470  * -AUBO_BAD_STATE
471  *
472  * @throws arcs::common_interface::AuboException
473  *
474  */
475  int generatePayloadIdentifyTraj(const std::string &name,
476  const TrajConfig &traj_conf);
477  /**
478  * 负载辨识轨迹是否生成完成
479  *
480  * @return 完成返回0; 正在进行中返回1; 计算失败返回<0;
481  *
482  * @throws arcs::common_interface::AuboException
483  *
484  */
485  int payloadIdentifyTrajGenFinished();
486 
487 protected:
488  void *d_;
489 };
490 using RobotAlgorithmPtr = std::shared_ptr<RobotAlgorithm>;
491 
492 // clang-format off
493 #define RobotAlgorithm_DECLARES \
494  _FUNC(RobotAlgorithm, 2, calibrateTcpForceSensor, forces, poses) \
495  _FUNC(RobotAlgorithm, 2, calibrateTcpForceSensor2, forces, poses) \
496  _FUNC(RobotAlgorithm, 2, payloadIdentify, data_no_payload, data_with_payload) \
497  _FUNC(RobotAlgorithm, 1, payloadIdentify1, file_name) \
498  _FUNC(RobotAlgorithm, 0, payloadCalculateFinished) \
499  _FUNC(RobotAlgorithm, 0, getPayloadIdentifyResult) \
500  _FUNC(RobotAlgorithm, 2, generatePayloadIdentifyTraj, name, TrajConfig) \
501  _FUNC(RobotAlgorithm, 0, payloadIdentifyTrajGenFinished) \
502  _FUNC(RobotAlgorithm, 4, frictionModelIdentify, q, qd, qdd, temp) \
503  _FUNC(RobotAlgorithm, 2, calibWorkpieceCoordinatePara, q, type) \
504  _FUNC(RobotAlgorithm, 2, forwardDynamics, q, torqs) \
505  _FUNC(RobotAlgorithm, 1, forwardKinematics, q) \
506  _FUNC(RobotAlgorithm, 1, forwardToolKinematics, q) \
507  _FUNC(RobotAlgorithm, 3, forwardDynamics1, q, torqs, tcp_offset) \
508  _FUNC(RobotAlgorithm, 2, forwardKinematics1, q, tcp_offset) \
509  _FUNC(RobotAlgorithm, 2, inverseKinematics, qnear, pose) \
510  _FUNC(RobotAlgorithm, 1, inverseKinematicsAll, pose) \
511  _FUNC(RobotAlgorithm, 3, inverseKinematics1, qnear, pose, tcp_offset) \
512  _FUNC(RobotAlgorithm, 2, inverseKinematicsAll1, pose, tcp_offset) \
513  _FUNC(RobotAlgorithm, 2, inverseToolKinematics, qnear, pose) \
514  _FUNC(RobotAlgorithm, 1, inverseToolKinematicsAll, pose) \
515  _FUNC(RobotAlgorithm, 5, pathMovej, q1, r1, q2, r2, d) \
516  _FUNC(RobotAlgorithm, 6, pathBlend3Points, type, q_start, q_via, q_to, r, d) \
517  _FUNC(RobotAlgorithm, 2, calcJacobian, q, base_or_end)
518 
519 // clang-format on
520 
521 } // namespace common_interface
522 } // namespace arcs
523 
524 #endif // AUBO_SDK_ROBOT_ALGORITHM_INTERFACE_H
数据类型的定义
std::tuple< std::vector< double >, int > ResultWithErrno
Definition: type_def.h:659
std::tuple< double, std::vector< double >, std::vector< double >, std::vector< double >> Payload
Definition: type_def.h:664
机器人算法相关的对外接口
std::tuple< std::vector< double >, std::vector< double >, double, std::vector< double >> ForceSensorCalibResult
Definition: type_def.h:669
用于负载辨识的轨迹配置
Definition: type_def.h:642
std::tuple< std::vector< std::vector< double >>, int > ResultWithErrno1
Definition: type_def.h:660
std::tuple< std::vector< double >, std::vector< double >, double, std::vector< double >, double > ForceSensorCalibResultWithError
Definition: type_def.h:674
Definition: aubo_api.h:17
std::shared_ptr< RobotAlgorithm > RobotAlgorithmPtr