Unverified Commit 2d4dbb05 authored by Justin Carpentier's avatar Justin Carpentier Committed by GitHub
Browse files

Merge pull request #1284 from jcarpent/topic/devel

Activate the sharing of memory between C++ and Python
parents b125aa20 3f29ef95
Pipeline #10937 passed with stage
in 255 minutes and 43 seconds
......@@ -124,13 +124,15 @@ IF(BUILD_WITH_CASADI_SUPPORT)
ENDIF(BUILD_WITH_CASADI_SUPPORT)
SET(BOOST_REQUIRED_COMPONENTS filesystem serialization system)
SET(BOOST_BUILD_COMPONENTS unit_test_framework)
SET(BOOST_OPTIONAL_COMPONENTS "")
SET_BOOST_DEFAULT_OPTIONS()
EXPORT_BOOST_DEFAULT_OPTIONS()
ADD_PROJECT_DEPENDENCY(Boost REQUIRED COMPONENTS ${BOOST_REQUIRED_COMPONENTS})
IF(BUILD_PYTHON_INTERFACE)
SET(BOOST_OPTIONAL_COMPONENTS ${BOOST_OPTIONAL_COMPONENTS} python)
FINDPYTHON()
ADD_PROJECT_DEPENDENCY(eigenpy 2.2.0 REQUIRED)
SEARCH_FOR_BOOST_PYTHON(REQUIRED)
ADD_PROJECT_DEPENDENCY(eigenpy 2.5.0 REQUIRED)
ENDIF(BUILD_PYTHON_INTERFACE)
IF(BUILD_WITH_HPP_FCL_SUPPORT)
......@@ -154,8 +156,6 @@ IF(BUILD_WITH_HPP_FCL_SUPPORT)
ENDIF(BUILD_PYTHON_INTERFACE)
ENDIF(BUILD_WITH_HPP_FCL_SUPPORT)
SET(BOOST_COMPONENTS ${BOOST_REQUIRED_COMPONENTS} ${BOOST_OPTIONAL_COMPONENTS} ${BOOST_BUILD_COMPONENTS})
SEARCH_FOR_BOOST()
# Enforce the preprocessed version of boost::list and boost::vector
# This information is redundant with the content of include/pinocchio/container/boost-container-limits.hpp
# but it avoids any compilation issue.
......
......@@ -2,8 +2,8 @@
// Copyright (c) 2015-2020 CNRS INRIA
//
#ifndef __pinocchio_python_data_hpp__
#define __pinocchio_python_data_hpp__
#ifndef __pinocchio_python_multibody_data_hpp__
#define __pinocchio_python_multibody_data_hpp__
#include <boost/python.hpp>
......@@ -11,6 +11,7 @@
#include "pinocchio/serialization/data.hpp"
#include <eigenpy/memory.hpp>
#include <eigenpy/eigen-to-python.hpp>
#include <eigenpy/exception.hpp>
#include "pinocchio/bindings/python/serialization/serializable.hpp"
......@@ -114,56 +115,56 @@ namespace pinocchio
.ADD_DATA_PROPERTY(oMi,"Body absolute placement (wrt world)")
.ADD_DATA_PROPERTY(oMf,"frames absolute placement (wrt world)")
.ADD_DATA_PROPERTY(liMi,"Body relative placement (wrt parent)")
.ADD_DATA_PROPERTY_READONLY_BYVALUE(tau,"Joint torques (output of RNEA)")
.ADD_DATA_PROPERTY_READONLY_BYVALUE(nle,"Non Linear Effects (output of nle algorithm)")
.ADD_DATA_PROPERTY_READONLY_BYVALUE(ddq,"Joint accelerations (output of ABA)")
.ADD_DATA_PROPERTY(tau,"Joint torques (output of RNEA)")
.ADD_DATA_PROPERTY(nle,"Non Linear Effects (output of nle algorithm)")
.ADD_DATA_PROPERTY(ddq,"Joint accelerations (output of ABA)")
.ADD_DATA_PROPERTY(Ycrb,"Inertia of the sub-tree composit rigid body")
.ADD_DATA_PROPERTY_READONLY_BYVALUE(M,"The joint space inertia matrix")
.ADD_DATA_PROPERTY_READONLY_BYVALUE(Minv,"The inverse of the joint space inertia matrix")
.ADD_DATA_PROPERTY_READONLY_BYVALUE(C,"The Coriolis C(q,v) matrix such that the Coriolis effects are given by c(q,v) = C(q,v)v")
.ADD_DATA_PROPERTY(M,"The joint space inertia matrix")
.ADD_DATA_PROPERTY(Minv,"The inverse of the joint space inertia matrix")
.ADD_DATA_PROPERTY(C,"The Coriolis C(q,v) matrix such that the Coriolis effects are given by c(q,v) = C(q,v)v")
.ADD_DATA_PROPERTY(Fcrb,"Spatial forces set, used in CRBA")
.ADD_DATA_PROPERTY(lastChild,"Index of the last child (for CRBA)")
.ADD_DATA_PROPERTY(nvSubtree,"Dimension of the subtree motion space (for CRBA)")
.ADD_DATA_PROPERTY_READONLY_BYVALUE(U,"Joint Inertia square root (upper triangle)")
.ADD_DATA_PROPERTY_READONLY_BYVALUE(D,"Diagonal of UDUT inertia decomposition")
.ADD_DATA_PROPERTY(U,"Joint Inertia square root (upper triangle)")
.ADD_DATA_PROPERTY(D,"Diagonal of UDUT inertia decomposition")
.ADD_DATA_PROPERTY(parents_fromRow,"First previous non-zero row in M (used in Cholesky)")
.ADD_DATA_PROPERTY(nvSubtree_fromRow,"Subtree of the current row index (used in Cholesky)")
.ADD_DATA_PROPERTY_READONLY_BYVALUE(J,"Jacobian of joint placement")
.ADD_DATA_PROPERTY_READONLY_BYVALUE(dJ,"Time variation of the Jacobian of joint placement (data.J).")
.ADD_DATA_PROPERTY(J,"Jacobian of joint placement")
.ADD_DATA_PROPERTY(dJ,"Time variation of the Jacobian of joint placement (data.J).")
.ADD_DATA_PROPERTY(iMf,"Body placement wrt to algorithm end effector.")
.ADD_DATA_PROPERTY_READONLY_BYVALUE(Ag,
"Centroidal matrix which maps from joint velocity to the centroidal momentum.")
.ADD_DATA_PROPERTY_READONLY_BYVALUE(dAg,
"Time derivative of the centroidal momentum matrix Ag.")
.ADD_DATA_PROPERTY_READONLY(hg,
"Centroidal momentum (expressed in the frame centered at the CoM and aligned with the world frame).")
.ADD_DATA_PROPERTY_READONLY(dhg,
"Centroidal momentum time derivative (expressed in the frame centered at the CoM and aligned with the world frame).")
.ADD_DATA_PROPERTY_READONLY(Ig,
"Centroidal Composite Rigid Body Inertia.")
.ADD_DATA_PROPERTY(Ag,
"Centroidal matrix which maps from joint velocity to the centroidal momentum.")
.ADD_DATA_PROPERTY(dAg,
"Time derivative of the centroidal momentum matrix Ag.")
.ADD_DATA_PROPERTY(hg,
"Centroidal momentum (expressed in the frame centered at the CoM and aligned with the world frame).")
.ADD_DATA_PROPERTY(dhg,
"Centroidal momentum time derivative (expressed in the frame centered at the CoM and aligned with the world frame).")
.ADD_DATA_PROPERTY(Ig,
"Centroidal Composite Rigid Body Inertia.")
.ADD_DATA_PROPERTY(com,"CoM position of the subtree starting at joint index i.")
.ADD_DATA_PROPERTY(vcom,"CoM velocity of the subtree starting at joint index i.")
.ADD_DATA_PROPERTY(acom,"CoM acceleration of the subtree starting at joint index i..")
.ADD_DATA_PROPERTY(mass,"Mass of the subtree starting at joint index i.")
.ADD_DATA_PROPERTY_READONLY_BYVALUE(Jcom,"Jacobian of center of mass.")
.ADD_DATA_PROPERTY(Jcom,"Jacobian of center of mass.")
.ADD_DATA_PROPERTY_READONLY_BYVALUE(C,"Joint space Coriolis matrix.")
.ADD_DATA_PROPERTY_READONLY_BYVALUE(dtau_dq,"Partial derivative of the joint torque vector with respect to the joint configuration.")
.ADD_DATA_PROPERTY_READONLY_BYVALUE(dtau_dv,"Partial derivative of the joint torque vector with respect to the joint velocity.")
.ADD_DATA_PROPERTY_READONLY_BYVALUE(ddq_dq,"Partial derivative of the joint acceleration vector with respect to the joint configuration.")
.ADD_DATA_PROPERTY_READONLY_BYVALUE(ddq_dv,"Partial derivative of the joint acceleration vector with respect to the joint velocity.")
.ADD_DATA_PROPERTY(C,"Joint space Coriolis matrix.")
.ADD_DATA_PROPERTY(dtau_dq,"Partial derivative of the joint torque vector with respect to the joint configuration.")
.ADD_DATA_PROPERTY(dtau_dv,"Partial derivative of the joint torque vector with respect to the joint velocity.")
.ADD_DATA_PROPERTY(ddq_dq,"Partial derivative of the joint acceleration vector with respect to the joint configuration.")
.ADD_DATA_PROPERTY(ddq_dv,"Partial derivative of the joint acceleration vector with respect to the joint velocity.")
.ADD_DATA_PROPERTY_READONLY_BYVALUE(kinetic_energy,"Kinetic energy in [J] computed by computeKineticEnergy")
.ADD_DATA_PROPERTY_READONLY_BYVALUE(potential_energy,"Potential energy in [J] computed by computePotentialEnergy")
.ADD_DATA_PROPERTY(kinetic_energy,"Kinetic energy in [J] computed by computeKineticEnergy")
.ADD_DATA_PROPERTY(potential_energy,"Potential energy in [J] computed by computePotentialEnergy")
.ADD_DATA_PROPERTY_READONLY_BYVALUE(lambda_c,"Lagrange Multipliers linked to contact forces")
.ADD_DATA_PROPERTY_READONLY_BYVALUE(impulse_c,"Lagrange Multipliers linked to contact impulses")
.ADD_DATA_PROPERTY(lambda_c,"Lagrange Multipliers linked to contact forces")
.ADD_DATA_PROPERTY(impulse_c,"Lagrange Multipliers linked to contact impulses")
.ADD_DATA_PROPERTY_READONLY_BYVALUE(dq_after,"Generalized velocity after the impact.")
.ADD_DATA_PROPERTY_READONLY_BYVALUE(staticRegressor,"Static regressor.")
.ADD_DATA_PROPERTY_READONLY_BYVALUE(jointTorqueRegressor,"Joint torque regressor.")
.ADD_DATA_PROPERTY(dq_after,"Generalized velocity after the impact.")
.ADD_DATA_PROPERTY(staticRegressor,"Static regressor.")
.ADD_DATA_PROPERTY(jointTorqueRegressor,"Joint torque regressor.")
.def(bp::self == bp::self)
.def(bp::self != bp::self)
......@@ -182,8 +183,13 @@ namespace pinocchio
.def(SerializableVisitor<Data>())
.def_pickle(PickleData<Data>());
StdAlignedVectorPythonVisitor<Vector3, true>::expose("StdVec_vec3d");
StdAlignedVectorPythonVisitor<Matrix6x, true>::expose("StdVec_Matrix6x");
typedef PINOCCHIO_ALIGNED_STD_VECTOR(Vector3) StdVec_Vector3;
typedef PINOCCHIO_ALIGNED_STD_VECTOR(Matrix6x) StdVec_Matrix6x;
StdAlignedVectorPythonVisitor<Vector3,false>::expose("StdVec_vec3d")
.def(details::overload_base_get_item_for_std_vector<StdVec_Vector3>());
StdAlignedVectorPythonVisitor<Matrix6x,false>::expose("StdVec_Matrix6x")
.def(details::overload_base_get_item_for_std_vector<StdVec_Matrix6x>());
StdVectorPythonVisitor<int>::expose("StdVec_int");
}
......@@ -191,4 +197,4 @@ namespace pinocchio
}} // namespace pinocchio::python
#endif // ifndef __pinocchio_python_data_hpp__
#endif // ifndef __pinocchio_python_multibody_data_hpp__
......@@ -3,13 +3,14 @@
// Copyright (c) 2015 Wandercraft, 86 rue de Paris 91400 Orsay, France.
//
#ifndef __pinocchio_python_model_hpp__
#define __pinocchio_python_model_hpp__
#ifndef __pinocchio_python_multibody_model_hpp__
#define __pinocchio_python_multibody_model_hpp__
#include <eigenpy/eigen-to-python.hpp>
#include "pinocchio/multibody/model.hpp"
#include "pinocchio/serialization/model.hpp"
#include <boost/python/suite/indexing/map_indexing_suite.hpp>
#include <boost/python/overloads.hpp>
#include <eigenpy/memory.hpp>
#include <eigenpy/exception.hpp>
......@@ -18,6 +19,7 @@
#include "pinocchio/bindings/python/serialization/serializable.hpp"
#include "pinocchio/bindings/python/utils/printable.hpp"
#include "pinocchio/bindings/python/utils/copyable.hpp"
#include "pinocchio/bindings/python/utils/std-map.hpp"
#include "pinocchio/bindings/python/utils/pickle-map.hpp"
#include "pinocchio/bindings/python/utils/std-vector.hpp"
......@@ -164,7 +166,8 @@ namespace pinocchio
void visit(PyClass& cl) const
{
cl
.def(bp::init<>(bp::arg("self"),"Default constructor. Constructs an empty model."))
.def(bp::init<>(bp::arg("self"),
"Default constructor. Constructs an empty model."))
// Class Members
.add_property("nq", &Model::nq)
......@@ -183,32 +186,22 @@ namespace pinocchio
.add_property("names",&Model::names)
.add_property("name",&Model::name)
.add_property("referenceConfigurations", &Model::referenceConfigurations)
.add_property("rotorInertia",
make_getter(&Model::rotorInertia, bp::return_value_policy<bp::return_by_value>()),
make_setter(&Model::rotorInertia, bp::return_value_policy<bp::return_by_value>()),
"Vector of rotor inertia parameters.")
.add_property("rotorGearRatio",
make_getter(&Model::rotorGearRatio, bp::return_value_policy<bp::return_by_value>()),
make_setter(&Model::rotorGearRatio, bp::return_value_policy<bp::return_by_value>()),
"Vector of rotor gear ratio parameters.")
.add_property("effortLimit",
make_getter(&Model::effortLimit, bp::return_value_policy<bp::return_by_value>()),
make_setter(&Model::effortLimit, bp::return_value_policy<bp::return_by_value>()),
"Joint max effort.")
.add_property("velocityLimit",
make_getter(&Model::velocityLimit, bp::return_value_policy<bp::return_by_value>()),
make_setter(&Model::velocityLimit, bp::return_value_policy<bp::return_by_value>()),
"Joint max velocity.")
.add_property("lowerPositionLimit",
make_getter(&Model::lowerPositionLimit, bp::return_value_policy<bp::return_by_value>()),
make_setter(&Model::lowerPositionLimit, bp::return_value_policy<bp::return_by_value>()),
"Limit for joint lower position.")
.add_property("upperPositionLimit",
make_getter(&Model::upperPositionLimit, bp::return_value_policy<bp::return_by_value>()),
make_setter(&Model::upperPositionLimit, bp::return_value_policy<bp::return_by_value>()),
"Limit for joint upper position.")
.def_readwrite("frames",&Model::frames,"Vector of frames contained in the model.")
.def_readwrite("rotorInertia",&Model::rotorInertia,
"Vector of rotor inertia parameters.")
.def_readwrite("rotorGearRatio",&Model::rotorGearRatio,
"Vector of rotor gear ratio parameters.")
.def_readwrite("effortLimit",&Model::effortLimit,
"Joint max effort.")
.def_readwrite("velocityLimit",&Model::velocityLimit,
"Joint max velocity.")
.def_readwrite("lowerPositionLimit",&Model::lowerPositionLimit,
"Limit for joint lower position.")
.def_readwrite("upperPositionLimit",&Model::upperPositionLimit,
"Limit for joint upper position.")
.def_readwrite("frames",&Model::frames,
"Vector of frames contained in the model.")
.def_readwrite("supports",
&Model::supports,
......@@ -219,41 +212,43 @@ namespace pinocchio
&Model::subtrees,
"Vector of subtrees. subtree[j] corresponds to the subtree supported by the joint j.")
.def_readwrite("gravity",&Model::gravity,"Motion vector corresponding to the gravity field expressed in the world Frame.")
.def_readwrite("gravity",&Model::gravity,
"Motion vector corresponding to the gravity field expressed in the world Frame.")
// Class Methods
.def("addJoint",&ModelPythonVisitor::addJoint,
bp::args("parent_id","joint_model","joint_placement","joint_name"),
bp::args("self","parent_id","joint_model","joint_placement","joint_name"),
"Adds a joint to the kinematic tree. The joint is defined by its placement relative to its parent joint and its name.")
.def("addJoint",&ModelPythonVisitor::addJointWithLimits,
bp::args("parent_id","joint_model","joint_placement","joint_name",
bp::args("self","parent_id","joint_model","joint_placement","joint_name",
"max_effort","max_velocity","min_config","max_config"),
"Adds a joint to the kinematic tree with given bounds. The joint is defined by its placement relative to its parent joint and its name.")
.def("addJointFrame", &Model::addJointFrame,
addJointFrame_overload(bp::args("joint_id", "frame_id"),
addJointFrame_overload(bp::args("self","joint_id", "frame_id"),
"Add the joint provided by its joint_id as a frame to the frame tree.\n"
"The frame_id may be optionally provided."))
.def("appendBodyToJoint",&Model::appendBodyToJoint,
bp::args("joint_id","body_inertia","body_placement"),
bp::args("self","joint_id","body_inertia","body_placement"),
"Appends a body to the joint given by its index. The body is defined by its inertia, its relative placement regarding to the joint and its name.")
.def("addBodyFrame", &Model::addBodyFrame, bp::args("body_name", "parentJoint", "body_placement", "previous_frame(parent frame)"), "add a body to the frame tree")
.def("getBodyId",&Model::getBodyId, bp::args("name"), "Return the index of a frame of type BODY given by its name")
.def("existBodyName", &Model::existBodyName, bp::args("name"), "Check if a frame of type BODY exists, given its name")
.def("getJointId",&Model::getJointId, bp::args("name"), "Return the index of a joint given by its name")
.def("existJointName", &Model::existJointName, bp::args("name"), "Check if a joint given by its name exists")
.def("addBodyFrame", &Model::addBodyFrame, bp::args("self","body_name", "parentJoint", "body_placement", "previous_frame(parent frame)"), "add a body to the frame tree")
.def("getBodyId",&Model::getBodyId, bp::args("self","name"), "Return the index of a frame of type BODY given by its name")
.def("existBodyName", &Model::existBodyName, bp::args("self","name"), "Check if a frame of type BODY exists, given its name")
.def("getJointId",&Model::getJointId, bp::args("self","name"), "Return the index of a joint given by its name")
.def("existJointName", &Model::existJointName, bp::args("self","name"), "Check if a joint given by its name exists")
.def("getFrameId",&Model::getFrameId,getFrameId_overload(bp::args("name","type"),"Returns the index of the frame given by its name and its type. If the frame is not in the frames vector, it returns the current size of the frames vector."))
.def("getFrameId",&Model::getFrameId,getFrameId_overload(bp::args("self","name","type"),"Returns the index of the frame given by its name and its type. If the frame is not in the frames vector, it returns the current size of the frames vector."))
.def("existFrame",&Model::existFrame,existFrame_overload(bp::args("name","type"),"Returns true if the frame given by its name exists inside the Model with the given type."))
.def("existFrame",&Model::existFrame,existFrame_overload(bp::args("self","name","type"),"Returns true if the frame given by its name exists inside the Model with the given type."))
.def("addFrame",(std::size_t (Model::*)(const Frame &)) &Model::addFrame,bp::args("frame"),"Add a frame to the vector of frames.")
.def("addFrame",(std::size_t (Model::*)(const Frame &)) &Model::addFrame,bp::args("self","frame"),"Add a frame to the vector of frames.")
.def("createData",
&ModelPythonVisitor::createData,
&ModelPythonVisitor::createData,bp::arg("self"),
"Create a Data object for the given model.")
.def("check",(bool (Model::*)(const Data &) const) &Model::check,bp::arg("data"),"Check consistency of data wrt model.")
.def("check",(bool (Model::*)(const Data &) const) &Model::check,bp::args("self","data"),
"Check consistency of data wrt model.")
.def(bp::self == bp::self)
.def(bp::self != bp::self)
......@@ -314,14 +309,17 @@ namespace pinocchio
/* --- Expose --------------------------------------------------------- */
static void expose()
{
typedef typename Model::ConfigVectorMap ConfigVectorMap;
typedef bp::map_indexing_suite<ConfigVectorMap,false> map_indexing_suite;
StdVectorPythonVisitor<Index>::expose("StdVec_Index");
StdVectorPythonVisitor<IndexVector>::expose("StdVec_IndexVector");
StdVectorPythonVisitor<std::string>::expose("StdVec_StdString");
StdVectorPythonVisitor<bool>::expose("StdVec_Bool");
StdVectorPythonVisitor<Scalar>::expose("StdVec_double");
bp::class_<typename Model::ConfigVectorMap>("StdMap_String_EigenVectorXd")
.def(bp::map_indexing_suite< typename Model::ConfigVectorMap, true >())
.def_pickle(PickleMap<typename Model::ConfigVectorMap>());
.def(map_indexing_suite())
.def_pickle(PickleMap<typename Model::ConfigVectorMap>())
.def(details::overload_base_get_item_for_std_map<typename Model::ConfigVectorMap>());
bp::class_<Model>("Model",
"Articulated Rigid Body model",
......@@ -337,4 +335,4 @@ namespace pinocchio
}} // namespace pinocchio::python
#endif // ifndef __pinocchio_python_model_hpp__
#endif // ifndef __pinocchio_python_multibody_model_hpp__
......@@ -3,10 +3,11 @@
// Copyright (c) 2016 Wandercraft, 86 rue de Paris 91400 Orsay, France.
//
#ifndef __pinocchio_python_force_hpp__
#define __pinocchio_python_force_hpp__
#ifndef __pinocchio_python_spatial_force_hpp__
#define __pinocchio_python_spatial_force_hpp__
#include <eigenpy/memory.hpp>
#include <eigenpy/eigen-to-python.hpp>
#include <boost/python/tuple.hpp>
#include "pinocchio/spatial/se3.hpp"
......@@ -55,6 +56,9 @@ namespace pinocchio
typedef typename Force::Vector3 Vector3;
typedef typename Force::Scalar Scalar;
typedef typename Eigen::Map<Vector3> MapVector3;
typedef typename Eigen::Ref<Vector3> RefVector3;
template<class PyClass>
void visit(PyClass& cl) const
{
......@@ -67,18 +71,23 @@ namespace pinocchio
.def(bp::init<Force>((bp::arg("other")),"Copy constructor."))
.add_property("linear",
&ForcePythonVisitor::getLinear,
bp::make_function(&ForcePythonVisitor::getLinear,
bp::with_custodian_and_ward_postcall<0,1>()),
&ForcePythonVisitor::setLinear,
"Linear part of a *this, corresponding to the linear velocity in case of a Spatial velocity.")
.add_property("angular",
&ForcePythonVisitor::getAngular,
bp::make_function(&ForcePythonVisitor::getAngular,
bp::with_custodian_and_ward_postcall<0,1>()),
&ForcePythonVisitor::setAngular,
"Angular part of a *this, corresponding to the angular velocity in case of a Spatial velocity.")
.add_property("vector",
&ForcePythonVisitor::getVector,
bp::make_function((typename Force::ToVectorReturnType (Force::*)())&Force::toVector,
bp::return_internal_reference<>()),
&ForcePythonVisitor::setVector,
"Returns the components of *this as a 6d vector.")
.add_property("np",&ForcePythonVisitor::getVector)
.add_property("np",
bp::make_function((typename Force::ToVectorReturnType (Force::*)())&Force::toVector,
bp::return_internal_reference<>()))
.def("se3Action",&Force::template se3Action<Scalar,Options>,
bp::args("self","M"),"Returns the result of the dual action of M on *this.")
......@@ -118,7 +127,8 @@ namespace pinocchio
.def("Zero",&Force::Zero,"Returns a zero Force.")
.staticmethod("Zero")
.def("__array__",&ForcePythonVisitor::getVector)
.def("__array__",bp::make_function((typename Force::ToVectorReturnType (Force::*)())&Force::toVector,
bp::return_internal_reference<>()))
.def_pickle(Pickle())
;
......@@ -147,20 +157,18 @@ namespace pinocchio
{ return bp::make_tuple((Vector3)f.linear(),(Vector3)f.angular()); }
};
static Vector3 getLinear(const Force & self ) { return self.linear(); }
static RefVector3 getLinear(Force & self ) { return self.linear(); }
static void setLinear(Force & self, const Vector3 & f) { self.linear(f); }
static Vector3 getAngular(const Force & self) { return self.angular(); }
static RefVector3 getAngular(Force & self) { return self.angular(); }
static void setAngular(Force & self, const Vector3 & n) { self.angular(n); }
static void setZero(Force & self) { self.setZero(); }
static void setRandom(Force & self) { self.setRandom(); }
static Vector6 getVector(const Force & self) { return self.toVector(); }
static void setVector(Force & self, const Vector6 & f) { self = f; }
};
} // namespace python
} // namespace pinocchio
#endif // ifndef __pinocchio_python_se3_hpp__
#endif // ifndef __pinocchio_python_spatial_force_hpp__
......@@ -3,11 +3,12 @@
// Copyright (c) 2016 Wandercraft, 86 rue de Paris 91400 Orsay, France.
//
#ifndef __pinocchio_python_inertia_hpp__
#define __pinocchio_python_inertia_hpp__
#ifndef __pinocchio_python_spatial_inertia_hpp__
#define __pinocchio_python_spatial_inertia_hpp__
#include <eigenpy/exception.hpp>
#include <eigenpy/memory.hpp>
#include <eigenpy/eigen-to-python.hpp>
#include <boost/python/tuple.hpp>
#include "pinocchio/spatial/inertia.hpp"
......@@ -74,7 +75,8 @@ namespace pinocchio
&InertiaPythonVisitor::setMass,
"Mass of the Spatial Inertia.")
.add_property("lever",
&InertiaPythonVisitor::getLever,
bp::make_function((typename Inertia::Vector3 & (Inertia::*)())&Inertia::lever,
bp::return_internal_reference<>()),
&InertiaPythonVisitor::setLever,
"Center of mass location of the Spatial Inertia. It corresponds to the location of the center of mass regarding to the frame where the Spatial Inertia is expressed.")
.add_property("inertia",
......@@ -169,7 +171,6 @@ namespace pinocchio
static Scalar getMass( const Inertia & self ) { return self.mass(); }
static void setMass( Inertia & self, Scalar mass ) { self.mass() = mass; }
static Vector3 getLever( const Inertia & self ) { return self.lever(); }
static void setLever( Inertia & self, const Vector3 & lever ) { self.lever() = lever; }
static Matrix3 getInertia( const Inertia & self ) { return self.inertia().matrix(); }
......@@ -233,4 +234,4 @@ namespace pinocchio
} // namespace python
} // namespace pinocchio
#endif // ifndef __pinocchio_python_se3_hpp__
#endif // ifndef __pinocchio_python_spatial_inertia_hpp__
......@@ -3,10 +3,11 @@
// Copyright (c) 2016 Wandercraft, 86 rue de Paris 91400 Orsay, France.
//
#ifndef __pinocchio_python_motion_hpp__
#define __pinocchio_python_motion_hpp__
#ifndef __pinocchio_python_spatial_motion_hpp__
#define __pinocchio_python_spatial_motion_hpp__
#include <eigenpy/memory.hpp>
#include <eigenpy/eigen-to-python.hpp>
#include <boost/python/tuple.hpp>
#include "pinocchio/spatial/se3.hpp"
......@@ -56,6 +57,9 @@ namespace pinocchio
typedef ForceTpl<Scalar,traits<Motion>::Options> Force;
typedef typename Motion::Vector6 Vector6;
typedef typename Motion::Vector3 Vector3;
typedef typename Eigen::Map<Vector3> MapVector3;
typedef typename Eigen::Ref<Vector3> RefVector3;
public:
......@@ -66,23 +70,28 @@ namespace pinocchio
.def(bp::init<>("Default constructor"))
.def(bp::init<Vector3,Vector3>
((bp::arg("linear"),bp::arg("angular")),
"Initialize from linear and angular components of a Motion vector (don(t mix the order)."))
"Initialize from linear and angular components of a Motion vector (don't mix the order)."))
.def(bp::init<Vector6>((bp::arg("vec")),"Init from a vector 6 [linear velocity, angular velocity]"))
.def(bp::init<Motion>((bp::arg("other")),"Copy constructor."))
.add_property("linear",
&MotionPythonVisitor::getLinear,
bp::make_function(&MotionPythonVisitor::getLinear,
bp::with_custodian_and_ward_postcall<0,1>()),
&MotionPythonVisitor::setLinear,
"Linear part of a *this, corresponding to the linear velocity in case of a Spatial velocity.")
.add_property("angular",
&MotionPythonVisitor::getAngular,
bp::make_function(&MotionPythonVisitor::getAngular,
bp::with_custodian_and_ward_postcall<0,1>()),
&MotionPythonVisitor::setAngular,
"Angular part of a *this, corresponding to the angular velocity in case of a Spatial velocity.")
.add_property("vector",
&MotionPythonVisitor::getVector,
bp::make_function((typename Motion::ToVectorReturnType (Motion::*)())&Motion::toVector,
bp::return_internal_reference<>()),
&MotionPythonVisitor::setVector,
"Returns the components of *this as a 6d vector.")
.add_property("np",&MotionPythonVisitor::getVector)
.add_property("np",
bp::make_function((typename Motion::ToVectorReturnType (Motion::*)())&Motion::toVector,
bp::return_internal_reference<>()))
.def("se3Action",&Motion::template se3Action<Scalar,Options>,
bp::args("self","M"),"Returns the result of the action of M on *this.")
......@@ -132,7 +141,8 @@ namespace pinocchio
.def("Zero",&Motion::Zero,"Returns a zero Motion.")
.staticmethod("Zero")
.def("__array__",&MotionPythonVisitor::getVector)
.def("__array__",bp::make_function((typename Motion::ToVectorReturnType (Motion::*)())&Motion::toVector,
bp::return_internal_reference<>()))
.def_pickle(Pickle())
;
......@@ -160,12 +170,11 @@ namespace pinocchio
{ return bp::make_tuple((Vector3)m.linear(),(Vector3)m.angular()); }
};
static Vector3 getLinear(const Motion & self) { return self.linear(); }
static RefVector3 getLinear(Motion & self) { return self.linear(); }
static void setLinear (Motion & self, const Vector3 & v) { self.linear(v); }
static Vector3 getAngular(const Motion & self) { return self.angular(); }
static RefVector3 getAngular(Motion & self) { return self.angular(); }
static void setAngular(Motion & self, const Vector3 & w) { self.angular(w); }
static Vector6 getVector(const Motion & self) { return self.toVector(); }
static void setVector(Motion & self, const Vector6 & v) { self = v; }
static void setZero(Motion & self) { self.setZero(); }
......@@ -173,9 +182,6 @@ namespace pinocchio
};
}} // namespace pinocchio::python
#endif // ifndef __pinocchio_python_se3_hpp__
#endif // ifndef __pinocchio_python_spatial_motion_hpp__
......@@ -3,10 +3,11 @@
// Copyright (c) 2016 Wandercraft, 86 rue de Paris 91400 Orsay, France.
//
#ifndef __pinocchio_python_se3_hpp__
#define __pinocchio_python_se3_hpp__
#ifndef __pinocchio_python_spatial_se3_hpp__
#define __pinocchio_python_spatial_se3_hpp__
#include <eigenpy/memory.hpp>
#include <eigenpy/eigen-to-python.hpp>
#include <boost/python/tuple.hpp>
#include "pinocchio/spatial/se3.hpp"
......@@ -46,7 +47,7 @@ namespace pinocchio
template<typename SE3>
struct SE3PythonVisitor
: public boost::python::def_visitor< SE3PythonVisitor<SE3> >
: public boost::python::def_visitor< SE3PythonVisitor<SE3> >
{
typedef typename SE3::Scalar Scalar;
typedef typename SE3::Matrix3 Matrix3;
......@@ -61,51 +62,49 @@ namespace pinocchio
{
cl
.def(bp::init<Matrix3,Vector3>
((bp::arg("Rotation matrix"),bp::arg("Translation vector")),
((bp::arg("rotation"),bp::arg("translation")),
"Initialize from a rotation matrix and a translation vector."))
.def(bp::init<Quaternion,Vector3>
((bp::arg("Quaternion"),bp::arg("Translation vector")),
((bp::arg("quat"),bp::arg("translation")),
"Initialize from a quaternion and a translation vector."))
.def(bp::init<int>((bp::arg("trivial arg (should be 1)")),"Init to identity."))
.def(bp::init<int>((bp::arg("int")),"Init to identity."))
.def(bp::init<SE3>((bp::arg("other")), "Copy constructor."))
.def(bp::init<Matrix4>
((bp::arg("Homogeneous matrix")),
"Initialize from a homogeneous matrix."))
((bp::arg("homegeneous_matrix")),
"Initialize from an homogeneous matrix."))
.add_property("rotation",
&getRotation,
bp::make_function((typename SE3::AngularRef (SE3::*)()) &SE3::rotation,bp::return_internal_reference<>()),
(void (SE3::*)(const Matrix3 &)) &SE3::rotation,
"The rotation part of the transformation."