Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add example test
  • Loading branch information
camevor committed Dec 22, 2025
commit 8f25d324b83cc2a03ae94f454e9af04b68a2e70e
12 changes: 12 additions & 0 deletions 12 newton/examples/sensors/example_sensor_imu.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import numpy as np
import warp as wp
from pxr import Usd

Expand Down Expand Up @@ -169,6 +170,17 @@ def step(self):
def test(self):
pass

def test_final(self):
acc = self.imu.accelerometer.numpy()
gravity_mag = np.linalg.norm(self.model.gravity.numpy()[0])

# Cubes settle with different faces up: cube 0 → Y, cube 1 → X, cube 2 → Z
expected_axes = [1, 0, 2]

for i, expected_axis in enumerate(expected_axes):
np.testing.assert_allclose(np.linalg.norm(acc[i]), gravity_mag, rtol=0.05)
assert abs(acc[i][expected_axis]) > gravity_mag * 0.95

def render(self):
self.viewer.begin_frame(self.sim_time)
self.viewer.log_state(self.state_0)
Expand Down
8 changes: 8 additions & 0 deletions 8 newton/tests/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,14 @@ class TestSensorExamples(unittest.TestCase):
use_viewer=True,
)

add_example_test(
TestSensorExamples,
name="sensors.example_sensor_imu",
devices=test_devices,
test_options={"num-frames": 200}, # allow cubes to settle
use_viewer=True,
)


class TestMPMExamples(unittest.TestCase):
pass
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.