Stopj(a) function not working for me

When I apply a force on the gripper, it will enter a protective stop, then give a message: Another thread is already controlling the robot

My code:

Robot Program
waypoint1
waypoint2
waypoint3
waypoint4

Event force > 5
stopj(1)
Halt

When I suppress stopj(1), it will halt as intended. Then I tried it with a Thread:
Thread
if force > 5
stopj(1)
Halt

and it still gives me that error.

I want my robot to slow to a stop and halt after detecting a force. What am I doing wrong?

So stopj()/stopl() is not allowed in a thread. You’re only allowed to control motion in the main program (or sub programs), not threads and events.
Also, stopj() only works after you’ve stopped a motion. stopj() is not a stop command, only a deceleration command. It allows the robot to decelerate instead of braking abrubtly, which can introduce wear to the joints of the robot arm.
So you need to stop the motion first.

This is how I would achieve this:
image

Remember to enable Check expression continuously with the If StopRobot = True. This allows the robot to “leave” the underlying commands, before they’re finished. :slight_smile:

1 Like

The stop motion doesn’t seem to take its time to slow to a halt. It happens instantly when it feels a force. If I uncheck the box, it will go through all the waypoints, then stop. I was hoping it would slow down and stop like one second later at any point in the program where it feels the force. This code is the same as just adding an event and making it halt after a force is over 5 Newtons. Do my waypoint speeds need to be faster for the stopj to work better?

As @efn points out. You can only control the motion from one thread at a time.

The argument you parse to stopj is the acceleration:
image

If you want the stopping time to be one second. You could use _ get_target_joint_speeds()_ find the maximum value(max_joint_speed) and calculate the acceleration by 1/max_joint_speed

If it is not important with one second and would like a simple solution. You could calculate the acceleration by:

1/norm(get_target_joint_speeds())

That will give a little longer time depending on the amount of joints moving.

Ebbe

Try lowering the value to 5 in the stopj(). If you do not see a proper deceleration, then there’s probably something wrong elsewhere.
If that’s the case, please take a screenshot or picture of your code and attach it. :slight_smile: