#### Discussion

Back to discussions page
Is it possible to set the distance as a variable for the direction command?

In my program, the robot is set to go down in -Z direction untill a distance is reached.
This distance has to be changed during a normal workday, so i want my operator to control this distance as a startup variable.

As of now i have made 4 different direction commands in my program with and if command, respectively 44, 46, 48 and 50mm
So if the operator where to enter 46, the direction command with the distance of 46mm will be the only one running.

I would like to get rid of the 4 different direction commands, so that i am left with only one.

• Founding Pro, Tactile Sensor Beta Testers Posts: 1,267 Handy
Not sure about in the "Until" node as I have never used that.  In our installations where we need to control motion relative to a distance traveled we will have a thread running that is measuring the current distance from some point.  In our main program when we get to the logic portion we set the position equal to the current tool position and then enter an if statement with the checkbox checked for continuous monitoring.

so here is some psuedo code

```local distanceToTravel = ASK THE OPERATOR
Move to the start position of the measured move
local startPose = get_actual_tcp_pose()
local actualDistanceTraveled = 0
if (actualDistanceTraveled < distanceToTravel): #make sure to check the box on the if statement
speedl(p[0,0,-speed to gpo in Z, 0,0,0])
else:
stopj(12) # This will stop the robot motion once the distance is tripped
end

while (True):
actualDistanceTraveled = actualDistanceTraveled + pose_dist(startPose - get_actual_tcp_pose())
sync()
end
end```
Another option if you just want to control the distance that the robot moves is to simply calculate the next position.

```local distanceToTravel = ASK THE OPERATOR

Move to the start position of the calculated move
local startPose = get_actual_tcp_pose()
local finishPose = pose_add(startPose, p[0,0,-distanceToTravel,0,0,0]) #this will act in base coordinates and calculate a point in -Z direction regarding base from the start pose

movel(finishPose)```