stack-of-tasks / pinocchio

A fast and flexible implementation of Rigid Body Dynamics algorithms and their analytical derivatives
http://stack-of-tasks.github.io/pinocchio/
BSD 2-Clause "Simplified" License
1.8k stars 379 forks source link

Usage of Casadi SX with Pinocchio #2078

Open UM-A opened 10 months ago

UM-A commented 10 months ago

Hi, I think this question has been asked previously and there were some answers. I want to go from my urdf file to Casadi SX robot equations. As far as I understand, it might be possible to do with pinocchio. However, when I try to use those expressions I get errors. I am sharing the code snippet, in case I am doing something wrong. Looking forward to any responses.

Code: model=pinocchio.buildModelFromUrdf("RobotURDF.urdf" ) data=model.createData() q = SX.sym("q", model.nq)

M = pinocchio.computePotentialEnergy(model, data, np.array([q[0],q[1],q[2],q[3]]))

Error: Python argument types in pinocchio.pinocchio_pywrap.computePotentialEnergy(Model, Data, numpy.ndarray) did not match C++ signature: computePotentialEnergy(struct pinocchio::ModelTpl<double,0,struct pinocchio::JointCollectionDefaultTpl> model, struct pinocchio::DataTpl<double,0,struct pinocchio::JointCollectionDefaultTpl> {lvalue} data) computePotentialEnergy(struct pinocchio::ModelTpl<double,0,struct pinocchio::JointCollectionDefaultTpl> model, struct pinocchio::DataTpl<double,0,struct pinocchio::JointCollectionDefaultTpl> {lvalue} data, class Eigen::MatrixBase<class Eigen::Matrix<double,-1,1,0,-1,1> > q)

jorisv commented 10 months ago

Hello @UM-A,

Pinocchio 2 is only supporting Casadi in C++. The Python support will be added in Pinocchio 3 that is not released and not public.

Hopefully a pre-release is available. You can find instruction in this tutorial. I recommend you to install it with conda (in a new environment), then to run the setup notebook to test your installation.

Others notebook will show you how to use the Pinocchio Casadi binding (from pinocchio import casadi as cpin).