YashsharmaPhD commited on
Commit
f5d6cbd
·
verified ·
1 Parent(s): 718d79d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -0
app.py CHANGED
@@ -81,6 +81,29 @@ def render_sim(joint_values, gripper_val):
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]
@@ -154,4 +177,9 @@ with gr.Blocks(title="Franka Arm Control with 7 DoF and Gripper Options") as dem
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)
 
81
  joint_text += f"\nGripper = {gripper_val:.3f} m"
82
  return tmp.name, joint_text
83
 
84
+ # Smooth motion to input angles
85
+ def move_to_input_angles(joint_str):
86
+ try:
87
+ target_angles = [float(x.strip()) for x in joint_str.split(",")]
88
+ if len(target_angles) != 7:
89
+ return None, "❌ Please enter exactly 7 joint angles."
90
+
91
+ # Get current joint positions
92
+ current = [p.getJointState(robot, idx)[0] for idx in arm_joints]
93
+ steps = 100
94
+ for i in range(steps):
95
+ blend = [(1 - i/steps) * c + (i/steps) * t for c, t in zip(current, target_angles)]
96
+ for idx, val in zip(arm_joints, blend):
97
+ p.setJointMotorControl2(robot, idx, p.POSITION_CONTROL, targetPosition=val)
98
+ p.stepSimulation()
99
+ time.sleep(0.01)
100
+
101
+ current_grip = p.getJointState(robot, finger_joints[0])[0]
102
+ return render_sim(target_angles, current_grip)
103
+
104
+ except Exception as e:
105
+ return None, f"Error: {str(e)}"
106
+
107
  # Pick and place motion
108
  def pick_and_place():
109
  pre_grasp = [0, -0.5, 0, -2.0, 0, 1.5, 0.8]
 
177
  # Pick and Place Button
178
  gr.Button("🤖 Pick and Place").click(fn=pick_and_place, inputs=[], outputs=[img_output, text_output])
179
 
180
+ # Joint angle input box
181
+ gr.Markdown("### 🧾 Enter Joint Angles (comma-separated)")
182
+ joint_input = gr.Textbox(label="Joint Angles (7 values in radians)", placeholder="e.g. 0.0, -0.5, 0.3, -1.2, 0.0, 1.5, 0.8")
183
+ gr.Button("▶️ Move to Angles").click(fn=move_to_input_angles, inputs=joint_input, outputs=[img_output, text_output])
184
+
185
  demo.launch(debug=True)