Welcome to DOFBOT Pro repository
10. Porter
Porter
1. Introduction
This experiment aims to stack four different colored blocks in the order of blue, green, red, and yellow from bottom to top, then place them on the central cross block. After running the code, the robotic arm will execute in sequence: grab the fourth layer block and place it in the yellow area, grab the third layer block and place it in the red area, grab the second layer block and place it in the green area, and grab the bottom layer block and place it in the blue area.
The block arrangement method is shown in the following figure:

After executing the code, the robotic arm will move the blocks to corresponding positions. The final effect is shown in the following figure:

2. Code Content
Code path:
~/dofbot_pro/dofbot_ctrl/scripts/10.move_block.ipynb
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()xxxxxxxxxx# 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)xxxxxxxxxx# 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_BLUEp_layer_4 = robot.P_CENTER_4p_layer_3 = robot.P_CENTER_3p_layer_2 = robot.P_CENTER_2p_layer_1 = robot.P_CENTERxxxxxxxxxx# Move the robotic arm to a ready-to-grab positionarm_clamp_block(0)arm_move(p_mould, 1000)time.sleep(1)xxxxxxxxxx# Move the fourth layer block to the yellow areaarm_move(p_top, 1000)arm_move(p_layer_4, 1000)arm_clamp_block(1)arm_move(p_top, 1000)arm_move(p_Yellow, 1000)arm_clamp_block(0)time.sleep(.1)arm_move_up()arm_move(p_mould, 1100)xxxxxxxxxx# Move the third layer block to the red areaarm_move(p_top, 1000)arm_move(p_layer_3, 1000)arm_clamp_block(1)arm_move(p_top, 1000)arm_move(p_Red, 1000)arm_clamp_block(0)time.sleep(.1)arm_move_up()arm_move(p_mould, 1100)xxxxxxxxxx# Move the second layer block to the green areaarm_move(p_top, 1000)arm_move(p_layer_2, 1000)arm_clamp_block(1)arm_move(p_top, 1000)arm_move(p_Green, 1000)arm_clamp_block(0)time.sleep(.1)arm_move_up()arm_move(p_mould, 1100)xxxxxxxxxx# Move the first layer block to the blue areaarm_move(p_top, 1000)arm_move(p_layer_1, 1000)arm_clamp_block(1)arm_move(p_top, 1000)arm_move(p_Blue, 1000)arm_clamp_block(0)time.sleep(.1)arm_move_up()arm_move(p_mould, 1100)xxxxxxxxxxdel Arm # Release the Arm object
Open the program file in jupyter lab and click the "Run entire notebook" button on the jupyter lab toolbar to see the robotic arm's nature porter function effect.
