PX4 ROS 2 Interface Library
Library to interface with PX4 from a companion computer using ROS 2
local_position_measurement_interface.hpp
1 /****************************************************************************
2  * Copyright (c) 2023 PX4 Development Team.
3  * SPDX-License-Identifier: BSD-3-Clause
4  ****************************************************************************/
5 
6 #pragma once
7 
8 #include <optional>
9 #include <rclcpp/rclcpp.hpp>
10 #include <Eigen/Eigen>
11 
12 #include <px4_msgs/msg/vehicle_odometry.hpp>
13 #include <px4_ros2/common/frame.hpp>
14 #include <px4_ros2/navigation/experimental/navigation_interface_base.hpp>
15 
16 namespace px4_ros2
17 {
18 
19 using AuxLocalPosition = px4_msgs::msg::VehicleOdometry;
20 
33 {
35  rclcpp::Time timestamp_sample {};
36 
38  std::optional<Eigen::Vector2f> position_xy {std::nullopt};
40  std::optional<Eigen::Vector2f> position_xy_variance {std::nullopt};
42  std::optional<float> position_z {std::nullopt};
44  std::optional<float> position_z_variance {std::nullopt};
45 
47  std::optional<Eigen::Vector2f> velocity_xy {std::nullopt};
49  std::optional<Eigen::Vector2f> velocity_xy_variance {std::nullopt};
51  std::optional<float> velocity_z {std::nullopt};
53  std::optional<float> velocity_z_variance {std::nullopt};
54 
56  std::optional<Eigen::Quaternionf> attitude_quaternion {std::nullopt};
58  std::optional<Eigen::Vector3f> attitude_variance {std::nullopt};
59 };
60 
66 {
67 public:
69  rclcpp::Node & node, PoseFrame pose_frame,
70  VelocityFrame velocity_frame);
71  ~LocalPositionMeasurementInterface() override = default;
72 
83  void update(const LocalPositionMeasurement & local_position_measurement) const;
84 
85 private:
89  bool isMeasurementNonEmpty(const LocalPositionMeasurement & measurement) const;
90 
94  bool isVarianceValid(const LocalPositionMeasurement & measurement) const;
95 
99  bool isFrameValid(const LocalPositionMeasurement & measurement) const;
100 
104  bool isValueNotNAN(const LocalPositionMeasurement & measurement) const;
105 
106  rclcpp::Publisher<AuxLocalPosition>::SharedPtr _aux_local_position_pub;
107 
108  const uint8_t _pose_frame;
109  const uint8_t _velocity_frame;
110 };
111 
113 } // namespace px4_ros2
Base class for a local position measurement provider.
Definition: local_position_measurement_interface.hpp:66
void update(const LocalPositionMeasurement &local_position_measurement) const
Publishes a local position measurement to the FMU. Throws an exception if the following conditions ar...
Base class for position measurement interface.
Definition: navigation_interface_base.hpp:27
Represents a local position measurement to be passed to LocalPositionMeasurementInterface::update.
Definition: local_position_measurement_interface.hpp:33
std::optional< Eigen::Vector3f > attitude_variance
Variance of attitude error in body frame.
Definition: local_position_measurement_interface.hpp:58
std::optional< Eigen::Quaternionf > attitude_quaternion
Attitude quaternion [w, x, y, z], Hamiltonian convention.
Definition: local_position_measurement_interface.hpp:56
rclcpp::Time timestamp_sample
Timestamp of the sample.
Definition: local_position_measurement_interface.hpp:35
std::optional< Eigen::Vector2f > position_xy
Position in the xy-plane.
Definition: local_position_measurement_interface.hpp:38
std::optional< float > velocity_z_variance
Variance of velocity error in the z-axis.
Definition: local_position_measurement_interface.hpp:53
std::optional< Eigen::Vector2f > velocity_xy_variance
Variance of velocity error in the xy-plane.
Definition: local_position_measurement_interface.hpp:49
std::optional< float > velocity_z
Velocity in the z-axis.
Definition: local_position_measurement_interface.hpp:51
std::optional< float > position_z_variance
Variance of position error in the z-axis.
Definition: local_position_measurement_interface.hpp:44
std::optional< float > position_z
Position in the z-axis.
Definition: local_position_measurement_interface.hpp:42
std::optional< Eigen::Vector2f > position_xy_variance
Variance of position error in the xy-plane.
Definition: local_position_measurement_interface.hpp:40
std::optional< Eigen::Vector2f > velocity_xy
Velocity in the xy-plane.
Definition: local_position_measurement_interface.hpp:47