案例/模板说明
机械臂主控主函数说明
轨迹移动同步模板
import os
import sys
JAKA_PYTHONPATH = os.path.join(os.path.dirname(__file__)) # 添加当前路径到环境变量
sys.path.append(JAKA_PYTHONPATH)
import socket
import const
import jkrc
import xyz_master_object
jk = xyz_master_object.jk_master("192.168.37.100") # 创建机械臂对象,传入机械臂 ip 地址
server_address = ("127.0.0.1", 11111) # 指定 robot server 的 ip 和端口
jk.socketConnect(server_address)
try:
err_code = jk.xyzSwitchFlow("traj_sync.t") # 切换任务
if err_code != 0:
os.system("pause") # 错误代码不为零,暂停程序
ws_id = 0
err_code = jk.xyzSwitchItem(ws_id,"item1") # 切换工件
if err_code != 0:
os.system("pause")
IO_CABINET = 0
IO_TOOL = 1 #
IO_EXTEND = 2
jk.robot.set_digital_output(IO_CABINET, 0, 0) # 设置数字输出
home_joints = [0,0,0,0,-90,0]
move_mode = 0
is_block = True
speed = 0.1 # unit: rad/s
jk.robot.joint_move(home_joints, move_mode, is_block, speed) # 移动到初始位置
while True:
ws_id = 0
err_code = jk.xyzReqPickPlace(ws_id) # 请求计算抓取放置轨迹
if err_code != 0:
os.system("pause")
err_code, pipeline_num, register_num, traj_num, wp_type, wp = jk.xyzGetPickin(0) # 获取抓取入筐轨迹
if err_code != 0:
os.system("pause")
if traj_num < 1: # 如果没有轨迹,退出循环
break
jk.xyzExecutePickinTraj(traj_num, wp_type, wp) # 执行抓取入筐轨迹
jk.robot.set_digital_output(IO_CABINET, 0, 1) # 抓取
err_code, pipeline_num, register_num, traj_num, wp_type, wp = jk.xyzGetPickout(0) # 获取抓取出筐轨迹
if err_code != 0:
os.system("pause")
jk.xyzExecutePickoutTraj(traj_num, wp_type, wp) # 执行抓取出筐轨迹
err_code, pipeline_num, register_num, traj_num, wp_type, wp = jk.xyzGetPlacein(0) # 获取放置入筐轨迹
if err_code != 0:
os.system("pause")
jk.xyzExecuteTraj(traj_num, wp_type, wp) # 执行放置入筐轨迹
jk.robot.set_digital_output(IO_CABINET, 0, 0) # 放置
err_code, pipeline_num, register_num, traj_num, wp_type, wp = jk.xyzGetPlaceout(0) # 获取放置出筐轨迹
if err_code != 0:
os.system("pause")
jk.xyzExecuteTraj(traj_num, wp_type, wp) # 执行放置出筐轨迹
finally:
jk.robot.logout()
print("robot disconnected")
轨迹移动异步模板
import os
import sys
JAKA_PYTHONPATH = os.path.join(os.path.dirname(__file__)) # 添加当前路径到环境变量
sys.path.append(JAKA_PYTHONPATH)
import socket
import const
import jkrc
import xyz_master_object
jk = xyz_master_object.jk_master("192.168.37.100") # 创建机械臂对象,传入机械臂 ip 地址
server_address = ("127.0.0.1", 11111) # 指定 robot server 的 ip 和端口
jk.socketConnect(server_address)
try:
err_code = jk.xyzSwitchFlow("traj_async.t") # 切换任务
if err_code != 0:
os.system("pause")
ws_id = 0
err_code = jk.xyzSwitchItem(ws_id,"item1") # 切换工件
if err_code != 0:
os.system("pause")
IO_CABINET = 0
IO_TOOL = 1 #
IO_EXTEND = 2
jk.robot.set_digital_output(IO_CABINET, 0, 0) # 设置数字输出
home_joints = [0,0,0,0,-90,0]
move_mode = 0
is_block = True
speed = 0.1 # unit: rad/s
jk.robot.joint_move(home_joints, move_mode, is_block, speed) # 移动到初始位置
while True:
ws_id = 0
err_code = jk.xyzReqPickPlace(ws_id) # 请求计算抓取放置轨迹
if err_code != 0:
os.system("pause")
ws_id = 0
err_code, pipeline_num, register_num, traj_num, wp_type, wp = jk.xyzGetPickin(ws_id) # 获取抓取入筐轨迹
if err_code != 0:
os.system("pause")
if traj_num < 1: # 如果没有轨迹,退出循环
break
jk.xyzExecutePickinTraj(traj_num, wp_type, wp) # 执行抓取入筐轨迹
jk.robot.set_digital_output(IO_CABINET, 0, 1) # 抓取
ws_id = 0
err_code, pipeline_num, register_num, traj_num, wp_type, wp = jk.xyzGetPickout(ws_id) # 获取抓取出筐轨迹
if err_code != 0:
os.system("pause")
jk.xyzExecutePickoutTraj(traj_num, wp_type, wp) # 执行抓取出筐轨迹
ws_id = 0
err_code = jk.xyzReqPickPlace(ws_id) # 提前请求下一次抓取放置轨迹
if err_code != 0:
os.system("pause")
ws_id = 0
err_code, pipeline_num, register_num, traj_num, wp_type, wp = jk.xyzGetPlacein(ws_id) # 获取放置入筐轨迹
if err_code != 0:
os.system("pause")
jk.xyzExecuteTraj(traj_num, wp_type, wp) # 执行放置入筐轨迹
jk.robot.set_digital_output(IO_CABINET, 0, 0) # 放置
ws_id = 0
err_code, pipeline_num, register_num, traj_num, wp_type, wp = jk.xyzGetPlaceout(ws_id) # 获取放置出筐轨迹
if err_code != 0:
os.system("pause")
jk.xyzExecuteTraj(traj_num, wp_type, wp) # 执行放置出筐轨迹
finally:
jk.robot.logout()
print("robot disconnected")
座标移动基础模板
import os
import sys
JAKA_PYTHONPATH = os.path.join(os.path.dirname(__file__)) # 添加当前路径到环境变量
sys.path.append(JAKA_PYTHONPATH)
import socket
import const
import jkrc
import xyz_master_object
jk = xyz_master_object.jk_master("192.168.37.100") # 创建机械臂对象,传入机械臂 ip 地址
server_address = ("127.0.0.1", 11111) # 指定 robot server 的 ip 和端口
jk.socketConnect(server_address)
try:
err_code = jk.xyzSwitchFlow("catr_basic.t") # 切换任务
if err_code != 0:
os.system("pause")
ws_id = 0
err_code = jk.xyzSwitchItem(ws_id,"item1") # 切换工件
if err_code != 0:
os.system("pause")
IO_CABINET = 0
IO_TOOL = 1 #
IO_EXTEND = 2
jk.robot.set_digital_output(IO_CABINET, 0, 0) # 设置数字输出
home_joints = [0,0,0,0,-90,0]
move_mode = 0
is_block = True
speed = 0.1 # unit: rad/s
jk.robot.joint_move(home_joints, move_mode, is_block, speed) # 移动到初始位置
is_eye_in_hand = True
while True:
if is_eye_in_hand:
scan_pose = [400,0,400,0,0,0]
speed = 10 # unit: mm/s
jk.robot.linear_move(scan_pose, move_mode, is_block, speed) # 移动到拍照位姿
err_code = jk.xyzSendCurrentPose() # 发送当前位姿
if err_code != 0:
os.system("pause")
err_code, grasp_token = jk.xyzReqGraspPose(ws_id) # 请求计算抓取位姿
if err_code != 0:
os.system("pause")
err_code, grasp_pose, grasp_pose_num, pipeline_num, register_num = jk.xyzGetGraspPose(grasp_token) # 获取抓取位姿
if err_code != 0:
os.system("pause")
if grasp_pose_num < 1: # 如果没有位姿,继续请求
print("No grasp pose, continure requesting...")
continue
speed = 10 # unit: mm/s
jk.robot.linear_move(grasp_pose, move_mode, is_block, speed) # 移动到抓取位姿
jk.robot.set_digital_output(IO_CABINET, 0, 1) # 抓取
place_pose = [400,0,400,0,0,0]
speed = 10 # unit: mm/s
jk.robot.linear_move(place_pose, move_mode, is_block, speed) # 移动到放置位姿
jk.robot.set_digital_output(IO_CABINET, 0, 0) # 放置
finally:
jk.robot.logout()
print("robot disconnected")
座标移动二次定位模板
import os
import sys
JAKA_PYTHONPATH = os.path.join(os.path.dirname(__file__)) # 添加当前路径到环境变量
sys.path.append(JAKA_PYTHONPATH)
import socket
import const
import jkrc
import xyz_master_object
jk = xyz_master_object.jk_master("192.168.37.100") # 创建机械臂对象,传入机械臂 ip 地址
server_address = ("127.0.0.1", 11111) # 指定 robot server 的 ip 和端口
jk.socketConnect(server_address)
try:
err_code = jk.xyzSwitchFlow("cart_repo.t") # 切换任务
if err_code != 0:
os.system("pause")
IO_CABINET = 0
IO_TOOL = 1 #
IO_EXTEND = 2
jk.robot.set_digital_output(IO_CABINET, 0, 0) # 设置数字输出0状态
jk.robot.set_digital_output(IO_CABINET, 1, 0) # 设置数字输出1状态
home_joints = [0,0,0,0,-90,0]
move_mode = 0
is_block = True
speed = 0.1 # unit: rad/s
jk.robot.joint_move(home_joints, move_mode, is_block, speed) # 移动到初始位置
ws_id = 0
err_code = jk.xyzSwitchItem(ws_id,"item1") # 切换工件
if err_code != 0:
os.system("pause")
err_code, rough_grasp_token = jk.xyzReqGraspPose(ws_id) # 请求计算抓取位姿
if err_code != 0:
os.system("pause")
while True:
# camera 1 get rough grasp pose 相机1获取粗抓取位姿
err_code, rough_grasp_pose, rough_grasp_pose_num, rough_pipeline_num, rough_register_num = jk.xyzGetGraspPose(rough_grasp_token)
if err_code != 0:
os.system("pause")
# no item, grasp board 没有工件,抓取隔板
if rough_grasp_pose_num < 1:
ws_id = 0
err_code = jk.xyzSwitchItem(ws_id,"board") # 切换工件
if err_code != 0:
os.system("pause")
err_code, board_grasp_token = jk.xyzReqGraspPose(ws_id) # 请求计算抓取位姿
if err_code != 0:
os.system("pause")
# 获取隔板抓取位姿
err_code, board_grasp_pose, board_grasp_pose_num, board_pipeline_num, board_register_num = jk.xyzGetGraspPose(board_grasp_token)
if err_code != 0:
os.system("pause")
if board_grasp_pose_num < 1:
# no board, you can change tote # 没有隔板,可以切换料箱
break
speed = 10 # unit: mm/s
jk.robot.linear_move(board_grasp_pose, move_mode, is_block, speed) # 移动到隔板抓取位姿
jk.robot.set_digital_output(IO_CABINET, 0, 1) # 抓取
# place board 放置隔板
board_place_pose = [400,0,400,0,0,0]
speed = 10 # unit: mm/s
jk.robot.linear_move(board_place_pose, move_mode, is_block, speed) # 移动到隔板放置位姿
jk.robot.set_digital_output(IO_CABINET, 0, 0) # 放置
ws_id = 0
err_code = jk.xyzSwitchItem(ws_id,"item1") # 切换工件
if err_code != 0:
os.system("pause")
err_code, rough_grasp_token = jk.xyzReqGraspPose(ws_id) # 请求粗抓取位姿
if err_code != 0:
os.system("pause")
continue
# move to rough grasp pose 移动到粗抓取位姿
speed = 10 # unit: mm/s
jk.robot.linear_move(rough_grasp_pose, move_mode, is_block, speed)
err_code = jk.xyzSendCurrentPose() # 发送当前位姿
# camera2 get grasp pose 相机2获取精确抓取位姿
ws_id = 1
err_code = jk.xyzSwitchItem(ws_id,"item1")
if err_code != 0:
os.system("pause")
err_code, fine_grasp_token = jk.xyzReqGraspPose(ws_id) # 请求精确抓取位姿
if err_code != 0:
os.system("pause")
# 获取精确抓取位姿
err_code, fine_grasp_pose, fine_grasp_pose_num, fine_pipeline_num, fine_register_num = jk.xyzGetGraspPose(fine_grasp_token)
if err_code != 0:
os.system("pause")
if fine_grasp_pose_num < 1: # 如果没有位姿,退出循环
break
# move to fine grasp pose 移动到精确抓取位姿
speed = 10 # unit: mm/s
jk.robot.linear_move(fine_grasp_pose, move_mode, is_block, speed) # 移动到精确抓取位姿
jk.robot.set_digital_output(IO_CABINET, 1, 1) # 抓取
# place item 放置工件
item_place_pose = [400,0,400,0,0,0]
speed = 10 # unit: mm/s
jk.robot.linear_move(item_place_pose, move_mode, is_block, speed) # 移动到放置位姿
jk.robot.set_digital_output(IO_CABINET, 1, 0) # 放置
ws_id = 0
err_code = jk.xyzSwitchItem(ws_id,"item1") # 切换工件
err_code, rough_grasp_token = jk.xyzReqGraspPose(ws_id) # 请求相机1粗抓取位姿
finally:
jk.robot.logout()
print("robot disconnected")