codegen-rnea.py
Go to the documentation of this file.
1 import numpy as np
2 import pinocchio as pin
3 import pinocchio.cppadcg as cgpin
4 from pycppad import (
5  ADCG,
6  CG,
7  ADCGFun,
8  CodeHandler,
9  Independent,
10  LangCDefaultVariableNameGenerator,
11  LanguageC,
12 )
13 
14 pinmodel = pin.buildSampleModelHumanoidRandom()
15 model = cgpin.Model(pinmodel)
16 data = model.createData()
17 
18 nq = model.nq
19 nv = model.nv
20 
21 x = np.array([ADCG(CG(0.0))] * (nq + nv + nv))
22 x[:nq] = cgpin.neutral(model)
23 Independent(x)
24 
25 y = cgpin.rnea(model, data, x[:nq], x[nq : nq + nv], x[nq + nv :])
26 
27 fun = ADCGFun(x, y)
28 
29 # /***************************************************************************
30 # * Generate the C source code
31 # **************************************************************************/
32 
33 # /**
34 # * start the special steps for source code generation for a Jacobian
35 # */
36 handler = CodeHandler(50)
37 
38 indVars = np.array([CG(1.0)] * (nq + nv + nv))
39 handler.makeVariables(indVars)
40 
41 jac = fun.Jacobian(indVars)
42 
43 langC = LanguageC("double", 3)
44 nameGen = LangCDefaultVariableNameGenerator("y", "x", "v", "array", "sarray")
45 code = handler.generateCode(langC, jac, nameGen, "source")
46 print(code)
pinocchio.cppadcg
Definition: bindings/python/pinocchio/cppadcg/__init__.py:1


pinocchio
Author(s):
autogenerated on Mon Dec 16 2024 03:41:00