Welcome to DOFBOT-Pi repository
9.DOFBOT grab block
Robotic Arm Grab Block
I. Gameplay Introduction
The purpose of this experiment is to move building blocks from the middle gray area to the surrounding colored block areas. First, put the yellow block into the gray area, then run the code units sequentially up to the sixth unit (grab a block from the gray block position and place it at the yellow block position). At this time, the robotic arm will automatically grab the block placed in the gray area, then place it in the yellow area, and then return to the preparation position. Before running the seventh code unit, you need to put the red block into the gray area, then run the seventh unit (grab a block from the gray block position and place it at the red block position). This way, the red block will also be grabbed to the red area. The operation method for other blocks is the same.

II. Start Docker
After entering the main board desktop, open a terminal and run the following command to start the corresponding Dofbot container:
xxxxxxxxxx./Docker_Ros.sh
Then enter the following command in the Docker terminal to start jupyter-lab,
xxxxxxxxxxcdjupyter-lab --allow-root
Then enter the main board's IP address followed by :9999 in the browser,
xxxxxxxxxxIP:9999 // Example: 192.168.1.11:9999
III. Code Content
Code path: /root/Dofbot/3.ctrl_Arm/9.clamp_block.ipynb
The following code content needs to be executed step by step according to each step, cannot run all at once. Before grabbing building blocks, you need to put the building blocks in the middle gray block position, and only one block can be placed at a time.
xxxxxxxxxx#!/usr/bin/env python3#coding=utf-8import timefrom Arm_Lib import Arm_Device# Create robotic arm objectArm = Arm_Device()time.sleep(.1)xxxxxxxxxx# Define block clamping function, enable=1: clamp, =0: releasedef arm_clamp_block(enable): if enable == 0: Arm.Arm_serial_servo_write(6, 60, 400) else: Arm.Arm_serial_servo_write(6, 130, 400) time.sleep(.5)# Define robotic arm movement function, simultaneously control 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)xxxxxxxxxx# Define variable parameters for different positionsp_mould = [90, 130, 0, 0, 90]p_top = [90, 80, 50, 50, 270]p_Brown = [90, 53, 33, 36, 270]p_Yellow = [65, 22, 64, 56, 270]p_Red = [117, 19, 66, 56, 270]p_Green = [136, 66, 20, 29, 270]p_Blue = [44, 66, 20, 28, 270]xxxxxxxxxx# Move the robotic arm to a preparation position for grabbingarm_clamp_block(0)arm_move(p_mould, 1000)time.sleep(1)xxxxxxxxxx# Grab a block from the gray block position 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)xxxxxxxxxx# Grab a block from the gray block position 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)xxxxxxxxxx# Grab a block from the gray block position 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)xxxxxxxxxx# Grab a block from the gray block position 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)xxxxxxxxxxdel Arm # Release the Arm object