MCPcopy Create free account
hub / github.com/Simple-Robotics/aligator / test_kinodynamics_diff

Function test_kinodynamics_diff

tests/python/test_continuous_dynamics.py:360–420  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

358 not HAS_PINOCCHIO, reason="Aligator was compiled without Pinocchio."
359)
360def test_kinodynamics_diff():
361 import pinocchio as pin
362
363 model = pin.buildSampleModelHumanoid()
364 contact_ids = [
365 model.getFrameId("lleg_effector_body"),
366 model.getFrameId("rleg_effector_body"),
367 model.getFrameId("rarm_effector_body"),
368 ]
369 # Test for 3D contact
370 force_size = 3
371 nk = 3
372 nu = force_size * nk + model.nv - 6
373 space = manifolds.MultibodyPhaseSpace(model)
374 mass = 0
375 for inertia in model.inertias:
376 mass += inertia.mass
377 gravity = np.array([0, 0, -9.81])
378 contact_states = [True, True, False]
379
380 ode = dynamics.KinodynamicsFwdDynamics(
381 space, model, gravity, contact_states, contact_ids, force_size
382 )
383 data = ode.createData()
384
385 x0 = space.neutral()
386 ndx = space.ndx
387 dx = np.random.randn(ndx)
388 x0 = space.integrate(x0, dx)
389 u0 = np.random.randn(nu)
390 epsilon = 1e-6
391
392 ode.forward(x0, u0, data)
393 ode.dForward(x0, u0, data)
394
395 Jx0 = data.Jx.copy()
396 Ju0 = data.Ju.copy()
397 Jxdiff, Judiff = ode_finite_difference(ode, space, x0, u0, epsilon)
398
399 assert np.linalg.norm(Jxdiff - Jx0) <= epsilon
400 assert np.linalg.norm(Judiff - Ju0) <= epsilon
401
402 # Test for 6D contact
403 force_size = 6
404 nu = force_size * nk + model.nv - 6
405
406 ode = dynamics.KinodynamicsFwdDynamics(
407 space, model, gravity, contact_states, contact_ids, force_size
408 )
409 data = ode.createData()
410 u0 = np.random.randn(nu)
411
412 ode.forward(x0, u0, data)
413 ode.dForward(x0, u0, data)
414
415 Jx0 = data.Jx.copy()
416 Ju0 = data.Ju.copy()
417 Jxdiff, Judiff = ode_finite_difference(ode, space, x0, u0, epsilon)

Callers

nothing calls this directly

Calls 9

ode_finite_differenceFunction · 0.90
getFrameIdMethod · 0.80
MultibodyPhaseSpaceMethod · 0.80
neutralMethod · 0.80
integrateMethod · 0.80
copyMethod · 0.80
createDataMethod · 0.45
forwardMethod · 0.45
dForwardMethod · 0.45

Tested by

no test coverage detected