Filtrer les cibles avec l’API

Le code suivant est un exemple de script Python qui utilise l’API RoboDK pour filtrer une cible (poser une cible ou une cible commune), en utilisant la commande FilterTarget:

pose_filt, joints = robot.FilterTarget(nominal_pose, estimated_joints)

Cet exemple est utile si une application tierce (autre que RoboDK) génère le programme de robot en utilisant des cibles de pose.

from robolink import *    # API to communicate with RoboDK

from robodk import *      # basic matrix operations

 

def XYZWPR_2_Pose(xyzwpr):

    return KUKA_2_Pose(xyzwpr) # Convert X,Y,Z,A,B,C to a pose

   

def Pose_2_XYZWPR(pose):

    return Pose_2_KUKA(pose) # Convert a pose to X,Y,Z,A,B,C

 

# Start the RoboDK API and retrieve the robot:

RDK = Robolink()

robot = RDK.Item('', ITEM_TYPE_ROBOT)

if not robot.Valid():

    raise Exception("Robot not available")

 

pose_tcp = XYZWPR_2_Pose([0, 0, 200, 0, 0, 0]) # Define the TCP

 

pose_ref = XYZWPR_2_Pose([400, 0, 0, 0, 0, 0]) # Define the Ref Frame

 

# Update the robot TCP and reference frame

robot.setTool(pose_tcp)

robot.setFrame(pose_ref)

 

# Very important for SolveFK and SolveIK (Forward/Inverse kinematics)

robot.setAccuracyActive(False) # Accuracy can be ON or OFF

 

# Define a nominal target in the joint space:

joints = [0, 0, 90, 0, 90, 0]

 

# Calculate the nominal robot position for the joint target:

pose_rob = robot.SolveFK(joints) # robot flange wrt the robot base

 

# Calculate pose_target: the TCP with respect to the reference frame

pose_target = invH(pose_ref)*pose_rob*pose_tcp

 

print('Target not filtered:')

print(Pose_2_XYZWPR(pose_target))

 

joints_approx = joints # joints_approx must be within 20 deg

pose_target_filt, real_joints = robot.FilterTarget(pose_target, joints)

print('Target filtered:')

print(real_joints.tolist())

print(Pose_2_XYZWPR(pose_target_filt))