Update app.py
Browse files
app.py
CHANGED
|
@@ -91,27 +91,41 @@ def pick_and_place(position_str, approach_str, place_str, cam_xyz, target_xyz):
|
|
| 91 |
if len(position_angles) != 7 or len(approach_angles) != 7 or len(place_angles) != 7:
|
| 92 |
return None, "❌ All inputs must have 7 joint angles."
|
| 93 |
|
|
|
|
| 94 |
move_to_input_angles(approach_str, cam_xyz, target_xyz)
|
| 95 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
for _ in range(30):
|
| 97 |
for fj in finger_joints:
|
| 98 |
-
p.setJointMotorControl2(robot, fj, p.POSITION_CONTROL, targetPosition=0.0)
|
| 99 |
p.stepSimulation()
|
| 100 |
time.sleep(0.01)
|
| 101 |
|
| 102 |
-
|
| 103 |
-
for
|
| 104 |
-
|
| 105 |
-
for
|
|
|
|
| 106 |
p.setJointMotorControl2(robot, idx, p.POSITION_CONTROL, targetPosition=val)
|
| 107 |
p.stepSimulation()
|
| 108 |
time.sleep(0.01)
|
| 109 |
|
|
|
|
| 110 |
move_to_input_angles(place_str, cam_xyz, target_xyz)
|
| 111 |
|
|
|
|
| 112 |
for _ in range(30):
|
| 113 |
for fj in finger_joints:
|
| 114 |
-
p.setJointMotorControl2(robot, fj, p.POSITION_CONTROL, targetPosition=0.04)
|
| 115 |
p.stepSimulation()
|
| 116 |
time.sleep(0.01)
|
| 117 |
|
|
@@ -119,6 +133,7 @@ def pick_and_place(position_str, approach_str, place_str, cam_xyz, target_xyz):
|
|
| 119 |
except Exception as e:
|
| 120 |
return None, f"Error: {str(e)}"
|
| 121 |
|
|
|
|
| 122 |
# Copy current joint angles
|
| 123 |
def copy_current_joint_angles(*vals):
|
| 124 |
return ", ".join([f"{v:.4f}" for v in vals])
|
|
|
|
| 91 |
if len(position_angles) != 7 or len(approach_angles) != 7 or len(place_angles) != 7:
|
| 92 |
return None, "❌ All inputs must have 7 joint angles."
|
| 93 |
|
| 94 |
+
# Move to pre-grasp approach pose
|
| 95 |
move_to_input_angles(approach_str, cam_xyz, target_xyz)
|
| 96 |
|
| 97 |
+
# Grasping: move to actual grasp pose (over the object)
|
| 98 |
+
steps = 50
|
| 99 |
+
for i in range(steps):
|
| 100 |
+
interpolated = [(1 - i/steps) * approach_angles[j] + (i/steps) * position_angles[j] for j in range(7)]
|
| 101 |
+
for idx, val in zip(arm_joints, interpolated):
|
| 102 |
+
p.setJointMotorControl2(robot, idx, p.POSITION_CONTROL, targetPosition=val)
|
| 103 |
+
p.stepSimulation()
|
| 104 |
+
time.sleep(0.01)
|
| 105 |
+
|
| 106 |
+
# Close the gripper to grasp
|
| 107 |
for _ in range(30):
|
| 108 |
for fj in finger_joints:
|
| 109 |
+
p.setJointMotorControl2(robot, fj, p.POSITION_CONTROL, targetPosition=0.0) # Closed
|
| 110 |
p.stepSimulation()
|
| 111 |
time.sleep(0.01)
|
| 112 |
|
| 113 |
+
# Lift object slightly from grasp position
|
| 114 |
+
lifted_angles = [a + 0.1 for a in position_angles] # Add a small lift to each joint
|
| 115 |
+
for i in range(steps):
|
| 116 |
+
lifted_pose = [(1 - i/steps) * position_angles[j] + (i/steps) * lifted_angles[j] for j in range(7)]
|
| 117 |
+
for idx, val in zip(arm_joints, lifted_pose):
|
| 118 |
p.setJointMotorControl2(robot, idx, p.POSITION_CONTROL, targetPosition=val)
|
| 119 |
p.stepSimulation()
|
| 120 |
time.sleep(0.01)
|
| 121 |
|
| 122 |
+
# Move to place location
|
| 123 |
move_to_input_angles(place_str, cam_xyz, target_xyz)
|
| 124 |
|
| 125 |
+
# Release the gripper
|
| 126 |
for _ in range(30):
|
| 127 |
for fj in finger_joints:
|
| 128 |
+
p.setJointMotorControl2(robot, fj, p.POSITION_CONTROL, targetPosition=0.04) # Open
|
| 129 |
p.stepSimulation()
|
| 130 |
time.sleep(0.01)
|
| 131 |
|
|
|
|
| 133 |
except Exception as e:
|
| 134 |
return None, f"Error: {str(e)}"
|
| 135 |
|
| 136 |
+
|
| 137 |
# Copy current joint angles
|
| 138 |
def copy_current_joint_angles(*vals):
|
| 139 |
return ", ".join([f"{v:.4f}" for v in vals])
|