5 #ifndef __pinocchio_utils_code_generator_base_hpp__ 6 #define __pinocchio_utils_code_generator_base_hpp__ 8 #include "pinocchio/codegen/cppadcg.hpp" 10 #include "pinocchio/multibody/model.hpp" 11 #include "pinocchio/multibody/data.hpp" 16 template<
typename _Scalar>
32 typedef Eigen::Matrix<Scalar,Eigen::Dynamic,Eigen::Dynamic,Options>
MatrixXs;
33 typedef Eigen::Matrix<Scalar,Eigen::Dynamic,1,Options>
VectorXs;
34 typedef Eigen::Matrix<Scalar,Eigen::Dynamic,Eigen::Dynamic,Options|Eigen::RowMajor>
RowMatrixXs;
35 typedef Eigen::Matrix<ADScalar,Eigen::Dynamic,1,Options>
ADVectorXs;
36 typedef Eigen::Matrix<ADScalar,Eigen::Dynamic,Eigen::Dynamic,Options>
ADMatrixXs;
44 typedef CppAD::ADFun<CGScalar>
ADFun;
47 const Eigen::DenseIndex dim_input,
48 const Eigen::DenseIndex dim_output,
53 , function_name(function_name)
54 , library_name(library_name +
"_" + model.
name)
77 libcgen_ptr = std::unique_ptr<CppAD::cg::ModelLibraryCSourceGen<Scalar> >(
new CppAD::cg::ModelLibraryCSourceGen<Scalar>(*cgen_ptr));
80 = std::unique_ptr<CppAD::cg::DynamicModelLibraryProcessor<Scalar> >(
new CppAD::cg::DynamicModelLibraryProcessor<Scalar>(*
libcgen_ptr,
library_name));
88 CppAD::cg::GccCompiler<Scalar> compiler;
89 std::vector<std::string> compile_options = compiler.getCompileFlags();
90 compile_options[0] =
"-Ofast";
91 compiler.setCompileFlags(compile_options);
97 const std::string filename =
dynamicLibManager_ptr->getLibraryName() + CppAD::cg::system::SystemInfo<>::DYNAMIC_LIB_EXTENSION;
98 std::ifstream file(filename.c_str());
102 void loadLib(
const bool generate_if_not_exist =
true)
104 if(!
existLib() && generate_if_not_exist)
114 int dlOpenMode = std::stoi(it->second);
115 dynamicLib_ptr.reset(
new CppAD::cg::LinuxDynamicLib<Scalar>(
dynamicLibManager_ptr->getLibraryName() + CppAD::cg::system::SystemInfo<>::DYNAMIC_LIB_EXTENSION, dlOpenMode));
121 template<
typename Vector>
129 template<
typename Vector>
135 CppAD::cg::ArrayView<Scalar> jac_(
jac.data(),(size_t)
jac.size());
169 std::unique_ptr<CppAD::cg::ModelCSourceGen<Scalar> >
cgen_ptr;
170 std::unique_ptr<CppAD::cg::ModelLibraryCSourceGen<Scalar> >
libcgen_ptr;
179 #endif // ifndef __pinocchio_utils_code_generator_base_hpp__ void evalJacobian(const Eigen::MatrixBase< Vector > &x)
CppAD::ADFun< CGScalar > ADFun
Eigen::Matrix< Scalar, Eigen::Dynamic, Eigen::Dynamic, Options > MatrixXs
ADTangentVectorType ad_dq
Model::ConfigVectorType ConfigVectorType
Model::TangentVectorType TangentVectorType
ADModel::ConfigVectorType ADConfigVectorType
NewScalar cast(const Scalar &value)
std::unique_ptr< CppAD::cg::DynamicLib< Scalar > > dynamicLib_ptr
pinocchio::DataTpl< ADScalar, Options > ADData
const std::string library_name
Name of the library.
std::unique_ptr< CppAD::cg::GenericModel< Scalar > > generatedFun_ptr
std::string name(const LieGroupGenericTpl< LieGroupCollection > &lg)
Visit a LieGroupVariant to get the name of it.
const std::string function_name
Name of the function.
Eigen::Matrix< ADScalar, Eigen::Dynamic, 1, Options > ADVectorXs
bool build_forward
Options to generate or not the source code for the evaluation function.
pinocchio::ModelTpl< Scalar, Options > Model
VectorXs TangentVectorType
Dense vectorized version of a joint tangent vector (e.g. velocity, acceleration, etc). It also handles the notion of co-tangent vector (e.g. torque, etc).
#define PINOCCHIO_EIGEN_CONST_CAST(TYPE, OBJ)
Macro for an automatic const_cast.
CppAD::AD< CGScalar > ADScalar
virtual void buildMap()=0
build the mapping Y = f(X)
CppAD::cg::ModelCSourceGen< Scalar > & codeGenerator()
void loadLib(const bool generate_if_not_exist=true)
pinocchio::DataTpl< Scalar, Options > Data
Eigen::Matrix< Scalar, Eigen::Dynamic, 1, Options > VectorXs
std::unique_ptr< CppAD::cg::ModelLibraryCSourceGen< Scalar > > libcgen_ptr
std::unique_ptr< CppAD::cg::ModelCSourceGen< Scalar > > cgen_ptr
pinocchio::ModelTpl< ADScalar, Options > ADModel
CodeGenBase(const Model &model, const Eigen::DenseIndex dim_input, const Eigen::DenseIndex dim_output, const std::string &function_name, const std::string &library_name)
void evalFunction(const Eigen::MatrixBase< Vector > &x)
Main pinocchio namespace.
pinocchio::ModelTpl< CGScalar, Options > CGModel
pinocchio::DataTpl< CGScalar, Options > CGData
Eigen::DenseIndex getInputDimension() const
Dimension of the input vector.
VectorXs ConfigVectorType
Dense vectorized version of a joint configuration vector.
ADModel::TangentVectorType ADTangentVectorType
Eigen::Matrix< ADScalar, Eigen::Dynamic, Eigen::Dynamic, Options > ADMatrixXs
std::unique_ptr< CppAD::cg::DynamicModelLibraryProcessor< Scalar > > dynamicLibManager_ptr
Eigen::DenseIndex getOutputDimension() const
Dimension of the output vector.
CppAD::cg::CG< Scalar > CGScalar
JointCollectionTpl & model
Eigen::Matrix< Scalar, Eigen::Dynamic, Eigen::Dynamic, Options|Eigen::RowMajor > RowMatrixXs
ADConfigVectorType ad_q_plus
bool build_jacobian
Options to build or not the Jacobian of he function.