02-28-2019, 11:25 PM
I am trying to write a python script to import a list of points from a TXT file, create a target at each point, and then move the robot TCP to each point for predefined amount of time. The problem is that the RDK.AddFile() function keeps giving me the error, "Failed to open file: SOURCE_6PTS.txt" and when I try to iterate through the imported points with a for loop, it gives the error, "TypeError: ‘Item’ object is not iterable." Is there any way to import points from a TXT file to an iterable object type?
The code I have written which is causing the errors is shown below, and the TXT file I am trying to import points from is included as an attachment.
# Add robot and tool
robot = RDK.Item('UR10')
tool = RDK.Item('meter')
# Add object from STL file & corresponding reference frame
base = RDK.Item('UR10 Base')
sourceFrame = RDK.AddFrame('Auto Source Reference',base)
SOURCE = RDK.AddFile(r'C:\Users\Michael\Documents\RoboDK\SOURCE_STL.STL',sourceFrame)
# Add points from TXT file
POINTS = RDK.AddFile('SOURCE_6PTS.txt')
# Set current position as home
home_pos = robot.Pose()
# Move to each point
for point in POINTS:
pose_i = home_pos
pose_i.setPos(point)
robot.setPoseTool(tool)
robot.MoveJ (pose_i)
robot.Pause(5000)
SOURCE_6PTS.txt(Size: 509 bytes / Downloads: 505)
The code I have written which is causing the errors is shown below, and the TXT file I am trying to import points from is included as an attachment.
# Add robot and tool
robot = RDK.Item('UR10')
tool = RDK.Item('meter')
# Add object from STL file & corresponding reference frame
base = RDK.Item('UR10 Base')
sourceFrame = RDK.AddFrame('Auto Source Reference',base)
SOURCE = RDK.AddFile(r'C:\Users\Michael\Documents\RoboDK\SOURCE_STL.STL',sourceFrame)
# Add points from TXT file
POINTS = RDK.AddFile('SOURCE_6PTS.txt')
# Set current position as home
home_pos = robot.Pose()
# Move to each point
for point in POINTS:
pose_i = home_pos
pose_i.setPos(point)
robot.setPoseTool(tool)
robot.MoveJ (pose_i)
robot.Pause(5000)
SOURCE_6PTS.txt(Size: 509 bytes / Downloads: 505)