# Dispensing around a cylindrical part held aligned with wrist 3

I have a dispensing application where I am rotating a gripped cylindrical part concentric to the robot axis and using the rotation of wrist 3 to provide the part axial rotation relative to a fixed dispensing tip. I need to be able to move 360 degrees around the part to dispense a continuous bead of material, I also need to be able to stop the digital output to the dispenser before the robot stops to prevent excess material being dispensed. I have had success driving to a position and using the inverse_kin function and adding additional degrees offset to the wrist 3 value using a jmove script command, this is providing the motion I need. I am struggling to incorporate switching the digital output. most of the examples I have found rely on calculating TCP distances, is there a way to achieve a similar thing comparing the current joint position to a target position and using an event to trigger the digital output. Any help would be appreciated.

Hi @jonathan.cherrington,
I’m not sure I understood correctly, but maybe something like this can help

``````# pick object
movej([2.40, -1.24, 0.91, -1.25, -1.57, -3.00])
movel(p[0.360, -0.152, 0.060, 2.95, 1.06, 0.01])
sim_grasp("cylinder") # simulation command
movel(p[0.361, -0.152, 0.160, 2.95, 1.06, 0.01])

# reverse object
movej([2.47, -0.58, 1.73, -2.71, -4.71, -3])
movel(p[0.378, -0.134, 0.482, -0.002, 0.013, -2.101])

# drive rotation
error = d2r(360)
delta = d2r(1)
joint_vel = 1
joint_acc = 0.8

start_pose = get_actual_joint_positions()

while error > delta:
speedj([0, 0, 0, 0, 0, joint_vel], joint_acc, 0.1)
joint_pose = get_actual_joint_positions()
error = start_pose[5] + d2r(360) - joint_pose[5]
end
stopj(joint_acc)

# stop dispensing
set_standard_digital_out(1, 0)

movel(p[0.378, -0.134, 0.402, 0.01, 0.00, 0.88])
``````

Thank you for responding @Robpod , your code looks much cleaner then my version. The part I was really stuck on is being able to stop the digital output before the robot reaches the end of its path because as it slows I end up with a blob of material building on the part. Using your while approach would allow me to insert a line to use value of ‘Error’ value to trigger the digital output to the dispensing equipment to go low. I will try this tomorrow. Really appreciate the help!