Most Runtime-Friendly way to activate / deactivate thread?

I’m having an application where the Cobot is turning an object around its tcp. While doing so, the Cobot is supposed to send a signal via the digital outputs every 10 °.

To handle this I wrote a function that checks the angle difference between the current pose and a given pose.

In a seperate thread (that is continously and repeatedly run) I constantly check the angle, and send a high (or low) signal.

After the wait, I built in a sync() command.

However, this implementation does not work the way it is intended, I got multiple runtime errors. What can I do to enhance the performance?

What are your runtime errors? Show us the code you’re working with and we can help a little more. In general, if you want to control a thread, as opposed to just running it 100% of the time, you’ll want to block the main execution with an while() statement and a global variable. Something like:

while(True):
  while(not var_runThread):
    sync()
  end
    -code you want to run in your thread-
  end
end

The outter most while() loop is just how a thread remains always running. The inner while loop tells the thread to do nothing when you don’t want it to run. Then in your main program, when you want to start/stop the thread, you just set var_runThread true or false.

1 Like

THank you, this answers my question.