Welcome to DOFBOT Pro repository
6.Color Recognition and Grasping with Voice Broadcast
Color Recognition and Grasping with Voice Broadcast
Before running the function, you need to close the App and large programs. For the closing method, refer to [4.Preparation] - [1. Manage APP control services].
Orin board users can directly open the terminal and enter the tutorial commands to run. Jetson-Nano board users need to enter the docker container first, then enter the tutorial commands in the docker to start the program.
1. Function Description
The voice module broadcasts the recognized block color, and the robotic arm grabs the corresponding color block and places it in the set position.
2. Startup and Operation
2.1. Startup
Open the terminal and enter the following command to start:
python3 ~/dofbot_voice/scripts/color_grab_broadcast.py2.2. Operation Steps
After the program runs successfully, hold a color block and place the green square in the image on the color block, as shown in the figure below:

The program will recognize the block color, the voice module will broadcast the recognized block color, and after the buzzer beeps once, it will grab a block of the same color and place it in the center area. Finally, the voice module will broadcast "Placement complete".
3. Core Code Analysis
Jetson-Nano users need to enter the docker container to view
Source code path: ~/dofbot_voice/scripts/color_grab_broadcast.py
x#Call get_color to recognize the current color block colorframe, color_name = get_color(frame)#According to the recognized color block color, pass the corresponding parameters to the start_move_arm function. This function will pass the recognized color block color,if len(color_name)==1: if color_name['name'] == 'yellow': start_move_arm(1) elif color_name['name'] == 'red': start_move_arm(2) elif color_name['name'] == 'green': start_move_arm(3) elif color_name['name'] == 'blue': start_move_arm(4)#Number function definitiondef number_action(index): if index == 1: # Grab yellow building block arm_move(p_top, 1000) arm_move(p_Yellow, 1500) elif index == 2: # Grab red building block arm_move(p_top, 1000) arm_move(p_Red, 1500) elif index == 3: # Grab green building block arm_move(p_top, 1000) arm_move(p_Green, 1500) elif index == 4: # Grab blue building block arm_move(p_top, 1000) arm_move(p_Blue, 1500) arm_clamp_block(1) arm_move(p_top, 1500)def ctrl_arm_move(index): arm_clamp_block(0) if index == 1: print("Yellow") mySpeech.void_write(66) time.sleep(0.1) Arm.Arm_Buzzer_On(1) time.sleep(.5) number_action(index) put_down_block() mySpeech.void_write(65) time.sleep(0.1) elif index == 2: print("Red") mySpeech.void_write(69) time.sleep(0.1) Arm.Arm_Buzzer_On(1) time.sleep(.5) number_action(index) put_down_block() mySpeech.void_write(65) time.sleep(0.1) elif index == 3: print("Green") mySpeech.void_write(67) time.sleep(0.1) Arm.Arm_Buzzer_On(1) time.sleep(.5) number_action(index) put_down_block() mySpeech.void_write(65) time.sleep(0.1) elif index == 4: print("Blue") mySpeech.void_write(67) time.sleep(0.1) Arm.Arm_Buzzer_On(1) time.sleep(.5) number_action(index) put_down_block() mySpeech.void_write(65) time.sleep(0.1)