YashsharmaPhD commited on
Commit
576f97f
·
verified ·
1 Parent(s): 86611cc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -10
app.py CHANGED
@@ -119,6 +119,10 @@ 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
  with gr.Blocks(title="Franka Arm with 3D Camera Control") as demo:
123
  gr.Markdown("## 🤖 Franka Robot with Camera + Joint Control")
124
 
@@ -132,25 +136,25 @@ with gr.Blocks(title="Franka Arm with 3D Camera Control") as demo:
132
  joint_sliders.append(gr.Slider(-3.14, 3.14, value=0, label=f"Joint {i+1}"))
133
  gripper = gr.Slider(0.0, 0.04, value=0.02, step=0.001, label="Gripper")
134
 
135
- # Camera and target sliders BELOW joint sliders
136
  with gr.Row():
137
- with gr.Column():
138
- gr.Markdown("**Camera Position**")
139
  cam_x = gr.Slider(-3, 3, value=1.5, label="X")
140
  cam_y = gr.Slider(-3, 3, value=0.0, label="Y")
141
  cam_z = gr.Slider(-1, 3, value=1.0, label="Z")
142
- with gr.Column():
143
- gr.Markdown("**Target Point**")
144
  tgt_x = gr.Slider(-1, 1, value=0.0, label="X")
145
  tgt_y = gr.Slider(-1, 1, value=0.0, label="Y")
146
  tgt_z = gr.Slider(0, 2, value=0.5, label="Z")
147
 
148
- # Simulation image and joint output
149
  with gr.Row():
150
  img_output = gr.Image(type="filepath", label="Simulation View")
151
  text_output = gr.Textbox(label="Joint States", lines=10)
152
 
153
- # Live update on any slider change
154
  def live_update(*vals):
155
  joints = list(vals[:7])
156
  grip = vals[7]
@@ -167,6 +171,7 @@ with gr.Blocks(title="Franka Arm with 3D Camera Control") as demo:
167
  inputs=[], outputs=[img_output, text_output]
168
  )
169
 
 
170
  gr.Markdown("### ✍️ Move Robot to Custom Joint Angles")
171
  joint_input_box = gr.Textbox(label="Enter 7 Joint Angles (comma-separated)")
172
  gr.Button("▶️ Move to Angles").click(
@@ -175,10 +180,21 @@ with gr.Blocks(title="Franka Arm with 3D Camera Control") as demo:
175
  outputs=[img_output, text_output]
176
  )
177
 
 
178
  gr.Markdown("### 🧾 Pick and Place Input (3 sets of joint angles)")
179
- position_input = gr.Textbox(label="Object Position Angles")
180
- approach_input = gr.Textbox(label="Approach Angles")
181
- place_input = gr.Textbox(label="Place Angles")
 
 
 
 
 
 
 
 
 
 
182
  gr.Button("🤖 Perform Pick and Place").click(
183
  fn=lambda p, a, pl, x, y, z, tx, ty, tz: pick_and_place(p, a, pl, [x, y, z], [tx, ty, tz]),
184
  inputs=[position_input, approach_input, place_input, cam_x, cam_y, cam_z, tgt_x, tgt_y, tgt_z],
 
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])
125
+
126
  with gr.Blocks(title="Franka Arm with 3D Camera Control") as demo:
127
  gr.Markdown("## 🤖 Franka Robot with Camera + Joint Control")
128
 
 
136
  joint_sliders.append(gr.Slider(-3.14, 3.14, value=0, label=f"Joint {i+1}"))
137
  gripper = gr.Slider(0.0, 0.04, value=0.02, step=0.001, label="Gripper")
138
 
139
+ # Compact camera + target controls
140
  with gr.Row():
141
+ with gr.Column(scale=1):
142
+ gr.Markdown("<span style='font-size: 14px'><b>Camera Position</b></span>", unsafe_allow_html=True)
143
  cam_x = gr.Slider(-3, 3, value=1.5, label="X")
144
  cam_y = gr.Slider(-3, 3, value=0.0, label="Y")
145
  cam_z = gr.Slider(-1, 3, value=1.0, label="Z")
146
+ with gr.Column(scale=1):
147
+ gr.Markdown("<span style='font-size: 14px'><b>Target Point</b></span>", unsafe_allow_html=True)
148
  tgt_x = gr.Slider(-1, 1, value=0.0, label="X")
149
  tgt_y = gr.Slider(-1, 1, value=0.0, label="Y")
150
  tgt_z = gr.Slider(0, 2, value=0.5, label="Z")
151
 
152
+ # Live image + output
153
  with gr.Row():
154
  img_output = gr.Image(type="filepath", label="Simulation View")
155
  text_output = gr.Textbox(label="Joint States", lines=10)
156
 
157
+ # Live simulation update
158
  def live_update(*vals):
159
  joints = list(vals[:7])
160
  grip = vals[7]
 
171
  inputs=[], outputs=[img_output, text_output]
172
  )
173
 
174
+ # Move to angles box
175
  gr.Markdown("### ✍️ Move Robot to Custom Joint Angles")
176
  joint_input_box = gr.Textbox(label="Enter 7 Joint Angles (comma-separated)")
177
  gr.Button("▶️ Move to Angles").click(
 
180
  outputs=[img_output, text_output]
181
  )
182
 
183
+ # Pick and Place section
184
  gr.Markdown("### 🧾 Pick and Place Input (3 sets of joint angles)")
185
+
186
+ with gr.Row():
187
+ position_input = gr.Textbox(label="Object Position Angles")
188
+ gr.Button("📋 Copy").click(fn=copy_current_joint_angles, inputs=joint_sliders, outputs=position_input)
189
+
190
+ with gr.Row():
191
+ approach_input = gr.Textbox(label="Approach Angles")
192
+ gr.Button("📋 Copy").click(fn=copy_current_joint_angles, inputs=joint_sliders, outputs=approach_input)
193
+
194
+ with gr.Row():
195
+ place_input = gr.Textbox(label="Place Angles")
196
+ gr.Button("📋 Copy").click(fn=copy_current_joint_angles, inputs=joint_sliders, outputs=place_input)
197
+
198
  gr.Button("🤖 Perform Pick and Place").click(
199
  fn=lambda p, a, pl, x, y, z, tx, ty, tz: pick_and_place(p, a, pl, [x, y, z], [tx, ty, tz]),
200
  inputs=[position_input, approach_input, place_input, cam_x, cam_y, cam_z, tgt_x, tgt_y, tgt_z],