Working with Asynchronous and Parallel Applications

Working with Asynchronous and Parallel Applications

In this article, we discuss how to use the Background Application feature, which allows the user to run more than one application at the same time.

This feature is alternative for Auxiliary Thread feature, which is not recommended to use according to FAIRINO team.

---

An asynchronous application enables the cobot to execute two or more independent logic threads concurrently. This is particularly useful when certain events or conditions must be monitored continuously, even while the main program is executing. With a single-thread setup, the robot must finish the entire foreground program before evaluating conditions again, making real-time reactions difficult or impossible.



A common example is conveyor-belt handling. In a typical workflow, the cobot must:
  • Check whether a package is present at a specific location

  • Stop the conveyor when the package arrives

  • Remove the package from the conveyor and place it on a shelf

  • Restart the conveyor until the next package arrives

In the previous implementation, the cobot could not check for Package B until it finished all instructions for moving Package A to the shelf. This meant the conveyor could not restart or be monitored until the entire pick-and-place cycle was completed.


This limitation can be resolved by separating the package-detection logic from the package-removal logic. By running the detection logic in a Background Application, the cobot can continuously monitor for new packages while the foreground application handles movement, gripping, and other tasks.



Foreground vs. Background Applications

Typically, the cobot runs:

  • A foreground application — the main LUA script used for pick-and-place or general robot motion.

  • One or more background applications — additional scripts that run asynchronously with independent logic.
    (For example, you can run both logic_A_background and logic_B_background simultaneously.)




Implementation Details


To create a background application, open the Background Applications panel by clicking the icon shown in the screenshot.


Inside this section, you can write your conveyor-monitoring logic—or any other continuous background logic. Give each background LUA file a unique name so it is easy to distinguish from the foreground application.


In many cases, you need to share information between foreground and background threads. In the conveyor example, we use a global variable such as UserVal. This allows the background task to report when a package is detected, and the foreground application can read this value to trigger the pick sequence.

Background Logic Example

The logic running in the background will continuously monitor the proximity sensor.
Assuming your proximity sensor is Digital Input 2 (Responsible for detecting the package arrival), you can follow this structure:

  • If DI2 = 1 (a part is present):
    → Stop the conveyor
    → Set a global user variable (e.g., SetUserVal(uservar1,1))

  • If DI2 = 0 (no part present):
    → Set the global user variable to  (e.g., SetUserVal(uservar1,0))
    → Turn the conveyor back on (DO0 = 1)
    → Keep it running until a new part arrives

Save the script and run it from the Background Applications tab.
Note that background applications continue running even if the robot is not in automatic mode or is temporarily stationary.

To start the background application, simply select your script from the list and click Run.


 


This approach significantly speeds up the process of detecting and removing items from the conveyor. The same technique applies to any application that benefits from interrupt-like behavior, continuous monitoring, or asynchronous execution.
you can find sudo script for the background and foreground application.
    • Related Articles

    • 3D Object Mapping using Force Sensor & Servo Cart (Python SDK)

      This article contains code for mapping and visualizing an object from probing the target **PLEASE NOTE THIS CODE IS MEANT AS AN EXAMPLE/TEMPLATE AND SHOULD NOT BE RAN!!! USE THIS TO CREATE MODIFICATIONS TO ENSURE SAFETY AND COMPATABILITY WITH YOUR ...