Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
pinocchio
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Stack Of Tasks
pinocchio
Commits
9d66e32e
Commit
9d66e32e
authored
5 years ago
by
Gabriele Buondonno
Committed by
Gabriele Buondonno
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
[math] matrixToRpy
parent
38487dcc
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/math/rpy.hpp
+36
-0
36 additions, 0 deletions
src/math/rpy.hpp
unittest/rpy.cpp
+15
-0
15 additions, 0 deletions
unittest/rpy.cpp
with
51 additions
and
0 deletions
src/math/rpy.hpp
+
36
−
0
View file @
9d66e32e
...
...
@@ -60,6 +60,42 @@ namespace pinocchio
return
rpyToMatrix
(
v
[
0
],
v
[
1
],
v
[
2
]);
}
///
/// \brief Convert from Transformation Matrix to Roll, Pitch, Yaw
///
/// Given a rotation matrix \f$R\f$, the angles \f$r, p, y\f$ are given
/// so that \f$ R = R_z(y)R_y(p)R_x(r) \f$,
/// where \f$R_{\alpha}(\theta)\f$ denotes the rotation of \f$\theta\f$ degrees
/// around axis \f$\alpha\f$.
/// The angles are guaranteed to be in the ranges \f$r\in[-\pi,\pi]\f$
/// \f$p\in[-\frac{\pi}{2},\frac{\pi}{2}]\f$ \f$y\in[-\pi,\pi]\f$.
/// As this is a specialized implementation, it is expected to be very efficient.
///
/// \warning the method assumes \f$R\f$ is a rotation matrix. If it is not, the result is undefined.
///
template
<
typename
Matrix3Like
>
Eigen
::
Matrix
<
typename
Matrix3Like
::
Scalar
,
3
,
1
,
PINOCCHIO_EIGEN_PLAIN_TYPE
(
Matrix3Like
)
::
Options
>
matrixToRpy
(
const
Eigen
::
MatrixBase
<
Matrix3Like
>
&
R
)
{
PINOCCHIO_ASSERT_MATRIX_SPECIFIC_SIZE
(
Matrix3Like
,
R
,
3
,
3
);
typedef
typename
Matrix3Like
::
Scalar
Scalar
;
typedef
Eigen
::
Matrix
<
Scalar
,
3
,
1
>
ResultType
;
ResultType
res
;
Scalar
m
=
sqrt
(
R
(
2
,
1
)
*
R
(
2
,
1
)
+
R
(
2
,
2
)
*
R
(
2
,
2
));
Scalar
p
=
atan2
(
-
R
(
2
,
0
),
m
);
Scalar
r
,
y
;
if
(
fabs
(
fabs
(
p
)
-
M_PI
/
2.
)
<
0.001
)
{
r
=
0
;
y
=
-
atan2
(
R
(
0
,
1
),
R
(
1
,
1
));
}
else
{
y
=
atan2
(
R
(
1
,
0
),
R
(
0
,
0
));
r
=
atan2
(
R
(
2
,
1
),
R
(
2
,
2
));
}
res
<<
r
,
p
,
y
;
return
res
;
}
}
// namespace rpy
}
#endif //#ifndef __pinocchio_math_rpy_hpp__
This diff is collapsed.
Click to expand it.
unittest/rpy.cpp
+
15
−
0
View file @
9d66e32e
...
...
@@ -34,5 +34,20 @@ BOOST_AUTO_TEST_CASE(test_rpyToMatrix)
BOOST_CHECK
(
Rv
.
isApprox
(
R_Eig
));
}
BOOST_AUTO_TEST_CASE
(
test_matrixToRpy
)
{
double
r
=
static_cast
<
double
>
(
rand
())
/
(
static_cast
<
double
>
(
RAND_MAX
/
(
2
*
M_PI
)))
-
M_PI
;
double
p
=
static_cast
<
double
>
(
rand
())
/
(
static_cast
<
double
>
(
RAND_MAX
/
M_PI
))
-
(
M_PI
/
2
);
double
y
=
static_cast
<
double
>
(
rand
())
/
(
static_cast
<
double
>
(
RAND_MAX
/
(
2
*
M_PI
)))
-
M_PI
;
Eigen
::
Matrix3d
R
=
pinocchio
::
rpy
::
rpyToMatrix
(
r
,
p
,
y
);
Eigen
::
Vector3d
v
=
pinocchio
::
rpy
::
matrixToRpy
(
R
);
BOOST_CHECK_CLOSE
(
r
,
v
[
0
],
1e-12
);
BOOST_CHECK_CLOSE
(
p
,
v
[
1
],
1e-12
);
BOOST_CHECK_CLOSE
(
y
,
v
[
2
],
1e-12
);
}
BOOST_AUTO_TEST_SUITE_END
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment