Update app.py
Browse files
app.py
CHANGED
|
@@ -18,8 +18,11 @@ def get_panda_joints(robot):
|
|
| 18 |
for i in range(p.getNumJoints(robot)):
|
| 19 |
info = p.getJointInfo(robot, i)
|
| 20 |
name = info[1].decode()
|
| 21 |
-
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
| 23 |
return arm, fingers
|
| 24 |
|
| 25 |
arm_joints, finger_joints = get_panda_joints(robot)
|
|
@@ -43,8 +46,12 @@ def render_sim(joint_values, gripper_val):
|
|
| 43 |
# Apply joint controls
|
| 44 |
for idx, tgt in zip(arm_joints, joint_values):
|
| 45 |
p.setJointMotorControl2(robot, idx, p.POSITION_CONTROL, targetPosition=tgt)
|
| 46 |
-
|
| 47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
for _ in range(10): p.stepSimulation()
|
| 49 |
|
| 50 |
# Refresh joint labels
|
|
@@ -73,8 +80,6 @@ def render_sim(joint_values, gripper_val):
|
|
| 73 |
# Load gripper type (placeholder logic)
|
| 74 |
def switch_gripper(gripper_type):
|
| 75 |
print(f"Switching to gripper: {gripper_type}")
|
| 76 |
-
# In real case, remove current gripper, attach new one
|
| 77 |
-
# For demo, just return something to show
|
| 78 |
return f"Switched to: {gripper_type}"
|
| 79 |
|
| 80 |
# Gradio UI
|
|
@@ -117,5 +122,3 @@ with gr.Blocks(title="Franka Arm Control with 7 DoF and Gripper Options") as dem
|
|
| 117 |
gr.Button("🔄 Reset Robot").click(fn=reset, inputs=[], outputs=[img_output, text_output])
|
| 118 |
|
| 119 |
demo.launch(debug=True)
|
| 120 |
-
|
| 121 |
-
|
|
|
|
| 18 |
for i in range(p.getNumJoints(robot)):
|
| 19 |
info = p.getJointInfo(robot, i)
|
| 20 |
name = info[1].decode()
|
| 21 |
+
joint_type = info[2]
|
| 22 |
+
if "finger" in name and joint_type == p.JOINT_PRISMATIC:
|
| 23 |
+
fingers.append(i)
|
| 24 |
+
elif joint_type == p.JOINT_REVOLUTE:
|
| 25 |
+
arm.append(i)
|
| 26 |
return arm, fingers
|
| 27 |
|
| 28 |
arm_joints, finger_joints = get_panda_joints(robot)
|
|
|
|
| 46 |
# Apply joint controls
|
| 47 |
for idx, tgt in zip(arm_joints, joint_values):
|
| 48 |
p.setJointMotorControl2(robot, idx, p.POSITION_CONTROL, targetPosition=tgt)
|
| 49 |
+
|
| 50 |
+
# Open/close gripper symmetrically
|
| 51 |
+
if len(finger_joints) == 2:
|
| 52 |
+
p.setJointMotorControl2(robot, finger_joints[0], p.POSITION_CONTROL, targetPosition=gripper_val)
|
| 53 |
+
p.setJointMotorControl2(robot, finger_joints[1], p.POSITION_CONTROL, targetPosition=gripper_val)
|
| 54 |
+
|
| 55 |
for _ in range(10): p.stepSimulation()
|
| 56 |
|
| 57 |
# Refresh joint labels
|
|
|
|
| 80 |
# Load gripper type (placeholder logic)
|
| 81 |
def switch_gripper(gripper_type):
|
| 82 |
print(f"Switching to gripper: {gripper_type}")
|
|
|
|
|
|
|
| 83 |
return f"Switched to: {gripper_type}"
|
| 84 |
|
| 85 |
# Gradio UI
|
|
|
|
| 122 |
gr.Button("🔄 Reset Robot").click(fn=reset, inputs=[], outputs=[img_output, text_output])
|
| 123 |
|
| 124 |
demo.launch(debug=True)
|
|
|
|
|
|