Commit 257fd6da authored by Valenza Florian's avatar Valenza Florian
Browse files

[Python] Update python's API to C++'s one

parent d23a19f1
......@@ -85,6 +85,7 @@ namespace se3
.def("__add__",&ForcePythonVisitor::add)
.def("__sub__",&ForcePythonVisitor::subst)
.def("__neg__",&ForcePythonVisitor::neg)
.def(bp::self_ns::str(bp::self_ns::self))
.def(bp::self_ns::repr(bp::self_ns::self))
......@@ -108,6 +109,7 @@ namespace se3
static Force_fx add(const Force_fx & f1, const Force_fx & f2) { return f1+f2; }
static Force_fx subst(const Force_fx & f1, const Force_fx & f2) { return f1-f2; }
static Force_fx neg(const Force_fx & f1) { return -f1; }
static void expose()
{
......
......@@ -63,6 +63,9 @@ namespace se3
&FramePythonVisitor::setPlacementWrtParentJoint,
"placement in the parent joint local frame")
.def_readwrite("type", &Frame::type, "type of the frame")
.def(bp::self_ns::str(bp::self_ns::self))
.def(bp::self_ns::repr(bp::self_ns::self))
;
}
......
......@@ -110,18 +110,33 @@ namespace se3
bp::make_function(&GeometryDataPythonVisitor::oMg,
bp::return_internal_reference<>()),
"Vector of collision objects placement relative to the world.")
#ifdef WITH_HPP_FCL
.add_property("distance_results",
bp::make_function(&GeometryDataPythonVisitor::distance_results,
#ifdef WITH_HPP_FCL
.add_property("activeCollisionPairs",
bp::make_function(&GeometryDataPythonVisitor::activeCollisionPairs,
bp::return_internal_reference<>()))
.add_property("distanceRequest",
bp::make_function(&GeometryDataPythonVisitor::distanceRequest,
bp::return_internal_reference<>()),
"Defines what information should be computed by fcl for distances")
.add_property("distanceResults",
bp::make_function(&GeometryDataPythonVisitor::distanceResults,
bp::return_internal_reference<>()),
"Vector of distance results computed in ")
.add_property("CollisionRequest",
bp::make_function(&GeometryDataPythonVisitor::CollisionRequest,
bp::return_internal_reference<>()),
"Defines what information should be computed by fcl for collision tests")
.add_property("collision_results",
bp::make_function(&GeometryDataPythonVisitor::collision_results,
bp::return_internal_reference<>()) )
.add_property("activeCollisionPairs",
bp::make_function(&GeometryDataPythonVisitor::activeCollisionPairs,
bp::return_internal_reference<>()))
.add_property("radius",
bp::make_function(&GeometryDataPythonVisitor::radius,
bp::return_internal_reference<>()),
"Vector of radius of bodies, ie distance of the further point of the geometry object from the joint center ")
.def("fillInnerOuterObjectMaps", &GeometryDataPythonVisitor::fillInnerOuterObjectMaps,
bp::args("GeometryModel"),
"Fill inner and outer objects maps")
.def("activateCollisionPair",&GeometryDataPythonVisitor::activateCollisionPair,
bp::args("pairIndex (int)"),
"Activate pair ID <pairIndex> in geomModel.collisionPairs."
......@@ -142,9 +157,15 @@ namespace se3
static std::vector<SE3> & oMg(GeometryDataHandler & m) { return m->oMg; }
#ifdef WITH_HPP_FCL
static std::vector<fcl::DistanceResult> & distance_results( GeometryDataHandler & m ) { return m->distanceResults; }
static std::vector<fcl::CollisionResult> & collision_results( GeometryDataHandler & m ) { return m->collisionResults; }
static std::vector<bool> & activeCollisionPairs(GeometryDataHandler & m) { return m->activeCollisionPairs; }
static fcl::DistanceRequest & distanceRequest( GeometryDataHandler & m ) { return m->distanceRequest; }
static std::vector<fcl::DistanceResult> & distanceResults( GeometryDataHandler & m ) { return m->distanceResults; }
static fcl::CollisionRequest & CollisionRequest( GeometryDataHandler & m ) { return m->collisionRequest; }
static std::vector<fcl::CollisionResult> & collision_results( GeometryDataHandler & m ) { return m->collisionResults; }
static std::vector<double> & radius( GeometryDataHandler & m ) { return m->radius; }
static void fillInnerOuterObjectMaps(GeometryDataHandler & m, const GeometryModelHandler & model)
{m->fillInnerOuterObjectMaps(*model);}
static void activateCollisionPair(GeometryDataHandler & m,
Index pairID) { m->activateCollisionPair(pairID); }
......
......@@ -28,6 +28,8 @@
#include "pinocchio/multibody/geometry.hpp"
#include "pinocchio/bindings/python/model.hpp"
namespace se3
{
namespace python
......@@ -62,17 +64,19 @@ namespace se3
{
cl
.add_property("ngeoms", &GeometryModelPythonVisitor::ngeoms)
.def("getGeometryId",&GeometryModelPythonVisitor::getGeometryId)
.def("existGeometryName",&GeometryModelPythonVisitor::existGeometryName)
.def("getGeometryName",&GeometryModelPythonVisitor::getGeometryName)
.add_property("geometryObjects",
bp::make_function(&GeometryModelPythonVisitor::geometryObjects,
bp::return_internal_reference<>()) )
.def("addGeometryObject", &GeometryModelPythonVisitor::addGeometryObject,
bp::args("GeometryObject", "Model", "bool"),
"Add a GeometryObject to a GeometryModel")
.def("getGeometryId",&GeometryModelPythonVisitor::getGeometryId)
.def("existGeometryName",&GeometryModelPythonVisitor::existGeometryName)
.def("__str__",&GeometryModelPythonVisitor::toString)
#ifdef WITH_HPP_FCL
.add_property("collision_pairs",
bp::make_function(&GeometryModelPythonVisitor::collision_pairs,
.add_property("collisionPairs",
bp::make_function(&GeometryModelPythonVisitor::collisionPairs,
bp::return_internal_reference<>()),
"Vector of collision pairs.")
.def("addCollisionPair",&GeometryModelPythonVisitor::addCollisionPair,
......@@ -106,12 +110,14 @@ namespace se3
{ return gmodelPtr->getGeometryId(name); }
static bool existGeometryName(const GeometryModelHandler & gmodelPtr, const std::string & name)
{ return gmodelPtr->existGeometryName(name);}
static std::string getGeometryName(const GeometryModelHandler & gmodelPtr, const GeomIndex index)
{ return gmodelPtr->getGeometryName(index);}
static std::vector<GeometryObject> & geometryObjects( GeometryModelHandler & m ) { return m->geometryObjects; }
static GeomIndex addGeometryObject( GeometryModelHandler & m, GeometryObject gobject, const ModelHandler & model, const bool autofillJointParent)
{ return m-> addGeometryObject(gobject, *model, autofillJointParent); }
#ifdef WITH_HPP_FCL
static std::vector<CollisionPair> & collision_pairs( GeometryModelHandler & m )
static std::vector<CollisionPair> & collisionPairs( GeometryModelHandler & m )
{ return m->collisionPairs; }
static void addCollisionPair (GeometryModelHandler & m, const GeomIndex co1, const GeomIndex co2)
......
......@@ -135,6 +135,7 @@ namespace se3
// Class Methods
.def("addJoint",&ModelPythonVisitor::addJoint,bp::args("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.")
// ADD addJoint with limits ? See boost::python overloading/default parameters
.def("addJointFrame", &ModelPythonVisitor::addJointFrame, bp::args("jointIndex", "frameIndex"), "add the joint at index jointIndex as a frame to the frame tree")
.def("appendBodyToJoint",&ModelPythonVisitor::appendBodyToJoint,bp::args("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", &ModelPythonVisitor::addBodyFrame, bp::args("body_name", "parentJoint", "body_plaement", "previous_frame(parent frame)"), "add a body to the frame tree")
......@@ -188,6 +189,11 @@ namespace se3
return boost::apply_visitor(addJointVisitor(model,parent_id,joint_placement,joint_name), jmodel_variant);
}
static int addJointFrame( ModelHandler & m, const JointIndex jointIndex, int frameIndex)
{
return m->addJointFrame(jointIndex, frameIndex);
}
static void appendBodyToJoint(ModelHandler & model,
const JointIndex joint_parent_id,
const Inertia_fx & inertia,
......
......@@ -91,6 +91,7 @@ namespace se3
.def("__add__",&MotionPythonVisitor::add)
.def("__sub__",&MotionPythonVisitor::subst)
.def("__neg__",&MotionPythonVisitor::neg)
.def(bp::self_ns::str(bp::self_ns::self))
.def("Random",&Motion_fx::Random)
......@@ -113,6 +114,7 @@ namespace se3
static Motion_fx add( const Motion_fx& m1,const Motion_fx& m2 ) { return m1+m2; }
static Motion_fx subst( const Motion_fx& m1,const Motion_fx& m2 ) { return m1-m2; }
static Motion_fx neg(const Motion_fx & m1) { return -m1; }
static Motion_fx cross_motion( const Motion_fx& m1,const Motion_fx& m2 ) { return m1.cross(m2); }
static Force_fx cross_force( const Motion_fx& m,const Force_fx& f ) { return m.cross(f); }
......
......@@ -86,7 +86,9 @@ class ModelWrapper(object):
self.display.viewer.gui.addSphere(body_name, dimensions, color(body_color))
body_inertia.lever = lever.translation
joint_id = self.model.addJoint(parent, joint_model, joint_placement, joint_name)
self.model.appendBodyToJoint(joint_id, body_inertia, se3.SE3.Identity(), body_name)
self.model.appendBodyToJoint(joint_id, body_inertia, se3.SE3.Identity())
self.model.addJointFrame(joint_id, -1)
self.model.addBodyFrame(body_name, joint_id, se3.SE3.Identity(),-1)
self.visuals.append((body_name, joint_placement, lever))
self.data = self.model.createData()
if self.display:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment