4 import pinocchio
as pin
8 def df_dq(model, func, q, h=1e-9):
9 """Perform df/dq by num_diff. q is in the lie manifold.
10 :params func: function to differentiate f : np.array -> np.array
11 :params q: configuration value at which f is differentiated. type np.array
16 dq = np.zeros(model.nv)
18 res = np.zeros([len(f0), model.nv])
19 for iq
in range(model.nv):
21 res[:, iq] = (func(pin.integrate(model, q, dq)) - f0) / h
28 self.
rmodel = rmodel = pin.buildSampleModelHumanoid()
29 self.
rdata = rmodel.createData()
32 self.
rmodel.lowerPositionLimit[:3] = -1.0
33 self.
rmodel.upperPositionLimit[:3] = -1.0
34 self.
q = pin.randomConfiguration(rmodel)
42 q, vq = self.
q, self.
vq
45 pin.computeAllTerms(rmodel, rdata, q, vq)
46 dvc_dq = pin.getCenterOfMassVelocityDerivatives(rmodel, rdata)
50 """Compute COM velocity"""
51 pin.centerOfMass(rmodel, rdata_fd, q, vq)
52 return rdata_fd.vcom[0].
copy()
54 dvc_dqn =
df_dq(rmodel,
lambda _q: calc_vc(_q, vq), q)
56 self.assertTrue(np.allclose(dvc_dq, dvc_dqn, atol=np.sqrt(self.
precision)))
59 if __name__ ==
"__main__":