Welcome to DOFBOT-Ultra repository
5. Label code sorting
Label Code Sorting
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!!!
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.
Through AprilTag label code recognition, detect multiple blocks with different IDs in the recognition area, then grab and sort them into the corresponding numbered areas sequentially according to the ID order.
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_Sorting.ipynb
Click the Run All button on the JupyterLab toolbar, then scroll to the bottom.

Operation Steps

2. Technical Overview
The core workflow of label code sorting:
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: Use the AprilTag detection library (TAG36H11 format) to recognize label codes on blocks, obtaining ID numbers and positions
Sorting Planning: Determine the grab order based on ID numbers
Arm Sorting: Grab blocks sequentially and place them into the corresponding numbered areas on the map according to ID numbers
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_sorting, 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()