0% found this document useful (0 votes)
10 views11 pages

Tọa độ Robo

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views11 pages

Tọa độ Robo

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Tọa độ part 1: [ 160.000000, -99.600000, 50.000000, 0.000000, 0.000000, 0.

000000 ]
Tọa độ box: [ 70.000000, -176.832000, 50.000000, 0.000000, 0.000000, 0.000000 ]
Tọa độ băng tải vật: [ -400.000000, -430.000000, 0.000000, 0.000000, 0.000000, -
90.000000 ]
Tọa độ băng tải box: [ 1190.000000, -310.000000, 0.000000, 0.000000, 0.000000,
0.000000 ]
Tọa độ cánh tay robot: [ 672.947510, 7.719360, 0.000000, 0.000000, 0.000000,
0.000000 ]
Tọa độ bàn: [ 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000 ]

Tọa độ chuẩn bị hút: [ 663.512000, -647.543000, 212.864000, 180.000000, 0.000000, -


90.000000 ]

Tọa độ hút[ 614.275000, -647.543000, 103.465000, 180.000000, 0.000000, -90.000000 ]


Tọa độ chuẩn bị thả: [ 649.411000, -134.437000, 365.543000, 180.000000, 0.000000, -
90.000000 ]
Tọa độ vật 1: [ 649.411000, -124.437000, 95.543000, 180.000000, 0.000000, -90.000000 ]
Tọa độ vật 2: [ 819.411000, -124.437000, 95.543000, 180.000000, 0.000000, -90.000000 ]
Tọa độ vật 3: [ 649.000000, 65.563000, 95.543000, 180.000000, 0.000000, -90.000000 ]
Tọa độ vật 4: [ 819.000000, 65.000000, 95.543000, 180.000000, 0.000000, -90.000000 ]
Tọa độ vật 5: [ 659.411000, 235.563000, 95.543000, 180.000000, 0.000000, -90.000000 ]
Tọa độ vật 6: [ 819.000000, 235.563000, 95.543000, 180.000000, 0.000000, -90.000000 ]
CODE VẬT:
# Type help("robolink") or help("robodk") for more information
# Press F5 to run the script
# Note: you do not need to keep a copy of this file, your python script is saved with the station
from robolink import * # API to communicate with RoboDK
from robodk import * # basic matrix operations
RDK = Robolink()

# This script simulates a conveyor belt


CONVEYOR_NAME = 'Conveyor'
PICKABLE_OBJECTS_KEYWORD = 'Part'

# Speed of movement in MM/S with respect to the conveyor coordinates:


MOVE_SPEED_MMS = [0,30,0]
REFRESH_RATE = 0.005

# Define workspace of the conveyor to pick the objects:


CONV_SZ_X_MIN = 0
CONV_SZ_X_MAX = 440
CONV_SZ_Y_MIN = 0
CONV_SZ_Y_MAX = 2000
CONV_SZ_Z_MIN = -200
CONV_SZ_Z_MAX = 500

# Move objects that reached the end of the conveyor and were not picked:
FALLEN_OBJECTS = [0,0,-500]

# Get the conveyor item and reference for work space:


conv = RDK.Item(CONVEYOR_NAME)
conv_reference = conv.Parent()
poseconv = conv_reference.PoseAbs()

# One second in real life means 1 second of simulation. The simulation speed is taken from the station
SIMULATION_SPEED = 1

def is_inside_conveyor(pose):
"""Checks if a pose is inside the conveyor workspace"""
pos = pose.Pos()
if pos[0] > CONV_SZ_X_MIN and pos[0] < CONV_SZ_X_MAX and pos[1] >
CONV_SZ_Y_MIN and pos[1] < CONV_SZ_Y_MAX and pos[2] > CONV_SZ_Z_MIN and pos[2]
< CONV_SZ_Z_MAX:
return True
return False

def conveyor_move_object(pose, delta_time):


"""Moves the object pose through the conveyor depending on the time and speed"""
delta_mm = mult3(MOVE_SPEED_MMS, delta_time)
newpose = transl(delta_mm)*pose
return newpose

# Get all objects (string list)


all_objects = RDK.ItemList(ITEM_TYPE_OBJECT, True)

# Convert object list into item pointers (faster)


# Also filter the list to take into account pickable objects only
objects = []
objects_name = []
objects_active = []
for i in range(len(all_objects)):
if all_objects[i].count(PICKABLE_OBJECTS_KEYWORD) > 0:
objects.append(RDK.Item(all_objects[i]))
objects_name.append(all_objects[i])
objects_active.append(False)

# The number of objects that can go in the conveyor


nobjects = len(objects)

# Infinite loop to simulate the conveyor behavior


current_time = 0
tic()
time_last = toc()

poseiXXX = objects[len(objects)-1].PoseAbs() #Toa do


while True:
# First: Look for objects that are not in the conveyor but are in the conveyor workspace
for i in range(nobjects):
obj_i = objects[i]

# Skip if the object is already in the conveyor


if objects_active[i]:
continue

# Check if the object has already been taken by a tool. If so, do not take it in the conveyor
if obj_i.Parent().Type() == ITEM_TYPE_TOOL:
continue

# Check if the object is within the conveyor work area


posei = obj_i.PoseAbs()
poseirel = invH(poseconv)*posei
if is_inside_conveyor(poseirel):
# take the object
obj_i.setParentStatic(conv)
print('Adding object %s to the conveyor' % objects_name[i])
objects_active[i] = True

# Second step: Update the position of every object in the conveyor


SIMULATION_SPEED = RDK.SimulationSpeed()
time_current = toc()
time_delta = 0.05
time_last = time_current
current_time = current_time + time_delta*SIMULATION_SPEED

# Make a list of objects with their matching positions to update


obj_items = []
obj_poses_abs = []
for i in range(nobjects):
obj_i = objects[i]

# Check if the object has been picked from the conveyor


if objects_active[i] and not obj_i.Parent().equals(conv):
objects_active[i] = False
print('Object %s was picked from the conveyor' % objects_name[i])
continue

# Skip update for objects that are not in the conveyor


if not objects_active[i]:
continue

# Update the position of the object


posei = invH(poseconv)*obj_i.PoseAbs()
newposei = conveyor_move_object(posei, time_delta*SIMULATION_SPEED)
if not is_inside_conveyor(newposei):
print('Warning!! Object %s fell from the conveyor at %.1f seconds after simulation started' %
(objects_name[i], current_time))
#raise Exception('Object %s was not picked from the conveyor!' % objects_name[i])
newposei = transl(FALLEN_OBJECTS)*newposei
objects_active[i] = False

#obj_i.setPose(newposei) # this will provoke a refresh (can be slow)


obj_items.append(obj_i)
obj_poses_abs.append(poseconv*newposei)

# Update the object positions


RDK.setPosesAbs(obj_items, obj_poses_abs)

# Take a break...
pause(REFRESH_RATE)
if current_time>5:
objects[0].Copy()
newObject =RDK.Paste()
nameXXX='Part '+str(len(objects)+1)
newObject.setName(nameXXX)
newObject.setPose(poseiXXX)
break
CODE BOX:
# Type help("robolink") or help("robodk") for more information
# Press F5 to run the script
# Note: you do not need to keep a copy of this file, your python script is saved with the station
from robolink import * # API to communicate with RoboDK
from robodk import * # basic matrix operations

RDK = Robolink()

# This script simulates a conveyor belt


CONVEYOR_NAME = 'Conveyor2'
PICKABLE_OBJECTS_KEYWORD = ['Box', 'Part']

# Speed of movement in MM/S with respect to the conveyor coordinates:


MOVE_SPEED_MMS = [0,50, 0]
REFRESH_RATE = 0.005

# Define workspace of the conveyor to pick the objects:


CONV_SZ_X_MIN = 0
CONV_SZ_X_MAX = 440
CONV_SZ_Y_MIN = 0
CONV_SZ_Y_MAX = 2000
CONV_SZ_Z_MIN = -200
CONV_SZ_Z_MAX = +500

# Move objects that reached the end of the conveyor and were not picked:
FALLEN_OBJECTS = [0, 0, -500]

# Get the conveyor item and reference for work space:


conv = RDK.Item(CONVEYOR_NAME)
conv_reference = conv.Parent()
poseconv = conv_reference.PoseAbs()

# One second in real life means 1 second of simulation. The simulation speed is taken from the station
SIMULATION_SPEED = 1

def is_inside_conveyor(pose):
"""Checks if a pose is inside the conveyor workspace"""
pos = pose.Pos()
return (CONV_SZ_X_MIN < pos[0] < CONV_SZ_X_MAX and
CONV_SZ_Y_MIN < pos[1] < CONV_SZ_Y_MAX and
CONV_SZ_Z_MIN < pos[2] < CONV_SZ_Z_MAX)

def conveyor_move_object(pose, delta_time):


"""Moves the object pose through the conveyor depending on the time and speed"""
delta_mm = mult3(MOVE_SPEED_MMS, delta_time)
newpose = transl(delta_mm) * pose
return newpose

# Get all objects (string list)


all_objects = RDK.ItemList(ITEM_TYPE_OBJECT, True)

# Convert object list into item pointers (faster)


# Also filter the list to take into account pickable objects only
objects = []
objects_name = []
objects_active = []

for i in range(len(all_objects)):
for keyword in PICKABLE_OBJECTS_KEYWORD:
if keyword in all_objects[i]:
objects.append(RDK.Item(all_objects[i]))
objects_name.append(all_objects[i])
objects_active.append(False)
break # Break after finding the first match

# The number of objects that can go in the conveyor


nobjects = len(objects)

# Infinite loop to simulate the conveyor behavior


current_time = 0
tic()
time_last = toc()
obj_box= objects[len(objects)-1]
PoseiXXX = obj_box.PoseAbs()

while True:
# First: Look for objects that are not in the conveyor but are in the conveyor workspace
for i in range(nobjects):
obj_i = objects[i]

# Skip if the object is already in the conveyor


if objects_active[i]:
continue

# Check if the object has already been taken by a tool. If so, do not take it in the conveyor
if obj_i.Parent().Type() == ITEM_TYPE_TOOL:
continue

# Check if the object is within the conveyor work area


posei = obj_i.PoseAbs()
poseirel = invH(poseconv) * posei
if is_inside_conveyor(poseirel):
# Take the object
obj_i.setParentStatic(conv)
print(f'Adding object {objects_name[i]} to the conveyor')
objects_active[i] = True

# Store the position of 'Box' for later use


if 'Box' in objects_name[i]:
PoseiBox = obj_i.PoseAbs()

# Second step: Update the position of every object in the conveyor


SIMULATION_SPEED = RDK.SimulationSpeed()
time_current = toc()
time_delta = 0.05
time_last = time_current
current_time = current_time + time_delta * SIMULATION_SPEED

# Make a list of objects with their matching positions to update


obj_items = []
obj_poses_abs = []
for i in range(nobjects):
obj_i = objects[i]

# Check if the object has been picked from the conveyor


if objects_active[i] and not obj_i.Parent().equals(conv):
objects_active[i] = False
print(f'Object {objects_name[i]} was picked from the conveyor')
continue

# Skip update for objects that are not in the conveyor


if not objects_active[i]:
continue

# Update the position of the object


posei = invH(poseconv) * obj_i.PoseAbs()
newposei = conveyor_move_object(posei, time_delta * SIMULATION_SPEED)
if not is_inside_conveyor(newposei):
print(f'Warning!! Object {objects_name[i]} fell from the conveyor at {current_time:.1f}
seconds after simulation started')
newposei = transl(FALLEN_OBJECTS) * newposei
objects_active[i] = False

obj_items.append(obj_i)
obj_poses_abs.append(poseconv * newposei)

# Update the object positions


RDK.setPosesAbs(obj_items, obj_poses_abs)

# Take a break...
pause(REFRESH_RATE)

# Copy and paste 'Box' once at the initial position


if current_time >= 13 and PoseiBox is not None:
for obj in objects:
if 'Box' in obj.Name():
obj.Copy()
newObjectBox = RDK.Paste()
nameBox = 'Box ' + str(len(objects) + 1)
newObjectBox.setName(nameBox)
newObjectBox.setPose(PoseiBox)
break
break

CODE XÓA:
from robodk import robolink

# Kết nối với RoboDK


RDK = robolink.Robolink()

# Tạo danh sách tên đối tượng "Part" từ "Part 2" đến "Part 100"
part_names = [f'Part {i}' for i in range(11, 100)]

# Tạo danh sách tên đối tượng "Box" từ "Box 2" đến "Box 100"
box_names = [f'Box {i}' for i in range(2, 100)]

# Kết hợp hai danh sách


object_names = part_names + box_names

# Lặp qua danh sách và xóa từng đối tượng


for name in object_names:
item = RDK.Item(name, itemtype=robolink.ITEM_TYPE_OBJECT)

# Kiểm tra nếu đối tượng tồn tại


if item.Valid():
# Xóa đối tượng
item.Delete()
print(f"Đối tượng {name} đã bị xóa")
else:
print(f"Đối tượng {name} không tồn tại")

You might also like