-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathharvest.py
executable file
·131 lines (76 loc) · 3.55 KB
/
harvest.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
from interbotix_xs_modules.arm import InterbotixManipulatorXS
import rospy
from time import sleep
from config import GRIPPER_JOINT_OPEN, GRIPPER_JOINT_CLOSE, TARGETS
from utilities import Utils
from base_control.agv_control import BaseMove
from transform_co import Detection
class Harvest:
def __init__(self, robot_name='puppet_left'):
self.bot = InterbotixManipulatorXS("vx300s", "arm", "gripper", robot_name=robot_name, moving_time=4)
self.base_robot = BaseMove()
self.detect_obj_pose = Detection(self.bot)
self.moving_time = 3
self.place_trajectory = [
{0.0: [0.010737866163253784, -1.3867186307907104, 0.7853981852531433, 0.03681553900241852, 0.6412039995193481, -0.02761165425181389]},
{2.0: [0.010737866163253784, -1.3867186307907104, 0.7853981852531433, 0.03681553900241852, 0.6412039995193481, -0.02761165425181389]},
{4.0: [-0.45712628960609436, -1.1090681552886963, 0.08897088468074799, 0.5537670850753784, 0.9464661478996277, -0.1426602154970169]},
{6.0: [-0.9480001330375671, -1.026233196258545, -0.5322913527488708, 1.8008935451507568, 1.3253594636917114, 0.06902913749217987]}
]
def opening_ceremony(self , bot):
bot.dxl.robot_reboot_motors("single", "gripper", True)
bot.dxl.robot_set_operating_modes("group", "arm", "position")
bot.dxl.robot_set_operating_modes("single", "gripper", "current_based_position")
Utils.torque_on(bot)
def execute_trajectory(self, trajectory):
self.bot.dxl.robot_write_trajectory('group', 'arm', 'position', trajectory)
def place_in_basket(self):
rospy.sleep(1)
self.execute_trajectory(self.place_trajectory)
sleep(9)
self.bot.gripper.open()
def move_backward(self):
self.base_robot.backward()
def move_forward(self):
self.base_robot.forward()
def set_end_effector_pose(self, x, y, z, moving_time):
self.bot.arm.set_ee_pose_components(x=x, y=y, z=z, moving_time=moving_time)
def move_to_start(self):
self.base_robot.move_to_start()
def operation(self, cucu_id):
target = TARGETS.get(cucu_id, None)
if target is None:
rospy.logerr(f"Target {cucu_id} not found!")
return
initial_pose = target['initial_pose']
self.set_end_effector_pose(initial_pose['x'], initial_pose['y'], initial_pose['z'], self.moving_time)
Utils.gripper_posiition("open")
object_pose = self.detect_obj_pose.object_pose()
offset = [0.1, 0, 0.1]
new_pose = Utils.cal_offset(object_pose, offset)
if not Utils.check_tolerance(new_pose, target['position'].values()):
new_pose = target['position']
self.set_end_effector_pose(*new_pose, self.moving_time)
rospy.sleep(1)
Utils.gripper_position('close')
Utils.standard_pose()
self.place_in_basket()
def perform_task(self):
self.operation('cucu1')
self.move_forward()
self.operation('cucu2')
self.operation('cucu3')
self.move_forward()
self.operation('cucu4')
self.operation('cucu5')
self.move_forward()
self.operation('cucu6')
self.operation('cucu7')
self.move_forward()
self.operation('cucu8')
self.move_forward()
self.operation('cucu9')
self.move_to_start()
if __name__ == "__main__":
task = Harvest()
task.perform_task()