1. Home
  2. Knowledge Base
  3. CNC milling machine Tending

CNC milling machine Tending:


Application Description:
This program example is a situation with where one UR5 is tending to 3 desktop Levil CNC milling machines. The robot unload a CNC machine that reports idle and place the processed item in one single output tray.

The robot picks from one single tray and load tend to one of the CNC machines that is idle.


Function description:
The robot pickup items placed in a tray with 9 positions and place the item in a CNC milling machine that has completed the previous milling.
If all CNC milling machines are loaed the robot will remove a processed item in another tray with 9 positions before picking a item to be loaded into the CNC milling machine.
Therefore the robot keeps track on which in the pick and where to place and als the robot keeps track on which milling machine is loaded or unloaded.

Also if a CNC milling machine is offline it will not be tended to.

In this example the “Pallet” wizard is used for the input picking tray and for the placing output tray. Each of these trays has 9 positions and they have been pre-taught by setting each corner of the trays and then defining the tray with 3 row and 3 columns which make up 9 position. This cause a counter with 9 steps to be generated for each tray and this counter will count from 8 to 0 (9 steps).

Each subroutine has waypoints corresponding the the location of the CNC milling machine in relation to the robot, and this includes the positions for the input tray and output tray which are Pallet sequences. These subroutines are called when the robot needs to go to such position.
In this example the robot is also mechanically pulling and pushing a lever that lock and unlock the item to be processed by the CNC milling machine.


I/O table Inputs:
DI0 =
DI1 = Machine 1 ready
DI2 = Machine 2 ready
DI3 = Machine 3 ready


I/O table Outputs:
DO0 =
DO1 = Start cycle Machine 1
DO2 = Start cycle Machine 2
DO3 = Start cycle Machine 3
DO4 =
DO5 =
DO6 = Open Gripper
DO7 = Close Gripper


Variable Table:
cnt_1 = Position counter for output tray counting 8 to 0 (9 steps)
cnt_2 = Position counter for input tray counting 8 to 0 (9 steps)
In_tray_empty = Flag set when input tray is empty.
out_tray_full = Flag set when output tray is full
m1_done = Flag set when CNC machine 1 is done processing
m2_done = Flag set when CNC machine 2 is done processing
m3_done = Flag set when CNC machine 3 is done processing
activate_m1 = Flag set to activate CNC machine 1
activate_m2 = Flag set to activate CNC machine 2
activate_m3 = Flag set to activate CNC machine 3
m1_loaded = Flag set when CNC machine 1 has been loaded
m2_loaded = Flag set when CNC machine 2 has been loaded
m3_loaded = Flag set when CNC machine 3 has been loaded
pulse_m1 = Flag for sending pulse to CNC machine 1
pulse_m2 = Flag for sending pulse to CNC machine 2
pulse_m2 = Flag for sending pulse to CNC machine 3
m1_inprogress = Flag set when CNC machine 1 is in progress
m2_inprogress = Flag set when CNC machine 2 is in progress
m3_inprogress = Flag set when CNC machine 3 is in progress
complete = check flag for service purpose


Electrical diagram:


Program description:
In the BeforeStart routine the variables and outputs are reset to known values.

At the beginning of the program the variable “complete” is reset as this is a variable that can be used for program service to disable a part of program.

The first “IF” statement checks if the counter for the output tray has reached 0 which means the robot has visited all positions in the output tray and therefore the output tray is full. This cause a Popup messages to notify the operator to empty the output tray.

The second “IF” statement checks if the counter for the input tray has reached 0 which means the robot has visited all positions in the input tray and therefore the input tray is empty. This causes a Popup massages top notify the operator to load items into the input tray ready for process in the CNC milling machine.

The third “IF” statement checks on the service variable “complete” which is normal circumstance is permanent 0 and therefore this “IF” statement is always true.

The fourth-sixth “IF” statements checks each CNC milling machine for being done (ready – online) and not loaded with items. (This is considered the “first” run because the CNC machine is empty).

The seventh-nineth “IF” statement checks each CNC milling machine for being done (ready – online) and loaded with items. (This is considered to be successive runs because the CNC machine is now loaded with the previous item whish has to be unloaded before a new item can be loaded.).

During each of the 6 “IF” routines the robot move to different waypoints defined in subroutines that has positions that fit the location to each CNC milling machine in relation to the robot. At the same time status flags for the status of a CNC machine is set according to loaded and readiness.

The first Thread_1 routine is used to open the gripper. By setting the variable “open” true in the main program will open the gripper.

The second Thread_2 routine is used to check if a CNC milling machine wen into error (offline) during the milling porcess. This is order not to pick items that is only half finish from the milling machine and therefore not to put them in the output tray as this item would most likely not pass quality standard.

The third Thread_3 routine is used to activate each CNC milling machine cycle (corresponding digital output goes On and the Off after 2 seconds which creates a pulse that activates the CNC milling machine). There are several status check in this routine because the CNC machine might in this case not be ready to receive the “Start cycle” signal and therefore it can be send again if the status signal reflect so.

This program example uses Thread to open and close the gripper – and also Thread to send “Start cycle signal” to the CNC milling machine in order to save time so the robot can start moveing to next task earlier and not be waiting for the return of status signal from the CNC milling machine.

Program code:



For the pneumatic parts can be used similar parts as shown in the example “Pick and Place using pneumatic gripper”


Contribute moderator

Disclaimer: 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.

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.

By Zacobria Lars Skovsgaard
Accredited 2015-2018 Universal Robots support Centre and Forum.

Also check out the CB3 forum

Article Attachments

Was this article helpful?

Leave a Reply

Your email address will not be published. Required fields are marked *