15#ifndef SEMANTIC_COMPONENTS__GPS_SENSOR_HPP_
16#define SEMANTIC_COMPONENTS__GPS_SENSOR_HPP_
24#include "rclcpp/version.h"
25#include "semantic_components/semantic_component_interface.hpp"
26#include "sensor_msgs/msg/nav_sat_fix.hpp"
28namespace semantic_components
31enum class GPSSensorOption
37template <GPSSensorOption sensor_option>
41#if RCLCPP_VERSION_MAJOR >= 28
42 static constexpr int8_t STATUS_UNKNOWN = sensor_msgs::msg::NavSatStatus::STATUS_UNKNOWN;
43 static constexpr uint16_t SERVICE_UNKNOWN = sensor_msgs::msg::NavSatStatus::SERVICE_UNKNOWN;
45 static constexpr int8_t STATUS_UNKNOWN = -2;
46 static constexpr uint16_t SERVICE_UNKNOWN = 0;
50 sensor_option == GPSSensorOption::WithCovariance ||
51 sensor_option == GPSSensorOption::WithoutCovariance,
52 "Invalid GPSSensorOption");
53 explicit GPSSensor(
const std::string & name)
55 name, {{name +
"/" +
"status"},
56 {name +
"/" +
"service"},
57 {name +
"/" +
"latitude"},
58 {name +
"/" +
"longitude"},
59 {name +
"/" +
"altitude"}})
61 if constexpr (sensor_option == GPSSensorOption::WithCovariance)
63 interface_names_.emplace_back(name +
"/" +
"latitude_covariance");
64 interface_names_.emplace_back(name +
"/" +
"longitude_covariance");
65 interface_names_.emplace_back(name +
"/" +
"altitude_covariance");
66 state_interfaces_.reserve(state_interfaces_.capacity() + 3);
77 const auto data = state_interfaces_[0].get().get_optional();
80 return static_cast<int8_t
>(data.value());
82 return STATUS_UNKNOWN;
92 const auto data = state_interfaces_[1].get().get_optional();
95 return static_cast<uint16_t
>(data.value());
97 return SERVICE_UNKNOWN;
107 const auto data = state_interfaces_[2].get().get_optional();
108 if (data.has_value())
112 return std::numeric_limits<double>::quiet_NaN();
122 const auto data = state_interfaces_[3].get().get_optional();
123 if (data.has_value())
127 return std::numeric_limits<double>::quiet_NaN();
137 const auto data = state_interfaces_[4].get().get_optional();
138 if (data.has_value())
142 return std::numeric_limits<double>::quiet_NaN();
152 typename = std::enable_if_t<sensor_option == GPSSensorOption::WithCovariance, U>>
155 const auto data_1 = state_interfaces_[5].get().get_optional();
156 const auto data_2 = state_interfaces_[6].get().get_optional();
157 const auto data_3 = state_interfaces_[7].get().get_optional();
158 if (data_1.has_value())
160 covariance_[0] = data_1.value();
162 if (data_2.has_value())
164 covariance_[4] = data_2.value();
166 if (data_3.has_value())
168 covariance_[8] = data_3.value();
187 if constexpr (sensor_option == GPSSensorOption::WithCovariance)
196 std::array<double, 9> covariance_{{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}};
Definition gps_sensor.hpp:39
double get_latitude() const
Return latitude reported by a GPS.
Definition gps_sensor.hpp:105
double get_longitude() const
Return longitude reported by a GPS.
Definition gps_sensor.hpp:120
int8_t get_status() const
Return GPS's status e.g. fix/no_fix.
Definition gps_sensor.hpp:75
bool get_values_as_message(sensor_msgs::msg::NavSatFix &message)
Fills a NavSatFix message from the current values.
Definition gps_sensor.hpp:179
const std::array< double, 9 > & get_covariance()
Return covariance reported by a GPS.
Definition gps_sensor.hpp:153
double get_altitude() const
Return altitude reported by a GPS.
Definition gps_sensor.hpp:135
uint16_t get_service() const
Return service used by GPS e.g. fix/no_fix.
Definition gps_sensor.hpp:90
Definition semantic_component_interface.hpp:29