Skip to content

Commit

Permalink
Add parameters to maintain backward compatibility
Browse files Browse the repository at this point in the history
Signed-off-by: yamacir-kit <httperror@404-notfound.jp>
  • Loading branch information
yamacir-kit committed Feb 26, 2025
1 parent 69915ac commit eb295db
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,61 @@ class DetectionSensor : public DetectionSensorBase

std::unordered_map<std::string, NoiseOutput> noise_outputs;

template <typename Message, typename std::enable_if_t<std::is_same_v<Message, T>, int> = 0>
auto delay() const
{
static const auto override_legacy_configuration = concealer::getParameter<bool>(
detected_objects_publisher->get_topic_name() + std::string(".override_legacy_configuration"));
if (override_legacy_configuration) {
static const auto delay = concealer::getParameter<double>(
detected_objects_publisher->get_topic_name() + std::string(".delay"));
return delay;
} else {
return configuration_.object_recognition_delay();
}
}

template <typename Message, typename std::enable_if_t<std::is_same_v<Message, U>, int> = 0>
auto delay() const
{
static const auto override_legacy_configuration = concealer::getParameter<bool>(
ground_truth_objects_publisher->get_topic_name() +
std::string(".override_legacy_configuration"));
if (override_legacy_configuration) {
static const auto delay = concealer::getParameter<double>(
ground_truth_objects_publisher->get_topic_name() + std::string(".delay"));
return delay;
} else {
return configuration_.object_recognition_ground_truth_delay();
}
}

auto range() const
{
static const auto override_legacy_configuration = concealer::getParameter<bool>(
detected_objects_publisher->get_topic_name() + std::string(".override_legacy_configuration"));
if (override_legacy_configuration) {
static const auto range = concealer::getParameter<double>(
detected_objects_publisher->get_topic_name() + std::string(".range"), 300.0);
return range;
} else {
return configuration_.range();
}
}

auto detect_all_objects_in_range() const
{
static const auto override_legacy_configuration = concealer::getParameter<bool>(
detected_objects_publisher->get_topic_name() + std::string(".override_legacy_configuration"));
if (override_legacy_configuration) {
static const auto clairvoyant = concealer::getParameter<bool>(
detected_objects_publisher->get_topic_name() + std::string(".clairvoyant"));
return clairvoyant;
} else {
return configuration_.detect_all_objects_in_range();
}
}

public:
explicit DetectionSensor(
const double current_simulation_time,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,9 @@ auto DetectionSensor<autoware_perception_msgs::msg::DetectedObjects>::update(

auto is_in_range = [&](const auto & status) {
return not isEgoEntityStatusToWhichThisSensorIsAttached(status) and
distance(status.pose(), ego_entity_status->pose()) <= configuration_.range() and
distance(status.pose(), ego_entity_status->pose()) <= range() and
isOnOrAboveEgoPlane(status.pose(), ego_entity_status->pose()) and
(configuration_.detect_all_objects_in_range() or
(detect_all_objects_in_range() or
std::find(
lidar_detected_entities.begin(), lidar_detected_entities.end(), status.name()) !=
lidar_detected_entities.end());
Expand All @@ -296,8 +296,23 @@ auto DetectionSensor<autoware_perception_msgs::msg::DetectedObjects>::update(
simulator publishes, copy the following function and implement new one.
*/
auto noise_v1 = [&](auto detected_entities, [[maybe_unused]] auto simulation_time) {
auto position_noise_distribution =
std::normal_distribution<>(0.0, configuration_.pos_noise_stddev());
static const auto override_legacy_configuration = concealer::getParameter<bool>(
detected_objects_publisher->get_topic_name() +
std::string(".override_legacy_configuration"));

static const auto standard_deviation =
override_legacy_configuration ? concealer::getParameter<double>(
detected_objects_publisher->get_topic_name() +
std::string(".noise.v1.position.standard_deviation"))
: configuration_.pos_noise_stddev();

static const auto missing_probability = override_legacy_configuration
? concealer::getParameter<double>(
detected_objects_publisher->get_topic_name() +
std::string(".noise.v1.missing_probability"))
: configuration_.probability_of_lost();

auto position_noise_distribution = std::normal_distribution<>(0.0, standard_deviation);

for (auto && detected_entity : detected_entities) {
detected_entity.mutable_pose()->mutable_position()->set_x(
Expand All @@ -310,8 +325,7 @@ auto DetectionSensor<autoware_perception_msgs::msg::DetectedObjects>::update(
std::remove_if(
detected_entities.begin(), detected_entities.end(),
[this](auto &&) {
return std::uniform_real_distribution()(random_engine_) <
configuration_.probability_of_lost();
return std::uniform_real_distribution()(random_engine_) < missing_probability;
}),
detected_entities.end());

Expand Down Expand Up @@ -529,7 +543,7 @@ auto DetectionSensor<autoware_perception_msgs::msg::DetectedObjects>::update(

if (
current_simulation_time - unpublished_detected_entities.front().second >=
configuration_.object_recognition_delay()) {
delay<autoware_perception_msgs::msg::DetectedObjects>()) {
const auto modified_detected_entities =
std::apply(noise, unpublished_detected_entities.front());
detected_objects_publisher->publish(make_detected_objects(modified_detected_entities));
Expand All @@ -540,7 +554,7 @@ auto DetectionSensor<autoware_perception_msgs::msg::DetectedObjects>::update(

if (
current_simulation_time - unpublished_ground_truth_entities.front().second >=
configuration_.object_recognition_ground_truth_delay()) {
delay<autoware_perception_msgs::msg::TrackedObjects>()) {
ground_truth_objects_publisher->publish(
make_ground_truth_objects(unpublished_ground_truth_entities.front().first));
unpublished_ground_truth_entities.pop();
Expand Down
14 changes: 13 additions & 1 deletion test_runner/scenario_test_runner/config/parameters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,18 @@ simulation:
/perception/object_recognition/detection/objects:
version: 20240605 # architecture_type suffix (mandatory)
seed: 0 # If 0 is specified, a random seed value will be generated for each run.
override_legacy_configuration: false
delay: 0.0 # This value is used only if `override_legacy_configuration` is true. If it is false, the value of `detectedObjectPublishingDelay` in `ObjectController.Properties` in the scenario file is used.
range: 300.0 # This value is used only if `override_legacy_configuration` is true. If it is false, the value of `detectionSensorRange` in `ObjectController.Properties` in the scenario file is used.
clairvoyant: false # This value is used only if `override_legacy_configuration` is true. If it is false, the value of `isClairvoyant` in `ObjectController.Properties` in the scenario file is used.
noise:
model:
version: 2 # Any of [1, 2].
v2:
v1: # This clause is used only if `model.version` is 1.
position:
standard_deviation: 0.0 # This value is used only if `override_legacy_configuration` is true. If it is false, the value of `detectedObjectPositionStandardDeviation` in `ObjectController.Properties` in the scenario file is used.
missing_probability: 0.0 # This value is used only if `override_legacy_configuration` is true. If it is false, the value of `detectedObjectMissingProbability` in `ObjectController.Properties` in the scenario file is used.
v2: # This clause is used only if `model.version` is 2.
ellipse_y_radii: [10.0, 20.0, 40.0, 60.0, 80.0, 120.0, 150.0, 180.0, 1000.0]
distance:
autocorrelation_coefficient:
Expand Down Expand Up @@ -172,3 +180,7 @@ simulation:
rate:
ellipse_normalized_x_radius: 0.7
values: [0.96, 0.78, 0.57, 0.48, 0.27, 0.07, 0.01, 0.0, 0.0]
/perception/object_recognition/ground_truth/objects:
version: 20240605 # architecture_type suffix (mandatory)
override_legacy_configuration: false
delay: 0.0 # This value is used only if `override_legacy_configuration` is true. If it is false, the value of `detectedObjectGroundTruthPublishingDelay` in `ObjectController.Properties` in the scenario file is used.

0 comments on commit eb295db

Please sign in to comment.