10. 机器人外设
10.1. 配置夹爪
1/**
2* @brief 配置夹爪
3* @param [in] company 夹爪厂商,待定
4* @param [in] device 设备号,暂不使用,默认为0
5* @param [in] softvesion 软件版本号,暂不使用,默认为0
6* @param [in] bus 设备挂在末端总线位置,暂不使用,默认为0
7* @return 错误码
8*/
9errno_t SetGripperConfig(int company, int device, int softvesion, int bus);
10.2. 获取夹爪配置
1/**
2* @brief 获取夹爪配置
3* @param [in] company 夹爪厂商,待定
4* @param [in] device 设备号,暂不使用,默认为0
5* @param [in] softvesion 软件版本号,暂不使用,默认为0
6* @param [in] bus 设备挂在末端总线位置,暂不使用,默认为0
7* @return 错误码
8*/
9errno_t GetGripperConfig(int *company, int *device, int *softvesion, int *bus);
10.3. 激活夹爪
1/**
2* @brief 激活夹爪
3* @param [in] index 夹爪编号
4* @param [in] act 0-复位,1-激活
5* @return 错误码
6*/
7int ActGripper(int index, byte act);
10.4. 控制夹爪
1/**
2* @brief 控制夹爪
3* @param [in] index 夹爪编号
4* @param [in] pos 位置百分比,范围[0~100]
5* @param [in] vel 速度百分比,范围[0~100]
6* @param [in] force 力矩百分比,范围[0~100]
7* @param [in] max_time 最大等待时间,范围[0~30000],单位ms
8* @param [in] block 0-阻塞,1-非阻塞
9* @return 错误码
10*/
11int MoveGripper(int index, int pos, int vel, int force, int max_time, byte block);
10.5. 获取夹爪运动状态
1/**
2* @brief 获取夹爪运动状态
3* @param [out] fault 0-无错误,1-有错误
4* @param [out] staus 0-运动未完成,1-运动完成
5* @return 错误码
6*/
7int GetGripperMotionDone(ref int fault, ref int status);
10.6. 代码示例
1private void btnOperateGripper_Click(object sender, EventArgs e)
2{
3 Robot robot = new Robot();
4 robot.RPC("192.168.58.2");
5
6 int company = 4;
7 int device = 0;
8 int softversion = 0;
9 int bus = 1;
10 int index = 1;
11 byte act = 0;
12 int max_time = 30000;
13 byte block = 0;
14 int status = 0, fault = 0;
15 int rtn = -1;
16
17 robot.SetGripperConfig(company, device, softversion, bus);
18 Thread.Sleep(1000);
19 robot.GetGripperConfig(ref company, ref device, ref softversion, ref bus);
20 Console.WriteLine($"gripper config : {company}, {device}, {softversion}, {bus}");
21
22 rtn = robot.ActGripper(index, act);
23 Console.WriteLine($"ActGripper {rtn}");
24 Thread.Sleep(1000);
25 act = 1;
26 rtn = robot.ActGripper(index, act);
27 Console.WriteLine($"ActGripper {rtn}");
28 Thread.Sleep(4000);
29
30 rtn = robot.MoveGripper(index, 20, 50, 50, max_time, block);
31 Console.WriteLine($"MoveGripper {rtn}");
32 Thread.Sleep(2000);
33 robot.MoveGripper(index, 10, 50, 0, max_time, block);
34
35 Thread.Sleep(4000);
36 robot.GetGripperMotionDone(ref fault, ref status);
37 Console.WriteLine($"motion status : {fault}, {status}");
38}
10.7. 计算预抓取点-视觉
1/**
2* @brief 计算预抓取点-视觉
3* @param [in] desc_pos 抓取点笛卡尔位姿
4* @param [in] zlength z轴偏移量
5* @param [in] zangle 绕z轴旋转偏移量
6* @param [out] pre_pos 预抓取点
7* @return 错误码
8*/
9int ComputePrePick(DescPose desc_pos, double zlength, double zangle, ref DescPose pre_pos);
10.8. 计算撤退点-视觉
1/**
2* @brief 计算撤退点-视觉
3* @param [in] desc_pos 撤退点笛卡尔位姿
4* @param [in] zlength z轴偏移量
5* @param [in] zangle 绕z轴旋转偏移量
6* @param [out] post_pos 撤退点
7* @return 错误码
8*/
9int ComputePostPick(DescPose desc_pos, double zlength, double zangle, ref DescPose post_pos);