lebai sdk 1.1.33
lebai c++ sdk with swig to support sereval languages.
Loading...
Searching...
No Matches
robot.hh
1
17#pragma once
18
19#include <memory>
20#include <string>
21#include <vector>
22#include <array>
23#include <map>
24
25namespace lebai {
26namespace l_master {
32std::string version();
38using CartesianPose = std::map<std::string, double>;
39using DoubleVector = std::vector<double>;
45 CartesianPose
49 bool ok = false;
50};
56 DoubleVector
60 bool ok = false;
61};
62/***
63 * @brief 夹爪数据结构.
64 *
65 */
66struct ClawData {
67 double force;
68 double amplitude;
69 bool hold_on;
70};
71
80class Robot {
81 public:
87 class RobotImpl;
88
99 explicit Robot(std::string ip, bool simulator = false);
104 virtual ~Robot();
105
106 // clang-format off
124 // clang-format on
125 std::tuple<int, std::string> call(const std::string &method,
126 const std::string &params);
127
135
200 void start_sys();
206 void stop_sys();
211 void powerdown();
216 void stop();
221 void estop();
236 void pause();
241 void resume();
245 void reboot();
273 int movej(const std::vector<double> &joint_positions, double a, double v,
274 double t, double r);
297 int movej(const CartesianPose &cart_pose, double a, double v, double t,
298 double r);
319 int movel(const std::vector<double> &joint_positions, double a, double v,
320 double t, double r);
343 int movel(const CartesianPose &cart_pose, double a, double v, double t,
344 double r);
369 int movec(const std::vector<double> &joint_via,
370 const std::vector<double> &joint, double rad, double a, double v,
371 double t, double r);
389 int movec(const CartesianPose &cart_via, const CartesianPose &cart,
390 double rad, double a, double v, double t, double r);
403 int speedj(double a, const std::vector<double> &v, double t = 0.0);
419 int speedl(double a, const CartesianPose &v, double t = 0.0,
420 const CartesianPose &reference = {{"x", 0.0},
421 {"y", 0.0},
422 {"z", 0.0},
423 {"rx", 0.0},
424 {"ry", 0.0},
425 {"rz", 0.0}});
447 int towardj(const std::vector<double> &joint_positions, double a, double v,
448 double t, double r);
457 void move_pvat(std::vector<double> p, std::vector<double> v,
458 std::vector<double> a, double t);
464 void wait_move(unsigned int id);
469 void wait_move();
473 unsigned int get_running_motion();
479 std::string get_motion_state(unsigned int id);
483 void stop_move();
532 bool is_down();
538 std::vector<double> get_actual_joint_positions();
544 std::vector<double> get_target_joint_positions();
550 std::vector<double> get_actual_joint_speed();
551 // get_target_joint_speed
557 std::vector<double> get_target_joint_speed();
564 CartesianPose get_actual_tcp_pose();
571 CartesianPose get_target_tcp_pose();
572
579 double get_joint_temp(unsigned int joint_index);
580
586 std::vector<double> get_actual_joint_torques();
592 std::vector<double> get_target_joint_torques();
593
616 void set_do(std::string device, unsigned int pin, unsigned int value);
624 unsigned int get_do(std::string device, unsigned int pin);
633 std::vector<unsigned int> get_dos(std::string device, unsigned int pin,
634 unsigned int num);
642 unsigned int get_di(std::string device, unsigned int pin);
651 std::vector<unsigned int> get_dis(std::string device, unsigned int pin,
652 unsigned int num);
653
661 void set_ao(std::string device, unsigned int pin, double value);
669 double get_ao(std::string device, unsigned int pin);
678 std::vector<double> get_aos(std::string device, unsigned int pin,
679 unsigned int num);
687 double get_ai(std::string device, unsigned int pin);
696 std::vector<double> get_ais(std::string device, unsigned int pin,
697 unsigned int num);
706 void set_dio_mode(std::string device, unsigned int pin, bool value);
715 std::vector<bool> get_dios_mode(std::string device, unsigned int pin,
716 unsigned int count);
729 void set_claw(double force, double amplitude);
736 std::tuple<double, double, bool> get_claw();
757 void set_led(unsigned int mode, unsigned int speed,
758 const std::vector<unsigned int> &color);
765 void set_voice(unsigned int voice, unsigned int volume);
771 void set_fan(unsigned int status);
784 void set_signal(unsigned int index, int value);
791 int get_signal(unsigned int index);
798 void add_signal(unsigned int index, int value);
816 unsigned int start_task(const std::string &name,
817 const std::vector<std::string> &params,
818 const std::string &dir, bool is_parallel,
819 unsigned int loop_to);
825 unsigned int start_task(const std::string &name);
829 std::vector<unsigned int> load_task_list();
836 bool wait_task(unsigned int id);
844 void pause_task(unsigned int id, unsigned long time, bool wait);
849 void pause_task(unsigned int id);
855 void resume_task(unsigned int id);
861 void cancel_task(unsigned int id);
867 unsigned int exec_hook(unsigned int id);
871 std::string get_task_state();
877 std::string get_task_state(unsigned int id);
890 const std::vector<double> &joint_positions);
891
899 const CartesianPose &pose,
900 const std::vector<double> &joint_init_positions = {});
901
909 CartesianPose pose_times(const CartesianPose &a, const CartesianPose &b);
910
917 CartesianPose pose_inverse(const CartesianPose &in);
931 void save_file(const std::string &dir, const std::string &name, bool is_dir,
932 const std::string &data);
941 void rename_file(const std::string &from_dir, const std::string &from_name,
942 const std::string &to_dir, const std::string &to_name);
943
952 std::tuple<bool, std::string> load_file(const std::string &dir,
953 const std::string &name);
954
964 std::vector<std::tuple<bool, std::string>> load_file_list(
965 const std::string &dir, const std::string &prefix,
966 const std::string &suffix);
975 // void zip(const std::string &from_dir, std::vector<std::string> files, const
976 // std::string &to_dir, const std::string &name);
977 // /**
978 // * @brief 将zip文件解压到文件系统.
979 // *
980 // * @param from_dir zip文件的路径.
981 // * @param name zip文件的名称.
982 // * @param files zip文件内的文件名.
983 // * @param to_dir 解压到的路径.
984 // */
985 // void unzip(const std::string &from_dir, const std::string &name,
986 // std::vector<std::string> files, const std::string &to_dir);
987 // /**
988 // * @brief 查询文件列表.
989 // *
990 // * @brief 目标zip文件名.
991 // * @param dir 文件的目录.
992 // * @param prefix 前缀.
993 // * @param suffix 后缀.
994 // *
995 // * @return 文件列表.
996 // */
997 // //std::vector<std::tuple<bool,string>> load_zip_list(const std::string
998 // &zip,const std::string &dir,const std::string &prefix,const std::string
999 // &suffix);
1000
1011 void set_tcp(std::array<double, 6> tcp);
1017 std::array<double, 6> get_tcp();
1023 void set_velocity_factor(int factor);
1036 void set_payload(double mass, std::map<std::string, double> cog);
1042 void set_payload_mass(double mass);
1048 void set_payload_cog(std::map<std::string, double> cog);
1054 std::map<std::string, double> get_payload();
1060 void set_gravity(std::map<std::string, double> gravity);
1066 std::map<std::string, double> get_gravity();
1073 CartesianPose load_tcp(std::string name, std::string dir = "");
1087 void write_single_coil(std::string device, std::string addr, bool value);
1088
1096 void wirte_multiple_coils(std::string device, std::string addr,
1097 std::vector<bool> values);
1098
1106 std::vector<bool> read_coils(std::string device, std::string addr,
1107 unsigned int num);
1115 std::vector<bool> read_discrete_inputs(std::string device, std::string addr,
1116 unsigned int num);
1117
1125 void write_single_register(std::string device, std::string addr,
1126 unsigned int value);
1134 void write_multiple_registers(std::string device, std::string addr,
1135 std::vector<unsigned int> values);
1136
1144 std::vector<unsigned int> read_holding_registers(std::string device,
1145 std::string addr,
1146 unsigned int num);
1154 std::vector<unsigned int> read_input_registers(std::string device,
1155 std::string addr,
1156 unsigned int num);
1169 void set_serial_baud_rate(std::string device, unsigned int baud_rate);
1177 void set_serial_parity(std::string device, unsigned int parity);
1179 protected:
1180 std::unique_ptr<RobotImpl> impl_;
1181};
1182
1183} // namespace l_master
1184
1185} // namespace lebai
机械臂的主要接口对象,通过本对象的方法与机械臂进行数据交互.
Definition robot.hh:80
std::unique_ptr< RobotImpl > impl_
Definition robot.hh:1180
std::tuple< int, std::string > call(const std::string &method, const std::string &params)
用JSON格式字符串调用机械臂的接口.
virtual ~Robot()
析构Robot对象.
Robot(std::string ip, bool simulator=false)
构造Robot对象.
bool is_network_connected()
返回是否和机械臂的网络连接正常,如果网络连接异常,调用和机械臂交互的接口会抛出异常std::runtime_error。
ClawData get_claw_data()
获取夹爪当前数据
std::tuple< double, double, bool > get_claw()
获取夹爪当前数据
void set_claw(double force, double amplitude)
设置夹爪力度(力控)和幅度(位控).如果在闭合过程中抓取到物体,则不再继续闭合以避免夹坏物体,判断的准则为这里设置的力的大小.
int get_velocity_factor()
获取当前的速度因子.
void set_payload_cog(std::map< std::string, double > cog)
设置机器人末端负载重心.
void set_gravity(std::map< std::string, double > gravity)
设置机器人重力加速度方向.
std::map< std::string, double > get_gravity()
获取机器人重力加速度的方向.
CartesianPose load_tcp(std::string name, std::string dir="")
从资源库加载tcp.
void set_payload(double mass, std::map< std::string, double > cog)
设置机器人末端负载.
void set_tcp(std::array< double, 6 > tcp)
设置工具中心点(TCP)坐标,坐标值相对于工具坐标系.
std::array< double, 6 > get_tcp()
获取当前机器人工具中心点设置.
void set_velocity_factor(int factor)
设置速度因子.
std::map< std::string, double > get_payload()
获取末端负载设置.
void set_payload_mass(double mass)
设置机器人末端负载质量.
void rename_file(const std::string &from_dir, const std::string &from_name, const std::string &to_dir, const std::string &to_name)
重命名文件
std::vector< std::tuple< bool, std::string > > load_file_list(const std::string &dir, const std::string &prefix, const std::string &suffix)
查询文件列表.
void save_file(const std::string &dir, const std::string &name, bool is_dir, const std::string &data)
保存文件(以字节形式).
std::tuple< bool, std::string > load_file(const std::string &dir, const std::string &name)
查询文件
void set_do(std::string device, unsigned int pin, unsigned int value)
设置数字输出
std::vector< double > get_aos(std::string device, unsigned int pin, unsigned int num)
获取多个模拟输出
double get_ai(std::string device, unsigned int pin)
获取模拟输入
unsigned int get_do(std::string device, unsigned int pin)
获取数字输出
std::vector< unsigned int > get_dis(std::string device, unsigned int pin, unsigned int num)
获取多个数字输入
std::vector< double > get_ais(std::string device, unsigned int pin, unsigned int num)
获取多个模拟输入
std::vector< bool > get_dios_mode(std::string device, unsigned int pin, unsigned int count)
获取数字端口模式
unsigned int get_di(std::string device, unsigned int pin)
获取数字输入
void set_ao(std::string device, unsigned int pin, double value)
设置模拟输出
std::vector< unsigned int > get_dos(std::string device, unsigned int pin, unsigned int num)
获取多个数字输出
double get_ao(std::string device, unsigned int pin)
获取模拟输出
void set_dio_mode(std::string device, unsigned int pin, bool value)
设置数字端口模式
void set_fan(unsigned int status)
开关风扇
void set_voice(unsigned int voice, unsigned int volume)
设置声音
void set_led(unsigned int mode, unsigned int speed, const std::vector< unsigned int > &color)
设置LED灯状态.
std::vector< bool > read_discrete_inputs(std::string device, std::string addr, unsigned int num)
读离散输入
void wirte_multiple_coils(std::string device, std::string addr, std::vector< bool > values)
写多个线圈
std::vector< unsigned int > read_holding_registers(std::string device, std::string addr, unsigned int num)
读保持寄存器
std::vector< unsigned int > read_input_registers(std::string device, std::string addr, unsigned int num)
读输入寄存器
std::vector< bool > read_coils(std::string device, std::string addr, unsigned int num)
读线圈
void write_single_coil(std::string device, std::string addr, bool value)
写单个线圈.
void write_multiple_registers(std::string device, std::string addr, std::vector< unsigned int > values)
写多个寄存器
void write_single_register(std::string device, std::string addr, unsigned int value)
写单个寄存器
std::string get_motion_state(unsigned int id)
查询指定MotionId的运动状态.
int speedl(double a, const CartesianPose &v, double t=0.0, const CartesianPose &reference={{"x", 0.0}, {"y", 0.0}, {"z", 0.0}, {"rx", 0.0}, {"ry", 0.0}, {"rz", 0.0}})
通过坐标速度矢量发送机械臂关节匀速运动
int movej(const std::vector< double > &joint_positions, double a, double v, double t, double r)
通过关节位置发送机械臂关节移动
int towardj(const std::vector< double > &joint_positions, double a, double v, double t, double r)
通过关节位置发送机械臂关节自由移动.
int movel(const CartesianPose &cart_pose, double a, double v, double t, double r)
通过坐标位置发送机械臂直线移动
int movec(const std::vector< double > &joint_via, const std::vector< double > &joint, double rad, double a, double v, double t, double r)
通过关节位置发送机械臂圆弧运动.
void move_pvat(std::vector< double > p, std::vector< double > v, std::vector< double > a, double t)
伺服运动PVAT
int movel(const std::vector< double > &joint_positions, double a, double v, double t, double r)
通过关节位置发送机械臂直线移动
void stop_move()
停止所有运动.
int movec(const CartesianPose &cart_via, const CartesianPose &cart, double rad, double a, double v, double t, double r)
通过坐标位置发送机械臂圆弧运动
void wait_move(unsigned int id)
等待运动完成.
void wait_move()
等待所有运动完成.
int speedj(double a, const std::vector< double > &v, double t=0.0)
通过关节速度矢量发送机械臂关节匀速运动
unsigned int get_running_motion()
查询当前正在运动的MotionId(无运动时返回上次MotionId).
int movej(const CartesianPose &cart_pose, double a, double v, double t, double r)
通过坐标位置发送机械臂关节移动
KinematicsInverseResp kinematics_inverse(const CartesianPose &pose, const std::vector< double > &joint_init_positions={})
根据机械臂的末端位姿计算关节位置(位置的运动学逆解).
CartesianPose pose_times(const CartesianPose &a, const CartesianPose &b)
位姿变换乘法(等价于对应的齐次坐标矩阵乘法)
KinematicsForwardResp kinematics_forward(const std::vector< double > &joint_positions)
根据机械臂关节位置计算机器人末端位姿(位置的运动学正解).
CartesianPose pose_inverse(const CartesianPose &in)
位姿变换的逆(等价于对应的齐次坐标矩的逆)
void cancel_task(unsigned int id)
取消任务与运动.
unsigned int start_task(const std::string &name, const std::vector< std::string > &params, const std::string &dir, bool is_parallel, unsigned int loop_to)
调用场景
unsigned int start_task(const std::string &name)
调用场景
unsigned int exec_hook(unsigned int id)
根据已设置的Hook执行对应场景
std::string get_task_state(unsigned int id)
获取任务状态.
void pause_task(unsigned int id, unsigned long time, bool wait)
暂停任务与运动
void resume_task(unsigned int id)
恢复任务与运动
std::vector< unsigned int > load_task_list()
查询任务列表
std::string get_task_state()
获取任务状态.
void pause_task(unsigned int id)
暂停任务与运动
bool wait_task(unsigned int id)
等待任务完成
void set_serial_parity(std::string device, unsigned int parity)
设置串口校验位.
void set_serial_baud_rate(std::string device, unsigned int baud_rate)
设置串口波特率.
int get_signal(unsigned int index)
获取信号量
void add_signal(unsigned int index, int value)
增加指定下标的信号量值,该操作是原子的.
void set_signal(unsigned int index, int value)
设置信号量
void estop()
紧急停止(急停).
void teach_mode()
进入示教模式.
void start_sys()
启动机械臂(机械臂上使能).
void resume()
恢复运动.
void stop()
停止运动(但不下电).
void end_teach_mode()
退出示教模式.
void powerdown()
关闭机器人电源(关机).
void stop_sys()
停止机械臂(机械臂下使能).
void pause()
暂停运动.
void reboot()
重新启动机箱
std::vector< double > get_target_joint_speed()
获取机械臂关节当前控制力矩
std::vector< double > get_target_joint_positions()
获取机械臂关节当前控制位置
int get_estop_reason()
查看急停原因
bool is_disconnected()
是否已与手臂断开连接
CartesianPose get_target_tcp_pose()
获取机械臂末端在机械臂基坐标系下的控制位姿,CartesianPose = std::map<std::string,double>,应当包括键为x,y,z,rz,...
bool is_down()
手臂是否已下电
std::vector< double > get_actual_joint_speed()
获取机械臂关节当前反馈速度
std::vector< double > get_actual_joint_torques()
获取机械臂关节当前反馈力矩
std::vector< double > get_actual_joint_positions()
获取机械臂关节当前反馈位置
double get_joint_temp(unsigned int joint_index)
获取单个关节温度
std::vector< double > get_target_joint_torques()
获取机械臂关节当前控制力矩
CartesianPose get_actual_tcp_pose()
获取机械臂末端在机械臂基坐标系下的实际位姿,CartesianPose = std::map<std::string,double>,应当包括键为x,y,z,rz,...
int get_robot_mode()
获取机器人状态码
Definition discovery.hh:23
Definition robot.hh:66
double amplitude
Definition robot.hh:68
bool hold_on
Definition robot.hh:69
double force
Definition robot.hh:67
运动学正解的返回值数据结构.
Definition robot.hh:44
bool ok
Definition robot.hh:49
CartesianPose pose
Definition robot.hh:46
运动学逆解的返回值数据结构
Definition robot.hh:55
bool ok
Definition robot.hh:60
DoubleVector joint_positions
Definition robot.hh:57