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");
76 const auto data = state_interfaces_[0].get().get_optional();
79 return static_cast<int8_t
>(data.value());
81 return STATUS_UNKNOWN;
91 const auto data = state_interfaces_[1].get().get_optional();
94 return static_cast<uint16_t
>(data.value());
96 return SERVICE_UNKNOWN;
106 const auto data = state_interfaces_[2].get().get_optional();
107 if (data.has_value())
111 return std::numeric_limits<double>::quiet_NaN();
121 const auto data = state_interfaces_[3].get().get_optional();
122 if (data.has_value())
126 return std::numeric_limits<double>::quiet_NaN();
136 const auto data = state_interfaces_[4].get().get_optional();
137 if (data.has_value())
141 return std::numeric_limits<double>::quiet_NaN();
151 typename = std::enable_if_t<sensor_option == GPSSensorOption::WithCovariance, U>>
154 const auto data_1 = state_interfaces_[5].get().get_optional();
155 const auto data_2 = state_interfaces_[6].get().get_optional();
156 const auto data_3 = state_interfaces_[7].get().get_optional();
157 if (data_1.has_value())
159 covariance_[0] = data_1.value();
161 if (data_2.has_value())
163 covariance_[4] = data_2.value();
165 if (data_3.has_value())
167 covariance_[8] = data_3.value();
186 if constexpr (sensor_option == GPSSensorOption::WithCovariance)
195 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:104
double get_longitude() const
Return longitude reported by a GPS.
Definition gps_sensor.hpp:119
int8_t get_status() const
Return GPS's status e.g. fix/no_fix.
Definition gps_sensor.hpp:74
bool get_values_as_message(sensor_msgs::msg::NavSatFix &message)
Fills a NavSatFix message from the current values.
Definition gps_sensor.hpp:178
const std::array< double, 9 > & get_covariance()
Return covariance reported by a GPS.
Definition gps_sensor.hpp:152
double get_altitude() const
Return altitude reported by a GPS.
Definition gps_sensor.hpp:134
uint16_t get_service() const
Return service used by GPS e.g. fix/no_fix.
Definition gps_sensor.hpp:89
Definition semantic_component_interface.hpp:29