-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
odometry: add OdometryAttitude class
- Loading branch information
1 parent
3f3ff64
commit cce0e88
Showing
4 changed files
with
109 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/**************************************************************************** | ||
* Copyright (c) 2024 PX4 Development Team. | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
****************************************************************************/ | ||
|
||
#pragma once | ||
|
||
#include <Eigen/Eigen> | ||
#include <px4_msgs/msg/vehicle_attitude.hpp> | ||
#include <px4_ros2/common/context.hpp> | ||
#include <px4_ros2/odometry/subscription.hpp> | ||
#include <px4_ros2/utils/geometry.hpp> | ||
|
||
namespace px4_ros2 | ||
{ | ||
/** \ingroup odometry | ||
* @{ | ||
*/ | ||
|
||
/** | ||
* Provides access to the vehicle's attitude estimate | ||
*/ | ||
class OdometryAttitude : public Subscription<px4_msgs::msg::VehicleAttitude> | ||
{ | ||
public: | ||
explicit OdometryAttitude(Context & context); | ||
|
||
/** | ||
* @brief Get the vehicle's attitude. | ||
* | ||
* @return the attitude quaternion | ||
*/ | ||
Eigen::Quaternionf attitude() const | ||
{ | ||
const px4_msgs::msg::VehicleAttitude & att = last(); | ||
return Eigen::Quaternionf{att.q[0], att.q[1], att.q[2], att.q[3]}; | ||
} | ||
|
||
/** | ||
* @brief Get the vehicle's roll in extrinsic RPY order. | ||
* | ||
* @return the attitude roll in radians within [-pi, pi] | ||
*/ | ||
float roll() const | ||
{ | ||
const px4_msgs::msg::VehicleAttitude & att = last(); | ||
const Eigen::Quaternionf q{att.q[0], att.q[1], att.q[2], att.q[3]}; | ||
return quaternionToRoll(q); | ||
} | ||
|
||
/** | ||
* @brief Get the vehicle's pitch in extrinsic RPY order. | ||
* | ||
* @return the attitude pitch in radians within [-pi, pi] | ||
*/ | ||
float pitch() const | ||
{ | ||
const px4_msgs::msg::VehicleAttitude & att = last(); | ||
const Eigen::Quaternionf q{att.q[0], att.q[1], att.q[2], att.q[3]}; | ||
return quaternionToPitch(q); | ||
} | ||
|
||
/** | ||
* @brief Get the vehicle's yaw in extrinsic RPY order. | ||
* | ||
* @return the attitude yaw in radians within [-pi, pi] | ||
*/ | ||
float yaw() const | ||
{ | ||
const px4_msgs::msg::VehicleAttitude & att = last(); | ||
const Eigen::Quaternionf q{att.q[0], att.q[1], att.q[2], att.q[3]}; | ||
return quaternionToYaw(q); | ||
} | ||
}; | ||
|
||
/** @}*/ | ||
} /* namespace px4_ros2 */ |
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,19 @@ | ||
/**************************************************************************** | ||
* Copyright (c) 2023 PX4 Development Team. | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
****************************************************************************/ | ||
|
||
#include <px4_ros2/odometry/attitude.hpp> | ||
|
||
namespace px4_ros2 | ||
{ | ||
|
||
OdometryAttitude::OdometryAttitude(Context & context) | ||
: Subscription<px4_msgs::msg::VehicleAttitude>(context, "/fmu/out/vehicle_attitude") | ||
{ | ||
RequirementFlags requirements{}; | ||
requirements.attitude = true; | ||
context.setRequirement(requirements); | ||
} | ||
|
||
} // namespace px4_ros2 |