Articles Download Safety & Security Forum myUR Go to Main Site

Universal Robots A/S
Energivej 51
DK-5260 Odense S

T: +45 8993 8989
sales@universal-robots.com

 
  • Articles
  • Download
  • Safety & Security
  • Forum
  • myUR
  • Go to Main Site
  • Support
  • Articles
  • Design a Counter on your program

Design a Counter on your program

This example will allow you to keep track of counting cycles, quantity, etc.

Last modified on Jan 29, 2025

Examples are valid starting from:
CB2 Software version: 1.8.16941
CB3 Software version: 3.1.17779
E-series Software version: All
Note that older or newer software versions may behave differently.

These examples can be used for both CB2, CB3 and E-series.

Simple use:

This simple example is showing how to count events using a digital input.

1) First set up an BeforeStart/INT variable (Counter=0).
2) We just use wait timer 4 sec as an example.
3) And then the counter will be added in an Event

 Simple

Advance use:

Suppose we have a proximity sensor connected to a digital input, in such a way the input is High when the sensor detects an object, and low otherwise.

Now we want to count objects as they pass by the sensor, so we can let the robot perform an action, when eg. 24 objects have passed.

This picture shows how to make such a program:

Adv Var

I order to detect an object passing by the sensor, we need to detect the low to high transition on the digital input the sensor is connected to.

We therefor need to know not only the current sensor value, but also the last sensor value we read from the input. Given this information, we can now conclude the sensor has detected an object when the old sensor value is "False" and the current sensor value is "True".

The rest of the program should be pretty self-explanatory, but we should remember to give the variables some sensible starting values, using the "Set initial variable values" feature:

Adv Variable

The program presented above, solves the problem, but it has a disadvantage. Suppose, the robot had to do a time consuming job in the DoStuff section of the program, in that case we run the risk of missing some objects passing by the sensor! This happens because programs are executed sequentially, so we will not read the sensor value before the program returns to the top of the program. I order to overcome this limitation, we can make the counter run inside a thread of its own:

Adv Part 2

This way the counter is running in parallel with the main program, and the sensor is read independently of the main program. The wait statement at the beginning of the thread can be used to control how often we wish to read the sensor.

Download Polyscope .urp example below

Attached files


eventcounter-advance-part-2.urp
eventcounter-advance.urp
eventcounter-simple.urp

Attached files

eventcounter-advance-part-2.urp
eventcounter-advance.urp
eventcounter-simple.urp

Related articles

Design a Timer Function
Creating a cycle timer via Polyscope
logo

Product

  • UR3e Robot
  • UR5e Robot
  • UR10e Robot
  • UR16e Robot
  • UR20 Robot
  • UR+ Products

Company

  • About us
  • Contact us
  • Careers We're hiring
  • UR merchandise

Training / Resources

  • Academy
  • Technical Resources
  • Articles
  • FAQ

Insights

  • Blog
  • Case stories
  • Content library
  • News centre
  • Podcast
  • Webinars & Events

Get in touch

  • Ask an Expert
  • Schedule a no-cost assessment
  • Find a distributor
  • Customer support

Connect with us

  • LinkedIn
  • Facebook
  • Twitter
  • YouTube
  • Instagram
  • Universal Robots A/S
  • Energivej 51
  • DK-5260 Odense S
  • T: +45 89 93 89 89
  • sales@universal-robots.com
  • US Corporate Office
  • 27-43 Wormwood St.
  • 02210 Boston, MA.
  • +1-844-GO-COBOT
  • ur.na@universal-robots.com
  • Copyright @ Universal Robots 2025
  • Cookie policy
  • Privacy policy
  • Universal Robots A/S
  • Energivej 51
  • DK-5260 Odense S
  • T: +45 89 93 89 89
  • sales@universal-robots.com
  • US Corporate Office
  • 27-43 Wormwood St.
  • 02210 Boston, MA.
  • +1-844-GO-COBOT
  • ur.na@universal-robots.com

Copyright © Universal Robots 2025

Cookie policy
Privacy policy