Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Import and follow points from TXT file
#1
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)


.txt SOURCE_6PTS.txt(Size: 509 bytes / Downloads: 505)
#2
You should use GetPoints if you want to import the list points as an object in RoboDK, then, iterate through those points. This is an example:

Code:
pointsObject = RDK.AddFile(points_file_path)
pointList, featureName = POINTS.GetPoints(FEATURE_POINT)
for point in pointList:
# point = [x,y,z,i,j,k]
x,y,z,i,j,k = point
print("XYZ = [%.3f,%.3f,%.3f]" % (x,y,z)

Alternatively, you can also use LoadList. Example:

Code:
pointList = LoadList(points_file_path)
for point in pointList:
# point is each row of the file as a list of float
x,y,z = point
print("XYZ = [%.3f,%.3f,%.3f]" % (x,y,z)

I attached an example project that shows how to move through points using these 2 methods.

I also attached a second example that allows you to create a program given a list of points with orientation information (Euler angles).

More examples here:
//www.sinclairbody.com/doc/en/PythonAPI/exam...ugh-points


Attached Files
.rdk Example-AddFile-LoadList.rdk(Size: 1.06 MB / Downloads: 541)
.zip Example-Load-TXT-XYZWPR.zip(Size: 1.88 MB / Downloads: 532)




Users browsing this thread:
1 Guest(s)