PX4 ROS 2 Interface Library
Library to interface with PX4 from a companion computer using ROS 2
global_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_global_position.hpp>
13 #include <px4_ros2/navigation/experimental/navigation_interface_base.hpp>
14 
15 namespace px4_ros2
16 {
29 {
31  rclcpp::Time timestamp_sample {};
32 
34  std::optional<Eigen::Vector2d> lat_lon {std::nullopt};
36  std::optional<float> horizontal_variance {std::nullopt};
37 
39  std::optional<float> altitude_msl {std::nullopt};
41  std::optional<float> vertical_variance {std::nullopt};
42 };
43 
49 {
50 public:
51  explicit GlobalPositionMeasurementInterface(rclcpp::Node & node);
52  ~GlobalPositionMeasurementInterface() override = default;
53 
63  void update(const GlobalPositionMeasurement & global_position_measurement) const;
64 
73  inline void reset() {++_lat_lon_reset_counter;}
74 
75 private:
79  bool isMeasurementNonEmpty(const GlobalPositionMeasurement & measurement) const;
80 
84  bool isVarianceValid(const GlobalPositionMeasurement & measurement) const;
85 
89  bool isFrameValid(const GlobalPositionMeasurement & measurement) const;
90 
94  bool isValueNotNAN(const GlobalPositionMeasurement & measurement) const;
95 
96  rclcpp::Publisher<px4_msgs::msg::VehicleGlobalPosition>::SharedPtr _aux_global_position_pub;
97 
98  uint8_t _lat_lon_reset_counter{0};
99  // uint8_t _altitude_frame;
100 };
101 
103 } // namespace px4_ros2
Base class for a global position measurement provider.
Definition: global_position_measurement_interface.hpp:49
void update(const GlobalPositionMeasurement &global_position_measurement) const
Publishes a global position measurement to the FMU. Throws an exception if the following conditions a...
void reset()
Notify the FMU that the global position estimate has been reset.
Definition: global_position_measurement_interface.hpp:73
Base class for position measurement interface.
Definition: navigation_interface_base.hpp:27
Represents a global position measurement to be passed to GlobalPositionMeasurementInterface::update.
Definition: global_position_measurement_interface.hpp:29
std::optional< float > horizontal_variance
Variance of horizontal position error (meters).
Definition: global_position_measurement_interface.hpp:36
rclcpp::Time timestamp_sample
Timestamp of the sample.
Definition: global_position_measurement_interface.hpp:31
std::optional< float > altitude_msl
Altitude in the MSL frame.
Definition: global_position_measurement_interface.hpp:39
std::optional< float > vertical_variance
Variance of vertical position error (meters).
Definition: global_position_measurement_interface.hpp:41
std::optional< Eigen::Vector2d > lat_lon
Latitude and longitude.
Definition: global_position_measurement_interface.hpp:34