Welcome to DOFBOT SE repository
9.Voice Control Stacking
Voice Control Stacking
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
Through voice commands, specify the color of the block to grab. The robotic arm will grab the corresponding color block and stack them layer by layer.
2. Startup and Operation
2.1 Startup
Open the terminal and enter the following command to start:
xxxxxxxxxxpython3 ~/dofbot_voice/scripts/voice_control_stack.py
2.2 Operation Steps
After the program runs successfully, place the blocks in positions: yellow area for yellow blocks, red area for red blocks, green area for green blocks, blue area for blue blocks, as shown in the figure below. Unlike previous stacking cases, this case allows you to specify the order of stacking.

2.2.1 Stacking
Say "Hi, yahboom" to the voice module. The voice module replies "I'm here" indicating successful wake-up. Then say "Stack the yellow block"/"Stack the red block"/"Stack the green block"/"Stack the blue block", the voice module will broadcast "ok". The robotic arm will go to the corresponding color block area, grab the block, and place it in the set area. The voice module will broadcast "Placement complete". Each time you use a voice command to grab the target color block and place it, and finally complete the stacking.
2.2.2 Pushing Down
Say "Hi, yahboom" to the voice module. The voice module replies "I'm here" indicating successful wake-up. Then say "Push down", the voice module will broadcast "ok". Then the robotic arm will execute the action to push down the stacked blocks.
3. Core Code Analysis
Jetson-Nano users need to enter the docker container to view.
`Source code path: ~/dofbot_voice/scripts/voice_control_stack.py
x while True: # Get voice recognition result res = mySpeech.speech_read() time.sleep(0.01) # Grab yellow block if res == 77: if yellow_grabbed == 0: mySpeech.void_write(77) Arm.Arm_Buzzer_On(1) time.sleep(.1) start_move_arm(1) time.sleep(1) # global yellow_grabbed yellow_grabbed = 1 # Grab red block elif res == 78: if red_grabbed == 0: mySpeech.void_write(77) Arm.Arm_Buzzer_On(1) time.sleep(.1) start_move_arm(2) # global red_grabbed red_grabbed = 1 # Grab green block elif res == 79: if green_grabbed == 0: mySpeech.void_write(77) Arm.Arm_Buzzer_On(1) time.sleep(.1) start_move_arm(3) # global green_grabbed green_grabbed = 1 # Grab blue block elif res == 80: if blue_grabbed == 0: mySpeech.void_write(77) Arm.Arm_Buzzer_On(1) time.sleep(.1) start_move_arm(4) # global blue_grabbed blue_grabbed = 1 elif res == 82: # Push down mySpeech.void_write(82) Arm.Arm_Buzzer_On(1) time.sleep(.1) start_move_arm(5) yellow_grabbed = 0 red_grabbed = 0 green_grabbed = 0 blue_grabbed = 0 # Number function definitiondef number_action(index): if index == 1: # Grab yellow block arm_move(p_top, 1000) arm_move(p_Yellow, 1000) arm_clamp_block(1) Arm.Arm_serial_servo_write(2, 90, 1000) time.sleep(1) arm_move(p_top, 1000) elif index == 2: # Grab red block arm_move(p_top, 1000) arm_move(p_Red, 1000) arm_clamp_block(1) Arm.Arm_serial_servo_write(2, 90, 1000) time.sleep(1) arm_move(p_top, 1000) elif index == 3: # Grab green block arm_move(p_top, 1000) arm_move(p_Green, 1000) arm_clamp_block(1) Arm.Arm_serial_servo_write(2, 90, 1000) time.sleep(1) arm_move(p_top, 1000) elif index == 4: # Grab blue block arm_move(p_top, 1000) arm_move(p_Blue, 1000) arm_clamp_block(1) Arm.Arm_serial_servo_write(2, 90, 1000) time.sleep(1) arm_move(p_top, 1000)# Place stacked blocks, layer indicates which layer to place ondef put_down_block(layer): if layer == 1: arm_move(p_layer_1, 1000) arm_clamp_block(0) arm_move_6(look_at, 1000) elif layer == 2: arm_move(p_layer_2, 1000) arm_clamp_block(0) arm_move_6(look_at, 1000) elif layer == 3: arm_move(p_layer_3, 1000) arm_clamp_block(0) arm_move_6(look_at, 1000) elif layer == 4: arm_move(p_layer_4, 1000) time.sleep(.1) arm_clamp_block(0) arm_move_6(look_at, 1000) # Voice broadcast, placement complete mySpeech.void_write(81)