Using analog input to change the speed slider

Hello,

since it can be quite challenging to quickly change the speed slider on the pendant while trying out new programms or changes to existing ones I wanted to add an external potentiometer as an override like you typically have on cnc machines.

Therefore I followed the example shown here: Setting the speed slider from a program 15293 UR Support

And added a thread to my main programm:

Thread_2
ok=socket_open("127.0.0.1",30002)
Loop
  RobotSetSpeed=floor(analog_in[0]*0,175*100)/100
  If RobotSetSpeed>1
    RobotSetSpeed=1
  socket_send_string("set speed")
  socket_send_string(RobotSetSpeed)
  socket_send_byte(10)
  Wait RobotSetSpeed! ≠ floor(analog_in[0]*0,175*100)/100

Doing it counter based like in the article did not really work for me as the speed change was very delayed.
While my script works well between 1-99% it stays on 0% once you drop the poti that law and does not go back up unless you change the speed slider on the teach pendant. It is probably because the programm is effectively paused on 0% and does not execute/evaluate the wait statement. How can I resolve that? I still want to be able to completely pause the programm by turning it down to zero.

The second problem I encounter is that I immediately get a security stop when the poti/speed value is maxed out. “C271A1: Lowlevel-Realtime-Thread” because the runtime is too far behind.
It seems to be the if statement I added to top off the analog value at 1 the speed slider would sometimes jump to 101% otherwise. But I do not understand why. The wait should be unaffected by that, isn´t it?

Kind regards,
Martin

What happens if you change your if statement to set the value to 1.0 instead of 1? I know that seems really dumb, but I’ve seen some dumb things in my day. If it is expecting a double (1.0) but receives an int (1) you’re putting your trust in the compiler to do that type conversion and it doesn’t always do it right.

As for the runtime too far behind, I would advise you just add a sync() command after the Wait command. Generally any time I have threads or loops within that thread, I put a sync() at the end.