PX4 ROS 2 Interface Library
Library to interface with PX4 from a companion computer using ROS 2
attitude.hpp
1 /****************************************************************************
2  * Copyright (c) 2024 PX4 Development Team.
3  * SPDX-License-Identifier: BSD-3-Clause
4  ****************************************************************************/
5 
6 #pragma once
7 
8 #include <Eigen/Eigen>
9 #include <px4_msgs/msg/vehicle_attitude.hpp>
10 #include <px4_ros2/common/context.hpp>
11 #include <px4_ros2/utils/geometry.hpp>
12 #include <px4_ros2/utils/subscription.hpp>
13 
14 namespace px4_ros2
15 {
23 class OdometryAttitude : public Subscription<px4_msgs::msg::VehicleAttitude>
24 {
25 public:
26  explicit OdometryAttitude(Context & context);
27 
33  Eigen::Quaternionf attitude() const
34  {
35  const px4_msgs::msg::VehicleAttitude & att = last();
36  return Eigen::Quaternionf{att.q[0], att.q[1], att.q[2], att.q[3]};
37  }
38 
44  float roll() const
45  {
46  return quaternionToRoll(attitude());
47  }
48 
54  float pitch() const
55  {
56  return quaternionToPitch(attitude());
57  }
58 
64  float yaw() const
65  {
66  return quaternionToYaw(attitude());
67  }
68 };
69 
71 } /* namespace px4_ros2 */
Definition: context.hpp:20
Provides access to the vehicle's attitude estimate.
Definition: attitude.hpp:24
Eigen::Quaternionf attitude() const
Get the vehicle's attitude.
Definition: attitude.hpp:33
float pitch() const
Get the vehicle's pitch in extrinsic RPY order.
Definition: attitude.hpp:54
float roll() const
Get the vehicle's roll in extrinsic RPY order.
Definition: attitude.hpp:44
float yaw() const
Get the vehicle's yaw in extrinsic RPY order.
Definition: attitude.hpp:64
Provides a subscription to arbitrary ROS topics.
Definition: subscription.hpp:23
const px4_msgs::msg::VehicleAttitude & last() const
Get the last-received message.
Definition: subscription.hpp:58
Type quaternionToRoll(const Eigen::Quaternion< Type > &q)
Convert quaternion to roll angle in extrinsic RPY order (intrinsic YPR)
Definition: geometry.hpp:148
Type quaternionToPitch(const Eigen::Quaternion< Type > &q)
Convert quaternion to pitch angle in extrinsic RPY order (intrinsic YPR)
Definition: geometry.hpp:165
Type quaternionToYaw(const Eigen::Quaternion< Type > &q)
Convert quaternion to yaw angle in extrinsic RPY order (intrinsic YPR)
Definition: geometry.hpp:182