头文件: c/interface/nrc_c_queue_operate.h
1. queue_motion_set_status - 打开、关闭队列运动模式
方法: int queue_motion_set_status_c(SOCKETFD socket_fd, bool status);
功能描述: true开启队列模式,false关闭。
参数:
socket_fd:已连接的句柄
status:true开启,false关闭
返回值:
C++
bool test_queue_motion_set_status(bool status) {
if (socket_fd_6001_ <= 0) return false;
// 传入控制端口句柄和状态标志,调用底层接口开启/关闭队列运动模式
int ret = queue_motion_set_status_c(socket_fd_6001_, status);
std::string status_msg = status ? "开启" : "关闭";
CHECK_RET(ret, "队列运动模式 " + status_msg);
return ret == SUCCESS;
}
2. queue_motion_send_to_controller - 将本地队列的前size个数据发送到控制器
方法: int queue_motion_send_to_controller_c(SOCKETFD socket_fd, int size, bool is_continue);
功能描述: 将本地队列中的前size条指令(0表示全部)发送给控制器并开始运动。
参数:
socket_fd:已连接的句柄
size:发送的指令条数,0表示全部
is_continue:是否从断点继续执行
返回值:
C++
bool test_send_queue(int size, bool isContinue = false) {
if (socket_fd_6001_ <= 0) return false;
// 传入控制端口句柄、本次提交的指令条数以及是否连续执行的标志,下发缓冲队列至控制器执行
int ret = queue_motion_send_to_controller_c(socket_fd_6001_, size, isContinue);
CHECK_RET(ret, "发送队列数据(size=" + std::to_string(size) + ")");
return ret == SUCCESS;
}
3. queue_motion_push_back_moveJ - 队列运动模式的本地队列最后插入一条moveJ运动
方法: int queue_motion_push_back_moveJ_c(SOCKETFD socket_fd, int coord, double vel, double acc, double dec, int pl, double* pos);
功能描述: 向本地队列尾部添加一条关节运动指令。
参数:
socket_fd:已连接的句柄
coord:坐标系(关节运动填0)
vel:速度(1~100)
acc、dec:加减速(1~100)
pl:平滑度,一般填0
pos:指向至少6个double的数组(关节角度)
返回值:
C++
bool test_push_moveJ_queue(const std::vector<double>& angles, int vel = 30, int acc = 20, int dec = 20, int coord = 0) {
if (socket_fd_6001_ <= 0) return false;
// 规避手动内存分配,直接通过.data()获取vector的底层连续内存指针传给底层C接口
const double* angles_ptr = angles.data();
// 传入控制端口句柄、坐标系、速度、加减速等参数,将该条关节运动指令压入控制器的缓冲队列中
int ret = queue_motion_push_back_moveJ_c(socket_fd_6001_, coord, vel, acc, dec, 0, angles_ptr);
CHECK_RET(ret, "压入队列 MoveJ");
return ret == SUCCESS;
}
4. queue_motion_push_back_moveL - 队列运动模式的本地队列最后插入一条moveL运动
方法: int queue_motion_push_back_moveL_c(SOCKETFD socket_fd, int coord, double vel, double acc, double dec, int pl, double* pos);
功能描述: 向本地队列尾部添加一条直线运动指令。
参数:
socket_fd:已连接的句柄
coord:坐标系(直角运动填1)
vel:速度(1~100)
acc、dec:加减速(1~100)
pl:平滑度,一般填0
pos:6维直角坐标[X,Y,Z,RX,RY,RZ]
返回值:
C++
bool test_push_moveL_queue(const std::vector<double>& pos, double vel = 30.0, double acc = 20.0, double dec = 20.0, int coord = 0, int pl = 0) {
if (socket_fd_6001_ <= 0) return false;
// 规避手动的动态内存分配,直接利用.data()获取vector内部连续存储的底层双精度浮点数指针
const double* pos_ptr = pos.data();
// 传入控制端口句柄、坐标系、速度、加减速、平滑度等参数,将该条直角坐标直线运动指令压入控制器的缓冲队列
int ret = queue_motion_push_back_moveL_c(socket_fd_6001_, coord, vel, acc, dec, pl, pos_ptr);
CHECK_RET(ret, "压入队列 MoveL");
return ret == SUCCESS;
}
5. queue_motion_push_back_moveC - 队列运动模式的本地队列最后插入一条moveC运动
方法: int queue_motion_push_back_moveC_c(SOCKETFD socket_fd, int coord, double vel, double acc, double dec, int pl, double* pos);
功能描述: 添加圆弧运动指令。
参数:
socket_fd:已连接的句柄
coord:坐标系(直角运动填1)
vel:速度(1~100)
acc、dec:加减速(1~100)
pl:平滑度,一般填0
pos:指向12个double:前6个中间点,后6个终点
返回值:
注意: moveC的前一条指令应该是movej或者movel。
C++
bool test_push_moveC_queue(const std::vector<double>& via_and_end_pos, double vel = 30.0, double acc = 20.0, double dec = 20.0, int coord = 0, int pl = 0) {
if (socket_fd_6001_ <= 0) return false;
// 校验传入的点位数据,MoveC圆弧运动必须同时包含完整的中间点(6维)与目标终点(6维),总长不得少于12位
if (via_and_end_pos.size() < 12) {
std::cout << "[提示] MoveC圆弧运动需要传入中间点和终点,数据长度不足12位" << std::endl;
return false;
}
const double* pos_ptr = via_and_end_pos.data();
int ret = queue_motion_push_back_moveC_c(socket_fd_6001_, coord, vel, acc, dec, pl, pos_ptr);
CHECK_RET(ret, "压入队列 MoveC");
return ret == SUCCESS;
}
6. queue_motion_push_back_moveS - 队列运动模式的本地队列最后插入一条moveS运动
方法: int queue_motion_push_back_moveS_c(SOCKETFD socket_fd, int coord, double vel, double acc, double dec, int pl, double* pos);
功能描述: 添加B样条曲线控制点。
参数:
socket_fd:已连接的句柄
coord:坐标系(直角运动填1)
vel:速度(1~100)
acc、dec:加减速(1~100)
pl:平滑度,一般填0
pos:6维终点坐标
返回值:
注意: moveS的前一条指令应该是movej或者movel。
C++
bool test_push_moveS_queue(const std::vector<double>& pos, double vel = 30.0, double acc = 20.0, double dec = 20.0, int coord = 0, int pl = 0) {
if (socket_fd_6001_ <= 0) return false;
const double* pos_ptr = pos.data();
int ret = queue_motion_push_back_moveS_c(socket_fd_6001_, coord, vel, acc, dec, pl, pos_ptr);
CHECK_RET(ret, "压入队列 MoveS");
return ret == SUCCESS;
}
完整队列运动模型见使用示例7所示。