3 from pathlib
import Path
5 sys.path.append(str(Path(__file__).parent.parent))
8 import pinocchio
as pin
10 from pinocchio
import casadi
as cpin
11 from test_case
import PinocchioTestCase
as TestCase
16 self.
model = pin.buildSampleModelHumanoidRandom()
22 qmax = np.full((self.
model.nq, 1), np.pi)
23 self.
q = pin.randomConfiguration(self.
model, -qmax, qmax)
24 self.
v = np.random.rand(self.
model.nv)
25 self.
a = np.random.rand(self.
model.nv)
35 for i
in range(self.
model.njoints):
40 self.
fext[0].setZero()
49 cM = cpin.crba(cmodel, cdata, self.
cq)
50 f_crba = casadi.Function(
"crba", [self.
cq], [cM])
52 arg_crba = [list(self.
q)]
53 M = f_crba.call(arg_crba)[0].full()
55 M_ref = pin.crba(model, data, self.
q)
57 self.assertApprox(M, M_ref)
66 ctau = cpin.rnea(cmodel, cdata, self.
cq, self.
cv, self.
ca)
67 f_rnea = casadi.Function(
"rnea", [self.
cq, self.
cv, self.
ca], [ctau])
69 arg_rnea = [list(self.
q), list(self.
v), list(self.
a)]
70 tau = f_rnea.call(arg_rnea)[0].full()
72 tau_ref = pin.rnea(model, data, self.
q, self.
v, self.
a)
74 self.assertApprox(tau, tau_ref)
76 ctau_fext = cpin.rnea(cmodel, cdata, self.
cq, self.
cv, self.
ca, self.
cfext)
77 carg_in = [self.
cq, self.
cv, self.
ca]
80 f_rnea_fext = casadi.Function(
"rnea_fext", carg_in, [ctau_fext])
82 arg_rnea_fext = arg_rnea
84 arg_rnea_fext += [f.vector]
85 tau_fext = f_rnea_fext.call(arg_rnea_fext)[0].full()
87 tau_fext_ref = pin.rnea(model, data, self.
q, self.
v, self.
a, self.
fext)
89 self.assertApprox(tau_fext, tau_fext_ref)
98 cddq = cpin.aba(cmodel, cdata, self.
cq, self.
cv, self.
ctau)
99 f_aba = casadi.Function(
"aba", [self.
cq, self.
cv, self.
ctau], [cddq])
101 arg_aba = [list(self.
q), list(self.
v), list(self.
tau)]
102 a = f_aba.call(arg_aba)[0].full()
104 a_ref = pin.aba(model, data, self.
q, self.
v, self.
tau)
106 self.assertApprox(a, a_ref)
108 cddq_fext = cpin.aba(cmodel, cdata, self.
cq, self.
cv, self.
ctau, self.
cfext)
109 carg_in = [self.
cq, self.
cv, self.
ctau]
111 carg_in += [f.vector]
112 f_aba_fext = casadi.Function(
"aba_fext", carg_in, [cddq_fext])
114 arg_aba_fext = arg_aba
116 arg_aba_fext += [f.vector]
117 a_fext = f_aba_fext.call(arg_aba_fext)[0].full()
119 a_fext_ref = pin.aba(model, data, self.
q, self.
v, self.
tau, self.
fext)
121 self.assertApprox(a_fext, a_fext_ref)
125 Minv = pin.computeMinverse(model, self.
data, self.
q)
127 data2 = model.createData()
128 M = pin.crba(model, data2, self.
q)
130 self.assertApprox(np.linalg.inv(M), Minv)
133 if __name__ ==
"__main__":