Cobot Thread Control: Configuring Runtime-Friendly Gating

Jason IP2 min read
Best PracticesOther ManufacturerRobotics
Licensed PE Working through this on a live machine? A Maine-licensed engineer can take it from here — included with IMD hardware, by the hour for everything else. Book an engineer

Control the continuously running cobot thread with a global Boolean run flag. Keep the thread alive in an outer loop, block it with an inner loop while the flag is false, and call sync() while blocked so the wait yields execution time.

Supported Thread-Control Pattern

The available evidence supports gating the angle-checking and digital-output logic instead of repeatedly creating or terminating the thread. The main program activates or deactivates that logic by writing a global variable.

while (True):
  while (not var_runThread):
    sync()
  end

  # Check the angular difference.
  # Set the required digital output state.
end

Activation and Deactivation Procedure

  1. Declare var_runThread as a global variable accessible to both the main program and the thread.
  2. Set var_runThread to true when angle monitoring and output control must run.
  3. Set var_runThread to false when that work must pause. The thread remains inside its outer loop but blocks in the inner loop.
  4. Retain sync() inside the blocking loop so the inactive thread does not execute an empty, unrestricted loop.

Placement of the Application Logic

Place the pose-angle comparison and digital-output command after the inner blocking loop. When the run flag becomes true, execution leaves the blocking loop and performs the application logic repeatedly. When the flag becomes false, the next outer-loop pass returns the thread to the blocking loop.

The evidence states that the application must change a digital output every 10 degrees, but it does not provide the comparison function, output pulse behavior, motion direction handling, or code that generated the runtime errors. Preserve the existing angle and output logic until those details can be reviewed separately.

Verification and Diagnostic Limits

Verify that the application logic does not execute while var_runThread is false, begins executing after the variable becomes true, and returns to the blocked state after it becomes false. Then confirm that output transitions still occur at the required 10-degree intervals during rotation.

The reported runtime errors are unspecified, so the evidence does not support assigning a particular root cause. Capture the exact error text and the complete thread code if errors remain after applying the run-flag pattern.

FAQ

How do I pause a cobot thread without terminating it?

Use a global Boolean run flag and block the thread in while (not var_runThread). Include sync() inside that blocking loop.

Where should the angle-check and digital-output code run?

Place it after the inner blocking loop and inside the outer continuous loop. It then runs only while the global run flag is true.

Why is the cobot still producing runtime errors after adding sync()?

The available evidence does not include the error text or complete code, so it cannot establish the cause. Record the exact runtime errors and review them with the full thread implementation.

Back to blog