From 4cf7492042a80c39bcc255aa9b94b9373f218de3 Mon Sep 17 00:00:00 2001
From: Olivier Stasse <ostasse@laas.fr>
Date: Mon, 14 Oct 2019 16:27:43 +0200
Subject: [PATCH] [wip/py-tsid] Fix bindings problem with tsid.

---
 py-tsid/Makefile         |   1 +
 py-tsid/distinfo         |   2 +
 py-tsid/patches/patch-ad | 113 +++++++++++++++++++++++++++++++++++++++
 py-tsid/patches/patch-ae |  16 ++++++
 4 files changed, 132 insertions(+)
 create mode 100644 py-tsid/patches/patch-ad
 create mode 100644 py-tsid/patches/patch-ae

diff --git a/py-tsid/Makefile b/py-tsid/Makefile
index d08c2102..7474b506 100644
--- a/py-tsid/Makefile
+++ b/py-tsid/Makefile
@@ -5,6 +5,7 @@
 ORG=			stack-of-tasks
 NAME=			tsid
 VERSION=		1.2.1
+PKGREVISION=		1
 
 CATEGORIES=		wip
 COMMENT=		Efficient Inverse Dynamics based on Pinocchio (python bindings)
diff --git a/py-tsid/distinfo b/py-tsid/distinfo
index 45b97c29..60e6e6a5 100644
--- a/py-tsid/distinfo
+++ b/py-tsid/distinfo
@@ -4,3 +4,5 @@ Size (tsid-1.2.1.tar.gz) = 9247070 bytes
 SHA1 (patch-aa) = 5794c89861c6a84d47428939af6d19da36930631
 SHA1 (patch-ab) = 4af606a78e78c4e14c489e0b86b9eb4d8aca03f3
 SHA1 (patch-ac) = c5625ba8c746eb5e04d63e258171d4f947aa90ed
+SHA1 (patch-ad) = 50a7fa80e9dd0e5d7d4a8f07716119a4f3149011
+SHA1 (patch-ae) = 0361dfe851401d831c1a150c246ef1ec5d044969
diff --git a/py-tsid/patches/patch-ad b/py-tsid/patches/patch-ad
new file mode 100644
index 00000000..a55da42f
--- /dev/null
+++ b/py-tsid/patches/patch-ad
@@ -0,0 +1,113 @@
+--- bindings/python/robots/robot-wrapper.hpp
++++ bindings/python/robots/robot-wrapper.hpp
+@@ -23,15 +23,17 @@
+ #include <string>
+ #include <eigenpy/eigenpy.hpp>
+ #include <boost/python/suite/indexing/vector_indexing_suite.hpp>
++#include <boost/python/make_constructor.hpp>
+ 
++#include <pinocchio/bindings/python/parsers/parsers.hpp>
+ #include "tsid/robots/robot-wrapper.hpp"
+ 
+ namespace tsid
+ {
+   namespace python
+-  {    
++  {
+     namespace bp = boost::python;
+-    
++
+     template<typename Robot>
+     struct RobotPythonVisitor
+     : public boost::python::def_visitor< RobotPythonVisitor<Robot> >
+@@ -39,18 +41,19 @@ namespace tsid
+       typedef std::vector<std::string> std_vec;
+       typedef Eigen::Matrix<double,3,Eigen::Dynamic> Matrix3x;
+ 
+-      template<class PyClass>     
++      template<class PyClass >
+ 
+       void visit(PyClass& cl) const
+       {
+         cl
+         .def(bp::init<std::string, std_vec, bool>((bp::arg("filename"), bp::arg("package_dir"), bp::arg("verbose")), "Default constructor without RootJoint."))
+         .def(bp::init<pinocchio::Model, bool>((bp::arg("Pinocchio Model"), bp::arg("verbose")), "Default constructor from pinocchio model"))
+-        .def(bp::init<std::string, std_vec, pinocchio::JointModelVariant, bool>((bp::arg("filename"), bp::arg("package_dir"), bp::arg("roottype"), bp::arg("verbose")), "Default constructor without RootJoint."))
++        .def(bp::init<std::string, std_vec, pinocchio::JointModelVariant &, bool>((bp::arg("filename"), bp::arg("package_dir"), bp::arg("roottype"), bp::arg("verbose")), "Default constructor without RootJoint."))
++        .def("__init__",bp::make_constructor(RobotPythonVisitor<Robot> ::makeClass))
+         .add_property("nq", &Robot::nq)
+         .add_property("nv", &Robot::nv)
+         .add_property("na", &Robot::na)
+-        
++
+         .def("model", &RobotPythonVisitor::model)
+         .def("data", &RobotPythonVisitor::data)
+ 
+@@ -58,18 +61,18 @@ namespace tsid
+         .add_property("gear_ratios", &RobotPythonVisitor::gear_ratios)
+         .def("set_rotor_inertias", &RobotPythonVisitor::set_rotor_inertias, bp::arg("inertia vector"))
+         .def("set_gear_ratios", &RobotPythonVisitor::set_gear_ratios, bp::arg("gear ratio vector"))
+-        
++
+         .def("computeAllTerms", &RobotPythonVisitor::computeAllTerms, bp::args("data", "q", "v"), "compute all dynamics")
+         .def("com", &RobotPythonVisitor::com, bp::arg("data"))
+         .def("com_vel", &RobotPythonVisitor::com_vel, bp::arg("data"))
+         .def("com_acc", &RobotPythonVisitor::com_acc, bp::arg("data"))
+         .def("Jcom", &RobotPythonVisitor::Jcom, bp::arg("data"))
+-        .def("mass", &RobotPythonVisitor::mass, bp::arg("data")) 
++        .def("mass", &RobotPythonVisitor::mass, bp::arg("data"))
+         .def("nonLinearEffect", &RobotPythonVisitor::nonLinearEffects, bp::arg("data"))
+-        .def("position", &RobotPythonVisitor::position, bp::args("data", "index")) 
++        .def("position", &RobotPythonVisitor::position, bp::args("data", "index"))
+         .def("velocity", &RobotPythonVisitor::velocity, bp::args("data", "index"))
+         .def("acceleration", &RobotPythonVisitor::acceleration, bp::args("data", "index"))
+-        
++
+         .def("framePosition", &RobotPythonVisitor::framePosition, bp::args("data", "index"))
+         .def("frameVelocity", &RobotPythonVisitor::frameVelocity, bp::args("data", "index"))
+         .def("frameAcceleration", &RobotPythonVisitor::frameAcceleration, bp::args("data", "index"))
+@@ -77,9 +80,27 @@ namespace tsid
+         .def("frameVelocityWorldOriented", &RobotPythonVisitor::frameVelocityWorldOriented, bp::args("data", "index"))
+         .def("frameAccelerationWorldOriented", &RobotPythonVisitor::frameAccelerationWorldOriented, bp::args("data", "index"))
+         .def("frameClassicAccelerationWorldOriented", &RobotPythonVisitor::frameClassicAccelerationWorldOriented, bp::args("data", "index"))
+-   
++
+         ;
+       }
++
++      static boost::shared_ptr<Robot> makeClass(const std::string &filename,
++                                                const std::vector<std::string>
++                                                &stdvec,
++                                                bp::object & bpObject,
++                                                bool verbose)
++      {
++        std::cout << "Before extraction " << std::endl;
++        pinocchio::JointModelFreeFlyer root_joint =
++            bp::extract<pinocchio::JointModelFreeFlyer>(bpObject)();
++        std::cout << "After extraction " << std::endl;
++        boost::shared_ptr<Robot> p(new tsid::robots::RobotWrapper(filename,
++                                                                  stdvec,
++                                                                  root_joint,
++                                                                  verbose));
++        return p;
++      }
++
+       static pinocchio::Model model (const Robot & self){
+         return self.model();
+       }
+@@ -108,10 +129,10 @@ namespace tsid
+       }
+       static Eigen::Vector3d com_acc (const Robot & self, const pinocchio::Data & data){
+         return self.com_acc(data);
+-      } 
++      }
+       static Matrix3x Jcom (const Robot & self, const pinocchio::Data & data){
+         return self.Jcom(data);
+-      } 
++      }
+       static void computeAllTerms (const Robot & self, pinocchio::Data & data, const Eigen::VectorXd & q, const Eigen::VectorXd & v){
+          self.computeAllTerms(data, q, v);
+       }
+-- 
+2.7.4
+
diff --git a/py-tsid/patches/patch-ae b/py-tsid/patches/patch-ae
new file mode 100644
index 00000000..07867499
--- /dev/null
+++ b/py-tsid/patches/patch-ae
@@ -0,0 +1,16 @@
+--- bindings/python/robots/robot-wrapper.hpp
++++ bindings/python/robots/robot-wrapper.hpp
+@@ -90,10 +90,8 @@ namespace tsid
+                                                 bp::object & bpObject,
+                                                 bool verbose)
+       {
+-        std::cout << "Before extraction " << std::endl;
+         pinocchio::JointModelFreeFlyer root_joint =
+             bp::extract<pinocchio::JointModelFreeFlyer>(bpObject)();
+-        std::cout << "After extraction " << std::endl;
+         boost::shared_ptr<Robot> p(new tsid::robots::RobotWrapper(filename,
+                                                                   stdvec,
+                                                                   root_joint,
+-- 
+2.7.4
+
-- 
GitLab