-
Notifications
You must be signed in to change notification settings - Fork 0
/
objectMover.py
78 lines (65 loc) · 2.12 KB
/
objectMover.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env python3
#coding=utf-8
import time
from Arm_Lib import Arm_Device
# Initialize DOFBOT
Arm = Arm_Device()
time.sleep(0.1)
# Control the clamp (servo 6)
def arm_clamp_block(enable):
if enable == 0: # Release
Arm.Arm_serial_servo_write(6, 60, 400)
else: # Clamp
Arm.Arm_serial_servo_write(6, 130, 400)
time.sleep(0.5)
# Move the arm to specified positions
def arm_move(p, s_time=500):
for i in range(5):
id = i + 1
if id == 5:
time.sleep(0.1)
Arm.Arm_serial_servo_write(id, p[i], int(s_time * 1.2))
elif id == 1:
Arm.Arm_serial_servo_write(id, p[i], int(3 * s_time / 4))
else:
Arm.Arm_serial_servo_write(id, p[i], int(s_time))
time.sleep(0.01)
time.sleep(s_time / 1000)
# Positions for different actions
p_front = [90, 60, 50, 50, 90] # Front position
p_right = [0, 60, 50, 50, 90] # Right position
p_left = [180, 60, 50, 50, 90] # Left position
p_top = [90, 80, 50, 50, 90] # Top (transition) position
p_rest = [90, 130, 0, 0, 90] # Rest position
def move_object(target):
"""
Move an object from the front to the specified target side.
Parameters:
target (str): 'left' or 'right' indicating the movement direction.
"""
if target not in ['left', 'right']:
print("Invalid target! Use 'left' or 'right'.")
return
# Move to front position to pick object
arm_clamp_block(0) # Open clamp
arm_move(p_front, 1000) # Move to front position
arm_clamp_block(1) # Clamp object
# Transition to top position
arm_move(p_top, 1000)
# Move to target position
if target == 'left':
arm_move(p_left, 1000)
elif target == 'right':
arm_move(p_right, 1000)
# Release object
arm_clamp_block(0)
# Return to rest position
arm_move(p_top, 1000)
arm_move(p_rest, 1000)
# User input for selecting target side
while True:
target = input("Enter target position ('left' or 'right', or 'exit' to quit): ").strip().lower()
if target == 'exit':
break
move_object(target)
del Arm # Release DOFBOT object