3. robodk Module

The robodk module is a robotics toolbox for Python, inspired from Peter Corke's Robotics Toolbox: http://petercorke.com/Robotics_Toolbox.html.

The following page provides an overview of the RoboDK API for Python: https://www.robodk.com/offline-programming

3.1. robodk Example

More examples are available in the 举例 section.

3.2. robodk Module

robodk.Adept_2_Pose(xyzrpw)

Converts an Adept XYZRPW target to a pose (4x4 matrix)

robodk.Comau_2_Pose(xyzrpw)

Converts a Comau XYZRPW target to a pose (4x4 matrix), the same representation required by PDL Comau programs.

robodk.DateCreated(filepath, stringformat=False)

Returns the time that a file was modified

robodk.DateModified(filepath, stringformat=False)

Returns the time that a file was modified

robodk.DirExists(folder)

Returns true if the folder exists

robodk.Fanuc_2_Pose(xyzwpr)

Converts a Motoman target to a pose (4x4 matrix)

robodk.FileExists(file)

Returns true if the file exists

robodk.FilterName(namefilter, safechar='P', reserved_names=None)

Get a safe program or variable name that can be used for robot programming

robodk.KUKA_2_Pose(xyzrpw)

Converts a KUKA XYZABC target to a pose (4x4 matrix), required by KUKA KRC controllers.

robodk.LoadList(strfile, separator=', ', codec='utf-8')

Load data from a CSV file or a TXT file to a Python list (list of list of numbers)

Example:

csvdata = LoadList(strfile, ',')
values = []
for i in range(len(csvdata)):
    print(csvdata[i])
    values.append(csvdata[i])
  
# We can also save the list back to a CSV file
# SaveList(csvdata, strfile, ',')
robodk.LoadMat(strfile, separator=', ')

Load data from a CSV file or a TXT file to a Mat Matrix

class robodk.Mat(rows=None, ncols=None)

Mat is a matrix object. The main purpose of this object is to represent a pose in the 3D space (position and orientation).

A pose is a 4x4 matrix that represents the position and orientation of one reference frame with respect to another one, in the 3D space.

Poses are commonly used in robotics to place objects, reference frames and targets with respect to each other.

Example:

from robolink import *                  # import the robolink library
from robodk import *                    # import the robodk library

RDK = Robolink()                        # connect to the RoboDK API
robot  = RDK.Item('', ITEM_TYPE_ROBOT)  # Retrieve a robot available in RoboDK
#target  = RDK.Item('Target 1')         # Retrieve a target (example)


pose = robot.Pose()                     # retrieve the current robot position as a pose (position of the active tool with respect to the active reference frame)
# target = target.Pose()                # the same can be applied to targets (taught position)

# Read the 4x4 pose matrix as [X,Y,Z , A,B,C] Euler representation (mm and deg): same representation as KUKA robots
XYZABC = Pose_2_KUKA(pose)
print(XYZABC)

# Read the 4x4 pose matrix as [X,Y,Z, q1,q2,q3,q4] quaternion representation (position in mm and orientation in quaternion): same representation as ABB robots (RAPID programming)
xyzq1234 = Pose_2_ABB(pose)
print(xyzq1234)

# Read the 4x4 pose matrix as [X,Y,Z, u,v,w] representation (position in mm and orientation vector in radians): same representation as Universal Robots
xyzuvw = Pose_2_UR(pose)
print(xyzuvw)

x,y,z,a,b,c = XYZABC                    # Use the KUKA representation (for example) and calculate a new pose based on the previous pose
XYZABC2 = [x,y,z+50,a,b,c+45]
pose2 = KUKA_2_Pose(XYZABC2)            # Convert the XYZABC array to a pose (4x4 matrix)

robot.MoveJ(pose2)                      # Make a joint move to the new position
# target.setPose(pose2)                  # We can also update the pose to targets, tools, reference frames, objects, ...
Cols()

Retrieve the matrix as a list of columns (list of list of float).

Example:

>>> transl(10,20,30).Rows()
[[1, 0, 0, 10], [0, 1, 0, 20], [0, 0, 1, 30], [0, 0, 0, 1]]

>>> transl(10,20,30).Cols()
[[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [10, 20, 30, 1]]
ColsCount()

Return the number of coumns. Same as len().

Offset(x, y, z, rx=0, ry=0, rz=0)

Calculates a relative target with respect to the reference frame coordinates. X,Y,Z are in mm, W,P,R are in degrees.

Pos()

Returns the position of a pose (assumes that a 4x4 homogeneous matrix is being used)

RelTool(x, y, z, rx=0, ry=0, rz=0)

Calculates a target relative with respect to the tool coordinates. X,Y,Z are in mm, W,P,R are in degrees. The behavior of this function is the same as ABB's RAPID RelTool command.

Rot33()

Returns the sub 3x3 rotation matrix

Rows()

Get the matrix as a list of lists

RowsCount()

Return the number of rows

SaveCSV(strfile)

Save the Mat Matrix to a CSV (Comma Separated Values) file. The file can be easily opened as a spreadsheet such as Excel.

SaveMat(strfile, separator=', ')

Save the Mat Matrix to a CSV or TXT file

VX()

Returns the X vector of a pose (assumes that a 4x4 homogeneous matrix is being used)

VY()

Returns the Y vector of a pose (assumes that a 4x4 homogeneous matrix is being used)

VZ()

Returns the Z vector of a pose (assumes that a 4x4 homogeneous matrix is being used)

catH(mat2)

Concatenate with another matrix (horizontal concatenation)

catV(mat2)

Concatenate with another matrix (vertical concatenation)

eye(m=4)

Make identity matrix of size (mxm)

invH()

Calculates the inverse of a homogeneous matrix

isHomogeneous()

returns 1 if it is a Homogeneous matrix

list()

Returns the first column of the matrix as a list

list2()

Returns the matrix as list of lists (one list per column)

setPos(newpos)

Sets the XYZ position of a pose (assumes that a 4x4 homogeneous matrix is being used)

setVX(v_xyz)

Sets the VX vector of a pose, which is the first column of a homogeneous matrix (assumes that a 4x4 homogeneous matrix is being used)

setVY(v_xyz)

Sets the VY vector of a pose, which is the first column of a homogeneous matrix (assumes that a 4x4 homogeneous matrix is being used)

setVZ(v_xyz)

Sets the VZ vector of a pose, which is the first column of a homogeneous matrix (assumes that a 4x4 homogeneous matrix is being used)

size(dim=None)

Returns the size of a matrix (m,n). Dim can be set to 0 to return m (rows) or 1 to return n (columns)

tolist()

Returns the first column of the matrix as a list

tr()

Returns the transpose of the matrix

exception robodk.MatrixError

An exception class for Matrix

robodk.Motoman_2_Pose(xyzwpr)

Converts a Motoman target to a pose (4x4 matrix)

robodk.Nachi_2_Pose(xyzwpr)

Converts a Nachi XYZRPW target to a pose (4x4 matrix)

robodk.Offset(target_pose, x, y, z, rx=0, ry=0, rz=0)

Calculates a relative target with respect to the reference frame coordinates. X,Y,Z are in mm, RX,RY,RZ are in degrees.

参数
  • x (float) -- translation along the Reference X axis (mm)

  • y (float) -- translation along the Reference Y axis (mm)

  • z (float) -- translation along the Reference Z axis (mm)

  • rx (float) -- rotation around the Reference X axis (deg) (optional)

  • ry (float) -- rotation around the Reference Y axis (deg) (optional)

  • rz (float) -- rotation around the Reference Z axis (deg) (optional)

robodk.Pose(tx, ty, tz, rx, ry, rz)

Returns the pose (Mat) given the position (mm) and Euler angles (deg) as an array [x,y,z,rx,ry,rz]. The result is the same as calling: H = transl(x,y,z)*rotx(rx*pi/180)*roty(ry*pi/180)*rotz(rz*pi/180) This pose format is printed for homogeneous poses automatically. This Pose is the same representation used by Mecademic or Staubli robot controllers.

参数
  • tx (float) -- position (X coordinate)

  • ty (float) -- position (Y coordinate)

  • tz (float) -- position (Z coordinate)

  • rx (float) -- first rotation (X coordinate)

  • ry (float) -- first rotation (Y coordinate)

  • rz (float) -- first rotation (Z coordinate)

robodk.Pose_2_ABB(H)

Converts a pose to an ABB target (using quaternion representation).

参数

H (Mat) -- pose

robodk.Pose_2_Adept(H)

Converts a pose to an Adept target

参数

H (Mat) -- pose

robodk.Pose_2_Comau(H)

Converts a pose to a Comau target, the same representation required by PDL Comau programs.

参数

H (Mat) -- pose

robodk.Pose_2_Fanuc(H)

Converts a pose (4x4 matrix) to a Fanuc XYZWPR target (mm and deg)

参数

H (Mat) -- pose

robodk.Pose_2_KUKA(H)

Converts a pose (4x4 matrix) to an XYZABC KUKA target (Euler angles), required by KUKA KRC controllers.

参数

H (Mat) -- pose

robodk.Pose_2_Motoman(H)

Converts a pose (4x4 matrix) to a Motoman XYZWPR target (mm and deg)

参数

H (Mat) -- pose

robodk.Pose_2_Nachi(pose)

Converts a pose to a Nachi XYZRPW target

参数

pose (Mat) -- pose

robodk.Pose_2_Staubli(H)

Converts a pose (4x4 matrix) to a Staubli XYZWPR target

参数

H (Mat) -- pose

robodk.Pose_2_TxyzRxyz(H)

Retrieve the position (mm) and Euler angles (rad) as an array [x,y,z,rx,ry,rz] given a pose. It returns the values that correspond to the following operation: H = transl(x,y,z)*rotx(rx)*roty(ry)*rotz(rz).

参数

H (Mat) -- pose

robodk.Pose_2_UR(pose)

Calculate the p[x,y,z,u,v,w] position with rotation vector for a pose target. This is the same format required by Universal Robot controllers.

robodk.RelTool(target_pose, x, y, z, rx=0, ry=0, rz=0)

Calculates a relative target with respect to the tool coordinates. This procedure has exactly the same behavior as ABB's RelTool instruction. X,Y,Z are in mm, W,P,R are in degrees.

参数
  • x (float) -- translation along the Tool X axis (mm)

  • y (float) -- translation along the Tool Y axis (mm)

  • z (float) -- translation along the Tool Z axis (mm)

  • rx (float) -- rotation around the Tool X axis (deg) (optional)

  • ry (float) -- rotation around the Tool Y axis (deg) (optional)

  • rz (float) -- rotation around the Tool Z axis (deg) (optional)

robodk.RemoveDirFTP(ftp, path)

Recursively delete a directory tree on a remote server.

robodk.RemoveFileFTP(ftp, filepath)

Delete a file on a remote server.

robodk.SaveList(list_variable, strfile, separator=', ')

Save a list or a list of lists as a CSV or TXT file.

robodk.TxyzRxyz_2_Pose(xyzrpw)

Returns the pose given the position (mm) and Euler angles (rad) as an array [x,y,z,rx,ry,rz]. The result is the same as calling: H = transl(x,y,z)*rotx(rx)*roty(ry)*rotz(rz)

参数

xyzrpw (list of float) -- [x,y,z,rx,ry,rz] in mm and radians

robodk.UR_2_Pose(xyzwpr)

Calculate the pose target given a p[x,y,z,u,v,w] cartesian target with rotation vector. This is the same format required by Universal Robot controllers.

robodk.UploadDirFTP(localpath, server_ip, remote_path, username, password)

Upload a folder to a robot through FTP recursively

robodk.UploadFTP(program, robot_ip, remote_path, ftp_user, ftp_pass, pause_sec=2)

Upload a program or a list of programs to the robot through FTP provided the connection parameters

robodk.UploadFileFTP(file_path_name, server_ip, remote_path, username, password)

Upload a file to a robot through FTP

robodk.acos(value)

Returns the arc cosinus in radians

robodk.add3(a, b)

Adds two 3D vectors c=a+b

robodk.angle3(a, b)

Returns the angle in radians of two 3D vectors

robodk.angles_2_joints(jin, type)

Converts the angles between links into the robot motor space depending on the type of the robot.

robodk.asin(value)

Returns the arc sinus in radians

robodk.atan2(y, x)

Returns angle of a 2D coordinate in the XY plane

robodk.catH(mat1, mat2)

Concatenate 2 matrices (horizontal concatenation)

robodk.catV(mat1, mat2)

Concatenate 2 matrices (vertical concatenation)

robodk.cos(value)

Returns the cosinus of an angle in radians

robodk.cross(a, b)

Returns the cross product of two 3D vectors

robodk.dh(rz, tx=None, tz=None, rx=None)

Returns the Denavit-Hartenberg 4x4 matrix for a robot link. calling dh(rz,tx,tz,rx) is the same as using rotz(rz)*transl(tx,0,tx)*rotx(rx) calling dh(rz,tx,tz,rx) is the same as calling dh([rz,tx,tz,rx])

robodk.dhm(rx, tx=None, tz=None, rz=None)

Returns the Denavit-Hartenberg Modified 4x4 matrix for a robot link (Craig 1986).

calling dhm(rx,tx,tz,rz) is the same as using rotx(rx)*transl(tx,0,tx)*rotz(rz)

calling dhm(rx,tx,tz,rz) is the same as calling dhm([rx,tx,tz,rz])

robodk.distance(a, b)

Calculates the distance between two points

robodk.dot(a, b)

Returns the dot product of two 3D vectors

robodk.eye(size=4)

Returns the identity matrix

T(t_x, t_y, t_z) = \begin{bmatrix} 1 & 0 & 0 & 0 \\
0 & 1 & 0 & 0 \\
0 & 0 & 1 & 0 \\
0 & 0 & 0 & 1
\end{bmatrix}

参数

size (int) -- square matrix size (4x4 Identity matrix by default, otherwise it is initialized to 0)

robodk.fitPlane(points)

Best fits a plane to a cloud of points

robodk.getBaseName(filepath)

Returns the file name and extension of a file path

robodk.getFileDir(filepath)

Returns the directory of a file path

robodk.getFileName(filepath)

Returns the file name (with no extension) of a file path

robodk.getOpenFile(path_preference='C:/RoboDK/Library/')

Pop up a file dialog window to select a file to open.

robodk.getSaveFile(path_preference='C:/RoboDK/Library/', strfile='file.txt', strtitle='Save file as ...')

Pop up a file dialog window to select a file to save.

robodk.getSaveFolder(path_programs='/', popup_msg='Select a directory to save your program')

Ask the user to select a folder to save a program or other file

robodk.intersect_line_2_plane(pline, vline, pplane, vplane)

Calculates the intersection betweeen a line and a plane

robodk.invH(matrix)

Returns the inverse of a homogeneous matrix

参数

matrix (Mat) -- pose

robodk.joints_2_angles(jin, type)

Converts the robot encoders into angles between links depending on the type of the robot.

robodk.mbox(msg, b1='OK', b2='Cancel', frame=True, t=False, entry=None)

Create an instance of MessageBox, and get data back from the user.

参数
  • msg (str) -- string to be displayed

  • b1 (str, tuple) -- left button text, or a tuple (<text for button>, <to return on press>)

  • b2 (str, tuple) -- right button text, or a tuple (<text for button>, <to return on press>)

  • frame (bool) -- include a standard outerframe: True or False

  • t (int, float) -- time in seconds (int or float) until the msgbox automatically closes

  • entry (None, bool, str) -- include an entry widget that will provide its contents returned. Provide text to fill the box

Example:

name = mbox('Enter your name', entry=True)
name = mbox('Enter your name', entry='default')
if name:
    print("Value: " + name)

value = mbox('Male or female?', ('male', 'm'), ('female', 'f'))
mbox('Process done')
robodk.mult3(v, d)

Multiplies a 3D vector to a scalar

robodk.name_2_id(str_name_id)

Returns the number of a numbered object. For example: "Frame 3" returns 3

robodk.norm(p)

Returns the norm of a 3D vector

robodk.normalize3(a)

Returns the unitary vector

robodk.pause(seconds)

Pause in seconds

参数

pause (float) -- time in seconds

robodk.point_Zaxis_2_pose(point, zaxis, yaxis_hint1=[0, 0, 1], yaxis_hint2=[0, 1, 1])

Returns a pose given the origin as a point, a Z axis and a preferred orientation for the Y axis

robodk.pose_2_quaternion(Ti)

Returns the quaternion orientation vector of a pose (4x4 matrix)

参数

Ti (Mat) -- pose

robodk.pose_2_xyzrpw(H)

Calculates the equivalent position (mm) and Euler angles (deg) as an [x,y,z,r,p,w] array, given a pose. It returns the values that correspond to the following operation: transl(x,y,z)*rotz(w*pi/180)*roty(p*pi/180)*rotx(r*pi/180)

参数

H (Mat) -- pose

返回

[x,y,z,w,p,r] in mm and deg

robodk.pose_angle(pose)

Returns the angle in radians of a 4x4 matrix pose

参数

pose (Mat) -- pose

robodk.pose_angle_between(pose1, pose2)

Returns the angle in radians between two poses (4x4 matrix pose)

robodk.print_pose_ABB(pose)

Displays an ABB RAPID target (the same way it is displayed in IRC5 controllers).

参数

pose (Mat) -- pose

robodk.proj_pt_2_line(point, paxe, vaxe)

Projects a point to a line

robodk.proj_pt_2_plane(point, planepoint, planeABC)

Projects a point to a plane

robodk.quaternion_2_pose(qin)

Returns the pose orientation matrix (4x4 matrix) given a quaternion orientation vector

参数

qin (list) -- quaternions as 4 float values

robodk.rotx(rx)

Returns a rotation matrix around the X axis (radians)

R_x(\theta) = \begin{bmatrix} 1 & 0 & 0 & 0 \\
0 & c_\theta & -s_\theta & 0 \\
0 & s_\theta & c_\theta & 0 \\
0 & 0 & 0 & 1
\end{bmatrix}

参数

rx (float) -- rotation around X axis in radians

robodk.roty(ry)

Returns a rotation matrix around the Y axis (radians)

R_y(\theta) = \begin{bmatrix} c_\theta & 0 & s_\theta & 0 \\
0 & 1 & 0 & 0 \\
-s_\theta & 0 & c_\theta & 0 \\
0 & 0 & 0 & 1
\end{bmatrix}

参数

ry (float) -- rotation around Y axis in radians

robodk.rotz(rz)

Returns a rotation matrix around the Z axis (radians)

R_x(\theta) = \begin{bmatrix} c_\theta & -s_\theta & 0 & 0 \\
s_\theta & c_\theta & 0 & 0 \\
0 & 0 & 1 & 0 \\
0 & 0 & 0 & 1
\end{bmatrix}

参数

ry (float) -- rotation around Y axis in radians

robodk.searchfiles(pattern='C:\\RoboDK\\Library\\*.rdk')

List the files in a directory with a given extension

robodk.sin(value)

Returns the sinus of an angle in radians

robodk.size(matrix, dim=None)

Returns the size of a matrix (m,n). Dim can be set to 0 to return m (rows) or 1 to return n (columns)

参数
  • matrix (Mat) -- pose

  • dim (int) -- dimension

robodk.sqrt(value)

Returns the square root of a value

robodk.subs3(a, b)

Subtracts two 3D vectors c=a-b

robodk.tic()

Start a stopwatch timer

robodk.toc()

Read the stopwatch timer

robodk.tr(matrix)

Returns the transpose of the matrix

参数

matrix (Mat) -- pose

robodk.transl(tx, ty=None, tz=None)

Returns a translation matrix (mm)

T(t_x, t_y, t_z) = \begin{bmatrix} 1 & 0 & 0 & t_x \\
0 & 1 & 0 & t_y \\
0 & 0 & 1 & t_z \\
0 & 0 & 0 & 1
\end{bmatrix}

参数
  • tx (float) -- translation along the X axis

  • ty (float) -- translation along the Y axis

  • tz (float) -- translation along the Z axis

robodk.xyzrpw_2_pose(xyzrpw)

Calculates the pose from the position (mm) and Euler angles (deg), given a [x,y,z,r,p,w] array. The result is the same as calling: H = transl(x,y,z)*rotz(w*pi/180)*roty(p*pi/180)*rotx(r*pi/180)