# Is there a a G-code that moves the arm down until the limit switch gives a signal?

Is there a a G-code that moves the arm down until the limit switch gives a signal?

If not, what is a good solution? I tried the following:

//pseudocode:
float z = 30;
while(not getLimitSwitch()){
z = z-0.2;
moveArm(x,y,z)
}

But is doesn’t work everytime.

Found a solution with:

@6 N0 V1, which reports the event of the limit switch end effector.

I solve this with the following code (Python):
//
swift.set_position(240, 0, 30, speed = 20000, wait = True)
r = 30
while r > -5:
r = r - 1
swift.set_position(z = r, speed = 2000, wait = True)
if swift.get_limit_switch():
swift.set_pump(True)
break
swift.flush_cmd()
//
Greetings Klaus

Any way of making this a smooth movement down to the switch?
My arm moves very jittery as it does these small increments one-by-one. I would like to see if there is a way to optimise this for better speed.

Hi, matt,
you can also try these: Bring the arm at your standard speed to a safe height above your object. Try the following code:

``````    r = startingheight

while not swift.get_limit_switch():
r = r - 1
#r = r - 2
#r = r - 3
#r = r - 4
swift.set_position(z = r)

swift.set_pump(True)    #False
swift.set_position(z = startingheight)
``````

r is the starting height. Try to change the factor (r-1) until you have a good result.
Greetings Klaus