Update app.py
Browse files
app.py
CHANGED
|
@@ -4,6 +4,7 @@ import numpy as np
|
|
| 4 |
import matplotlib.pyplot as plt
|
| 5 |
import tempfile
|
| 6 |
import gradio as gr
|
|
|
|
| 7 |
|
| 8 |
# Setup PyBullet
|
| 9 |
p.connect(p.DIRECT)
|
|
@@ -12,6 +13,9 @@ p.setGravity(0, 0, -9.8)
|
|
| 12 |
p.loadURDF("plane.urdf")
|
| 13 |
robot = p.loadURDF("franka_panda/panda.urdf", basePosition=[0, 0, 0], useFixedBase=True)
|
| 14 |
|
|
|
|
|
|
|
|
|
|
| 15 |
# Get joint indices
|
| 16 |
def get_panda_joints(robot):
|
| 17 |
arm, fingers = [], []
|
|
@@ -77,6 +81,32 @@ def render_sim(joint_values, gripper_val):
|
|
| 77 |
joint_text += f"\nGripper = {gripper_val:.3f} m"
|
| 78 |
return tmp.name, joint_text
|
| 79 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
# Load gripper type (placeholder logic)
|
| 81 |
def switch_gripper(gripper_type):
|
| 82 |
print(f"Switching to gripper: {gripper_type}")
|
|
@@ -121,4 +151,7 @@ with gr.Blocks(title="Franka Arm Control with 7 DoF and Gripper Options") as dem
|
|
| 121 |
|
| 122 |
gr.Button("🔄 Reset Robot").click(fn=reset, inputs=[], outputs=[img_output, text_output])
|
| 123 |
|
|
|
|
|
|
|
|
|
|
| 124 |
demo.launch(debug=True)
|
|
|
|
| 4 |
import matplotlib.pyplot as plt
|
| 5 |
import tempfile
|
| 6 |
import gradio as gr
|
| 7 |
+
import time
|
| 8 |
|
| 9 |
# Setup PyBullet
|
| 10 |
p.connect(p.DIRECT)
|
|
|
|
| 13 |
p.loadURDF("plane.urdf")
|
| 14 |
robot = p.loadURDF("franka_panda/panda.urdf", basePosition=[0, 0, 0], useFixedBase=True)
|
| 15 |
|
| 16 |
+
# Add a cube to pick
|
| 17 |
+
cube_id = p.loadURDF("cube_small.urdf", basePosition=[0.6, 0, 0.02])
|
| 18 |
+
|
| 19 |
# Get joint indices
|
| 20 |
def get_panda_joints(robot):
|
| 21 |
arm, fingers = [], []
|
|
|
|
| 81 |
joint_text += f"\nGripper = {gripper_val:.3f} m"
|
| 82 |
return tmp.name, joint_text
|
| 83 |
|
| 84 |
+
# Pick and place motion
|
| 85 |
+
def pick_and_place():
|
| 86 |
+
pre_grasp = [0, -0.5, 0, -2.0, 0, 1.5, 0.8]
|
| 87 |
+
grasp = [0, -0.5, 0, -2.1, 0, 1.7, 0.8]
|
| 88 |
+
lift = [0, -0.3, 0, -1.5, 0, 1.3, 0.6]
|
| 89 |
+
place = [0.5, -0.4, 0.2, -1.8, 0, 1.4, 0.6]
|
| 90 |
+
|
| 91 |
+
sequence = [
|
| 92 |
+
(pre_grasp, 0.04),
|
| 93 |
+
(grasp, 0.0), # Close gripper
|
| 94 |
+
(lift, 0.0),
|
| 95 |
+
(place, 0.0),
|
| 96 |
+
(place, 0.04) # Open gripper
|
| 97 |
+
]
|
| 98 |
+
|
| 99 |
+
for joints, grip in sequence:
|
| 100 |
+
for _ in range(50):
|
| 101 |
+
for idx, val in zip(arm_joints, joints):
|
| 102 |
+
p.setJointMotorControl2(robot, idx, p.POSITION_CONTROL, targetPosition=val)
|
| 103 |
+
for fj in finger_joints:
|
| 104 |
+
p.setJointMotorControl2(robot, fj, p.POSITION_CONTROL, targetPosition=grip)
|
| 105 |
+
p.stepSimulation()
|
| 106 |
+
time.sleep(0.01)
|
| 107 |
+
|
| 108 |
+
return render_sim(sequence[-1][0], sequence[-1][1])
|
| 109 |
+
|
| 110 |
# Load gripper type (placeholder logic)
|
| 111 |
def switch_gripper(gripper_type):
|
| 112 |
print(f"Switching to gripper: {gripper_type}")
|
|
|
|
| 151 |
|
| 152 |
gr.Button("🔄 Reset Robot").click(fn=reset, inputs=[], outputs=[img_output, text_output])
|
| 153 |
|
| 154 |
+
# Pick and Place Button
|
| 155 |
+
gr.Button("🤖 Pick and Place").click(fn=pick_and_place, inputs=[], outputs=[img_output, text_output])
|
| 156 |
+
|
| 157 |
demo.launch(debug=True)
|