bindings/python/robots/robot-wrapper.hpp
Go to the documentation of this file.
1 //
2 // Copyright (c) 2018 CNRS
3 //
4 // This file is part of tsid
5 // tsid is free software: you can redistribute it
6 // and/or modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation, either version
8 // 3 of the License, or (at your option) any later version.
9 // tsid is distributed in the hope that it will be
10 // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
11 // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // General Lesser Public License for more details. You should have
13 // received a copy of the GNU Lesser General Public License along with
14 // tsid If not, see
15 // <http://www.gnu.org/licenses/>.
16 //
17 
18 #ifndef __tsid_python_robot_wrapper_hpp__
19 #define __tsid_python_robot_wrapper_hpp__
20 
22 
24 
25 namespace tsid {
26 namespace python {
27 namespace bp = boost::python;
28 
29 template <typename Robot>
31  : public boost::python::def_visitor<RobotPythonVisitor<Robot> > {
32  typedef std::vector<std::string> std_vec;
33  typedef Eigen::Matrix<double, 3, Eigen::Dynamic> Matrix3x;
34 
35  template <class PyClass>
36 
37  void visit(PyClass &cl) const {
38  cl
39  .def(bp::init<std::string, std_vec, bool>(
40  (bp::arg("filename"), bp::arg("package_dir"), bp::arg("verbose")),
41  "Default constructor without RootJoint."))
42  .def(bp::init<std::string, std_vec, pinocchio::JointModelVariant &,
43  bool>((bp::arg("filename"), bp::arg("package_dir"),
44  bp::arg("roottype"), bp::arg("verbose")),
45  "Default constructor with RootJoint."))
46  .def(bp::init<pinocchio::Model, bool>(
47  (bp::arg("Pinocchio Model"), bp::arg("verbose")),
48  "Default constructor from pinocchio model without RootJoint."))
50  bool>(
51  (bp::arg("Pinocchio Model"), bp::arg("rootJoint"),
52  bp::arg("verbose")),
53  "Default constructor from pinocchio model with RootJoint."))
54  .def("__init__",
55  bp::make_constructor(RobotPythonVisitor<Robot>::makeClass))
56  .add_property("nq", &Robot::nq)
57  .add_property("nv", &Robot::nv)
58  .add_property("na", &Robot::na)
59  .add_property("nq_actuated", &Robot::nq_actuated)
60  .add_property("is_fixed_base", &Robot::is_fixed_base)
61 
62  .def("model", &RobotPythonVisitor::model)
63  .def("data", &RobotPythonVisitor::data)
64 
65  .add_property("rotor_inertias", &RobotPythonVisitor::rotor_inertias)
66  .add_property("gear_ratios", &RobotPythonVisitor::gear_ratios)
67  .def("set_rotor_inertias", &RobotPythonVisitor::set_rotor_inertias,
68  bp::arg("inertia vector"))
69  .def("set_gear_ratios", &RobotPythonVisitor::set_gear_ratios,
70  bp::arg("gear ratio vector"))
71 
72  .def("computeAllTerms", &RobotPythonVisitor::computeAllTerms,
73  bp::args("data", "q", "v"), "compute all dynamics")
74  .def("com", &RobotPythonVisitor::com, bp::arg("data"))
75  .def("com_vel", &RobotPythonVisitor::com_vel, bp::arg("data"))
76  .def("com_acc", &RobotPythonVisitor::com_acc, bp::arg("data"))
77  .def("Jcom", &RobotPythonVisitor::Jcom, bp::arg("data"))
78  .def("mass", &RobotPythonVisitor::mass, bp::arg("data"))
79  .def("nonLinearEffect", &RobotPythonVisitor::nonLinearEffects,
80  bp::arg("data"))
81  .def("position", &RobotPythonVisitor::position,
82  bp::args("data", "index"))
83  .def("velocity", &RobotPythonVisitor::velocity,
84  bp::args("data", "index"))
85  .def("acceleration", &RobotPythonVisitor::acceleration,
86  bp::args("data", "index"))
87 
88  .def("framePosition", &RobotPythonVisitor::framePosition,
89  bp::args("data", "index"))
90  .def("frameVelocity", &RobotPythonVisitor::frameVelocity,
91  bp::args("data", "index"))
92  .def("frameAcceleration", &RobotPythonVisitor::frameAcceleration,
93  bp::args("data", "index"))
94  .def("frameClassicAcceleration",
96  bp::args("data", "index"))
97  .def("frameVelocityWorldOriented",
99  bp::args("data", "index"))
100  .def("frameAccelerationWorldOriented",
102  bp::args("data", "index"))
103  .def("frameClassicAccelerationWorldOriented",
105  bp::args("data", "index"))
106  .def("angularMomentumTimeVariation",
108  .def("setGravity", &RobotPythonVisitor::setGravity, bp::arg("gravity"));
109  }
110 
111  static boost::shared_ptr<Robot> makeClass(
112  const std::string &filename, const std::vector<std::string> &stdvec,
113  bp::object &bpObject, bool verbose) {
114  pinocchio::JointModelFreeFlyer root_joint =
115  bp::extract<pinocchio::JointModelFreeFlyer>(bpObject)();
116  boost::shared_ptr<Robot> p(
117  new tsid::robots::RobotWrapper(filename, stdvec, root_joint, verbose));
118  return p;
119  }
120 
121  static pinocchio::Model model(const Robot &self) { return self.model(); }
122  static pinocchio::Data data(const Robot &self) {
123  pinocchio::Data data(self.model());
124  return data;
125  }
126  static Eigen::VectorXd rotor_inertias(const Robot &self) {
127  return self.rotor_inertias();
128  }
129  static Eigen::VectorXd gear_ratios(const Robot &self) {
130  return self.gear_ratios();
131  }
132  static bool set_rotor_inertias(Robot &self, Eigen::VectorXd &rotor_inertias) {
133  return self.rotor_inertias(rotor_inertias);
134  }
135  static bool set_gear_ratios(Robot &self, Eigen::VectorXd &gear_ratios) {
136  return self.gear_ratios(gear_ratios);
137  }
138 
139  static Eigen::Vector3d com(const Robot &self, const pinocchio::Data &data) {
140  return self.com(data);
141  }
142  static Eigen::Vector3d com_vel(const Robot &self,
143  const pinocchio::Data &data) {
144  return self.com_vel(data);
145  }
146  static Eigen::Vector3d com_acc(const Robot &self,
147  const pinocchio::Data &data) {
148  return self.com_acc(data);
149  }
150  static Matrix3x Jcom(const Robot &self, const pinocchio::Data &data) {
151  return self.Jcom(data);
152  }
153  static void computeAllTerms(const Robot &self, pinocchio::Data &data,
154  const Eigen::VectorXd &q,
155  const Eigen::VectorXd &v) {
156  self.computeAllTerms(data, q, v);
157  }
158  static Eigen::MatrixXd mass(Robot &self, pinocchio::Data &data) {
159  return self.mass(data);
160  }
161  static Eigen::VectorXd nonLinearEffects(const Robot &self,
162  const pinocchio::Data &data) {
163  return self.nonLinearEffects(data);
164  }
165  static pinocchio::SE3 position(const Robot &self, const pinocchio::Data &data,
166  const pinocchio::Model::JointIndex &index) {
167  return self.position(data, index);
168  }
169  static pinocchio::Motion velocity(const Robot &self,
170  const pinocchio::Data &data,
171  const pinocchio::Model::JointIndex &index) {
172  return self.velocity(data, index);
173  }
175  const Robot &self, const pinocchio::Data &data,
176  const pinocchio::Model::JointIndex &index) {
177  return self.acceleration(data, index);
178  }
180  const Robot &self, const pinocchio::Data &data,
181  const pinocchio::Model::FrameIndex &index) {
182  return self.framePosition(data, index);
183  }
185  const Robot &self, const pinocchio::Data &data,
186  const pinocchio::Model::FrameIndex &index) {
187  return self.frameVelocity(data, index);
188  }
190  const Robot &self, const pinocchio::Data &data,
191  const pinocchio::Model::FrameIndex &index) {
192  return self.frameAcceleration(data, index);
193  }
195  const Robot &self, const pinocchio::Data &data,
196  const pinocchio::Model::FrameIndex &index) {
197  return self.frameClassicAcceleration(data, index);
198  }
200  const Robot &self, const pinocchio::Data &data,
201  const pinocchio::Model::FrameIndex &index) {
202  return self.frameVelocityWorldOriented(data, index);
203  }
205  const Robot &self, const pinocchio::Data &data,
206  const pinocchio::Model::FrameIndex &index) {
207  return self.frameAccelerationWorldOriented(data, index);
208  }
210  const Robot &self, const pinocchio::Data &data,
211  const pinocchio::Model::FrameIndex &index) {
212  return self.frameClassicAccelerationWorldOriented(data, index);
213  }
214  static Eigen::Vector3d angularMomentumTimeVariation(
215  const Robot &self, const pinocchio::Data &data) {
216  return self.angularMomentumTimeVariation(data);
217  }
218  static void setGravity(Robot &self, const pinocchio::Motion &gravity) {
219  return self.setGravity(gravity);
220  }
221  static void expose(const std::string &class_name) {
222  std::string doc = "Robot Wrapper info.";
223  bp::class_<Robot>(class_name.c_str(), doc.c_str(), bp::no_init)
225  ;
226  bp::enum_<robots::RobotWrapper::RootJointType>("RootJointType")
227  .value("FIXED_BASE_SYSTEM", robots::RobotWrapper::FIXED_BASE_SYSTEM)
228  .value("FLOATING_BASE_SYSTEM",
230  .export_values();
231  }
232 };
233 } // namespace python
234 } // namespace tsid
235 
236 #endif // ifndef __tsid_python_robot_wrapper_hpp__
static Eigen::VectorXd rotor_inertias(const Robot &self)
enum tsid::robots::RobotWrapper::e_RootJointType RootJointType
static Eigen::Vector3d com_vel(const Robot &self, const pinocchio::Data &data)
static pinocchio::SE3 position(const Robot &self, const pinocchio::Data &data, const pinocchio::Model::JointIndex &index)
void def(const char *name, Func func)
static Eigen::VectorXd gear_ratios(const Robot &self)
static pinocchio::Motion velocity(const Robot &self, const pinocchio::Data &data, const pinocchio::Model::JointIndex &index)
Eigen::Matrix< double, 3, Eigen::Dynamic > Matrix3x
float value
pinocchio::FrameIndex FrameIndex
static Eigen::Vector3d angularMomentumTimeVariation(const Robot &self, const pinocchio::Data &data)
static bool set_gear_ratios(Robot &self, Eigen::VectorXd &gear_ratios)
static Matrix3x Jcom(const Robot &self, const pinocchio::Data &data)
static void computeAllTerms(const Robot &self, pinocchio::Data &data, const Eigen::VectorXd &q, const Eigen::VectorXd &v)
pinocchio::JointIndex JointIndex
int nv
Definition: ex_4_conf.py:25
static pinocchio::Data data(const Robot &self)
static boost::shared_ptr< Robot > makeClass(const std::string &filename, const std::vector< std::string > &stdvec, bp::object &bpObject, bool verbose)
static Eigen::Vector3d com(const Robot &self, const pinocchio::Data &data)
static Eigen::Vector3d com_acc(const Robot &self, const pinocchio::Data &data)
static pinocchio::Motion frameClassicAcceleration(const Robot &self, const pinocchio::Data &data, const pinocchio::Model::FrameIndex &index)
static pinocchio::Model model(const Robot &self)
void init(bool compute_local_aabb=true)
static pinocchio::Motion frameClassicAccelerationWorldOriented(const Robot &self, const pinocchio::Data &data, const pinocchio::Model::FrameIndex &index)
Wrapper for a robot based on pinocchio.
static Eigen::VectorXd nonLinearEffects(const Robot &self, const pinocchio::Data &data)
static pinocchio::Motion frameAccelerationWorldOriented(const Robot &self, const pinocchio::Data &data, const pinocchio::Model::FrameIndex &index)
static Eigen::MatrixXd mass(Robot &self, pinocchio::Data &data)
JointCollectionDefault::JointModelVariant JointModelVariant
static void setGravity(Robot &self, const pinocchio::Motion &gravity)
static pinocchio::Motion frameVelocityWorldOriented(const Robot &self, const pinocchio::Data &data, const pinocchio::Model::FrameIndex &index)
p
static void expose(const std::string &class_name)
static pinocchio::Motion acceleration(const Robot &self, const pinocchio::Data &data, const pinocchio::Model::JointIndex &index)
static bool set_rotor_inertias(Robot &self, Eigen::VectorXd &rotor_inertias)
static pinocchio::Motion frameAcceleration(const Robot &self, const pinocchio::Data &data, const pinocchio::Model::FrameIndex &index)
static pinocchio::SE3 framePosition(const Robot &self, const pinocchio::Data &data, const pinocchio::Model::FrameIndex &index)
static pinocchio::Motion frameVelocity(const Robot &self, const pinocchio::Data &data, const pinocchio::Model::FrameIndex &index)


tsid
Author(s): Andrea Del Prete, Justin Carpentier
autogenerated on Sun Jul 2 2023 02:21:51