Skip to content

Commit aa410d2

Browse files
committed
2 parents 853c195 + bdbaf55 commit aa410d2

File tree

5 files changed

+34
-9
lines changed

5 files changed

+34
-9
lines changed

robosuite/controllers/composite/composite_controller.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,23 @@ def get_control_dim(self, part_name):
122122
return self.part_controllers[part_name].control_dim
123123

124124
def get_controller_base_pose(self, controller_name):
125+
"""
126+
Get the base position and orientation of a specified controller's part. Note: this pose may likely differ from
127+
the robot base's pose.
128+
129+
Args:
130+
controller_name (str): The name of the controller, used to look up part-specific information.
131+
132+
Returns:
133+
tuple[np.ndarray, np.ndarray]: A tuple containing:
134+
- base_pos (np.ndarray): The 3D position of the part's center in world coordinates (shape: (3,)).
135+
- base_ori (np.ndarray): The 3x3 rotation matrix representing the part's orientation in world coordinates.
136+
137+
Details:
138+
- Uses the controller's `naming_prefix` and `part_name` to construct the corresponding site name.
139+
- Queries the simulation (`self.sim`) for the site's position (`site_xpos`) and orientation (`site_xmat`).
140+
- The site orientation matrix is reshaped from a flat array of size 9 to a 3x3 rotation matrix.
141+
"""
125142
naming_prefix = self.part_controllers[controller_name].naming_prefix
126143
part_name = self.part_controllers[controller_name].part_name
127144
base_pos = np.array(self.sim.data.site_xpos[self.sim.model.site_name2id(f"{naming_prefix}{part_name}_center")])

robosuite/controllers/parts/arm/osc.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -242,18 +242,19 @@ def set_goal(self, action):
242242

243243
# Parse action based on the impedance mode, and update kp / kd as necessary
244244
if self.impedance_mode == "variable":
245-
damping_ratio, kp, delta = action[:6], action[6:12], action[12:]
245+
damping_ratio, kp, goal_update = action[:6], action[6:12], action[12:]
246246
self.kp = np.clip(kp, self.kp_min, self.kp_max)
247247
self.kd = 2 * np.sqrt(self.kp) * np.clip(damping_ratio, self.damping_ratio_min, self.damping_ratio_max)
248248
elif self.impedance_mode == "variable_kp":
249-
kp, delta = action[:6], action[6:]
249+
kp, goal_update = action[:6], action[6:]
250250
self.kp = np.clip(kp, self.kp_min, self.kp_max)
251251
self.kd = 2 * np.sqrt(self.kp) # critically damped
252252
else: # This is case "fixed"
253-
delta = action
253+
goal_update = action
254254

255255
# If we're using deltas, interpret actions as such
256256
if self.input_type == "delta":
257+
delta = goal_update
257258
scaled_delta = self.scale_action(delta)
258259
self.goal_pos = self.compute_goal_pos(scaled_delta[0:3])
259260
if self.use_ori is True:
@@ -262,9 +263,10 @@ def set_goal(self, action):
262263
self.goal_ori = self.compute_goal_ori(np.zeros(3))
263264
# Else, interpret actions as absolute values
264265
elif self.input_type == "absolute":
265-
self.goal_pos = action[0:3]
266+
abs_action = goal_update
267+
self.goal_pos = abs_action[0:3]
266268
if self.use_ori is True:
267-
self.goal_ori = Rotation.from_rotvec(action[3:6]).as_matrix()
269+
self.goal_ori = Rotation.from_rotvec(abs_action[3:6]).as_matrix()
268270
else:
269271
self.goal_ori = self.compute_goal_ori(np.zeros(3))
270272
else:

robosuite/renderers/context/egl_context.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
raise ImportError(
2727
"Cannot use EGL rendering platform. "
2828
"The PYOPENGL_PLATFORM environment variable is set to {!r} "
29-
"(should be either unset or 'egl')."
29+
"(should be either unset or 'egl').".format(PYOPENGL_PLATFORM)
3030
)
3131

3232
from mujoco.egl import egl_ext as EGL

robosuite/robots/robot.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -356,10 +356,14 @@ def joint_pos_sin(obs_cache):
356356
def joint_vel(obs_cache):
357357
return np.array([self.sim.data.qvel[x] for x in self._ref_joint_vel_indexes])
358358

359-
sensors = [joint_pos, joint_pos_cos, joint_pos_sin, joint_vel]
360-
names = ["joint_pos", "joint_pos_cos", "joint_pos_sin", "joint_vel"]
359+
@sensor(modality=modality)
360+
def joint_acc(obs_cache):
361+
return np.array([self.sim.data.qacc[x] for x in self._ref_joint_vel_indexes])
362+
363+
sensors = [joint_pos, joint_pos_cos, joint_pos_sin, joint_vel, joint_acc]
364+
names = ["joint_pos", "joint_pos_cos", "joint_pos_sin", "joint_vel", "joint_acc"]
361365
# We don't want to include the direct joint pos sensor outputs
362-
actives = [True, True, True, True]
366+
actives = [True, True, True, True, True]
363367

364368
for arm in self.arms:
365369
arm_sensors, arm_sensor_names = self._create_arm_sensors(arm, modality=modality)

robosuite/wrappers/data_collection_wrapper.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ def _start_new_episode(self):
7777

7878
# trick for ensuring that we can play MuJoCo demonstrations back
7979
# deterministically by using the recorded actions open loop
80+
self.env.set_ep_meta(self.env.get_ep_meta())
8081
self.env.reset_from_xml_string(self._current_task_instance_xml)
8182
self.env.sim.reset()
8283
self.env.sim.set_state_from_flattened(self._current_task_instance_state)
@@ -144,6 +145,7 @@ def reset(self):
144145
Returns:
145146
OrderedDict: Environment observation space after reset occurs
146147
"""
148+
self.env.unset_ep_meta() # unset any episode meta data that was previously set
147149
ret = super().reset()
148150
self._start_new_episode()
149151
return ret

0 commit comments

Comments
 (0)