-
Notifications
You must be signed in to change notification settings - Fork 990
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
55 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/** | ||
* @brief Eigen::Quaternion helter functions | ||
* @file uas_quaternion_utils.cpp | ||
* @author Vladimir Ermakov <vooon341@gmail.com> | ||
* | ||
* @addtogroup nodelib | ||
* @{ | ||
*/ | ||
/* | ||
* Copyright 2015 Vladimir Ermakov. | ||
* | ||
* This file is part of the mavros package and subject to the license terms | ||
* in the top-level LICENSE file of the mavros repository. | ||
* https://github.com/mavlink/mavros/tree/master/LICENSE.md | ||
*/ | ||
#include <mavros/mavros_uas.h> | ||
|
||
using namespace mavros; | ||
|
||
/* | ||
* Note: order of axis are match tf2::LinearMath (bullet). | ||
* Compatibility checked by unittests. | ||
*/ | ||
|
||
Eigen::Quaterniond UAS::quaternion_from_rpy(const Eigen::Vector3d &rpy) | ||
{ | ||
#if 0 | ||
// RPY - XYZ | ||
return Eigen::Quaterniond( | ||
Eigen::AngleAxisd(rpy.x(), Eigen::Vector3d::UnitX()) * | ||
Eigen::AngleAxisd(rpy.y(), Eigen::Vector3d::UnitY()) * | ||
Eigen::AngleAxisd(rpy.z(), Eigen::Vector3d::UnitZ()) | ||
); | ||
#else | ||
// YPR - ZYX | ||
return Eigen::Quaterniond( | ||
Eigen::AngleAxisd(rpy.z(), Eigen::Vector3d::UnitZ()) * | ||
Eigen::AngleAxisd(rpy.y(), Eigen::Vector3d::UnitY()) * | ||
Eigen::AngleAxisd(rpy.x(), Eigen::Vector3d::UnitX()) | ||
); | ||
#endif | ||
} | ||
|
||
Eigen::Vector3d UAS::quaternion_to_rpy(const Eigen::Quaterniond &q) | ||
{ | ||
#if 0 | ||
// RPY - XYZ | ||
return q.toRotationMatrix().eulerAngles(0, 1, 2); | ||
#else | ||
// YPR - ZYX | ||
return q.toRotationMatrix().eulerAngles(2, 1, 0).reverse(); | ||
#endif | ||
} | ||
|