Usage of the cpin.aba function #2303
-
Bug descriptionI am trying to use pinocchio.casadi for a 2 DOF planar manipulator. When calling cpin.aba with the provided inputs, an ArgumentError is raised due to a mismatch in the expected argument types. Code to reproduceimport pinocchio as pin
print(pin.__version__)
from pinocchio import casadi as cpin
import casadi as ca
import numpy as np
model_name = 'double_pendulum_ode'
# Create the model
pin_model = pin.Model()
dof = 2
a = np.array([0.0, 1.0])
d = np.array([0.0, 0.0])
m = np.array([1.0, 1.0])
ell = np.array([[0.5, 0.0, 0.0], [0.5, 0.0, 0.0]])
I = np.zeros((3, 3, 2))
# Set the slices
I[:,:,0] = np.diag([0.01, 0.01, 0.0])
I[:,:,1] = np.diag([0.01, 0.01, 0.0])
I_sptl = []
joint_placement = []
joint_id = []
for i in range(dof):
I_sptl.append(pin.Inertia(m[i], ell[i], I[:,:,i])) # Inertia object
joint_placement.append(pin.SE3(np.eye(3), np.array([a[i], 0.0, d[i]])))
if i == 0:
joint_id.append(pin_model.addJoint(
0, pin.JointModelRZ(), joint_placement[-1], "joint_{}".format(i+1)
))
else:
joint_id.append(pin_model.addJoint(
joint_id[-1], pin.JointModelRZ(), joint_placement[-1], "joint_{}".format(i+1)
))
pin_model.appendBodyToJoint(joint_id[-1], I_sptl[-1], pin.SE3.Identity())
# Create data required for computations
data = pin.Data(pin_model)
q = ca.SX.sym('q', pin_model.nq)
v = ca.SX.sym('v', pin_model.nv)
x = ca.vertcat(q, v)
xdot = ca.SX.sym('xdot', pin_model.nq + pin_model.nv)
tau = ca.SX.sym('tau', pin_model.nq)
print("Type of model: ", type(pin_model))
print("Type of data: ", type(data))
print("Type of q: ", type(q), " Shape: ", q.shape)
print("Type of v: ", type(v), " Shape: ", v.shape)
print("Type of tau: ", type(tau), " Shape: ", tau.shape)
a = cpin.aba(pin_model, data, q, v, tau) Output
SystemI have tried both on an Ubuntu 22.04 machine and in Google Colab, and the same error arises. |
Beta Was this translation helpful? Give feedback.
Answered by
jorisv
Jun 24, 2024
Replies: 1 comment 2 replies
-
Hello @DomenicoDona, To call cpin.aba you have to provide him a casadi model and data. |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
jcarpent
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello @DomenicoDona,
To call cpin.aba you have to provide him a casadi model and data.
You can check in this example how to create it from a double model : https://github.com/stack-of-tasks/pinocchio/blob/master/examples/cartpole-casadi.py#L64-L65