Context

The code below presents the different steps involved in the detection and sorting process of metal screws on Conveyor 1. It introduces the use of an if / else logical condition based on camera vision. The code can be downloaded here.

Here is how it works step by step:

Tool Initialization and Configuration

Before starting the loop, the robot configures its tools:

  • It performs the tool scan and conveyor scan functions.

  • It configures the electromagnet connected to digital output DO4.

The program then enters an infinite loop (while true). The robot first moves to its observation position, directly above the conveyor.

Sensor Detection

  • Action: The robot starts Conveyor 1 at a speed of 50%. Depending on the conveyor installation orientation, the direction can be set to FORWARD or BACKWARD.

  • Condition: The conveyor runs as long as input DI5 (the infrared sensor) remains active.

  • Stop: As soon as an object (a screw or a token) interrupts the DI5 beam, the program exits the loop and immediately stops the conveyor.

Vision-Based Sorting: The if / else Condition

The robot uses its built-in camera to analyze the object that has just triggered the sensor within the virtual workspace (Workspace_1).

"IF" Branch: The Detected Object Is a Token
  • Condition: Is object detected Color ANY Shape OBJECT

    ```
    • Logic note: In NiryoStudio, the setting "Shape: OBJECT" generally refers to a recognized flat geometric object (such as round or square tokens).

    ```
  • Action if TRUE (It is a token): The robot must not interact with it, as its role is only to pick up screws.

    ```
    1. It restarts the conveyor to move the token out of the vision area and toward the next robot.

    2. The program then jumps directly to the end of the block and restarts the main loop.

    ```

"ELSE" Branch: The Object Is a Screw

If the camera does not validate the shape as a standard token, the robot assumes it is a metal screw. It then initiates the pick procedure:

  1. Magnet Activation: The electromagnet is energized so it can attract the screw.

  2. Approach and Pick: The first three Move joints blocks move the robotic arm vertically down toward the conveyor and then across its width, ensuring that the screw is properly attracted by the magnet before being lifted.

  3. Clearance: The fourth Move joints block slightly raises the robot to lift the screw off the conveyor belt.

  4. Rotation Toward the Drop-Off Location (Place): The fifth block rotates the robot toward Conveyor 5 and positions it above the conveyor.

  5. Placement and Release: The robot lowers itself close to Conveyor 5 using the sixth block. The magnet is switched off, allowing the screw to drop onto the conveyor.

The robot moves back up, and the loop starts again by returning to its waiting position above Conveyor 1.

Summary

Robot 1 drives the conveyor at 50% speed. As soon as an object interrupts the DI5 sensor beam, the conveyor stops. The robot then inspects the object using its camera:

  • If it is a token, the robot reactivates the conveyor to move it out of the vision area and allow it to continue toward Robot 2.

  • If it is not a token (therefore a screw), the robot activates its electromagnet, lowers itself to pick up the screw, rotates toward Conveyor 5, places the screw on it, and then returns to its starting position.

Video Demonstration

Last modified: Wednesday, 10 June 2026, 5:01 PM