PX4 ROS 2 Interface Library
Library to interface with PX4 from a companion computer using ROS 2
home_position.hpp
1 /****************************************************************************
2  * Copyright (c) 2023-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/home_position.hpp>
10 #include <px4_ros2/common/context.hpp>
11 #include <px4_ros2/utils/subscription.hpp>
12 
13 namespace px4_ros2
14 {
24 class HomePosition : public Subscription<px4_msgs::msg::HomePosition>
25 {
26 public:
27  explicit HomePosition(Context & context)
28  : Subscription<px4_msgs::msg::HomePosition>(context, "fmu/out/home_position") {}
29 
35  Eigen::Vector3f localPosition() const
36  {
37  const px4_msgs::msg::HomePosition & home = last();
38  return Eigen::Vector3f{home.x, home.y, home.z};
39  }
40 
46  Eigen::Vector3d globalPosition() const
47  {
48  const px4_msgs::msg::HomePosition & home = last();
49  return Eigen::Vector3d{home.lat, home.lon, home.alt};
50  }
51 
57  float yaw() const
58  {
59  return last().yaw;
60  }
61 
67  bool localPositionValid() const
68  {
69  return lastValid() && last().valid_lpos;
70  }
71 
78  {
79  return lastValid() && last().valid_hpos;
80  }
81 
87  bool altitudeValid() const
88  {
89  return lastValid() && last().valid_alt;
90  }
91 
97  bool manualHome() const
98  {
99  return last().manual_home;
100  }
101 
102 };
103 
105 } /* namespace px4_ros2 */
Definition: context.hpp:20
Provides access to the vehicle's home position.
Definition: home_position.hpp:25
bool localPositionValid() const
Check if vehicle's local home position is valid (xyz).
Definition: home_position.hpp:67
bool globaHorizontalPositionValid() const
Check if vehicle's global horizontal home position is valid (lat, lon).
Definition: home_position.hpp:77
Eigen::Vector3d globalPosition() const
Get the vehicle's home position in global coordinates.
Definition: home_position.hpp:46
Eigen::Vector3f localPosition() const
Get the vehicle's home position in local coordinates.
Definition: home_position.hpp:35
float yaw() const
Get the vehicle's home position yaw.
Definition: home_position.hpp:57
bool manualHome() const
Check if home position has been set manually.
Definition: home_position.hpp:97
bool altitudeValid() const
Check if vehicle's home position altitude is valid.
Definition: home_position.hpp:87
Provides a subscription to arbitrary ROS topics.
Definition: subscription.hpp:23
bool lastValid(const std::chrono::duration< int64_t, DurationT > max_delay=500ms) const
Check whether the last message is still valid. To be valid, the message must have been received withi...
Definition: subscription.hpp:84
const px4_msgs::msg::HomePosition & last() const
Get the last-received message.
Definition: subscription.hpp:58