Code - Robot 3
Context
The code below presents the different steps involved in the detection and sorting process of circular tokens by color (red, green, blue) on Conveyor 3, in order to place them in the Beta Zone. Note that the coordinates and axis orientations used here are specific to this example and will likely need to be adapted to your own application.
1. Variable Initialization
Before starting the sorting cycle, the program prepares its vision tools and initializes several memory variables required for position calculations and token placement tracking:

-
y_red = 0.21, y_green = 0.21, y_blue = 0.21: These are the initial Y-axis positions for each color within the Beta Zone.
-
x_zone = 0: The initial X-axis coordinate.
-
token = 0: The global part counter, initialized to zero to monitor the filling status of the storage area.

2. End-of-Cycle Condition and Active Monitoring

The core of the program runs inside a conditional structure that controls the entire process:
-
Batch Management: The robot executes the sorting loop until the token counter reaches a value of 9 (storage area full). Once the Beta Zone is filled, the robot exits the loop and starts a new cycle using the initial positions, beginning again with the leftmost column.
-
Conveyor Monitoring: As long as the camera does not detect any object within the workspace, the robot remains in its high observation position and keeps the conveyor running at 80% of its maximum speed.
-
Decision Making: As soon as a circular token enters the camera's field of view, the waiting condition ends. The robot immediately stops the conveyor and pauses for 1 second to ensure a reliable Vision Pick operation.
3. Color Sorting and Matrix Storage Logic

Once the conveyor has stopped, the robot analyzes the color of the detected circular token using three successive "IF" blocks. Each block follows the same mathematical logic while applying color-specific coordinates:
Case 1: The Token Is RED
-
Row Selection: The program sets the X coordinate to Pose X: x_zone (the row dedicated to red tokens).
-
Pick and Place: The intelligent Vision Pick block guides the robot directly to the part for picking. The robot then places it at the combined coordinates Pose X: x_zone and Y: y_red (initially 0.21).
-
Row Increment: The program adds 45 mm (the center-to-center distance between two storage slots) to the y_red variable so that the next red token is automatically placed in the next column.
-
Counter Update: The robot records the token in the overall count.
Case 2: The Token Is GREEN
-
Row Selection: The X coordinate is set to x_zone = -0.169 (the center row).
-
Pick and Place: The robot performs a Vision Pick and places the green token at the position currently stored in the y_green variable.
-
Row Increment: The program shifts the storage position in preparation for the next green token.
-
Token Counter Update: The robot adds 1 to the global token variable.
Case 3: The Token Is BLUE
-
Row Selection: The X coordinate is set to x_zone = -0.125 (the third row).
-
Pick and Place: The robot picks the blue token and places it at the location managed by the y_blue variable.
-
Row Increment: The Y target is shifted by 45 mm for the next blue token.
-
Counter Update: The blue token is validated and increments the global counter.
Summary
Robot 3 moves the incoming parts along the conveyor, intercepts circular tokens, sorts them by color, and places them accordingly. Thanks to the individual +0.045 m geometric offsets applied to each color row, it autonomously fills the Beta Zone in an organized matrix pattern. Finally, using the token counter variable, the robot knows exactly when its task is complete: as soon as the ninth token has been placed, a new cycle automatically begins.

