Using a thread to stop a linear movement

Hi @efn @mvrooij,

Can you please upload the photo and video again? I have to stop my robot when e.g. DI[4] = TRUE.

Best regards,
Sepehr

This could be some ugly but working workaround to resume motion from where it sopped.
Please keep in mind that:

  • this use some internal commands
  • if this pause/resume action is a safety behaviour, then safety signals should be used instead
socket_open("127.0.0.1", 30002)
paused = False

# change runtime velocity function
def set_vel(speed):
    command = str_cat("set speed ", speed)
    socket_send_line(command)
end

# check I/O condition
thread check_cond():
    while True:
        if not paused and get_standard_digital_out(1):
            paused = True
            set_vel(0.00001)
        end

        if paused and not get_standard_digital_out(1):
            paused = False
	        set_vel(1.0)
        end

        sync()
    end
end

run check_cond()

# main program
set_vel(1.0)

while True:
    # long motion
    movej([1.20, -1.73, -2.20, -0.81, 1.60, -0.03])
    movej([-1.60, -1.73, -2.20, -0.81, 1.60, -0.03])
end

Hello Sepehr,

I do not have the video from earlier, I’m afraid. But you can see the screenshot.
I made another simple example here:

It will stop its movement towards EndPosition, if DI4 is enabled. All you gotta remember is to check the “Check expression continuously”.
You can put whatever you like in the If command. :slight_smile:

Hi @Robpod,

thank you for your reply!

I’ve tried this workaround, and it works!

Best regards
Sepehr

Hi @efn ,

thanks for your answer.

Unfortunately, this solution does not work for all movement commands. In other words, I should write a (continuous) if command for all movement commands, which I don’t think is a suitable/smart solution.

Best regards,
Sepehr

That’s right, yes. :slight_smile: Or include everything within a single If command.
But that’s what the thread was about (stopping a single movement).

I’m glad Robpod’s solution works for you!