task-joint-posture.hpp 6.59 KB
Newer Older
ggory15's avatar
ggory15 committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
//
// Copyright (c) 2018 CNRS
//
// This file is part of tsid
// tsid 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.
// tsid 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
// tsid If not, see
// <http://www.gnu.org/licenses/>.
//

ggory15's avatar
ggory15 committed
18
19
20
#ifndef __tsid_python_task_joint_hpp__
#define __tsid_python_task_joint_hpp__

21
#include "tsid/bindings/python/fwd.hpp"
ggory15's avatar
ggory15 committed
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48

#include "tsid/tasks/task-joint-posture.hpp"
#include "tsid/robots/robot-wrapper.hpp"
#include "tsid/trajectories/trajectory-base.hpp"
#include "tsid/math/constraint-equality.hpp"
#include "tsid/math/constraint-base.hpp"
namespace tsid
{
  namespace python
  {    
    namespace bp = boost::python;

    template<typename TaskJoint>
    struct TaskJointPosturePythonVisitor
    : public boost::python::def_visitor< TaskJointPosturePythonVisitor<TaskJoint> >
    {
      
      template<class PyClass>     
      

      void visit(PyClass& cl) const
      {
        cl
        .def(bp::init<std::string, robots::RobotWrapper &> ((bp::arg("name"), bp::arg("robot")), "Default Constructor"))
        .add_property("dim", &TaskJoint::dim, "return dimension size")
        .def("setReference", &TaskJointPosturePythonVisitor::setReference, bp::arg("ref"))
        .add_property("getDesiredAcceleration", bp::make_function(&TaskJointPosturePythonVisitor::getDesiredAcceleration, bp::return_value_policy<bp::copy_const_reference>()), "Return Acc_desired")
49
50
        .add_property("mask", bp::make_function(&TaskJointPosturePythonVisitor::getmask, bp::return_value_policy<bp::copy_const_reference>()), "Return mask")
        .def("setMask", &TaskJointPosturePythonVisitor::setmask, bp::arg("mask"))
ggory15's avatar
ggory15 committed
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
        .def("getAcceleration", &TaskJointPosturePythonVisitor::getAcceleration, bp::arg("dv"))
        .add_property("position_error", bp::make_function(&TaskJointPosturePythonVisitor::position_error, bp::return_value_policy<bp::copy_const_reference>()))
        .add_property("velocity_error", bp::make_function(&TaskJointPosturePythonVisitor::velocity_error, bp::return_value_policy<bp::copy_const_reference>()))
        .add_property("position", bp::make_function(&TaskJointPosturePythonVisitor::position, bp::return_value_policy<bp::copy_const_reference>()))
        .add_property("velocity", bp::make_function(&TaskJointPosturePythonVisitor::velocity, bp::return_value_policy<bp::copy_const_reference>()))
        .add_property("position_ref", bp::make_function(&TaskJointPosturePythonVisitor::position_ref, bp::return_value_policy<bp::copy_const_reference>()))
        .add_property("velocity_ref", bp::make_function(&TaskJointPosturePythonVisitor::velocity_ref, bp::return_value_policy<bp::copy_const_reference>()))
        .add_property("Kp", bp::make_function(&TaskJointPosturePythonVisitor::Kp, bp::return_value_policy<bp::copy_const_reference>()))
        .add_property("Kd", bp::make_function(&TaskJointPosturePythonVisitor::Kd, bp::return_value_policy<bp::copy_const_reference>()))
        .def("setKp", &TaskJointPosturePythonVisitor::setKp, bp::arg("Kp"))
        .def("setKd", &TaskJointPosturePythonVisitor::setKd, bp::arg("Kd"))
        .def("compute", &TaskJointPosturePythonVisitor::compute, bp::args("t", "q", "v", "data"))
        .def("getConstraint",  &TaskJointPosturePythonVisitor::getConstraint)
        .add_property("name", &TaskJointPosturePythonVisitor::name)
        ;
      }
      static std::string name(TaskJoint & self){
        std::string name = self.name();
        return name;
      }
71
      static math::ConstraintEquality compute(TaskJoint & self, const double t, const Eigen::VectorXd & q, const Eigen::VectorXd & v, pinocchio::Data & data){
ggory15's avatar
ggory15 committed
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
        self.compute(t, q, v, data);
        math::ConstraintEquality cons(self.getConstraint().name(), self.getConstraint().matrix(), self.getConstraint().vector());
        return cons;
      }
      static math::ConstraintEquality getConstraint(const TaskJoint & self){
        math::ConstraintEquality cons(self.getConstraint().name(), self.getConstraint().matrix(), self.getConstraint().vector());
        return cons;
      }
      static void setReference(TaskJoint & self, const trajectories::TrajectorySample & ref){
        self.setReference(ref);
      }
      static const Eigen::VectorXd & getDesiredAcceleration(const TaskJoint & self){
        return self.getDesiredAcceleration();
      }
      static const Eigen::VectorXd & getmask(const TaskJoint & self){
87
        return self.getMask();
ggory15's avatar
ggory15 committed
88
89
      }
      static void setmask (TaskJoint & self, const Eigen::VectorXd mask){
90
        return self.setMask(mask);
ggory15's avatar
ggory15 committed
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
      }
      static Eigen::VectorXd getAcceleration (TaskJoint & self, const Eigen::VectorXd dv){
        return self.getAcceleration(dv);
      }
      static const Eigen::VectorXd & position_error(const TaskJoint & self){
        return self.position_error();
      }
      static const Eigen::VectorXd & velocity_error(const TaskJoint & self){
        return self.velocity_error();
      }
      static const Eigen::VectorXd & position (const TaskJoint & self){
        return self.position();
      }
      static const Eigen::VectorXd & velocity (const TaskJoint & self){
        return self.velocity();
      }
      static const Eigen::VectorXd & position_ref (const TaskJoint & self){
        return self.position_ref();
      }
      static const Eigen::VectorXd & velocity_ref (const TaskJoint & self){
        return self.velocity_ref();
      }     
      static const Eigen::VectorXd & Kp (TaskJoint & self){
        return self.Kp();
      }  
      static const Eigen::VectorXd & Kd (TaskJoint & self){
        return self.Kd();
      }    
      static void setKp (TaskJoint & self, const::Eigen::VectorXd Kp){
        return self.Kp(Kp);
      }
      static void setKd (TaskJoint & self, const::Eigen::VectorXd Kv){
        return self.Kd(Kv);
      }
      static void expose(const std::string & class_name)
      {
        std::string doc = "TaskJoint info.";
        bp::class_<TaskJoint>(class_name.c_str(),
                          doc.c_str(),
                          bp::no_init)
        .def(TaskJointPosturePythonVisitor<TaskJoint>());

      //  bp::register_ptr_to_python< boost::shared_ptr<math::ConstraintBase> >();
      }
    };
  }
}


140
#endif // ifndef __tsid_python_task_joint_hpp__