{"id":2763,"date":"2021-08-22T07:35:23","date_gmt":"2021-08-22T07:35:23","guid":{"rendered":"https:\/\/www.zacobria.com\/universal-robots-knowledge-base-tech-support-forum-hints-tips-cb2-cb3\/?page_id=2763"},"modified":"2023-01-21T05:42:18","modified_gmt":"2023-01-21T05:42:18","slug":"threads","status":"publish","type":"page","link":"https:\/\/www.zacobria.com\/universal-robots-knowledge-base-tech-support-forum-hints-tips-cb2-cb3\/index.php\/threads\/","title":{"rendered":"Threads."},"content":{"rendered":"\n<p><a title=\"Visit Zacobria &amp; Webshop &amp; Universal-Robots solutions.\" href=\"https:\/\/www.zacobria.com\/automation\/webshop\/\">Visit Zacobria Webshop<\/a><\/p>\n\n\n\n<h1 class=\"wp-block-heading\">Using Thread.<\/h1>\n\n\n\n<p>To control a conveyor that has a function related to the machine the Robot is tending can by advantage be controlled from the Robot program. One way to do this is to use the function \u201dThread\u201d.<\/p>\n\n\n\n<p>First lest assume we have a program that is tending a machine. In this small example below Waypoint 1 and 2 is at the machine and grapping a work piece.<\/p>\n\n\n\n<p>Waypoint 3 and 4 is at the conveyor and at Waypoint 4 the gripper is released and the work piece is delivered to the conveyor.<\/p>\n\n\n\n<p>A Thread is a program sequence that is run in parallel of the main robot program and this can be totally independent of the robot task \u2013 or it can be related to the robot task \u2013 up to the programmer to choose.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"http:\/\/www.zacobria.com\/universal-robots-zacobria-forum-hints-tips-how-to\/thread\/universal-robots-zacobria-thread-1\/\"><img decoding=\"async\" src=\"http:\/\/www.zacobria.com\/universal-robots-zacobria-forum-hints-tips-how-to\/wp-content\/uploads\/2012\/12\/universal-robots-zacobria-thread-1.jpg\" alt=\"universal-robots-zacobria-thread-1\" class=\"wp-image-468\"\/><\/a><\/figure>\n\n\n\n<p>This program snippet is at the machine side, but the conveyor is not moving \u2013 and now we want to have the conveyor to move a notch forward after the robot has delivered a new work piece and then simultaneously let the robot continue its task while the conveyor is moving forward.<\/p>\n\n\n\n<p>For this function we will use the \u201dThread\u201d which can be found in the \u201dStructure\u201d menu and under \u201dAdvanced\u201d.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"http:\/\/www.zacobria.com\/universal-robots-zacobria-forum-hints-tips-how-to\/thread\/universal-robots-zacobria-thread-2\/\"><img decoding=\"async\" src=\"http:\/\/www.zacobria.com\/universal-robots-zacobria-forum-hints-tips-how-to\/wp-content\/uploads\/2012\/12\/universal-robots-zacobria-thread-2.jpg\" alt=\"universal-robots-zacobria-thread-2\" class=\"wp-image-470\"\/><\/a><\/figure>\n\n\n\n<p>Here we got an error messages because the Thread has to be at top level. So we have to move the cursor position up and highlight&nbsp; \u201dRobot Program\u201d in our program tree.<\/p>\n\n\n\n<p>And then click \u201dThread\u201d.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"http:\/\/www.zacobria.com\/universal-robots-zacobria-forum-hints-tips-how-to\/thread\/universal-robots-zacobria-thread-3\/\"><img decoding=\"async\" src=\"http:\/\/www.zacobria.com\/universal-robots-zacobria-forum-hints-tips-how-to\/wp-content\/uploads\/2012\/12\/universal-robots-zacobria-thread-3.jpg\" alt=\"universal-robots-zacobria-thread-3\" class=\"wp-image-471\"\/><\/a><\/figure>\n\n\n\n<p>Now a Thread statement has entered our program. It is shown below our Main program which is slightly confusing because we got told before that it should be at top level. However it is more correct to say that the Thread is at the side of our Main program because it twill run in parallel with our main program.<\/p>\n\n\n\n<p>The Thread can be programmed exactly in the same way as our main program \u2013 and we can even have Waypoints inside the Thread, but then make sure that is intended in relation to the main program \u2013 otherwise the Waypoint action inside the Thread might conflict with the Waypoint action in the Main program (The robot cannot be a two positions at the same time).<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"http:\/\/www.zacobria.com\/universal-robots-zacobria-forum-hints-tips-how-to\/thread\/universal-robots-zacobria-thread-4\/\"><img decoding=\"async\" src=\"http:\/\/www.zacobria.com\/universal-robots-zacobria-forum-hints-tips-how-to\/wp-content\/uploads\/2012\/12\/universal-robots-zacobria-thread-4.jpg\" alt=\"universal-robots-zacobria-thread-4\" class=\"wp-image-472\"\/><\/a><\/figure>\n\n\n\n<p>We want the conveyor to go on for a short while \u2013 and the off the conveyor again. An example of this function is shown under the Thread above.<\/p>\n\n\n\n<p>This example assumes that the conveyor is controlled by out put DO2. There is a Wait in between the ON and OFF statements which is our conveyor run time.<\/p>\n\n\n\n<p>After the OFF statement there is another Wait because otherwise the conveyor would go ON immediately we stopped it \u2013 and the result would be a continuously running conveyor.<\/p>\n\n\n\n<p>Although this will run the conveyor in 1.35 seconds in this case \u2013 it is still independent of the robot action \u2013 which is not our intention \u2013 so we need a little more programming.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"http:\/\/www.zacobria.com\/universal-robots-zacobria-forum-hints-tips-how-to\/thread\/universal-robots-zacobria-thread-5\/\"><img decoding=\"async\" src=\"http:\/\/www.zacobria.com\/universal-robots-zacobria-forum-hints-tips-how-to\/wp-content\/uploads\/2012\/12\/universal-robots-zacobria-thread-5.jpg\" alt=\"universal-robots-zacobria-thread-5\" class=\"wp-image-473\"\/><\/a><\/figure>\n\n\n\n<p>We need to synchronize the Thread with the Main Program and there are many ways to do it, but one way is setting a variable in the main program and then checking on this variable in the thread.<\/p>\n\n\n\n<p>The plan is to set a variable at a certain value in the main program at the time we want the conveyor to start \u2013 this is a flag to the Thread program.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"http:\/\/www.zacobria.com\/universal-robots-zacobria-forum-hints-tips-how-to\/thread\/universal-robots-zacobria-thread-6\/\"><img decoding=\"async\" src=\"http:\/\/www.zacobria.com\/universal-robots-zacobria-forum-hints-tips-how-to\/wp-content\/uploads\/2012\/12\/universal-robots-zacobria-thread-6.jpg\" alt=\"universal-robots-zacobria-thread-6\" class=\"wp-image-474\"\/><\/a><\/figure>\n\n\n\n<p>We have to identify in the main program \u2013 where is it we want the conveyor to move forward ?. In this case it is after the robot has delivered the work piece to the conveyor \u2013 which is at Waypoint 4 and after we have released the work piece.<\/p>\n\n\n\n<p>So we put the cursor there and go to \u201dStructure\u201d \u2013 \u201dAdvanced\u201d and choose \u201dAssignment\u201d.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"http:\/\/www.zacobria.com\/universal-robots-zacobria-forum-hints-tips-how-to\/thread\/universal-robots-zacobria-thread-7\/\"><img decoding=\"async\" src=\"http:\/\/www.zacobria.com\/universal-robots-zacobria-forum-hints-tips-how-to\/wp-content\/uploads\/2012\/12\/universal-robots-zacobria-thread-7.jpg\" alt=\"universal-robots-zacobria-thread-7\" class=\"wp-image-475\"\/><\/a><\/figure>\n\n\n\n<p>This will bring a \u201d=\u201d (equal) sign into the program. We need to define the \u201dAssignment\u201d.<\/p>\n\n\n\n<p>Click on \u201dCommand\u201d to get the property screen for \u201dAssignment\u201d.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"http:\/\/www.zacobria.com\/universal-robots-zacobria-forum-hints-tips-how-to\/thread\/universal-robots-zacobria-thread-8\/\"><img decoding=\"async\" src=\"http:\/\/www.zacobria.com\/universal-robots-zacobria-forum-hints-tips-how-to\/wp-content\/uploads\/2012\/12\/universal-robots-zacobria-thread-8.jpg\" alt=\"universal-robots-zacobria-thread-8\" class=\"wp-image-476\"\/><\/a><\/figure>\n\n\n\n<p>This is our first variable so we have to create it. Click on \u201dCreate New\u201d.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"http:\/\/www.zacobria.com\/universal-robots-zacobria-forum-hints-tips-how-to\/thread\/universal-robots-zacobria-thread-9\/\"><img decoding=\"async\" src=\"http:\/\/www.zacobria.com\/universal-robots-zacobria-forum-hints-tips-how-to\/wp-content\/uploads\/2012\/12\/universal-robots-zacobria-thread-9.jpg\" alt=\"universal-robots-zacobria-thread-9\" class=\"wp-image-477\"\/><\/a><\/figure>\n\n\n\n<p>The Robot will automatically name it \u201dvar_1\u201d, but you can rename to your own preferred name, but often for trouble shooting and discussion with colleagues it is better to leave as the original name.<\/p>\n\n\n\n<p>On the right hand side is an \u201dExpression\u201d field because we can assign the variable a fixed value or a value base don an expression \u2013 maybe base don the previous value of the variable for example to make counters.<\/p>\n\n\n\n<p>But in our case the variable is just a Flag to tell us where we are in the program sequence \u2013 so we just give it the value of \u201d1\u201d.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"http:\/\/www.zacobria.com\/universal-robots-zacobria-forum-hints-tips-how-to\/thread\/universal-robots-zacobria-thread-10\/\"><img decoding=\"async\" src=\"http:\/\/www.zacobria.com\/universal-robots-zacobria-forum-hints-tips-how-to\/wp-content\/uploads\/2012\/12\/universal-robots-zacobria-thread-10.jpg\" alt=\"universal-robots-zacobria-thread-10\" class=\"wp-image-478\"\/><\/a><\/figure>\n\n\n\n<p>Note how the \u201dvar_1\u201d in the main program has been assigned to the value of 1.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"http:\/\/www.zacobria.com\/universal-robots-zacobria-forum-hints-tips-how-to\/thread\/universal-robots-zacobria-thread-11\/\"><img decoding=\"async\" src=\"http:\/\/www.zacobria.com\/universal-robots-zacobria-forum-hints-tips-how-to\/wp-content\/uploads\/2012\/12\/universal-robots-zacobria-thread-11.jpg\" alt=\"universal-robots-zacobria-thread-11\" class=\"wp-image-479\"\/><\/a><\/figure>\n\n\n\n<p>When the \u201dvar_1\u201d variable is 1 &nbsp;&#8211; it tells us that the main program has reach the point when the work piece has been delivered to the conveyor. That\u2019s great because that\u2019s exactly when we want the conveyor to start.<\/p>\n\n\n\n<p>So we will make the Thread dependant on this \u201dvar_1\u201d variable.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"http:\/\/www.zacobria.com\/universal-robots-zacobria-forum-hints-tips-how-to\/thread\/universal-robots-zacobria-thread-12\/\"><img decoding=\"async\" src=\"http:\/\/www.zacobria.com\/universal-robots-zacobria-forum-hints-tips-how-to\/wp-content\/uploads\/2012\/12\/universal-robots-zacobria-thread-12.jpg\" alt=\"universal-robots-zacobria-thread-12\" class=\"wp-image-480\"\/><\/a><\/figure>\n\n\n\n<p>Insert an IF statement into the Thread.<\/p>\n\n\n\n<p>Define the IF statement by clicking on the formula button.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"http:\/\/www.zacobria.com\/universal-robots-zacobria-forum-hints-tips-how-to\/thread\/universal-robots-zacobria-thread-13\/\"><img decoding=\"async\" src=\"http:\/\/www.zacobria.com\/universal-robots-zacobria-forum-hints-tips-how-to\/wp-content\/uploads\/2012\/12\/universal-robots-zacobria-thread-13.jpg\" alt=\"universal-robots-zacobria-thread-13\" class=\"wp-image-481\"\/><\/a><\/figure>\n\n\n\n<p>This will bring up a screen where we can choose the \u201dvar_1\u201d variable and choose to design our expression as var_1=1. This means that only IF var_1 = 1 then we will execute the program line below the IF statement.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"http:\/\/www.zacobria.com\/universal-robots-zacobria-forum-hints-tips-how-to\/thread\/universal-robots-zacobria-thread-14\/\"><img decoding=\"async\" src=\"http:\/\/www.zacobria.com\/universal-robots-zacobria-forum-hints-tips-how-to\/wp-content\/uploads\/2012\/12\/universal-robots-zacobria-thread-14.jpg\" alt=\"universal-robots-zacobria-thread-14\" class=\"wp-image-482\"\/><\/a><\/figure>\n\n\n\n<p>Make sure the \u201dCheck expression continuously\u201d is not ticked. If this is checked the robot will check IF \u201dvar_1\u201d=1 is true also during the Thread execution. This means that if the \u201dvar_1\u201d becomes 0 during the Thread execution then the rest of the program lines inside the IF will not be executed. This can lead to unintended function if not handled correct. In our case we need to set the \u201dvar_1\u201d to 0 inside the Thread and if we do that on top of the program lines below the IF \u2013 then the rest of the IF program lines will not be executed.<\/p>\n\n\n\n<p>Now we have a little Editing work to do \u2013 because what we actually want the lines we originally had in the Thread to be under the IF statement (otherwise the lines will be executed no matter what is the result if the IF expression.<\/p>\n\n\n\n<p>So we need to move those 4 lines up under the IF by using Cut\/Paste or create them again.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"http:\/\/www.zacobria.com\/universal-robots-zacobria-forum-hints-tips-how-to\/thread\/universal-robots-zacobria-thread-15\/\"><img decoding=\"async\" src=\"http:\/\/www.zacobria.com\/universal-robots-zacobria-forum-hints-tips-how-to\/wp-content\/uploads\/2012\/12\/universal-robots-zacobria-thread-15.jpg\" alt=\"universal-robots-zacobria-thread-15\" class=\"wp-image-483\"\/><\/a><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"http:\/\/www.zacobria.com\/universal-robots-zacobria-forum-hints-tips-how-to\/thread\/universal-robots-zacobria-thread-16\/\"><img decoding=\"async\" src=\"http:\/\/www.zacobria.com\/universal-robots-zacobria-forum-hints-tips-how-to\/wp-content\/uploads\/2012\/12\/universal-robots-zacobria-thread-16.jpg\" alt=\"universal-robots-zacobria-thread-16\" class=\"wp-image-484\"\/><\/a><\/figure>\n\n\n\n<p>Notice how all 4 lines now is directly under the IF statement.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"http:\/\/www.zacobria.com\/universal-robots-zacobria-forum-hints-tips-how-to\/thread\/universal-robots-zacobria-thread-17\/\"><img decoding=\"async\" src=\"http:\/\/www.zacobria.com\/universal-robots-zacobria-forum-hints-tips-how-to\/wp-content\/uploads\/2012\/12\/universal-robots-zacobria-thread-17.jpg\" alt=\"universal-robots-zacobria-thread-17\" class=\"wp-image-485\"\/><\/a><\/figure>\n\n\n\n<p>But we only want the conveyor to run one time \u2013 every time it is triggered. So we have to make sure our IF statement becomes False next time the program check the IF expression.<\/p>\n\n\n\n<p>Therefore we insert a \u201dAssignment\u201d in the Thread where we zero the \u201dvar_1\u201d variable so it becomes False for the IF check.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"http:\/\/www.zacobria.com\/universal-robots-zacobria-forum-hints-tips-how-to\/thread\/universal-robots-zacobria-thread-18\/\"><img decoding=\"async\" src=\"http:\/\/www.zacobria.com\/universal-robots-zacobria-forum-hints-tips-how-to\/wp-content\/uploads\/2012\/12\/universal-robots-zacobria-thread-18.jpg\" alt=\"universal-robots-zacobria-thread-18\" class=\"wp-image-486\"\/><\/a><\/figure>\n\n\n\n<p>We set the \u201dvar_1\u201d variable to 0 in the property screen for the variable.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"http:\/\/www.zacobria.com\/universal-robots-zacobria-forum-hints-tips-how-to\/thread\/universal-robots-zacobria-thread-19\/\"><img decoding=\"async\" src=\"http:\/\/www.zacobria.com\/universal-robots-zacobria-forum-hints-tips-how-to\/wp-content\/uploads\/2012\/12\/universal-robots-zacobria-thread-19.jpg\" alt=\"universal-robots-zacobria-thread-19\" class=\"wp-image-488\"\/><\/a><\/figure>\n\n\n\n<p>If you get this error messages it is because we need to tell the Robot \u2013 what should the variable \u201dvar_1\u201d be when we start the program. This is uncertain for the robot if we have not explicit set the variable before the program execution.<\/p>\n\n\n\n<p>So we have to put the cursor up on top where it says \u201dRobot Program\u201d<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"http:\/\/www.zacobria.com\/universal-robots-zacobria-forum-hints-tips-how-to\/thread\/universal-robots-zacobria-thread-20\/\"><img decoding=\"async\" src=\"http:\/\/www.zacobria.com\/universal-robots-zacobria-forum-hints-tips-how-to\/wp-content\/uploads\/2012\/12\/universal-robots-zacobria-thread-20.jpg\" alt=\"universal-robots-zacobria-thread-20\" class=\"wp-image-489\"\/><\/a><\/figure>\n\n\n\n<p>And then tick \u201dSet Initial Variable Values\u201d.<\/p>\n\n\n\n<p>This will insert a line op top of the program called \u201dInit Variables\u201d.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"http:\/\/www.zacobria.com\/universal-robots-zacobria-forum-hints-tips-how-to\/thread\/universal-robots-zacobria-thread-21\/\"><img decoding=\"async\" src=\"http:\/\/www.zacobria.com\/universal-robots-zacobria-forum-hints-tips-how-to\/wp-content\/uploads\/2012\/12\/universal-robots-zacobria-thread-21.jpg\" alt=\"universal-robots-zacobria-thread-21\" class=\"wp-image-490\"\/><\/a><\/figure>\n\n\n\n<p>The Init Variables screen shows that the \u201dvar_1\u201d has no Initial Value.<\/p>\n\n\n\n<p>Below the messages box is a function to set variables.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"http:\/\/www.zacobria.com\/universal-robots-zacobria-forum-hints-tips-how-to\/thread\/universal-robots-zacobria-thread-22\/\"><img decoding=\"async\" src=\"http:\/\/www.zacobria.com\/universal-robots-zacobria-forum-hints-tips-how-to\/wp-content\/uploads\/2012\/12\/universal-robots-zacobria-thread-22.jpg\" alt=\"universal-robots-zacobria-thread-22\" class=\"wp-image-491\"\/><\/a><\/figure>\n\n\n\n<p>Choose \u201dvar_1\u201d and insert 0 in the Expression field.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"http:\/\/www.zacobria.com\/universal-robots-zacobria-forum-hints-tips-how-to\/thread\/universal-robots-zacobria-thread-23\/\"><img decoding=\"async\" src=\"http:\/\/www.zacobria.com\/universal-robots-zacobria-forum-hints-tips-how-to\/wp-content\/uploads\/2012\/12\/universal-robots-zacobria-thread-23.jpg\" alt=\"universal-robots-zacobria-thread-23\" class=\"wp-image-492\"\/><\/a><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"http:\/\/www.zacobria.com\/universal-robots-zacobria-forum-hints-tips-how-to\/thread\/universal-robots-zacobria-thread-24\/\"><img decoding=\"async\" src=\"http:\/\/www.zacobria.com\/universal-robots-zacobria-forum-hints-tips-how-to\/wp-content\/uploads\/2012\/12\/universal-robots-zacobria-thread-24.jpg\" alt=\"universal-robots-zacobria-thread-24\" class=\"wp-image-493\"\/><\/a><\/figure>\n\n\n\n<p>If you get this error messages is because the robot does not like to be caught in an Infinite loop. In this case the Thread program might be Infinite if the \u201dvar_1\u201d never change.<\/p>\n\n\n\n<p>So we do the trick by inserting a small and very short \u201dWait\u201d and put it at a very low value e.g. 0.01 seconds.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"http:\/\/www.zacobria.com\/universal-robots-zacobria-forum-hints-tips-how-to\/thread\/universal-robots-zacobria-thread-25\/\"><img decoding=\"async\" src=\"http:\/\/www.zacobria.com\/universal-robots-zacobria-forum-hints-tips-how-to\/wp-content\/uploads\/2012\/12\/universal-robots-zacobria-thread-25.jpg\" alt=\"universal-robots-zacobria-thread-25\" class=\"wp-image-495\"\/><\/a><\/figure>\n\n\n\n<p>This is done before the IF statement in the Thread \u2013 so the Thread has something else to do if \u201dvar-1\u201d is not 1. (In this case \u2013 to wait 0.01 seconds).<\/p>\n\n\n\n<p>The entire program looks like this below.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"http:\/\/www.zacobria.com\/universal-robots-zacobria-forum-hints-tips-how-to\/thread\/universal-robots-zacobria-thread-26\/\"><img decoding=\"async\" src=\"http:\/\/www.zacobria.com\/universal-robots-zacobria-forum-hints-tips-how-to\/wp-content\/uploads\/2012\/12\/universal-robots-zacobria-thread-26.jpg\" alt=\"universal-robots-zacobria-thread-26\" class=\"wp-image-496\"\/><\/a><\/figure>\n\n\n\n<p>This small program is working and the logic is like this.<\/p>\n\n\n\n<p>Before the program starts the variable \u201dvar_1\u201d is set to 0 in the Init Variables statement.<\/p>\n\n\n\n<p>The Robot Program and the Thread is run simultaneously, but because the \u201dvar_1\u201d equals 0 the IF statement in the Thread is False at this moment so the conveyor is stopped.<\/p>\n\n\n\n<p>The main program start moving the robot from Waypoint 1 to waypoint 2 \u2013 then the DO8 goes ON which could be the gripper closing (In my case I have set the DO9 to go off because of the configuration of the valves I use to open and close the gripper).<\/p>\n\n\n\n<p>The robot move through Waypoint 3 and 4 \u2013 where I imagine the robot is now at the conveyor position ready to deliver the item \u2013 so the out put DO8 go off and DO9 go on. This will deliver the item onto the conveyor. Right after this I set the variable \u201dvar_1\u201d to the value \u201d1\u201d because I want to flag to the Thread that the conveyor can move.<\/p>\n\n\n\n<p>In the Thread the IF statement now see the \u201dvar_1\u201d as \u201d1\u201d and therefore will perform our code inside the IF statement \u2013which is to Start the conveyor DO2 is set to ON. We wait 1.35 seconds and turn the conveyor OFF again. And then the \u201dvar_1\u201d is set to \u201d0\u201d because when the IF statement is checked again it is not False and the conveyor remains stopped&nbsp; &#8211; as we wish.<\/p>\n\n\n\n<p>While the Thread is doing this and the conveyor is moving \u2013 the robot is long moved on in its cycle in the main program.<\/p>\n\n\n\n<p>If a small Wait statement is inserted before the \u201dvar_1\u201d = 1 in the main program the conveyor has a delay before it starts and let the robot gripper get out of the way.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"http:\/\/www.zacobria.com\/universal-robots-zacobria-forum-hints-tips-how-to\/thread\/universal-robots-zacobria-thread-27\/\"><img decoding=\"async\" src=\"http:\/\/www.zacobria.com\/universal-robots-zacobria-forum-hints-tips-how-to\/wp-content\/uploads\/2012\/12\/universal-robots-zacobria-thread-27.jpg\" alt=\"universal-robots-zacobria-thread-27\" class=\"wp-image-497\"\/><\/a><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Placing the work pieces in rows on the conveyor.<\/h2>\n\n\n\n<p>If you wish to place the work pieces in rows on the conveyor \u2013 maybe 2 rows or 4 rows etc.<\/p>\n\n\n\n<p>So in this example I will show 4 rows.<\/p>\n\n\n\n<p>Maybe in a pattern something like this.<\/p>\n\n\n\n<p><strong>Basket<\/strong><\/p>\n\n\n\n<p>\u2191<\/p>\n\n\n\n<p>O&nbsp;&nbsp;&nbsp; O<\/p>\n\n\n\n<p>O&nbsp;&nbsp;&nbsp; O<\/p>\n\n\n\n<p>O&nbsp;&nbsp;&nbsp; O<\/p>\n\n\n\n<p>O&nbsp;&nbsp;&nbsp; O<\/p>\n\n\n\n<p>O &nbsp; &nbsp;O<\/p>\n\n\n\n<p>O&nbsp;&nbsp;&nbsp; O<\/p>\n\n\n\n<p><strong>Robot<\/strong><\/p>\n\n\n\n<p>The sequence the work pieces has been put on the conveyor is like this<\/p>\n\n\n\n<p><strong>Basket<\/strong><\/p>\n\n\n\n<p>\u2191<\/p>\n\n\n\n<p>1&nbsp;&nbsp;&nbsp; 2<\/p>\n\n\n\n<p>3&nbsp;&nbsp;&nbsp; 4<\/p>\n\n\n\n<p>1&nbsp;&nbsp;&nbsp; 2<\/p>\n\n\n\n<p>3&nbsp;&nbsp;&nbsp; 4<\/p>\n\n\n\n<p>1&nbsp;&nbsp;&nbsp;&nbsp; 2<\/p>\n\n\n\n<p>3&nbsp;&nbsp;&nbsp; 4<\/p>\n\n\n\n<p><strong>Robot<\/strong><\/p>\n\n\n\n<p>This means the Conveyor only have to move a notch forward in between 2 and 3. And again in between 4 and 1.<\/p>\n\n\n\n<p>A way to program this is just to use variables and IF statements to keep track of the sequences of placing work pieces in this pattern in the Main program.<\/p>\n\n\n\n<p>And then let the Thread take care of the moving the conveyor a notch forward. The Thread does actually not need to know the sequence of placing work pieces \u2013 the Thread just ON\/OFF the conveyor according to the timing set inside the Thread.<\/p>\n\n\n\n<p>So the Thread will remain like in the previously example.<\/p>\n\n\n\n<p>(There are many different ways to do this \u2013 as many there are creative programmers).<\/p>\n\n\n\n<p>So far there is only one Waypoint for delivering the work piece because it is always delivered at the same position on the conveyor. In previous chapter this is Waypoint 4 that is the position for delivering the work piece.<\/p>\n\n\n\n<p>Now in this example we need 4 different waypoints for delivering the work piece on the conveyor because position 1 \u2013 2 \u2013 3 \u2013 and 4 are different. To keep track of the delivery position we can use another variable.<\/p>\n\n\n\n<p>Let\u2019s get do some programming.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"http:\/\/www.zacobria.com\/universal-robots-zacobria-forum-hints-tips-how-to\/thread\/universal-robots-zacobria-thread-28\/\"><img decoding=\"async\" src=\"http:\/\/www.zacobria.com\/universal-robots-zacobria-forum-hints-tips-how-to\/wp-content\/uploads\/2012\/12\/universal-robots-zacobria-thread-28.jpg\" alt=\"universal-robots-zacobria-thread-28\" class=\"wp-image-499\"\/><\/a><\/figure>\n\n\n\n<p>The first part of the program is almost like before until we reach the point where we have to deliver the work piece onto the conveyor.<\/p>\n\n\n\n<p>However on top of the main program there has been an IF statement inserted which is to initialize our position counter. The position counter is a new variable called \u201dvar_2\u201d.<\/p>\n\n\n\n<p>In the Init Variables block we set the \u201dvar_2\u201d to 0. So first time we run the program \u2013 the variable will be 0 and thereby we know this is the first run and we can change the value to 1 so we can place the first work piece at position 1.<\/p>\n\n\n\n<p>If we use the function to store values of this variable in between runs \u2013 then we can achieve that the robot can remember which position on the conveyor is the next position \u2013 this will be explained later.<\/p>\n\n\n\n<p>Since we have 4 different positions for the robot to deliver the work piece to &#8211; we have to create 4 waypoint for this position across the conveyor belt. These 4 waypoint will be in line across the conveyor belt because it is the moving forward of the belt that provides the zigzag pattern. So we will put the first at position 1 and then position 2 \u2013 move the conveyor a little forward \u2013 then put at position 3 and finally at position 4 and move the belt a little forward.<\/p>\n\n\n\n<p>In the program I now call the waypoints 4_1, 4_2, 4_3, 4_4 just to illustrate that it is Waypoint 4 we are working with. There can be more Waypoints at these position e.g. an up and down and back up again for nice placement of the part.<\/p>\n\n\n\n<p>So before programming any further we will define the Waypoint_4_1&nbsp; , Waypoint_4_2&nbsp; , Waypoint_4_3&nbsp; , Waypoint_4_4 where we want them to be at the conveyor.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"http:\/\/www.zacobria.com\/universal-robots-zacobria-forum-hints-tips-how-to\/thread\/universal-robots-zacobria-thread-29\/\"><img decoding=\"async\" src=\"http:\/\/www.zacobria.com\/universal-robots-zacobria-forum-hints-tips-how-to\/wp-content\/uploads\/2012\/12\/universal-robots-zacobria-thread-29.jpg\" alt=\"universal-robots-zacobria-thread-29\" class=\"wp-image-500\"\/><\/a><\/figure>\n\n\n\n<p>After the 4 Waypoints have been defined we will introduce 4 IF statements because we need to check where the next work piece have to be placed.<\/p>\n\n\n\n<p>We introduced the variable \u201dvar_2\u201d for this purpose.<\/p>\n\n\n\n<p>The \u201dvar_2\u201d can in this case have 5 different values i.e. 0, 1, 2, 3 and 4.<\/p>\n\n\n\n<p>The value 0 is to tell that we start all over again.<\/p>\n\n\n\n<p>At the first run the \u201dvar_2\u201d will have the value 0 \u2013 which is very quickly changed to 1 in the beginning of the main program. So when we come down to the IF statements the value of \u201dvar_2\u201d is 1. And the program under \u201dIF var_2 = 1\u201d will be executed \u2013 which is to go over to Waypoint_4_1 and deliver the part.<\/p>\n\n\n\n<p>When the part has been delivered to Waypoint_4_1 the variable \u201dvar_2\u201d is set to 2 \u2013 to show the robot program that&nbsp; we have already been at position one and the next position in line is position 2.<\/p>\n\n\n\n<p>Notice how the IF statement of \u201dIF var_2 = 4\u201d is on top and going down to&nbsp; \u201dIF var_2 = 4\u201d. The reason for that is because we set the \u201dvar_2\u201d variable inside the IF statement to the next value \u2013 and if we had the \u201dIF var_2 = 1\u201d on top down to \u201dIF var_2 = 4\u201d \u2013 then all IF would be executed in a row because the change of \u201dvar_2\u201d will make it true for the next IF. That\u2019s why they are turned upside down.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"http:\/\/www.zacobria.com\/universal-robots-zacobria-forum-hints-tips-how-to\/thread\/universal-robots-zacobria-thread-30\/\"><img decoding=\"async\" src=\"http:\/\/www.zacobria.com\/universal-robots-zacobria-forum-hints-tips-how-to\/wp-content\/uploads\/2012\/12\/universal-robots-zacobria-thread-30.jpg\" alt=\"universal-robots-zacobria-thread-30\" class=\"wp-image-501\"\/><\/a><\/figure>\n\n\n\n<p>Leave the \u201dCheck expression continuously\u201d at each of these 4 IF statements in the main program unchecked.<\/p>\n\n\n\n<p>Since we only need to conveyor to move forward after position 2 and after position 4 the assignment of \u201dvar_1\u201d is only done inside the IF statement for Waypoint_4_2 and Waypoint_4_4.<\/p>\n\n\n\n<p>So the IF statement inside the Thread is only true after the robot has delivered to Waypoint_4_2 and Waypoint_4_4.<\/p>\n\n\n\n<p>The entire program looks like this.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"http:\/\/www.zacobria.com\/universal-robots-zacobria-forum-hints-tips-how-to\/thread\/universal-robots-zacobria-thread-31\/\"><img decoding=\"async\" src=\"http:\/\/www.zacobria.com\/universal-robots-zacobria-forum-hints-tips-how-to\/wp-content\/uploads\/2012\/12\/universal-robots-zacobria-thread-31.jpg\" alt=\"universal-robots-zacobria-thread-31\" class=\"wp-image-502\"\/><\/a><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"http:\/\/www.zacobria.com\/universal-robots-zacobria-forum-hints-tips-how-to\/thread\/universal-robots-zacobria-thread-32\/\"><img decoding=\"async\" src=\"http:\/\/www.zacobria.com\/universal-robots-zacobria-forum-hints-tips-how-to\/wp-content\/uploads\/2012\/12\/universal-robots-zacobria-thread-32.jpg\" alt=\"universal-robots-zacobria-thread-32\" class=\"wp-image-503\"\/><\/a><\/figure>\n\n\n\n<p><strong>Disclaimer:<\/strong> While the Zacobria Pte. Ltd. believes that information and guidance provided is correct, parties must rely upon their skill and judgement when making use of them. Zacobria Pte. Ltd. assumes no liability for loss or damage caused by error or omission, whether such an error or omission is the result of negligence or any other cause. Where reference is made to legislation it is not to be considered as legal advice. Any and all such liability is disclaimed.<\/p>\n\n\n\n<p>If you need specific advice (for example, medical, legal, financial or risk management), please seek a professional who is licensed or knowledgeable in that area.<\/p>\n\n\n\n<p>Author:<br><a href=\"https:\/\/plus.google.com\/u\/0\/116832821661215606670?rel=author\">By Zacobria Lars Skovsgaard<\/a><br>Accredited 2015-2018 Universal Robots support Centre and Forum.<br><br><br><\/p>\n\n\n\n<p><a href=\"https:\/\/twitter.com\/share\">Tweet<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/twitter.com\/zacobria\">Follow @zacobria<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Visit Zacobria Webshop Using Thread. To control a conveyor that has a function related to the machine the Robot is tending can by advantage be controlled from the Robot program. One way to do this is to use the function&#8230; <\/p>\n<div class=\"more-link-container\"><a class=\"more-link\" href=\"https:\/\/www.zacobria.com\/universal-robots-knowledge-base-tech-support-forum-hints-tips-cb2-cb3\/index.php\/threads\/\">Read More<\/a><\/div>\n","protected":false},"author":1,"featured_media":2481,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"templates\/full-width-page.php","meta":{"footnotes":""},"class_list":["post-2763","page","type-page","status-publish","has-post-thumbnail","hentry"],"_links":{"self":[{"href":"https:\/\/www.zacobria.com\/universal-robots-knowledge-base-tech-support-forum-hints-tips-cb2-cb3\/index.php\/wp-json\/wp\/v2\/pages\/2763","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.zacobria.com\/universal-robots-knowledge-base-tech-support-forum-hints-tips-cb2-cb3\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.zacobria.com\/universal-robots-knowledge-base-tech-support-forum-hints-tips-cb2-cb3\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.zacobria.com\/universal-robots-knowledge-base-tech-support-forum-hints-tips-cb2-cb3\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zacobria.com\/universal-robots-knowledge-base-tech-support-forum-hints-tips-cb2-cb3\/index.php\/wp-json\/wp\/v2\/comments?post=2763"}],"version-history":[{"count":4,"href":"https:\/\/www.zacobria.com\/universal-robots-knowledge-base-tech-support-forum-hints-tips-cb2-cb3\/index.php\/wp-json\/wp\/v2\/pages\/2763\/revisions"}],"predecessor-version":[{"id":3125,"href":"https:\/\/www.zacobria.com\/universal-robots-knowledge-base-tech-support-forum-hints-tips-cb2-cb3\/index.php\/wp-json\/wp\/v2\/pages\/2763\/revisions\/3125"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.zacobria.com\/universal-robots-knowledge-base-tech-support-forum-hints-tips-cb2-cb3\/index.php\/wp-json\/wp\/v2\/media\/2481"}],"wp:attachment":[{"href":"https:\/\/www.zacobria.com\/universal-robots-knowledge-base-tech-support-forum-hints-tips-cb2-cb3\/index.php\/wp-json\/wp\/v2\/media?parent=2763"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}