lebai sdk  1.1.28
lebai c++ sdk with swig to support sereval languages.
robot.hh
1 
17 #pragma once
18 
19 #include <memory>
20 #include <string>
21 #include <vector>
22 #include <array>
23 #include <map>
24 
25 namespace lebai {
26 namespace l_master {
32 std::string version();
38 using CartesianPose = std::map<std::string, double>;
39 using DoubleVector = std::vector<double>;
45  CartesianPose
46  pose;
49  bool ok = false;
50 };
56  DoubleVector
60  bool ok = false;
61 };
62 /***
63  * @brief 夹爪数据结构.
64  *
65  */
66 struct ClawData {
67  double force;
68  double amplitude;
69  bool hold_on;
70 };
71 
80 class Robot {
81  public:
87  class RobotImpl;
88 
99  explicit Robot(std::string ip, bool simulator = false);
104  virtual ~Robot();
124  std::tuple<int, std::string> call(const std::string &method,
125  const std::string &params);
126 
134 
199  void start_sys();
205  void stop_sys();
210  void powerdown();
215  void stop();
220  void estop();
225  void teach_mode();
235  void pause();
240  void resume();
244  void reboot();
272  int movej(const std::vector<double> &joint_positions, double a, double v,
273  double t, double r);
296  int movej(const CartesianPose &cart_pose, double a, double v, double t,
297  double r);
318  int movel(const std::vector<double> &joint_positions, double a, double v,
319  double t, double r);
342  int movel(const CartesianPose &cart_pose, double a, double v, double t,
343  double r);
368  int movec(const std::vector<double> &joint_via,
369  const std::vector<double> &joint, double rad, double a, double v,
370  double t, double r);
388  int movec(const CartesianPose &cart_via, const CartesianPose &cart,
389  double rad, double a, double v, double t, double r);
402  int speedj(double a, const std::vector<double> &v, double t = 0.0);
418  int speedl(double a, const CartesianPose &v, double t = 0.0,
419  const CartesianPose &reference = {{"x", 0.0},
420  {"y", 0.0},
421  {"z", 0.0},
422  {"rx", 0.0},
423  {"ry", 0.0},
424  {"rz", 0.0}});
446  int towardj(const std::vector<double> &joint_positions, double a, double v,
447  double t, double r);
456  void move_pvat(std::vector<double> p, std::vector<double> v,
457  std::vector<double> a, double t);
463  void wait_move(unsigned int id);
468  void wait_move();
472  unsigned int get_running_motion();
478  std::string get_motion_state(unsigned int id);
482  void stop_move();
531  bool is_down();
537  std::vector<double> get_actual_joint_positions();
543  std::vector<double> get_target_joint_positions();
549  std::vector<double> get_actual_joint_speed();
550  // get_target_joint_speed
556  std::vector<double> get_target_joint_speed();
563  CartesianPose get_actual_tcp_pose();
570  CartesianPose get_target_tcp_pose();
571 
578  double get_joint_temp(unsigned int joint_index);
579 
585  std::vector<double> get_actual_joint_torques();
591  std::vector<double> get_target_joint_torques();
592 
615  void set_do(std::string device, unsigned int pin, unsigned int value);
623  unsigned int get_do(std::string device, unsigned int pin);
632  std::vector<unsigned int> get_dos(std::string device, unsigned int pin,
633  unsigned int num);
641  unsigned int get_di(std::string device, unsigned int pin);
650  std::vector<unsigned int> get_dis(std::string device, unsigned int pin,
651  unsigned int num);
652 
660  void set_ao(std::string device, unsigned int pin, double value);
668  double get_ao(std::string device, unsigned int pin);
677  std::vector<double> get_aos(std::string device, unsigned int pin,
678  unsigned int num);
686  double get_ai(std::string device, unsigned int pin);
695  std::vector<double> get_ais(std::string device, unsigned int pin,
696  unsigned int num);
705  void set_dio_mode(std::string device, unsigned int pin, bool value);
714  std::vector<bool> get_dios_mode(std::string device, unsigned int pin,
715  unsigned int count);
728  void set_claw(double force, double amplitude);
735  std::tuple<double, double, bool> get_claw();
756  void set_led(unsigned int mode, unsigned int speed,
757  const std::vector<unsigned int> &color);
764  void set_voice(unsigned int voice, unsigned int volume);
770  void set_fan(unsigned int status);
783  void set_signal(unsigned int index, int value);
790  int get_signal(unsigned int index);
797  void add_signal(unsigned int index, int value);
815  unsigned int start_task(const std::string &name,
816  const std::vector<std::string> &params,
817  const std::string &dir, bool is_parallel,
818  unsigned int loop_to);
824  unsigned int start_task(const std::string &name);
828  std::vector<unsigned int> load_task_list();
836  void pause_task(unsigned int id, unsigned long time, bool wait);
841  void pause_task(unsigned int id);
847  void resume_task(unsigned int id);
853  void cancel_task(unsigned int id);
859  unsigned int exec_hook(unsigned int id);
863  std::string get_task_state();
869  std::string get_task_state(unsigned int id);
882  const std::vector<double> &joint_positions);
883 
891  const CartesianPose &pose,
892  const std::vector<double> &joint_init_positions = {});
893 
901  CartesianPose pose_times(const CartesianPose &a, const CartesianPose &b);
902 
909  CartesianPose pose_inverse(const CartesianPose &in);
923  void save_file(const std::string &dir, const std::string &name, bool is_dir,
924  const std::string &data);
933  void rename_file(const std::string &from_dir, const std::string &from_name,
934  const std::string &to_dir, const std::string &to_name);
935 
944  std::tuple<bool, std::string> load_file(const std::string &dir,
945  const std::string &name);
946 
956  std::vector<std::tuple<bool, std::string>> load_file_list(
957  const std::string &dir, const std::string &prefix,
958  const std::string &suffix);
967  // void zip(const std::string &from_dir, std::vector<std::string> files, const
968  // std::string &to_dir, const std::string &name);
969  // /**
970  // * @brief 将zip文件解压到文件系统.
971  // *
972  // * @param from_dir zip文件的路径.
973  // * @param name zip文件的名称.
974  // * @param files zip文件内的文件名.
975  // * @param to_dir 解压到的路径.
976  // */
977  // void unzip(const std::string &from_dir, const std::string &name,
978  // std::vector<std::string> files, const std::string &to_dir);
979  // /**
980  // * @brief 查询文件列表.
981  // *
982  // * @brief 目标zip文件名.
983  // * @param dir 文件的目录.
984  // * @param prefix 前缀.
985  // * @param suffix 后缀.
986  // *
987  // * @return 文件列表.
988  // */
989  // //std::vector<std::tuple<bool,string>> load_zip_list(const std::string
990  // &zip,const std::string &dir,const std::string &prefix,const std::string
991  // &suffix);
992 
1003  void set_tcp(std::array<double, 6> tcp);
1009  std::array<double, 6> get_tcp();
1015  void set_velocity_factor(int factor);
1028  void set_payload(double mass, std::map<std::string, double> cog);
1034  void set_payload_mass(double mass);
1040  void set_payload_cog(std::map<std::string, double> cog);
1046  std::map<std::string, double> get_payload();
1052  void set_gravity(std::map<std::string, double> gravity);
1058  std::map<std::string, double> get_gravity();
1065  CartesianPose load_tcp(std::string name, std::string dir = "");
1079  void write_single_coil(std::string device, std::string addr, bool value);
1080 
1088  void wirte_multiple_coils(std::string device, std::string addr,
1089  std::vector<bool> values);
1090 
1098  std::vector<bool> read_coils(std::string device, std::string addr,
1099  unsigned int num);
1107  std::vector<bool> read_discrete_inputs(std::string device, std::string addr,
1108  unsigned int num);
1109 
1117  void write_single_register(std::string device, std::string addr,
1118  unsigned int value);
1126  void write_multiple_registers(std::string device, std::string addr,
1127  std::vector<unsigned int> values);
1128 
1136  std::vector<unsigned int> read_holding_registers(std::string device,
1137  std::string addr,
1138  unsigned int num);
1146  std::vector<unsigned int> read_input_registers(std::string device,
1147  std::string addr,
1148  unsigned int num);
1161  void set_serial_baud_rate(std::string device, unsigned int baud_rate);
1169  void set_serial_parity(std::string device, unsigned int parity);
1171  protected:
1172  std::unique_ptr<RobotImpl> impl_;
1173 };
1174 
1175 } // namespace l_master
1176 
1177 } // namespace lebai
机械臂的主要接口对象,通过本对象的方法与机械臂进行数据交互.
Definition: robot.hh:80
std::unique_ptr< RobotImpl > impl_
Definition: robot.hh:1172
virtual ~Robot()
析构Robot对象.
Robot(std::string ip, bool simulator=false)
构造Robot对象.
std::tuple< int, std::string > call(const std::string &method, const std::string &params)
用JSON格式字符串调用机械臂的接口.
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)
设置机器人末端负载重心.
std::map< std::string, double > get_payload()
获取末端负载设置.
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)坐标,坐标值相对于工具坐标系.
void set_velocity_factor(int factor)
设置速度因子.
std::array< double, 6 > get_tcp()
获取当前机器人工具中心点设置.
void set_payload_mass(double mass)
设置机器人末端负载质量.
std::vector< std::tuple< bool, std::string > > load_file_list(const std::string &dir, const std::string &prefix, const std::string &suffix)
查询文件列表.
void rename_file(const std::string &from_dir, const std::string &from_name, const std::string &to_dir, const std::string &to_name)
重命名文件
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)
查询文件
std::vector< unsigned int > get_dos(std::string device, unsigned int pin, unsigned int num)
获取多个数字输出
void set_do(std::string device, unsigned int pin, unsigned int value)
设置数字输出
std::vector< bool > get_dios_mode(std::string device, unsigned int pin, unsigned int count)
获取数字端口模式
std::vector< unsigned int > get_dis(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< double > get_ais(std::string device, unsigned int pin, unsigned int num)
获取多个模拟输入
std::vector< double > get_aos(std::string device, unsigned int pin, unsigned int num)
获取多个模拟输出
unsigned int get_di(std::string device, unsigned int pin)
获取数字输入
void set_ao(std::string device, unsigned int pin, double value)
设置模拟输出
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灯状态.
void wirte_multiple_coils(std::string device, std::string addr, std::vector< bool > values)
写多个线圈
std::vector< bool > read_coils(std::string device, std::string addr, unsigned int num)
读线圈
std::vector< unsigned int > read_holding_registers(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::vector< unsigned int > read_input_registers(std::string device, std::string addr, unsigned int num)
读输入寄存器
std::vector< bool > read_discrete_inputs(std::string device, std::string addr, unsigned int num)
读离散输入
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::vector< unsigned int > load_task_list()
查询任务列表
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::string get_task_state()
获取任务状态.
void pause_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_actual_joint_torques()
获取机械臂关节当前反馈力矩
std::vector< double > get_actual_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,...
std::vector< double > get_actual_joint_positions()
获取机械臂关节当前反馈位置
bool is_down()
手臂是否已下电
std::vector< double > get_target_joint_torques()
获取机械臂关节当前控制力矩
double get_joint_temp(unsigned int joint_index)
获取单个关节温度
CartesianPose get_actual_tcp_pose()
获取机械臂末端在机械臂基坐标系下的实际位姿,CartesianPose = std::map<std::string,double>,应当包括键为x,y,z,rz,...
std::vector< double > get_target_joint_speed()
获取机械臂关节当前控制力矩
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