Welcome to JetCobot repository
3. Apriltag recognition and grabbing building blocks
Apriltag recognition and grasping blocks
1. Apriltag recognition instructions
The default format of Apriltag label code recognition is TAG36H11 format images. The relevant label codes are already provided at the factory and affixed to the building blocks.
2. Experimental placement
Place the building blocks with label codes on the cross of the recognition area.

3. Important code explanation
Code path: ~/jetcobot_ws/src/jetcobot_grasp/jetcobot_grasp/3_apriltag_recognition_grasp.py
~/jetcobot_ws/src/jetcobot_grasp/jetcobot_grasp/grasp_controller.py
Control the function of robot arm movement and grasping.
def grasp_run(self,tagId):self.graspController.goBoxCenterlayer1Pose()self.graspController.close_gripper(1.5)self.graspController.goColorOverPose()if tagId == '1':self.graspController.goApriltag1fixedPose()elif tagId == '2':self.graspController.goApriltag2fixedPose()elif tagId == '3':self.graspController.goApriltag3fixedPose()elif tagId == '4':self.graspController.goApriltag4fixedPose()else:self.graspController.init_watch_pose()self.status = 'waiting'returntime.sleep(1)self.graspController.open_gripper(1)self.graspController.rise_gripper(1)self.graspController.init_watch_pose()self.status = 'waiting'
The position coordinates of the cross in the middle of the recognition area.
xxxxxxxxxxdef goBoxCenterlayer1Pose(self):coords = [220, 0, 120, -175, 0, -45]self.go_coords(coords, 3)
The coordinate value of the location where the label code is placed. If the coordinate of the placement position is inaccurate, you can modify this coordinate value appropriately.
x# Apriltag标签位置def goApriltag1fixedPose(self, layer=1):coords = [-60, 170, 105+50*(layer-1), -175, 0, -45]self.go_coords(coords, 2)def goApriltag2fixedPose(self, layer=1):coords = [10, 170, 105+50*(layer-1), -175, 0, -45]self.go_coords(coords, 2)def goApriltag3fixedPose(self, layer=1):coords = [75, 170, 105+50*(layer-1), -175, 0, -45]self.go_coords(coords, 2)def goApriltag4fixedPose(self, layer=1):coords = [140, 170, 110+50*(layer-1), -175, 0, -45]self.go_coords(coords, 2)
4. Start the program
Start the program
Reopen a terminal and enter the following command.
xxxxxxxxxxros2 run jetcobot_grasp 3_apriltag_recognition_grasp
5. Experimental results
After the program runs, the camera will detect whether there is a tag code in the recognition area. If there is a tag code, it will grab the building block on the middle cross of the recognition area and place the ID of the corresponding building block in the corresponding area. After the placement is completed, the recognition state will be restored and the building block can be placed again. Note that if there are two building blocks with the same ID number, you need to clear the building blocks in the digital area first to avoid placement conflicts.
