Thread are used to monitor IO and to make some actions.
In the point of view of performance, what is more beneficial:
To have one thread and place the logic in different folders, or
To have different threads for certain logic?
For example:
I plane to use signal column in my application and it’s lights will be controlled by a number of DO. They will be set according a logic
I will have a few points to collect parts. I want it put an ID for the position, robot must go. I need to evaluate a few DIs and to set global variable.
Those logics can be put in one thread (placed in a folder each) or can be placed in two treds.
I don’t think there’s any sense in using more threads, if you don’t need it. I don’t know of any performance preferences.
A scenario where you need more than one thread is, if you have some sequence that requires a wait time (for a signal or a delay). Then you want to have your other sequence in another thread, so it’s not delayed by the wait time in the first sequence.
The main issue with putting multiple things into the same thread is that they can block each other.
For example, if you wrote something like:
Thread 1
Loop (D0 = High)
BlueLight = On
Wait 0.2sec
BlueLIght = Off
Wait 0.2sec
If (D1 = High)
Open Gripper (wait for motion to complete)
If D0 is high, it won’t check D1 until D0 goes back to Low.
if D1 goes high, it won’t check D1 until it finishes Opening the Gripper.
While having a large number of threads does cause performance issues, I’d still reccomend keeping individual logic blocks seperated into their own threads. The main exception is when you WANT to block another Logic Block.
Thread 1
if (D0 = High)
MoveL
WP01
If (D1 = High)
MoveL
WP02
in this example, we prevent two threads from trying to move the cobot simultaneously by combining them into One thread.
Finally, I’d wager that if you’re having performance issues from too many threads, you can likely eliminate the threads. (In the two examples I wrote up, the only piece of logic that needs to be in a thread is the blinking light, the others can be check in the main program as needed.)
TL;DR: Grouping Logic into the same threads causes those Logic to block each other, therefore preference separating Logic into different threads unless blocking is desired. If you have too many threads, you likely have logic that doesn’t need to be in a thread.)
P.S.: Don’t forget to put a Sync() at the end of Threads and Loops that don’t have any robot motion.