Skip to content

Commit e3fdc28

Browse files
committed
added pico_client, QP solver error handling, and deprecated single arm controller class.
1 parent 215c186 commit e3fdc28

File tree

6 files changed

+119
-334
lines changed

6 files changed

+119
-334
lines changed

scripts/ur5e_demo.py

Lines changed: 0 additions & 29 deletions
This file was deleted.

scripts/ur5e_dual_arm_demo.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ def main():
3737
# visualize_placo=True,
3838
)
3939

40-
controller.initialize()
41-
controller.xr_init()
4240
controller.run()
4341

4442

setup_conda.sh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ if [[ "$1" == "--conda" ]]; then
7070

7171
echo -e "[INFO] Created conda environment named '$ENV_NAME'.\n"
7272
echo -e "\t\t1. To activate the environment, run: conda activate $ENV_NAME"
73-
echo -e "\t\t2. To install the package, run: bash setup.sh --install"
73+
echo -e "\t\t2. To install the package, run: bash setup_conda.sh --install"
7474
echo -e "\t\t3. To deactivate the environment, run: conda deactivate"
7575
echo -e "\n"
7676

@@ -114,20 +114,21 @@ elif [[ "$1" == "--install" ]]; then
114114
cd RoboticsService-Python
115115
cp ../RoboticsService-PC/RoboticsService/PXREARobotSDK/build/libPXREARobotSDK.so lib/ || { echo "Failed to copy libPXREARobotSDK.so"; exit 1; }
116116
python setup.py install || { echo "Failed to install RoboticsService-Python"; exit 1; }
117+
cd ..
118+
rm -rf RoboticsService-PC
117119

118120
# cd ..
119121
# git clone https://github.com/zhigenzhao/placo.git
120122
# cd placo
121123
# git checkout xml_experimental || { echo "Failed to checkout xml_experimental branch"; exit 1; }
122124
# bash setup.sh --install || { echo "Failed to run placo setup"; exit 1; }
123125

124-
cd ../..
126+
cd ..
125127

126128
pip install -e . || { echo "Failed to install teleop_demo_mujoco with pip"; exit 1; }
127129

128130
echo -e "\n"
129-
echo -e "[INFO] Created conda environment named '$ENV_NAME'.\n"
130-
echo -e "To activate the environment, run: conda activate $ENV_NAME"
131+
echo -e "[INFO] teleop_demo_mujoco is installed in conda environment '$ENV_NAME'.\n"
131132
echo -e "\n"
132133
else
133134
echo "Invalid argument. Use --conda to create a conda environment or --install to install the package."

teleop_demo_mujoco/mujoco_teleop_controller.py

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import pinocchio
77
import placo
88
import meshcat.transformations as tf
9-
import pyroboticsservice as xr
109

1110
from placo_utils.visualization import (
1211
robot_viz,
@@ -20,6 +19,8 @@
2019
quat_diff_as_angle_axis,
2120
)
2221

22+
from teleop_demo_mujoco.pico_client import PicoClient
23+
2324

2425
class MujocoTeleopController:
2526
def __init__(
@@ -53,6 +54,7 @@ def __init__(
5354
self.visualize_placo = visualize_placo
5455
self.scale_factor = scale_factor
5556
self.q_init = q_init
57+
self.q_current = q_init
5658

5759
# To be initialized later
5860
self.mj_model = None
@@ -76,8 +78,8 @@ def __init__(
7678
name: None for name in end_effector_config.keys()
7779
}
7880

79-
def initialize(self):
80-
"""Set up the MuJoCo simulation and the IK solver."""
81+
self.pico_client = PicoClient()
82+
8183
self._setup_mujoco()
8284
self._setup_placo()
8385

@@ -196,10 +198,6 @@ def _setup_mocap_target(self):
196198
f"Mocap ID for '{vis_target}' body: {self.target_mocap_idx[name]}"
197199
)
198200

199-
def xr_init(self):
200-
"""Initialize XR tracking."""
201-
xr.init()
202-
203201
def run(self):
204202
"""Run the main teleoperation loop."""
205203

@@ -215,7 +213,7 @@ def run(self):
215213
self.t += self.dt
216214

217215
for name, config in self.end_effector_config.items():
218-
xr_grip = xr.get_key_value_by_name(
216+
xr_grip = self.pico_client.get_key_value_by_name(
219217
config["control_trigger"]
220218
)
221219
active = xr_grip > 0.5
@@ -227,7 +225,9 @@ def run(self):
227225
self._get_end_effector_info(config["link_name"])
228226
)
229227
print(f"{name} is activated.")
230-
xr_pose = xr.get_pose_by_name(config["pose_source"])
228+
xr_pose = self.pico_client.get_pose_by_name(
229+
config["pose_source"]
230+
)
231231
delta_xyz, delta_rot = self._process_xr_pose(
232232
xr_pose, name
233233
)
@@ -302,18 +302,36 @@ def _process_xr_pose(self, xr_pose, src_name):
302302
return delta_xyz, delta_rot
303303

304304
def _update_kinematics(self):
305-
# Solve IK
306-
self.solver.solve(True)
307-
self.placo_robot.update_kinematics()
305+
try:
306+
self.solver.solve(True)
307+
self.placo_robot.update_kinematics()
308+
except RuntimeError as e: # Catch RuntimeError
309+
if "QPError" in str(e) and "NaN in the QP solution" in str(e):
310+
print(f"IK solver failed with QPError (NaN): {e}")
311+
if self.floating_base:
312+
self.placo_robot.state.q = self.q_current
313+
else:
314+
self.placo_robot.state.q[7:] = self.q_current
315+
self.placo_robot.state.q[:7] = np.array(
316+
[0, 0, 0, 1, 0, 0, 0]
317+
)
318+
319+
self.placo_robot.update_kinematics()
320+
else:
321+
print(f"An unexpected RuntimeError occurred in IK solver: {e}")
322+
return
323+
except Exception as e:
324+
print(f"An unexpected error occurred in IK solver: {e}")
325+
return
326+
308327
if self.floating_base:
309-
q = self.placo_robot.state.q
328+
self.q_current = self.placo_robot.state.q
310329
else:
311-
q = self.placo_robot.state.q[7:]
312-
313-
self.mj_data.ctrl = q
330+
self.q_current = self.placo_robot.state.q[7:]
331+
self.mj_data.ctrl = self.q_current
314332

315333
if self.visualize_placo:
316-
self.placo_vis.display(self.placo_robot.state.q)
334+
self.placo_vis.display(self.q_current)
317335

318336
for name, config in self.end_effector_config.items():
319337
robot_frame_viz(self.placo_robot, config["link_name"])

0 commit comments

Comments
 (0)