6 #ifndef __pinocchio_python_multibody_model_hpp__ 7 #define __pinocchio_python_multibody_model_hpp__ 11 #include "pinocchio/multibody/model.hpp" 12 #include "pinocchio/serialization/model.hpp" 14 #include <boost/python/overloads.hpp> 18 #include "pinocchio/algorithm/check.hpp" 35 BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(existFrame_overload,
Model::existFrame,1,2)
36 BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(addJointFrame_overload,
Model::addJointFrame,1,2)
38 template<typename
Model>
43 return bp::make_tuple();
49 return bp::make_tuple(bp::str(
str));
54 if(bp::len(tup) == 0 || bp::len(tup) > 1)
56 throw eigenpy::Exception(
"Pickle was not able to reconstruct the model from the loaded data.\n" 57 "The pickle data structure contains too many elements.");
60 bp::object py_obj = tup[0];
61 boost::python::extract<std::string> obj_as_string(py_obj.ptr());
62 if(obj_as_string.check())
64 const std::string
str = obj_as_string;
69 throw eigenpy::Exception(
"Pickle was not able to reconstruct the model from the loaded data.\n" 70 "The entry is not a string.");
79 template<
typename Model>
81 :
public bp::def_visitor< ModelPythonVisitor<Model> >
101 BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(addFrame_overload,
Model::addFrame,1,2)
106 template<class PyClass>
110 .def(bp::init<>(bp::arg(
"self"),
111 "Default constructor. Constructs an empty model."))
119 .add_property(
"inertias",&Model::inertias)
120 .add_property(
"jointPlacements",&Model::jointPlacements)
132 "Vector of rotor inertia parameters.")
134 "Vector of rotor gear ratio parameters.")
136 "Vector of joint friction parameters.")
138 "Vector of joint damping parameters.")
142 "Joint max velocity.")
144 "Limit for joint lower position.")
146 "Limit for joint upper position.")
149 "Vector of frames contained in the model.")
151 .def_readwrite(
"supports",
153 "Vector of supports. supports[j] corresponds to the list of joints on the path between\n" 154 "the current *j* to the root of the kinematic tree.")
156 .def_readwrite(
"subtrees",
158 "Vector of subtrees. subtree[j] corresponds to the subtree supported by the joint j.")
161 "Motion vector corresponding to the gravity field expressed in the world Frame.")
165 bp::args(
"self",
"parent_id",
"joint_model",
"joint_placement",
"joint_name"),
166 "Adds a joint to the kinematic tree. The joint is defined by its placement relative to its parent joint and its name.")
168 bp::args(
"self",
"parent_id",
"joint_model",
"joint_placement",
"joint_name",
169 "max_effort",
"max_velocity",
"min_config",
"max_config"),
170 "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." 171 "This signature also takes as input effort, velocity limits as well as the bounds on the joint configuration.")
173 bp::args(
"self",
"parent_id",
"joint_model",
"joint_placement",
"joint_name",
174 "max_effort",
"max_velocity",
"min_config",
"max_config",
175 "friction",
"damping"),
176 "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.\n" 177 "This signature also takes as input effort, velocity limits as well as the bounds on the joint configuration.\n" 178 "The user should also provide the friction and damping related to the joint.")
180 addJointFrame_overload(bp::args(
"self",
"joint_id",
"frame_id"),
181 "Add the joint provided by its joint_id as a frame to the frame tree.\n" 182 "The frame_id may be optionally provided."))
184 bp::args(
"self",
"joint_id",
"body_inertia",
"body_placement"),
185 "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.")
187 .def(
"addBodyFrame", &
Model::addBodyFrame, bp::args(
"self",
"body_name",
"parentJoint",
"body_placement",
"previous_frame"),
"add a body to the frame tree")
188 .def(
"getBodyId",&
Model::getBodyId, bp::args(
"self",
"name"),
"Return the index of a frame of type BODY given by its name")
189 .def(
"existBodyName", &
Model::existBodyName, bp::args(
"self",
"name"),
"Check if a frame of type BODY exists, given its name")
190 .def(
"getJointId",&
Model::getJointId, bp::args(
"self",
"name"),
"Return the index of a joint given by its name")
191 .def(
"existJointName", &
Model::existJointName, bp::args(
"self",
"name"),
"Check if a joint given by its name exists")
193 .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."))
195 .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."))
198 addFrame_overload((bp::arg(
"self"), bp::arg(
"frame"), bp::arg(
"append_inertia") =
true),
199 "Add a frame to the vector of frames. If append_inertia set to True, " 200 "the inertia value contained in frame will be added to the inertia supported by the parent joint."))
204 "Create a Data object for the given model.")
206 .def(
"check",(
bool (
Model::*)(
const Data &)
const) &
Model::check,bp::args(
"self",
"data"),
207 "Check consistency of data wrt model.")
208 .def(
"hasConfigurationLimit",&
Model::hasConfigurationLimit, bp::args(
"self"),
"Returns list of boolean if joints have configuration limit.")
211 .def(bp::self == bp::self)
212 .def(bp::self != bp::self)
222 return model.
addJoint(parent_id,jmodel,joint_placement,joint_name);
230 const VectorXs & max_effort,
231 const VectorXs & max_velocity,
232 const VectorXs & min_config,
233 const VectorXs & max_config)
235 return model.
addJoint(parent_id,jmodel,joint_placement,joint_name,
236 max_effort,max_velocity,min_config,max_config);
244 const VectorXs & max_effort,
245 const VectorXs & max_velocity,
246 const VectorXs & min_config,
247 const VectorXs & max_config,
248 const VectorXs & friction,
249 const VectorXs & damping)
251 return model.
addJoint(parent_id,jmodel,joint_placement,joint_name,
252 max_effort,max_velocity,min_config,max_config,
269 static Index
index(std::vector<T>
const& x,
273 for(
typename std::vector<T>::const_iterator it = x.begin(); it != x.end(); ++it, ++
i)
287 typedef bp::map_indexing_suite<ConfigVectorMap,false> map_indexing_suite;
289 serialize< std::vector<Index> >();
291 serialize< std::vector<IndexVector> >();
293 serialize< std::vector<std::string> >();
295 serialize< std::vector<bool> >();
297 serialize< std::vector<Scalar> >();
298 bp::class_<typename Model::ConfigVectorMap>(
"StdMap_String_VectorXd")
299 .
def(map_indexing_suite())
303 bp::class_<Model>(
"Model",
304 "Articulated Rigid Body model",
317 #endif // ifndef __pinocchio_python_multibody_model_hpp__
bool existBodyName(const std::string &name) const
Check if a body given by its name exists.
JointModelVector joints
Model of joint i, encapsulated in a JointModelAccessor.
FrameIndex addJointFrame(const JointIndex &joint_index, int previous_frame_index=-1)
Add a joint to the frame tree.
static void setstate(Model &model, bp::tuple tup)
static JointIndex addJoint2(Model &model, JointIndex parent_id, const JointModel &jmodel, const SE3 &joint_placement, const std::string &joint_name, const VectorXs &max_effort, const VectorXs &max_velocity, const VectorXs &min_config, const VectorXs &max_config, const VectorXs &friction, const VectorXs &damping)
bool existFrame(const std::string &name, const FrameType &type=(FrameType)(JOINT|FIXED_JOINT|BODY|OP_FRAME|SENSOR)) const
Checks if a frame given by its name exists.
Model::JointIndex JointIndex
A Plucker coordinate frame attached to a parent joint inside a kinematic tree.
int njoints
Number of joints.
std::vector< std::string > names
Name of joint i
void visit(PyClass &cl) const
ConfigVectorType lowerPositionLimit
Lower joint configuration limit.
static bool getstate_manages_dict()
static bp::tuple getstate(const Model &model)
Set the Python method str and repr to use the overloading operator<<.
FrameVector frames
Vector of operational frames registered on the model.
void def(const char *name, Func func)
std::vector< bool > hasConfigurationLimit()
Check if joints have configuration limits.
std::vector< int > nvs
Dimension of the joint i tangent subspace.
TangentVectorType rotorInertia
Vector of rotor inertia parameters.
bool existJointName(const std::string &name) const
Check if a joint given by its name exists.
static JointIndex addJoint1(Model &model, JointIndex parent_id, const JointModel &jmodel, const SE3 &joint_placement, const std::string &joint_name, const VectorXs &max_effort, const VectorXs &max_velocity, const VectorXs &min_config, const VectorXs &max_config)
std::vector< IndexVector > subtrees
Vector of joint subtrees. subtree[j] corresponds to the subtree supported by the joint j...
std::string saveToString() const
Saves a Derived object to a string.
ConfigVectorMap referenceConfigurations
Map of reference configurations, indexed by user given names.
int nframes
Number of operational frames.
std::string name
Model name;.
TangentVectorType rotorGearRatio
Vector of rotor gear ratio parameters.
Model::FrameIndex FrameIndex
pinocchio::FrameIndex FrameIndex
JointIndex addJoint(const JointIndex parent, const JointModel &joint_model, const SE3 &joint_placement, const std::string &joint_name)
Add a joint to the kinematic tree with infinite bounds.
std::vector< int > nqs
Dimension of the joint i configuration subspace.
static Data createData(const Model &model)
TangentVectorType friction
Vector of joint friction parameters.
std::vector< int > idx_qs
Starting index of the joint i in the configuration space.
std::vector< Index > IndexVector
int nbodies
Number of bodies.
pinocchio::JointIndex JointIndex
FrameIndex getFrameId(const std::string &name, const FrameType &type=(FrameType)(JOINT|FIXED_JOINT|BODY|OP_FRAME|SENSOR)) const
Returns the index of a frame given by its name.
static ::boost::python::class_< vector_type > expose(const std::string &class_name, const std::string &doc_string="")
Motion gravity
Spatial gravity of the model.
std::map< std::string, ConfigVectorType > ConfigVectorMap
Map between a string (key) and a configuration vector.
EIGEN_MAKE_ALIGNED_OPERATOR_NEW typedef _Scalar Scalar
Add the Python method copy to allow a copy of this by calling the copy constructor.
static bp::tuple getinitargs(const Model &)
FrameIndex addFrame(const Frame &frame, const bool append_inertia=true)
Adds a frame to the kinematic tree. The inertia stored within the frame will be happened to the inert...
Model::IndexVector IndexVector
Main pinocchio namespace.
std::vector< int > idx_vs
Starting index of the joint i in the tangent configuration space.
std::vector< bool > hasConfigurationLimitInTangent()
Check if joints have configuration limits.
TangentVectorType effortLimit
Vector of maximal joint torques.
Eigen::Matrix< Scalar, Eigen::Dynamic, 1, Options > VectorXs
JointIndex getJointId(const std::string &name) const
Return the index of a joint given by its name.
void loadFromString(const std::string &str)
Loads a Derived object from a string.
TangentVectorType damping
Vector of joint damping parameters.
std::vector< JointIndex > parents
Joint parent of joint i, denoted li (li==parents[i]).
int nv
Dimension of the velocity vector space.
TangentVectorType velocityLimit
Vector of maximal joint velocities.
FrameIndex getBodyId(const std::string &name) const
Return the index of a body given by its name.
ConfigVectorType upperPositionLimit
Upper joint configuration limit.
static Index index(std::vector< T > const &x, typename std::vector< T >::value_type const &v)
Provide equivalent to python list index function for vectors.
#define EIGENPY_DEFINE_STRUCT_ALLOCATOR_SPECIALIZATION(...)
static JointIndex addJoint0(Model &model, JointIndex parent_id, const JointModel &jmodel, const SE3 &joint_placement, const std::string &joint_name)
std::vector< IndexVector > supports
Vector of joint supports. supports[j] corresponds to the collection of all joints located on the path...
void appendBodyToJoint(const JointIndex joint_index, const Inertia &Y, const SE3 &body_placement=SE3::Identity())
Append a body to a given joint of the kinematic tree.
Create a pickle interface for the std::map and aligned map.
JointCollectionTpl & model
int nq
Dimension of the configuration vector representation.
bool check() const
Run check(fusion::list) with DEFAULT_CHECKERS as argument.
FrameIndex addBodyFrame(const std::string &body_name, const JointIndex &parentJoint, const SE3 &body_placement=SE3::Identity(), int previousFrame=-1)
Add a body to the frame tree.