Commit cb989968 authored by jcarpent's avatar jcarpent Committed by Valenza Florian
Browse files

[Python] Split bindings in several .o files

parent ce8ec930
......@@ -36,7 +36,7 @@ MACRO(ADD_SOURCE_GROUP FILENAMES)
ENDMACRO(ADD_SOURCE_GROUP FILENAMES)
IF(BUILD_PYTHON_INTERFACE)
# --- Collect header files
SET(${PROJECT_NAME}_PYTHON_HEADERS
eigen_container.hpp
handler.hpp
......@@ -52,7 +52,7 @@ IF(BUILD_PYTHON_INTERFACE)
frame.hpp
model.hpp
data.hpp
algorithms.hpp
algorithm/algorithms.hpp
parsers.hpp
explog.hpp
geometry-object.hpp
......@@ -60,10 +60,48 @@ IF(BUILD_PYTHON_INTERFACE)
geometry-data.hpp
)
SET(${PROJECT_NAME}_PYTHON_SOURCES
module.cpp
expose-SE3.cpp
expose-motion.cpp
expose-force.cpp
expose-inertia.cpp
expose-explog.cpp
expose-joints.cpp
expose-frame.cpp
expose-model.cpp
expose-data.cpp
expose-parsers.cpp
algorithm/expose-algorithms.cpp
algorithm/expose-com.cpp
algorithm/expose-kinematics.cpp
algorithm/expose-dynamics.cpp
algorithm/expose-crba.cpp
algorithm/expose-rnea.cpp
algorithm/expose-aba.cpp
algorithm/expose-jacobian.cpp
algorithm/expose-joints.cpp
algorithm/expose-energy.cpp
algorithm/expose-frames.cpp
algorithm/expose-cat.cpp
)
LIST(APPEND ${PROJECT_NAME}_PYTHON_HEADERS
geometry-object.hpp
geometry-model.hpp
geometry-data.hpp
)
LIST(APPEND ${PROJECT_NAME}_PYTHON_SOURCES
expose-geometry.cpp
algorithm/expose-geometry.cpp
)
LIST(APPEND HEADERS ${${PROJECT_NAME}_PYTHON_HEADERS})
LIST(REMOVE_DUPLICATES HEADERS)
MAKE_DIRECTORY("${${PROJECT_NAME}_BINARY_DIR}/include/pinocchio/bindings/python")
MAKE_DIRECTORY("${${PROJECT_NAME}_BINARY_DIR}/include/pinocchio/bindings/python/algorithm")
FOREACH(header ${${PROJECT_NAME}_PYTHON_HEADERS})
GET_FILENAME_COMPONENT(headerName ${header} NAME)
GET_FILENAME_COMPONENT(headerPath ${header} PATH)
......@@ -79,7 +117,9 @@ IF(BUILD_PYTHON_INTERFACE)
# --- COMPILE WRAPPER
SET(PYWRAP ${PROJECT_NAME}_pywrap)
ADD_LIBRARY(${PYWRAP} SHARED module.cpp python.cpp)
ADD_LIBRARY(${PYWRAP} SHARED ${${PROJECT_NAME}_PYTHON_SOURCES} ${${PROJECT_NAME}_PYTHON_HEADERS})
ADD_HEADER_GROUP(${PROJECT_NAME}_PYTHON_HEADERS)
ADD_SOURCE_GROUP(${PROJECT_NAME}_PYTHON_SOURCES)
PKG_CONFIG_USE_DEPENDENCY(${PYWRAP} eigenpy)
IF(URDFDOM_FOUND)
......
//
// Copyright (c) 2015-2016 CNRS
//
// This file is part of Pinocchio
// Pinocchio is free software: you can redistribute it
// and/or modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation, either version
// 3 of the License, or (at your option) any later version.
//
// Pinocchio is distributed in the hope that it will be
// useful, but WITHOUT ANY WARRANTY; without even the implied warranty
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Lesser Public License for more details. You should have
// received a copy of the GNU Lesser General Public License along with
// Pinocchio If not, see
// <http://www.gnu.org/licenses/>.
#ifndef __se3_python_algorithm_hpp__
#define __se3_python_algorithm_hpp__
#include <eigenpy/exception.hpp>
#include <eigenpy/eigenpy.hpp>
#include "pinocchio/bindings/python/python.hpp"
#include "pinocchio/bindings/python/model.hpp"
#include "pinocchio/bindings/python/data.hpp"
namespace se3
{
namespace python
{
typedef eigenpy::UnalignedEquivalent<Eigen::VectorXd>::type VectorXd_fx;
typedef eigenpy::UnalignedEquivalent<Eigen::MatrixXd>::type MatrixXd_fx;
void exposeJointsAlgo();
void exposeABA();
void exposeCRBA();
void exposeRNEA();
void exposeCOM();
void exposeFramesAlgo();
void exposeEnergy();
void exposeKinematics();
void exposeDynamics();
void exposeCAT();
void exposeJacobian();
#ifdef WITH_HPP_FCL
void exposeGeometryAlgo();
#endif // ifdef WITH_HPP_FCL
void exposeAlgorithms();
} // namespace python
} // namespace se3
#endif // ifndef __se3_python_algorithm_hpp__
//
// Copyright (c) 2015-2016 CNRS
//
// This file is part of Pinocchio
// Pinocchio is free software: you can redistribute it
// and/or modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation, either version
// 3 of the License, or (at your option) any later version.
//
// Pinocchio is distributed in the hope that it will be
// useful, but WITHOUT ANY WARRANTY; without even the implied warranty
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Lesser Public License for more details. You should have
// received a copy of the GNU Lesser General Public License along with
// Pinocchio If not, see
// <http://www.gnu.org/licenses/>.
#include "pinocchio/bindings/python/algorithm/algorithms.hpp"
#include "pinocchio/algorithm/aba.hpp"
namespace se3
{
namespace python
{
static Eigen::MatrixXd aba_proxy(const ModelHandler & model,
DataHandler & data,
const VectorXd_fx & q,
const VectorXd_fx & v,
const VectorXd_fx & tau)
{
aba(*model,*data,q,v,tau);
return data->ddq;
}
void exposeABA()
{
bp::def("aba",aba_proxy,
bp::args("Model","Data",
"Joint configuration q (size Model::nq)",
"Joint velocity v (size Model::nv)",
"Joint torque tau (size Model::nv)"),
"Compute ABA, put the result in Data::ddq and return it.");
}
} // namespace python
} // namespace se3
//
// Copyright (c) 2015-2016 CNRS
//
// This file is part of Pinocchio
// Pinocchio is free software: you can redistribute it
// and/or modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation, either version
// 3 of the License, or (at your option) any later version.
//
// Pinocchio is distributed in the hope that it will be
// useful, but WITHOUT ANY WARRANTY; without even the implied warranty
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Lesser Public License for more details. You should have
// received a copy of the GNU Lesser General Public License along with
// Pinocchio If not, see
// <http://www.gnu.org/licenses/>.
#include "pinocchio/bindings/python/algorithm/algorithms.hpp"
namespace se3
{
namespace python
{
void exposeAlgorithms()
{
exposeJointsAlgo();
exposeABA();
exposeCRBA();
exposeRNEA();
exposeCOM();
exposeFramesAlgo();
exposeEnergy();
exposeKinematics();
exposeDynamics();
exposeCAT();
exposeJacobian();
#ifdef WITH_HPP_FCL
exposeGeometryAlgo();
#endif // ifdef WITH_HPP_FCL
}
} // namespace python
} // namespace se3
//
// Copyright (c) 2015-2016 CNRS
//
// This file is part of Pinocchio
// Pinocchio is free software: you can redistribute it
// and/or modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation, either version
// 3 of the License, or (at your option) any later version.
//
// Pinocchio is distributed in the hope that it will be
// useful, but WITHOUT ANY WARRANTY; without even the implied warranty
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Lesser Public License for more details. You should have
// received a copy of the GNU Lesser General Public License along with
// Pinocchio If not, see
// <http://www.gnu.org/licenses/>.
#include "pinocchio/bindings/python/algorithm/algorithms.hpp"
#include "pinocchio/algorithm/compute-all-terms.hpp"
namespace se3
{
namespace python
{
static void computeAllTerms_proxy(const ModelHandler & model,
DataHandler & data,
const VectorXd_fx & q,
const VectorXd_fx & v)
{
data->M.fill(0);
computeAllTerms(*model,*data,q,v);
data->M.triangularView<Eigen::StrictlyLower>()
= data->M.transpose().triangularView<Eigen::StrictlyLower>();
}
void exposeCAT()
{
bp::def("computeAllTerms",computeAllTerms_proxy,
bp::args("Model","Data",
"Configuration q (size Model::nq)",
"Velocity v (size Model::nv)"),
"Compute all the terms M, non linear effects and Jacobians in"
"in the same loop and put the results in data.");
}
} // namespace python
} // namespace se3
//
// Copyright (c) 2015-2016 CNRS
//
// This file is part of Pinocchio
// Pinocchio is free software: you can redistribute it
// and/or modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation, either version
// 3 of the License, or (at your option) any later version.
//
// Pinocchio is distributed in the hope that it will be
// useful, but WITHOUT ANY WARRANTY; without even the implied warranty
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Lesser Public License for more details. You should have
// received a copy of the GNU Lesser General Public License along with
// Pinocchio If not, see
// <http://www.gnu.org/licenses/>.
#include "pinocchio/bindings/python/algorithm/algorithms.hpp"
#include "pinocchio/algorithm/center-of-mass.hpp"
namespace se3
{
namespace python
{
static SE3::Vector3
com_0_proxy(const ModelHandler& model,
DataHandler & data,
const VectorXd_fx & q,
const bool updateKinematics = true)
{
return centerOfMass(*model,*data,q,
true,
updateKinematics);
}
static SE3::Vector3
com_1_proxy(const ModelHandler& model,
DataHandler & data,
const VectorXd_fx & q,
const VectorXd_fx & v,
const bool updateKinematics = true)
{
return centerOfMass(*model,*data,q,v,
true,
updateKinematics);
}
static SE3::Vector3
com_2_proxy(const ModelHandler & model,
DataHandler & data,
const VectorXd_fx & q,
const VectorXd_fx & v,
const VectorXd_fx & a,
const bool updateKinematics = true)
{
return centerOfMass(*model,*data,q,v,a,
true,
updateKinematics);
}
static Data::Matrix3x
Jcom_proxy(const ModelHandler& model,
DataHandler & data,
const VectorXd_fx & q)
{
return jacobianCenterOfMass(*model,*data,q);
}
void exposeCOM()
{
bp::def("centerOfMass",com_0_proxy,
bp::args("Model","Data",
"Joint configuration q (size Model::nq)",
"Update kinematics"),
"Compute the center of mass, putting the result in Data and return it.");
bp::def("centerOfMass",com_1_proxy,
bp::args("Model","Data",
"Joint configuration q (size Model::nq)",
"Joint velocity v (size Model::nv)",
"Update kinematics"),
"Computes the center of mass position and velocuty by storing the result in Data"
"and returns the center of mass position of the full model expressed in the world frame.");
bp::def("centerOfMass",com_2_proxy,
bp::args("Model","Data",
"Joint configuration q (size Model::nq)",
"Joint velocity v (size Model::nv)",
"Joint acceleration a (size Model::nv)",
"Update kinematics"),
"Computes the center of mass position, velocity and acceleration by storing the result in Data"
"and returns the center of mass position of the full model expressed in the world frame.");
bp::def("jacobianCenterOfMass",Jcom_proxy,
bp::args("Model","Data",
"Joint configuration q (size Model::nq)"),
"Computes the jacobian of the center of mass, puts the result in Data and return it.");
}
} // namespace python
} // namespace se3
//
// Copyright (c) 2015-2016 CNRS
//
// This file is part of Pinocchio
// Pinocchio is free software: you can redistribute it
// and/or modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation, either version
// 3 of the License, or (at your option) any later version.
//
// Pinocchio is distributed in the hope that it will be
// useful, but WITHOUT ANY WARRANTY; without even the implied warranty
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Lesser Public License for more details. You should have
// received a copy of the GNU Lesser General Public License along with
// Pinocchio If not, see
// <http://www.gnu.org/licenses/>.
#include "pinocchio/bindings/python/algorithm/algorithms.hpp"
#include "pinocchio/algorithm/crba.hpp"
namespace se3
{
namespace python
{
static Eigen::MatrixXd crba_proxy(const ModelHandler& model,
DataHandler & data,
const VectorXd_fx & q)
{
data->M.fill(0);
crba(*model,*data,q);
data->M.triangularView<Eigen::StrictlyLower>()
= data->M.transpose().triangularView<Eigen::StrictlyLower>();
return data->M;
}
static Data::Matrix6x ccrba_proxy(const ModelHandler& model,
DataHandler & data,
const VectorXd_fx & q,
const VectorXd_fx & v)
{
ccrba(*model,*data,q,v);
return data->Ag;
}
void exposeCRBA()
{
bp::def("crba",crba_proxy,
bp::args("Model","Data",
"Joint configuration q (size Model::nq)"),
"Computes CRBA, put the result in Data and return it.");
bp::def("ccrba",ccrba_proxy,
bp::args("Model","Data",
"Joint configuration q (size Model::nq)",
"Joint velocity v (size Model::nv)"),
"Computes the centroidal mapping, the centroidal momentum and the Centroidal Composite Rigid Body Inertia, puts the result in Data and returns the centroidal mapping.");
}
} // namespace python
} // namespace se3
//
// Copyright (c) 2015-2016 CNRS
//
// This file is part of Pinocchio
// Pinocchio is free software: you can redistribute it
// and/or modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation, either version
// 3 of the License, or (at your option) any later version.
//
// Pinocchio is distributed in the hope that it will be
// useful, but WITHOUT ANY WARRANTY; without even the implied warranty
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Lesser Public License for more details. You should have
// received a copy of the GNU Lesser General Public License along with
// Pinocchio If not, see
// <http://www.gnu.org/licenses/>.
#include "pinocchio/bindings/python/algorithm/algorithms.hpp"
#include "pinocchio/algorithm/dynamics.hpp"
namespace se3
{
namespace python
{
static Eigen::MatrixXd fd_llt_proxy(const ModelHandler & model,
DataHandler & data,
const VectorXd_fx & q,
const VectorXd_fx & v,
const VectorXd_fx & tau,
const eigenpy::MatrixXd_fx & J,
const VectorXd_fx & gamma,
const bool update_kinematics = true)
{
forwardDynamics(*model,*data,q,v,tau,J,gamma,update_kinematics);
return data->ddq;
}
static Eigen::MatrixXd id_llt_proxy(const ModelHandler & model,
DataHandler & data,
const VectorXd_fx & q,
const VectorXd_fx & v_before,
const eigenpy::MatrixXd_fx & J,
const double r_coeff,
const bool update_kinematics = true)
{
impulseDynamics(*model,*data,q,v_before,J,r_coeff,update_kinematics);
return data->dq_after;
}
void exposeDynamics()
{
bp::def("forwardDynamics",fd_llt_proxy,
bp::args("Model","Data",
"Joint configuration q (size Model::nq)",
"Joint velocity v (size Model::nv)",
"Joint torque tau (size Model::nv)",
"Contact Jacobian J (size nb_constraint * Model::nv)",
"Contact drift gamma (size nb_constraint)",
"Update kinematics (if true, it updates the dynamic variable according to the current state)"),
"Solves the forward dynamics problem with contacts, puts the result in Data::ddq and return it. The contact forces are stored in data.lambda_c");
bp::def("impactDynamics",id_llt_proxy,
bp::args("Model","Data",
"Joint configuration q (size Model::nq)",
"Joint velocity before impact v_before (size Model::nv)",
"Contact Jacobian J (size nb_constraint * Model::nv)",
"Coefficient of restitution r_coeff (0 = rigid impact; 1 = fully elastic impact.",
"Update kinematics (if true, it updates only the joint space inertia matrix)"),
"Solve the impact dynamics problem with contacts, put the result in Data::dq_after and return it. The contact impulses are stored in data.impulse_c");
}
} // namespace python
} // namespace se3
//
// Copyright (c) 2015-2016 CNRS
//
// This file is part of Pinocchio
// Pinocchio is free software: you can redistribute it
// and/or modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation, either version
// 3 of the License, or (at your option) any later version.
//
// Pinocchio is distributed in the hope that it will be
// useful, but WITHOUT ANY WARRANTY; without even the implied warranty
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Lesser Public License for more details. You should have
// received a copy of the GNU Lesser General Public License along with
// Pinocchio If not, see
// <http://www.gnu.org/licenses/>.
#include "pinocchio/bindings/python/algorithm/algorithms.hpp"
#include "pinocchio/algorithm/energy.hpp"
namespace se3
{
namespace python
{
static double kineticEnergy_proxy(const ModelHandler & model,
DataHandler & data,
const VectorXd_fx & q,
const VectorXd_fx & v,
const bool update_kinematics = true)
{
return kineticEnergy(*model,*data,q,v,update_kinematics);
}
static double potentialEnergy_proxy(const ModelHandler & model,
DataHandler & data,
const VectorXd_fx & q,
const bool update_kinematics = true)
{
return potentialEnergy(*model,*data,q,update_kinematics);
}
void exposeEnergy()
{
bp::def("kineticEnergy",kineticEnergy_proxy,
bp::args("Model","Data",
"Joint configuration q (size Model::nq)",
"Joint velocity v (size Model::nv)",
"Update kinematics (bool)"),
"Computes the kinematic energy of the model for the "
"given joint configuration and velocity and stores the result "
" in data.kinetic_energy. By default, the kinematics of model is updated.");
bp::def("potentialEnergy",potentialEnergy_proxy,
bp::args("Model","Data",
"Joint configuration q (size Model::nq)",
"Update kinematics (bool)"),
"Computes the potential energy of the model for the "
"given the joint configuration and stores the result "
" in data.potential_energy. By default, the kinematics of model is updated.");
}
} // namespace python
} // namespace se3
//
// Copyright (c) 2015-2016 CNRS
//
// This file is part of Pinocchio
// Pinocchio is free software: you can redistribute it
// and/or modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation, either version
// 3 of the License, or (at your option) any later version.
//
// Pinocchio is distributed in the hope that it will be
// useful, but WITHOUT ANY WARRANTY; without even the implied warranty
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Lesser Public License for more details. You should have
// received a copy of the GNU Lesser General Public License along with
// Pinocchio If not, see
// <http://www.gnu.org/licenses/>.
#include "pinocchio/bindings/python/algorithm/algorithms.hpp"
#include "pinocchio/algorithm/frames.hpp"
namespace se3
{
namespace python
{
static Data::Matrix6x frame_jacobian_proxy(const ModelHandler & model,
DataHandler & data,
const VectorXd_fx & q,
Model::F