15 #ifndef SIMPLE_SENSOR_SIMULATOR__SENSOR_SIMULATION__NOISE_PARAMETER_SELECTOR_HPP_
16 #define SIMPLE_SENSOR_SIMULATOR__SENSOR_SIMULATION__NOISE_PARAMETER_SELECTOR_HPP_
18 #include <boost/math/constants/constants.hpp>
20 #include <get_parameter/get_parameter.hpp>
29 namespace noise_parameter_selector
32 const std::string & parameter_base_path,
double x,
double y)
34 return [parameter_base_path, x, y](
const std::string & name) {
36 const auto ellipse_y_radii =
37 common::getParameter<std::vector<double>>(parameter_base_path +
"ellipse_y_radii");
38 const auto ellipse_normalized_x_radius =
39 common::getParameter<double>(parameter_base_path + name +
".ellipse_normalized_x_radius");
41 common::getParameter<std::vector<double>>(parameter_base_path + name +
".values");
42 if (ellipse_y_radii.size() == values.size()) {
52 for (
auto i = std::size_t(0); i < ellipse_y_radii.size(); ++i) {
60 "Array size mismatch: ", std::quoted(parameter_base_path +
"ellipse_y_radii"),
" has ",
61 ellipse_y_radii.size(),
" elements, but ",
62 std::quoted(parameter_base_path + name +
".values"),
" has ", values.size(),
63 " elements. Both arrays must have the same size.");
72 if (
const auto next_dot_pos = parameter_name.find(
'.', version_base_path.length());
73 next_dot_pos != std::string::npos) {
74 return parameter_name.substr(
75 version_base_path.length(), next_dot_pos - version_base_path.length());
81 -> std::vector<std::string>
83 const std::string version_base_path = topic_name +
".noise." + version +
".";
86 const auto parameter_names =
87 common::getParameterNode()
88 .list_parameters({}, rcl_interfaces::srv::ListParameters::Request::DEPTH_RECURSIVE)
92 std::set<std::string> config_names_set;
93 for (
const auto & parameter_name : parameter_names) {
94 if (parameter_name.rfind(version_base_path, 0) == 0) {
96 if (!config_name.empty()) {
97 config_names_set.insert(config_name);
102 return std::vector<std::string>(config_names_set.begin(), config_names_set.end());
109 const std::string version_base_path = topic_name +
".noise." + version +
".";
110 auto matches_noise_application_entities = [&](
113 const auto base_path = version_base_path + noise_config_name +
".noise_application_entities.";
115 const auto types = common::getParameter<std::vector<std::string>>(base_path +
"types");
116 const auto subtypes = common::getParameter<std::vector<std::string>>(base_path +
"subtypes");
117 const auto names = common::getParameter<std::vector<std::string>>(base_path +
"names");
119 auto string_with_wildcards_to_regex =
120 [](
const std::string & string_with_wildcards) -> std::regex {
122 for (
char c : string_with_wildcards) {
123 regex_pattern += (c ==
'*') ?
".*" : (c ==
'?') ?
"." :
std::string(1, c);
125 return std::regex(regex_pattern);
129 types.begin(), types.end(),
130 [entity_type = boost::lexical_cast<std::string>(entity.type()),
131 string_with_wildcards_to_regex](
const auto & target) {
132 return std::regex_match(entity_type, string_with_wildcards_to_regex(target));
135 subtypes.begin(), subtypes.end(),
136 [entity_subtype = boost::lexical_cast<std::string>(entity.subtype()),
137 string_with_wildcards_to_regex](
const auto & target) {
138 return std::regex_match(entity_subtype, string_with_wildcards_to_regex(target));
141 names.begin(), names.end(),
142 [entity_name = entity.name(), string_with_wildcards_to_regex](
const auto & target) {
143 return std::regex_match(entity_name, string_with_wildcards_to_regex(target));
147 const auto parameter_names =
148 common::getParameterNode()
149 .list_parameters({}, rcl_interfaces::srv::ListParameters::Request::DEPTH_RECURSIVE)
152 if (
auto matched_parameter = std::find_if(
153 parameter_names.begin(), parameter_names.end(),
154 [&](
const auto & parameter_name) {
155 if (parameter_name.rfind(version_base_path, 0) == 0) {
156 if (auto config_name = parseConfigNameFromParameter(parameter_name, version_base_path);
157 !config_name.empty()) {
158 return matches_noise_application_entities(entity, config_name);
163 matched_parameter != parameter_names.end()) {
auto hypot(const T &from, const U &to)
Definition: hypot.hpp:28
auto findMatchingNoiseConfigForEntity(const traffic_simulator_msgs::EntityStatus &entity, const std::string &version, const std::string &topic_name) -> std::string
Definition: noise_parameter_selector.hpp:105
auto parseConfigNameFromParameter(const std::string ¶meter_name, const std::string &version_base_path) -> std::string
Definition: noise_parameter_selector.hpp:69
auto createEllipticalParameterSelector(const std::string ¶meter_base_path, double x, double y)
Definition: noise_parameter_selector.hpp:31
auto listAvailableNoiseConfigs(const std::string &topic_name, const std::string &version) -> std::vector< std::string >
Definition: noise_parameter_selector.hpp:80
Definition: constants.hpp:19
auto distance(const geometry_msgs::Pose &pose1, const geometry_msgs::Pose &pose2)
Definition: detection_sensor.cpp:45
std::string string
Definition: junit5.hpp:26
traffic_simulator_msgs::EntityStatus EntityStatus
Definition: helper_functions.hpp:32
Definition: exception.hpp:27