Welcome to DOFBOT-Ultra repository
9. DOFBOT Grab Blocks
DOFBOT Grab Blocks
For all functions involving grabbing square blocks, please use 30x30x30 mm wooden blocks. Non-standard sized objects may cause servo 6 to stall and become damaged.
1. Overview
The purpose of this experiment is to move blocks from the center cross area to the four colored square areas around it. First, place the yellow block in the cross area, then run the code cells sequentially up to the sixth cell (grab a block from the cross position and place it at the yellow block position). The robotic arm will automatically grab the block from the cross area, place it into the yellow area, and return to the ready position. Before running the seventh code cell, place the red block in the cross area, then run the seventh cell (grab a block from the cross position and place it at the red block position). The red block will then be grabbed to the red area. The same operation applies to the other blocks.

2. Code
Code path:
xxxxxxxxxx~/dofbot_ctrl/scripts/09.clamp_block.ipynb
The following code must be executed step by step, not all at once. Before grabbing a block, place it at the center cross position, and only place one block at a time.
x
#!/usr/bin/env python3#coding=utf-8import timefrom Arm_Lib import Arm_Device# Create robotic arm objectArm = Arm_Device()time.sleep(.1)from dofbot_utils.robot_controller import Robot_Controllerrobot = Robot_Controller()x
# Define block grabbing function, enable=1: grab, =0: releasedef arm_clamp_block(enable): if enable == 0: Arm.Arm_serial_servo_write(6, 60, 400) else: Arm.Arm_serial_servo_write(6, 135, 400) time.sleep(.5) # Define robotic arm movement function, simultaneously controls servos 1-5 movement, p=[S1,S2,S3,S4,S5]def arm_move(p, s_time = 500): for i in range(5): id = i + 1 if id == 5: time.sleep(.1) Arm.Arm_serial_servo_write(id, p[i], int(s_time*1.2)) else : Arm.Arm_serial_servo_write(id, p[i], s_time) time.sleep(.01) time.sleep(s_time/1000)# Robotic arm moves upwarddef arm_move_up(): Arm.Arm_serial_servo_write(2, 90, 1500) Arm.Arm_serial_servo_write(3, 90, 1500) Arm.Arm_serial_servo_write(4, 90, 1500) time.sleep(.1)x
# Define variable parameters for different positionsp_mould = robot.P_LOOK_ATp_top = robot.P_TOPp_Brown = robot.P_CENTERp_Yellow = robot.P_YELLOWp_Red = robot.P_REDp_Green = robot.P_GREENp_Blue = robot.P_BLUEx
# Move the robotic arm to a ready-to-grab positionarm_clamp_block(0)arm_move(p_mould, 1000)time.sleep(1)x
# Grab a block from the center recognition area and place it at the yellow block position.arm_move(p_top, 1000)arm_move(p_Brown, 1000)arm_clamp_block(1)arm_move(p_top, 1000)arm_move(p_Yellow, 1000)arm_clamp_block(0)arm_move(p_mould, 1000)time.sleep(1)x
# Grab a block from the center recognition area and place it at the red block position.arm_move(p_top, 1000)arm_move(p_Brown, 1000)arm_clamp_block(1)arm_move(p_top, 1000)arm_move(p_Red, 1000)arm_clamp_block(0)arm_move_up()arm_move(p_mould, 1100)time.sleep(1)x
# Grab a block from the center recognition area and place it at the green block position.arm_move(p_top, 1000)arm_move(p_Brown, 1000)arm_clamp_block(1)arm_move(p_top, 1000)arm_move(p_Green, 1000)arm_clamp_block(0)arm_move_up()arm_move(p_mould, 1100)time.sleep(1)x
# Grab a block from the center recognition area and place it at the blue block position.arm_move(p_top, 1000)arm_move(p_Brown, 1000)arm_clamp_block(1)arm_move(p_top, 1000)arm_move(p_Blue, 1000)arm_clamp_block(0)arm_move_up()arm_move(p_mould, 1100)time.sleep(1)x
del Arm # Release the Arm object