expose-rpy.cpp
Go to the documentation of this file.
1 //
2 // Copyright (c) 2019-2021 CNRS INRIA
3 //
4 
7 #include "pinocchio/math/rpy.hpp"
8 
9 namespace pinocchio
10 {
11  namespace python
12  {
13  namespace bp = boost::python;
14 
15  context::Matrix3s rotate(const std::string & axis, const context::Scalar ang)
16  {
17  typedef context::Scalar Scalar;
18  if (axis.length() != 1U)
19  throw std::invalid_argument(std::string("Invalid axis: ").append(axis));
20  context::Vector3s u;
21  u.setZero();
22  const char axis_ = axis[0];
23  switch (axis_)
24  {
25  case 'x':
26  u[0] = Scalar(1);
27  break;
28  case 'y':
29  u[1] = Scalar(1);
30  break;
31  case 'z':
32  u[2] = Scalar(1);
33  break;
34  default:
35  throw std::invalid_argument(std::string("Invalid axis: ").append(1U, axis_));
36  }
37 
38  return context::AngleAxis(ang, u).matrix();
39  }
40 
41  void exposeRpy()
42  {
43  using namespace Eigen;
44  using namespace pinocchio::rpy;
45 
46  {
47  // using the rpy scope
48  bp::scope current_scope = getOrCreatePythonNamespace("rpy");
49 
50  bp::def(
51  "rpyToMatrix",
52  static_cast<context::Matrix3s (*)(
53  const context::Scalar &, const context::Scalar &, const context::Scalar &)>(
54  &rpyToMatrix),
55  bp::args("roll", "pitch", "yaw"),
56  "Given (r, p, y), the rotation is given as R = R_z(y)R_y(p)R_x(r),"
57  " where R_a(theta) denotes the rotation of theta radians axis a");
58 
59  bp::def(
60  "rpyToMatrix",
61  static_cast<context::Matrix3s (*)(const MatrixBase<context::Vector3s> &)>(&rpyToMatrix),
62  bp::arg("rpy"),
63  "Given (r, p, y), the rotation is given as R = R_z(y)R_y(p)R_x(r),"
64  " where R_a(theta) denotes the rotation of theta radians axis a");
65 
66  bp::def(
67  "matrixToRpy",
68  // &matrixToRpy<context::Matrix3s>, TODO: change internal routines to
69  // make them compliant with Autodiff Frameworks
70  &matrixToRpy<Eigen::Matrix3d>, bp::arg("R"),
71  "Given a rotation matrix R, the angles (r, p, y) are given so that R = "
72  "R_z(y)R_y(p)R_x(r),"
73  " where R_a(theta) denotes the rotation of theta radians axis a."
74  " The angles are guaranteed to be in the ranges: r in [-pi,pi],"
75  " p in[-pi/2,pi/2], y in [-pi,pi]");
76 
77  bp::def(
78  "rotate", &rotate, bp::args("axis", "angle"),
79  "Rotation matrix corresponding to a rotation about x, y or z"
80  " e.g. R = rot('x', pi / 4): rotate pi/4 rad about x axis");
81 
82  bp::def(
83  "computeRpyJacobian", &computeRpyJacobian<context::Vector3s>,
84  (bp::arg("rpy"), bp::arg("reference_frame") = LOCAL),
85  "Compute the Jacobian of the Roll-Pitch-Yaw conversion"
86  " Given phi = (r, p, y) such that that R = R_z(y)R_y(p)R_x(r)"
87  " and reference frame F (either LOCAL or WORLD),"
88  " the Jacobian is such that omega_F = J_F(phi)phidot,"
89  " where omega_F is the angular velocity expressed in frame F"
90  " and J_F is the Jacobian computed with reference frame F"
91  "\nParameters:\n"
92  "\trpy Roll-Pitch-Yaw vector"
93  "\treference_frame Reference frame in which the angular velocity is expressed."
94  " Notice LOCAL_WORLD_ALIGNED is equivalent to WORLD");
95 
96  bp::def(
97  "computeRpyJacobianInverse", &computeRpyJacobianInverse<context::Vector3s>,
98  (bp::arg("rpy"), bp::arg("reference_frame") = LOCAL),
99  "Compute the inverse Jacobian of the Roll-Pitch-Yaw conversion"
100  " Given phi = (r, p, y) such that that R = R_z(y)R_y(p)R_x(r)"
101  " and reference frame F (either LOCAL or WORLD),"
102  " the Jacobian is such that omega_F = J_F(phi)phidot,"
103  " where omega_F is the angular velocity expressed in frame F"
104  " and J_F is the Jacobian computed with reference frame F"
105  "\nParameters:\n"
106  "\trpy Roll-Pitch-Yaw vector"
107  "\treference_frame Reference frame in which the angular velocity is expressed."
108  " Notice LOCAL_WORLD_ALIGNED is equivalent to WORLD");
109 
110  bp::def(
111  "computeRpyJacobianTimeDerivative",
112  &computeRpyJacobianTimeDerivative<context::Vector3s, context::Vector3s>,
113  (bp::arg("rpy"), bp::arg("rpydot"), bp::arg("reference_frame") = LOCAL),
114  "Compute the time derivative of the Jacobian of the Roll-Pitch-Yaw conversion"
115  " Given phi = (r, p, y) such that that R = R_z(y)R_y(p)R_x(r)"
116  " and reference frame F (either LOCAL or WORLD),"
117  " the Jacobian is such that omega_F = J_F(phi)phidot,"
118  " where omega_F is the angular velocity expressed in frame F"
119  " and J_F is the Jacobian computed with reference frame F"
120  "\nParameters:\n"
121  "\trpy Roll-Pitch-Yaw vector"
122  "\treference_frame Reference frame in which the angular velocity is expressed."
123  " Notice LOCAL_WORLD_ALIGNED is equivalent to WORLD");
124  }
125  }
126 
127  } // namespace python
128 } // namespace pinocchio
boost::python
Eigen
pinocchio::u
JointCollectionTpl const Eigen::MatrixBase< ConfigVectorIn1 > const Eigen::MatrixBase< ConfigVectorIn2 > const Scalar & u
Definition: joint-configuration.hpp:1139
pinocchio::python::Scalar
context::Scalar Scalar
Definition: admm-solver.cpp:29
pinocchio::python::getOrCreatePythonNamespace
boost::python::object getOrCreatePythonNamespace(const std::string &submodule_name)
Helper to create or simply return an existing namespace in Python.
Definition: namespace.hpp:34
python
axis
axis
pinocchio::rpy
Roll-pitch-yaw operations.
pinocchio::python::exposeRpy
void exposeRpy()
Definition: expose-rpy.cpp:41
pinocchio::python::rotate
context::Matrix3s rotate(const std::string &axis, const context::Scalar ang)
Definition: expose-rpy.cpp:15
ocp.U
U
Definition: ocp.py:80
pinocchio::rpy::rpyToMatrix
Eigen::Matrix< Scalar, 3, 3 > rpyToMatrix(const Scalar &r, const Scalar &p, const Scalar &y)
Convert from Roll, Pitch, Yaw to rotation Matrix.
boost::fusion::append
result_of::push_front< V const, T >::type append(T const &t, V const &v)
Append the element T at the front of boost fusion vector V.
Definition: fusion.hpp:32
fwd.hpp
rpy.hpp
pinocchio::python::context::AngleAxis
Eigen::AngleAxis< Scalar > AngleAxis
Definition: bindings/python/context/generic.hpp:50
pinocchio::python::context::Scalar
PINOCCHIO_PYTHON_SCALAR_TYPE Scalar
Definition: bindings/python/context/generic.hpp:37
pinocchio
Main pinocchio namespace.
Definition: timings.cpp:27
namespace.hpp
pinocchio::LOCAL
@ LOCAL
Definition: multibody/fwd.hpp:50


pinocchio
Author(s):
autogenerated on Sun Dec 22 2024 03:41:09