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 #include <px4_ros2/utils/message_version.hpp>
13 
14 namespace px4_ros2
15 {
25 class HomePosition : public Subscription<px4_msgs::msg::HomePosition>
26 {
27 public:
28  explicit HomePosition(Context & context)
30  "fmu/out/home_position" + +px4_ros2::getMessageNameVersion<px4_msgs::msg::HomePosition>()) {}
31 
37  Eigen::Vector3f localPosition() const
38  {
39  const px4_msgs::msg::HomePosition & home = last();
40  return Eigen::Vector3f{home.x, home.y, home.z};
41  }
42 
48  Eigen::Vector3d globalPosition() const
49  {
50  const px4_msgs::msg::HomePosition & home = last();
51  return Eigen::Vector3d{home.lat, home.lon, home.alt};
52  }
53 
59  float yaw() const
60  {
61  return last().yaw;
62  }
63 
69  bool localPositionValid() const
70  {
71  return lastValid() && last().valid_lpos;
72  }
73 
80  {
81  return lastValid() && last().valid_hpos;
82  }
83 
89  bool altitudeValid() const
90  {
91  return lastValid() && last().valid_alt;
92  }
93 
99  bool manualHome() const
100  {
101  return last().manual_home;
102  }
103 
104 };
105 
107 } /* namespace px4_ros2 */
Definition: context.hpp:20
Provides access to the vehicle's home position.
Definition: home_position.hpp:26
bool localPositionValid() const
Check if vehicle's local home position is valid (xyz).
Definition: home_position.hpp:69
bool globaHorizontalPositionValid() const
Check if vehicle's global horizontal home position is valid (lat, lon).
Definition: home_position.hpp:79
Eigen::Vector3d globalPosition() const
Get the vehicle's home position in global coordinates.
Definition: home_position.hpp:48
Eigen::Vector3f localPosition() const
Get the vehicle's home position in local coordinates.
Definition: home_position.hpp:37
float yaw() const
Get the vehicle's home position yaw.
Definition: home_position.hpp:59
bool manualHome() const
Check if home position has been set manually.
Definition: home_position.hpp:99
bool altitudeValid() const
Check if vehicle's home position altitude is valid.
Definition: home_position.hpp:89
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