Skip to content

Commit 41c793d

Browse files
committed
add imu gyro draw_debug, update doc
1 parent 5f5126d commit 41c793d

File tree

3 files changed

+24
-17
lines changed

3 files changed

+24
-17
lines changed

examples/sensors/imu_franka.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def main():
4444
gs.sensors.IMU(
4545
entity_idx=franka.idx,
4646
link_idx_local=end_effector.idx_local,
47-
pos_offset=(0.0, 0.0, 0.2),
47+
pos_offset=(0.0, 0.0, 0.15),
4848
# noise parameters
4949
acc_axes_skew=(0.0, 0.01, 0.02),
5050
gyro_axes_skew=(0.03, 0.04, 0.05),

genesis/recorders/plotters.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,8 @@ class MPLImagePlotterOptions(BasePlotterOptions):
652652
class MPLImagePlotter(BaseMPLPlotter):
653653
"""
654654
Live image viewer using matplotlib.
655+
656+
The image data should be an array-like object with shape (H, W), (H, W, 1), (H, W, 3), or (H, W, 4).
655657
"""
656658

657659
def build(self):
@@ -676,13 +678,6 @@ def process(self, data, cur_time):
676678
else:
677679
img_data = np.asarray(data)
678680

679-
if img_data.ndim == 3 and img_data.shape[0] == 1:
680-
img_data = img_data[0] # remove batch dimension
681-
# TODO: color images?
682-
# elif img_data.ndim == 3 and img_data.shape[-1] in [1, 3, 4]:
683-
elif img_data.ndim == 3 and img_data.shape[-1] == 1:
684-
img_data = img_data.squeeze(-1)
685-
686681
vmin, vmax = np.min(img_data), np.max(img_data)
687682

688683
current_vmin, current_vmax = self.image_plot.get_clim()

genesis/sensors/imu.py

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,13 @@ class IMUOptions(RigidSensorOptionsMixin, NoisySensorOptionsMixin, SensorOptions
128128
draw_debug : bool, optional
129129
If True and the rasterizer visualization is active, an arrow for linear acceleration will be drawn.
130130
debug_acc_color : float, optional
131-
The rgba color of the debug acceleration arrow. Defaults to (1.0, 0.0, 0.0, 0.5).
131+
The rgba color of the debug acceleration arrow. Defaults to (0.0, 1.0, 1.0, 0.5).
132132
debug_acc_scale: float, optional
133133
The scale factor for the debug acceleration arrow. Defaults to 0.01.
134+
debug_gyro_color : float, optional
135+
The rgba color of the debug gyroscope arrow. Defaults to (1.0, 1.0, 0.0, 0.5).
136+
debug_gyro_scale: float, optional
137+
The scale factor for the debug gyroscope arrow. Defaults to 0.01.
134138
"""
135139

136140
acc_resolution: MaybeTuple3FType = 0.0
@@ -144,8 +148,10 @@ class IMUOptions(RigidSensorOptionsMixin, NoisySensorOptionsMixin, SensorOptions
144148
acc_random_walk: MaybeTuple3FType = 0.0
145149
gyro_random_walk: MaybeTuple3FType = 0.0
146150

147-
debug_acc_color: tuple[float, float, float, float] = (1.0, 0.0, 0.0, 0.5)
151+
debug_acc_color: tuple[float, float, float, float] = (0.0, 1.0, 1.0, 0.5)
148152
debug_acc_scale: float = 0.01
153+
debug_gyro_color: tuple[float, float, float, float] = (1.0, 1.0, 0.0, 0.5)
154+
debug_gyro_scale: float = 0.01
149155

150156
def validate(self, scene):
151157
super().validate(scene)
@@ -252,7 +258,7 @@ def build(self):
252258
)
253259

254260
if self._options.draw_debug:
255-
self.debug_object = None
261+
self.debug_objects = [None, None]
256262
self.quat_offset = self._shared_metadata.offsets_quat[0, self._idx]
257263
self.pos_offset = self._shared_metadata.offsets_pos[0, self._idx]
258264

@@ -334,9 +340,15 @@ def _draw_debug(self, context: "RasterizerContext"):
334340
pos = self.link.get_pos(envs_idx=envs_idx).squeeze(0) + transform_by_quat(self.pos_offset, quat)
335341

336342
data = self.read(envs_idx=envs_idx)
337-
vec = data["lin_acc"].squeeze(0) * self._options.debug_acc_scale
338-
vec = tensor_to_array(transform_by_quat(vec, transform_quat_by_quat(self.quat_offset, quat)))
339-
340-
if self.debug_object is not None:
341-
context.clear_debug_object(self.debug_object)
342-
self.debug_object = context.draw_debug_arrow(pos=pos, vec=vec, color=self._options.debug_acc_color)
343+
acc_vec = data["lin_acc"].squeeze(0) * self._options.debug_acc_scale
344+
gyro_vec = data["ang_vel"].squeeze(0) * self._options.debug_gyro_scale
345+
# transform from local frame to world frame
346+
offset_quat = transform_quat_by_quat(self.quat_offset, quat)
347+
acc_vec = tensor_to_array(transform_by_quat(acc_vec, offset_quat))
348+
gyro_vec = tensor_to_array(transform_by_quat(gyro_vec, offset_quat))
349+
350+
for debug_object in self.debug_objects:
351+
if debug_object is not None:
352+
context.clear_debug_object(debug_object)
353+
self.debug_objects[0] = context.draw_debug_arrow(pos=pos, vec=acc_vec, color=self._options.debug_acc_color)
354+
self.debug_objects[1] = context.draw_debug_arrow(pos=pos, vec=gyro_vec, color=self._options.debug_gyro_color)

0 commit comments

Comments
 (0)