Rules
Solutions
Example Code
Here is one example of a solution among several possibilities. The code is as follows and can be downloaded here.
The chosen approach relies on a standardization of the grip to guarantee a unique placement during stacking. By dynamically adjusting the gripper's position according to the detected package color, the robot grasps each object precisely by its center. This method compensates for dimensional variations and ensures perfect geometry during the tower's construction.
All packages are retrieved horizontally, resting against the conveyor's end stopper, which provides a constant reference point for the robotic arm.
Management of the Special Piece
To finalize the structure, the program integrates a specific condition:
-
Counting: A counter tracks the stack's progress in real-time.
-
Adaptation: As soon as the threshold of 8 packages is reached, the robot switches to a dedicated trajectory.
-
Technical Constraint: Since this special piece is twice as tall as standard packages, the gripper parameters and approach heights are automatically recalculated to accommodate this extra volume.
Note: This automation strategy is one optimized solution among other possible configurations to meet these specifications.
Initialization Phase and Variable Declaration
1. Initialization of variables

These gold-colored blocks first initialize the conveyor and the gripper, which we have just opened. The orange ones define the starting parameters for height management and counting:
- z_obs and z_release: Define the safety heights (approach) and the drop-off heights.
- z_offset: The value added at each level (32 mm) so that the robot rises as the tower grows.
- x_pose and y_pose: Base coordinates to move the gripper toward the package to be retrieved. Using variables is relevant because the packages are of the same size.
- package: A counter starting at 0 to track the number of blocks placed.
Conveyor Search Loop

- Repeat while true: An infinite loop so the robot works continuously.
- Move pose: The robot moves to an observation position above the conveyor.
- Repeat until (Is object detected): The robot activates the conveyor at 60% speed as long as no object is seen by the camera. As soon as a package appears, it stops the motor.
Sorting and Handling Red Blocks

This is where the placement of rejects into the bin located in the Beta Zone (waste area) is managed.
- Vision pick (Color RED): If the object is red, the robot catches it with a 5 mm offset.
- Led ring: The LEDs turn purple to visually indicate that waste is being processed.
- Movement sequence: The robot moves to specific joint coordinates (the waste area), releases the package, and then moves back up.
- Continue with next iteration: Very important: this tells the robot to ignore the rest of the code (the stacking) and return to the starting position to wait for the next package.
Color Identification and Positioning

If the block was not red, the robot continues here to sort the other colors (green and blue).
- If Color GREEN / BLUE: Depending on the detected color, the robot updates the x_pose and y_pose variables.
Note: This allows for a precise definition of where the gripper should position itself to retrieve the packages. The LEDs change color to match the object size (standard or large package).
Package Routing

Repeat while Get DI5: This block routes the packages after sorting. As long as digital input 5 is active (the IR sensor detects no package), the conveyor moves at 100%. As soon as the IR sensor detects the package, the conveyor remains on for 2 seconds to allow the package to position itself correctly against the end stopper.
Retrieval Logic, Transport, Stacking, and Special Piece

This is where all movements are defined to retrieve the package at the end stopper and transport it to the Vision Set for tower construction. Every cycle, we check that the number of packages placed on the Vision Set does not exceed 8 to leave room for the special piece.
- Condition if package = 8: If it is time for the special piece, the robot uses different pose coordinates and angles (roll, pitch, yaw) adapted to the object's larger size.
It adjusts the z_release and z_obs variables with the offset before placing to compensate for the height. For standard blocks (0 to 7), it uses the x_pose and y_pose coordinates defined previously to position itself above the package with a z coordinate that provides a safety margin before reaching the package height. For stacking, the logic is the same, using a safety margin with z_pose and the drop-off height with z_release.
- Grasp & Release: The final commands to grab the object in the pick zone (negative Y coordinates) and release it onto the tower.
- Increment: Increments the package counter by 1 and updates the z_release and z_obs values with the offset (z_offset) for the next level.