Welcome to DOFBOT SE repository
6.Color Recognition and Grasping with Voice Broadcast
Color Recognition Grasping Broadcast
Note: Due to unavoidable servo mechanical errors and the influence of servo center position, if the grabbing and placing positions are not ideal, you can try recalibrating the robotic arm or modify the grabbing and placing positions according to your needs.
1. Function Description
The voice module broadcasts the recognized color of the block, and then the robotic arm grabs the block of the corresponding color and places it in the set position.

2. Startup and Operation
Open the terminal and enter the following command to start:
xxxxxxxxxxpython3 ~/dofbot_voice/scripts/color_grab_broadcast.pyOperation Steps
After the program runs successfully, hold the color block and place the block within the green rectangle in the image, as shown in the figure below:

The program will recognize the block color. After the buzzer beeps once, you need to quickly place the block in the corresponding area (if it is a blue block like in the tutorial, place it in the blue area). The voice module will broadcast the recognized block color. Go to the corresponding color area to grab the block and place it in the middle gray-black area. Finally, the voice module will broadcast "Placement complete", and the terminal will print the recognized color.

3. Core Code Analysis
Source code path: ~/dofbot_voice/scripts/color_grab_broadcast.py
x# Call get_color to recognize the current block colorframe, color_name = get_color(frame)# According to the recognized block color, pass the corresponding parameters to the start_move_arm function, which will execute based on the recognized block colorif 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 block arm_move(p_top, 1000) arm_move(p_Yellow, 1500) elif index == 2: # Grab red block arm_move(p_top, 1000) arm_move(p_Red, 1500) elif index == 3: # Grab green block arm_move(p_top, 1000) arm_move(p_Green, 1500) elif index == 4: # Grab blue 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)