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

Function test_angular_acceleration

tests/python/test_centroidal.py:312–403  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

310
311
312def test_angular_acceleration():
313 x, d, x0 = sample_gauss(space)
314 force_size = 3
315 nu = force_size * nk
316 u0 = np.random.randn(nu)
317
318 contact_names = ["c1", "c2", "c3", "c4"]
319 contact_states = [True, False, True, True]
320 contact_poses = [
321 np.array([0.2, 0.1, 0.0]),
322 np.array([0.2, 0.0, 0.0]),
323 np.array([0.0, 0.1, 0.0]),
324 np.array([0.0, 0.0, 0]),
325 ]
326 contact_map = aligator.ContactMap(contact_names, contact_states, contact_poses)
327
328 fun = aligator.AngularAccelerationResidual(
329 ndx, nu, mass, gravity, contact_map, force_size
330 )
331 fdata = fun.createData()
332
333 fun.evaluate(x0, u0, fdata)
334
335 Ldot = np.zeros(3)
336 for i in range(nk):
337 if contact_states[i]:
338 Ldot += np.cross(contact_poses[i] - x0[:3], u0[i * 3 : (i + 1) * 3])
339
340 assert np.allclose(fdata.value, Ldot)
341
342 fun_fd = aligator.FiniteDifferenceHelper(space, fun, FD_EPS)
343 fdata2 = fun_fd.createData()
344 fun_fd.evaluate(x0, u0, fdata2)
345 assert np.allclose(fdata.value, fdata2.value)
346
347 fun_fd.computeJacobians(x0, u0, fdata2)
348 J_fd = fdata2.Jx
349 J_fd_u = fdata2.Ju
350 assert fdata.Jx.shape == J_fd.shape
351 assert fdata.Ju.shape == J_fd_u.shape
352
353 for i in range(100):
354 du = np.random.randn(nu) * sample_factor
355 u1 = u0 + du
356 x, d, x0 = sample_gauss(space)
357 fun.evaluate(x0, u1, fdata)
358 fun.computeJacobians(x0, u1, fdata)
359 fun_fd.evaluate(x0, u1, fdata2)
360 fun_fd.computeJacobians(x0, u1, fdata2)
361 assert np.allclose(fdata.Ju, fdata2.Ju, THRESH)
362 assert np.allclose(fdata.Jx, fdata2.Jx, THRESH)
363
364 force_size = 6
365 nu = force_size * nk
366 u0 = np.random.randn(nu)
367
368 fun = aligator.AngularAccelerationResidual(
369 ndx, nu, mass, gravity, contact_map, force_size

Callers

nothing calls this directly

Calls 8

createDataMethod · 0.95
evaluateMethod · 0.95
computeJacobiansMethod · 0.95
sample_gaussFunction · 0.70
createDataMethod · 0.45
evaluateMethod · 0.45
computeJacobiansMethod · 0.45

Tested by

no test coverage detected