MECA500 - SICK PLOC 2D Vision系统集成(使用Python)

介绍:

PLOC2D from SICK is an easy to use flexible part localization sensor system that can be used for Vision Guided Pick and Place Applications. PLOC 2D supports multiple interfaces including TCP/IP, EtherNet/IP and Profinet out of the box. They provide an intuitive browser based interface that allows an user to set up a job and run in matter of few minutes.

In this MecaNetwork article, we will discuss in detail about the integration of a SICK PLOC 2D Vision System with a Meca500-R3 using Python.


System Requirements:

MECA500-R3系统

SICK PLOC 2D Vision System with Power Supply

M12-D编码 - RJ45电缆

Windows or Linux PC with Python 3.6or above and numpy安装了

PLOC 2D机器人引导系统设置:

Ploc 2D的完整设置指南超出了本文的范围,但SICK提供了一个全面的集成指南,该指南描述了用于设置PLoC 2D的工作流程,该流程已经附上本文以供参考。

The key steps involved are

1.安装

2.校准

在该步骤中,系统将获取一组校准图像以估计镜头失真参数。

3.对齐:

In this step, the system will establish the pose of the camera in relation to the robot coordinate system. Once the origin of the reference frame has been detected by the vision system, use 3 point method to calculate the vision reference frame with respect to robot's Base Reference Frame.

4.配置作业

此步骤定义了系统将要查找的形状

5.运行工作



SICK PLOC-2D VisionController Python类:

This Python class is used to set up a TCP/IP communication interface with PLOC 2D vision system to send commands and receive responses.


import socket

class VisionController:
“”“课程为机器人指导的病例2D愿景
与逐习生的机器人一起使用

属性
----------

地址:字符串
The IP address associated to the SICK PLOC 2D vision system.
套接字:套接字对象
Socket connecting to physical SICK PLOC 2D vision system.
错误:布尔
Error Status of the SICK PLOC 2D vision system job.
X:浮动
The Cartseian value in mm for X.
Y:浮动
y的mm mm的carsseian值。
z : float
The Cartseian value in mm for z (incl. of offset).
RZ:浮动
The Cartseian value in mm for Rz. (Uses Staubli's Notation)
索引:INT.
一组匹配项中所确定的一部分的索引。
比赛:int.
所选工作的完整部分。
error_id:int.
The error ID returned by SICK PLOC 2D for the selected job.

"""

def __init__(self, address):
“”“构造函数,用于类生病_ploc2d视觉系统的实例

Parameters
----------
地址:字符串
The IP address associated to the SICK PLOC 2D vision system
"""
self.address =地址
自我。socket = None
自我。error = False
自我。errorID = None
自我。jobID =没有
自我。x = None
self.y = none
自我。z = None
自我。rz = None
自我。index = None
自我。matches = None


def connect(self):
“”“将生病的PLoC 2D视觉系统对象通信与物理生病的PLOC 2D视觉系统

回报
-------
status : boolean
Return whether the connection is established
"""

try:
self.socket = socket.socket()
self.socket.settimeout(0.1)
try:
自我。socket.connect((self.address,14158))
except socket.timeout:
raise TimeoutError

#接收连接确认
如果self.socket是none:
raise RuntimeError

返回真实

除了超时:
返回false.
except RuntimeError:
返回false.

def disconnect(self):
""" Disconnects SICK PLOC 2D vision system object communication to the physical SICK PLOC 2D vision system

"""
如果(self.socket不是没有):
self.socket.close()
自我。socket = None

def _send(self,cmd):
“”“向物理生病的PLoc 2D视觉系统发送命令。
Parameters
----------
cmd : string
命令要发送。
回报
-------
status : boolean
返回是否已发送消息。
"""
如果self.socket是none:#check that the connection is established
返回错误的#if检测到的问题,没有点尝试发送不会到达视觉系统的cmd
cmd = cmd.
status = 0.
while status == 0:
try: #while the message hasn't been sent
status = self.socket.send(cmd.encode('ascii')) #send command in ascii encoding
除:
打破
if status != 0:
返回true #return在发送消息时
#Message failed to be sent, return false
返回false.


def _get_data(self,delay = 1):
“”“从病人的Ploc 2D视觉系统中收到消息和
saves the values in appropriate variables.
Parameters
----------
延迟:int或浮动
时间设置套接字超时的时间。
"""

如果self.socket是none:
返回
自我。socket.settimeout(delay)
try:
raw_response = self.socket.recv(1024).decode('ascii').split(",") #read message from vision system
如果RAW_Response [0] .find('OK')!= -1:
自我。error = False
自我。errorID = 0
self.jobid = int(raw_response [1])
自我。index = int(raw_response[2])
self.matches = int(raw_response [3])
自我。x = float(raw_response[4])
self.y = float(raw_response [5])
自我。z = float(raw_response[6])
self.rz = float(raw_response [9])
self.score = int(raw_response [-4])
else:
self.Error = True
self.jobid = int(raw_response [1])
self.errorid = int(raw_response [-1])
除了超时:
pass

def run_job(self,jobId):
"""Sends and receives with the SICK PLOC 2D vision system.
Parameters
----------
乔迪:INT.
送到病例的Ploc 2D视觉系统的工作。
回报
-------
response : boolean
返回作业是否已完成而没有任何错误
"""

cmd =“run.locate”+“,”+ str(jobid)
status = self._send(cmd)
如果状态:
response = self._get_data()
if (not self.error):
返回真实
else:
返回false.

def locate_by_index(self,nobid,索引):
"""Sends and receives with the SICK PLOC 2D vision system.
Parameters
----------
乔迪:INT.
送到病例的Ploc 2D视觉系统的工作。
索引:INT.
所确定的部分索引
回报
-------
response : list
返回mm和deg中的当前索引和x,y,z和Rz值列表
"""
cmd =“run.locate”+“,”+ str(jobid)+“,”+ str(索引)
status = self._send(cmd)
如果状态:
response = self._get_data()
if (not self.error):
返回tuple((self.index,self.score,self.x,self.y,self.z,self.rz))

def is_in_error(self):
返回自我。error



mecademicrobot python类:

Mecademic Robots can be controlled via ourPython APIavailable at ourGitHub.page. The Python API has classes for both robot control on port 10000 and feedback on port 10001.

Vision Guided Pick Python Class:

VisionGuidedPick Python类是更高的水平abstraction class that handles the inetgration of the RobotControl and VisionControl as one and provides methods to perform vision guided pick and place applications. It provides a simple interface for both vision and robot control. It provides various methods that includes getting the total no of identified parts for a given vision job, pick by index, and place etc.,


def get_count(self,jobid):
""" Retrieves the total no of identified parts from the vision job

回报
-------

counts : int
没有鉴定的部分

"""
self.vision.run_job(jobid)
如果不是self.vision.Error:
返回自我。vision.matches


def pick_index(self,jobId,index):
“”“为匹配零件的给定索引开始选择循环

Parameters
----------
乔迪:INT.
用于识别零件的视觉工作ID
索引:INT.
视觉作业中所识别的部分列表的索引“n”
"""
自我。jobId = jobId
自我。index = index

self.count = self.get_count(self.jobid)

如果自我。count != 0:
[self.current_index, self.current_index_score, self.pose_x, self.pose_y, self.pose_z, self.pose_rz] = self.vision.locate_by_index(self.jobId,self.index)
如果self.current_index == self.index:

self.robot.movepose(self.pose_x,self.pose_y,self.pose_z + self.z_offset,self.pose_rx,self.pose_ry,self.pose_rz)
self.robot.setcartlinvel(self.linear_speed / 3)
self.robot.movelin(self.pose_x,self.pose_y,self.pose_z,self.pose_rx,self.pose_ry,self.pose_rz)
自我。gripper_close()
self.delay(0.25)
自我。robot.SetCartLinVel(self.linear_speed)
自我。robot.MoveLin(self.pose_x, self.pose_y, self.pose_z + self.z_offset, self.pose_rx, self.pose_ry, self.pose_rz)


def place(self,x,y,z,rx,ry,rz):
""" Starts the place sequence with Approach and Retract defined with a user defined Z offset
和用户定义的地方姿势

Parameters
----------
X:浮动
关于机器人的BRF的X轴值以mm为单位
Y:浮动
y轴值以mm相对于机器人的brf
z : float
z轴值以mm相对于机器人的brf
rx : float
旋转X轴以度为单位
ry : float
旋转y轴以度为单位
RZ:浮动
Rotation about Z axis in degrees
"""
自我。robot.MovePose(x, y, z + self.z_offset, rx, ry, rz)
self.robotmovelin(x,y,z,rx,Ry,Rz)
self.robot.gripper_open()
self.robot.delay(0.25)
自我。robot.MoveLin(x, y, z + self.z_offset, rx, ry, rz)


关于MECA500的BRF校准视觉参考框架:

An important step in implementing a vision guided pick and place application is calibration of the Vision Reference Frame with respect to the robot's Base Reference Frame. At Mecademic Robotics, we prefer使用3点法计算WRF。VisionGuideDpick类提供了一种计算视觉参考帧的方法并设置它。或者,用户还可以使用独立的可执行文件来计算视觉参考帧。伸出援手support@mecademic.com对于WRF计算器EXE文件。



应用程序代码:

Once we have all the required classes defined, then we can create an vision guided pick and place application by invoking an instance of the VisionGuidedPick class with the IP address of the Meca500 and PLOC 2D and use the methods of this class to get the total count of identified parts, pick by index and place the part.


来自VisionguideDpick导入VisionGuideDpick

# Create an instance of the vision guided pick class
app = VisionGuidedPick('192.168.0.100','192.168.0.1')
# Initialize the vision and robot
app.init_robot()
app.init_vision()

# Set the config parameters
app.set_vision_ref(100,50,25,0,0,0)
app.set_offset(25)
app.set_joint_speed(50)
app.set_linear_speed(150)
app.set_place_pose()

#获取所选视觉作业ID的匹配零件的总计数
count = app.get_count(1)

# Pick the first matched part
if count is not None:
app.pick_index(1,1)
app.place(-120,100,0,180,0,180)


#获取所选视觉作业ID的匹配零件的总计数
count = app.get_count(1)

# Loop through all the identified parts
if count is not None:
for i in range(1,count+1):
app.pick_index(1,i)
app.place(-120,100,0,180,0,180)


Summary:

The SICK PLOC 2D is an easy to use vision system that provides an intuitive user interface to setup vision tasks. With a simple TCP/IP communication interface that streams the responses in CSV format we can build an application class and get started. For PLC users, PLOC 2D supports EtherNet/IP which is also supported by Meca500 as well.


Please note that these examples are provided as-is by either Mecademic or it's Partners. These can be used as a starting point for development and testing but Mecademic or it's partners are not under obligation to provide support and are not liable for any errors or unintended behavior caused by the examples. These examples could be updated over time.

你发现它有用吗?No

发送反馈
对不起,我们无法乐于助人。通过您的反馈帮助我们改进本文。