Welcome to DOFBOT-Ultra repository
6. Label code stacking
Label Code Stacking
If using a depth camera (DABAI_DCW2), make sure to execute
ros2 run dofbot_ultra_driver calibrate_6pointfor a six-point calibration before running this example. Otherwise, the arm cannot accurately locate the target.
Please ensure that the web control program backend process is not running in the background. To close it, refer to the [Get Started Quickly - 2. Access the Terminal] section in [Disable the Auto-Start Web Control Backend Process]. After closing, please restart DofbotUltra!!!
The label code stacking function is built upon label code sorting, modifying the placement method to stacking blocks. It grabs blocks sequentially according to ID number order and stacks them in the designated area.
For all functions involving grasping of square blocks, please use 30x30x30 mm wooden blocks. Non-standard sized objects may cause servo No. 6 stall and damage.
Note: Before starting the program, please follow the [Assembly Tutorial] -> [Install the Map] tutorial to correctly install the map before operation.
1. Startup and Operation
Start ROS Node Service
Open the system terminal and enter the following command. If already running, there is no need to start again.
xxxxxxxxxxros2 run dofbot_ultra_info kinematics_dofbotultra
Start the Program
Open a browser (any browser on any host in the same local network) and enter the IP address:8888 in the address bar to access JupyterLab.
Code path:
xxxxxxxxxxdofbot_apriltag/scripts/Apriltag_Stacking.ipynb
Click the Run All button on the JupyterLab toolbar, then scroll to the bottom.

Operation Steps

2. Technical Overview
Label code stacking has the same recognition principle as label code sorting, with the difference being in the placement method:
Camera Calibration and Coordinate Mapping: Use calibrated camera intrinsics for automatic distortion correction, and map pixel coordinates to real-world coordinates via the six-point calibration homography matrix
AprilTag Detection: Recognize TAG36H11 format label codes on blocks, obtaining IDs and positions
Sorting Planning: Determine the grab order based on ID numbers
Stacking Placement: Unlike sorting, each block is stacked at the same position (green area) with increasing height per layer, achieving vertical stacking
3. Core Code Analysis
Import header files
ximport cv2 as cvimport threadingimport timeimport ipywidgets as widgetsfrom IPython.display import display
from apriltag_identify import ApriltagIdentifyfrom apriltag_grasp import Apriltag_Graspfrom dofbot_utils.fps import FPSCreate instances and initialize parameters
xxxxxxxxxxapriltag_Identify = ApriltagIdentify()target = Apriltag_Grasp()num = 0xy = [90, 120]msg = {}debug_pos = Falsemodel = "General"Main program
xxxxxxxxxxdef camera(): global model, msg, debug_pos, output from dofbot_utils.camera import create_camera capture = create_camera() while capture.isOpened(): try: _, img = capture.read() fps.update_fps() cv.putText(img, f"mode:{model}", (10, 60), cv.FONT_HERSHEY_SIMPLEX, 0.8, (0, 255, 0), 2) if model == 'Detection' or model == 'Grap': img, raw_pos = apriltag_Identify.getApriltagPosition(img) msg = {k: (v[0], v[1], 0) for k, v in raw_pos.items()} if debug_pos: debug_pos = False print("detect msg:", msg) if model == 'Grap': if len(msg) != 0: print("grasp msg:", msg) threading.Thread(target=target.target_stacking, args=(msg, xy)).start() msg = {} model = 'Detection' if model == 'Exit': capture.release() break fps.show_fps(img) imgbox.value = cv.imencode('.jpg', img)[1].tobytes() except Exception as e: print("program end") print(e) capture.release()Startup
display(controls_box,output)threading.Thread(target=camera, ).start()