Skip to content

Commit db40f8e

Browse files
committed
rename axes_skew to cross_axis_coupling
1 parent 462906c commit db40f8e

File tree

4 files changed

+30
-189
lines changed

4 files changed

+30
-189
lines changed

genesis/engine/sensors/imu.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@
3232
from genesis.vis.rasterizer_context import RasterizerContext
3333

3434

35-
def _get_skew_to_alignment_matrix(input: MaybeMatrix3x3Type, out: torch.Tensor | None = None) -> torch.Tensor:
35+
def _get_cross_axis_coupling_to_alignment_matrix(
36+
input: MaybeMatrix3x3Type, out: torch.Tensor | None = None
37+
) -> torch.Tensor:
3638
"""
3739
Convert the alignment input to a matrix. Modifies in place if provided, else allocate a new matrix.
3840
"""
@@ -97,15 +99,15 @@ def __init__(
9799
self.pos_offset: torch.Tensor
98100

99101
@gs.assert_built
100-
def set_acc_axes_skew(self, axes_skew: MaybeMatrix3x3Type, envs_idx=None):
102+
def set_acc_cross_axis_coupling(self, cross_axis_coupling: MaybeMatrix3x3Type, envs_idx=None):
101103
envs_idx = self._sanitize_envs_idx(envs_idx)
102-
rot_matrix = _get_skew_to_alignment_matrix(axes_skew)
104+
rot_matrix = _get_cross_axis_coupling_to_alignment_matrix(cross_axis_coupling)
103105
self._shared_metadata.alignment_rot_matrix[envs_idx, self._idx * 2, :, :] = rot_matrix
104106

105107
@gs.assert_built
106-
def set_gyro_axes_skew(self, axes_skew: MaybeMatrix3x3Type, envs_idx=None):
108+
def set_gyro_cross_axis_coupling(self, cross_axis_coupling: MaybeMatrix3x3Type, envs_idx=None):
107109
envs_idx = self._sanitize_envs_idx(envs_idx)
108-
rot_matrix = _get_skew_to_alignment_matrix(axes_skew)
110+
rot_matrix = _get_cross_axis_coupling_to_alignment_matrix(cross_axis_coupling)
109111
self._shared_metadata.alignment_rot_matrix[envs_idx, self._idx * 2 + 1, :, :] = rot_matrix
110112

111113
# ================================ internal methods ================================
@@ -128,8 +130,8 @@ def build(self):
128130
self._shared_metadata.alignment_rot_matrix,
129131
torch.stack(
130132
[
131-
_get_skew_to_alignment_matrix(self._options.acc_axes_skew),
132-
_get_skew_to_alignment_matrix(self._options.gyro_axes_skew),
133+
_get_cross_axis_coupling_to_alignment_matrix(self._options.acc_cross_axis_coupling),
134+
_get_cross_axis_coupling_to_alignment_matrix(self._options.gyro_cross_axis_coupling),
133135
],
134136
),
135137
expand=(self._manager._sim._B, 2, 3, 3),

genesis/options/sensors/options.py

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
1-
from dataclasses import dataclass
21
from typing import Sequence
32

43
import numpy as np
5-
import torch
64
from pydantic import Field
75

86
import genesis as gs
97

108
from ..options import Options
11-
from .raycaster import RaycastPattern, DepthCameraPattern
12-
9+
from .raycaster import DepthCameraPattern, RaycastPattern
1310

1411
Tuple3FType = tuple[float, float, float]
1512
MaybeTuple3FType = float | Tuple3FType
@@ -190,7 +187,7 @@ class IMU(RigidSensorOptionsMixin, NoisySensorOptionsMixin, SensorOptions):
190187
acc_resolution : float, optional
191188
The measurement resolution of the accelerometer (smallest increment of change in the sensor reading).
192189
Default is 0.0, which means no quantization is applied.
193-
acc_axes_skew : float | tuple[float, float, float] | Sequence[float]
190+
acc_cross_axis_coupling : float | tuple[float, float, float] | Sequence[float]
194191
Accelerometer axes alignment as a 3x3 rotation matrix, where diagonal elements represent alignment (0.0 to 1.0)
195192
for each axis, and off-diagonal elements account for cross-axis misalignment effects.
196193
- If a scalar is provided (float), all off-diagonal elements are set to the scalar value.
@@ -205,8 +202,8 @@ class IMU(RigidSensorOptionsMixin, NoisySensorOptionsMixin, SensorOptions):
205202
gyro_resolution : float, optional
206203
The measurement resolution of the gyroscope (smallest increment of change in the sensor reading).
207204
Default is 0.0, which means no quantization is applied.
208-
gyro_axes_skew : float | tuple[float, float, float] | Sequence[float]
209-
Gyroscope axes alignment as a 3x3 rotation matrix, similar to `acc_axes_skew`.
205+
gyro_cross_axis_coupling : float | tuple[float, float, float] | Sequence[float]
206+
Gyroscope axes alignment as a 3x3 rotation matrix, similar to `acc_cross_axis_coupling`.
210207
gyro_bias : tuple[float, float, float]
211208
The constant additive bias for each axis of the gyroscope.
212209
gyro_noise : tuple[float, float, float]
@@ -225,8 +222,8 @@ class IMU(RigidSensorOptionsMixin, NoisySensorOptionsMixin, SensorOptions):
225222

226223
acc_resolution: MaybeTuple3FType = 0.0
227224
gyro_resolution: MaybeTuple3FType = 0.0
228-
acc_axes_skew: MaybeMatrix3x3Type = 0.0
229-
gyro_axes_skew: MaybeMatrix3x3Type = 0.0
225+
acc_cross_axis_coupling: MaybeMatrix3x3Type = 0.0
226+
gyro_cross_axis_coupling: MaybeMatrix3x3Type = 0.0
230227
acc_noise: MaybeTuple3FType = 0.0
231228
gyro_noise: MaybeTuple3FType = 0.0
232229
acc_bias: MaybeTuple3FType = 0.0
@@ -240,15 +237,17 @@ class IMU(RigidSensorOptionsMixin, NoisySensorOptionsMixin, SensorOptions):
240237
debug_gyro_scale: float = 0.01
241238

242239
def model_post_init(self, _):
243-
self._validate_axes_skew(self.acc_axes_skew)
244-
self._validate_axes_skew(self.gyro_axes_skew)
245-
246-
def _validate_axes_skew(self, axes_skew):
247-
axes_skew_np = np.array(axes_skew)
248-
if axes_skew_np.shape not in ((), (3,), (3, 3)):
249-
gs.raise_exception(f"axes_skew shape should be (), (3,), or (3, 3), got: {axes_skew_np.shape}")
250-
if np.any(axes_skew_np < 0.0) or np.any(axes_skew_np > 1.0):
251-
gs.raise_exception(f"axes_skew values should be between 0.0 and 1.0, got: {axes_skew}")
240+
self._validate_cross_axis_coupling(self.acc_cross_axis_coupling)
241+
self._validate_cross_axis_coupling(self.gyro_cross_axis_coupling)
242+
243+
def _validate_cross_axis_coupling(self, cross_axis_coupling):
244+
cross_axis_coupling_np = np.array(cross_axis_coupling)
245+
if cross_axis_coupling_np.shape not in ((), (3,), (3, 3)):
246+
gs.raise_exception(
247+
f"cross_axis_coupling shape should be (), (3,), or (3, 3), got: {cross_axis_coupling_np.shape}"
248+
)
249+
if np.any(cross_axis_coupling_np < 0.0) or np.any(cross_axis_coupling_np > 1.0):
250+
gs.raise_exception(f"cross_axis_coupling values should be between 0.0 and 1.0, got: {cross_axis_coupling}")
252251

253252

254253
class Raycaster(RigidSensorOptionsMixin, SensorOptions):

tests/test_imu.py

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

tests/test_sensors.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ def test_imu_sensor(show_viewer, tol, n_envs):
5757
imu_noisy = scene.add_sensor(
5858
gs.sensors.IMU(
5959
entity_idx=box.idx,
60-
acc_axes_skew=0.01,
61-
gyro_axes_skew=(0.02, 0.03, 0.04),
60+
acc_cross_axis_coupling=0.01,
61+
gyro_cross_axis_coupling=(0.02, 0.03, 0.04),
6262
acc_noise=(0.01, 0.01, 0.01),
6363
gyro_noise=(0.01, 0.01, 0.01),
6464
acc_random_walk=(0.001, 0.001, 0.001),
@@ -141,11 +141,11 @@ def test_imu_sensor(show_viewer, tol, n_envs):
141141

142142
# rotate IMU 90 deg around x axis means gravity should be along -y axis
143143
imu.set_quat_offset(gu.euler_to_quat((90.0, 0.0, 0.0)))
144-
imu.set_acc_axes_skew((0.0, 1.0, 0.0))
144+
imu.set_acc_cross_axis_coupling((0.0, 1.0, 0.0))
145145
scene.step()
146146
assert_allclose(imu.read().lin_acc, GRAVITY, tol=5e-6)
147147
imu.set_quat_offset((0.0, 0.0, 0.0, 1.0))
148-
imu.set_acc_axes_skew((0.0, 0.0, 0.0))
148+
imu.set_acc_cross_axis_coupling((0.0, 0.0, 0.0))
149149

150150
scene.reset()
151151

0 commit comments

Comments
 (0)