Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exclude LiDAR occluded object on OccupancyGrid #1227

Merged
merged 4 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class DetectionSensor : public DetectionSensorBase

auto update(
const double, const std::vector<traffic_simulator_msgs::EntityStatus> &, const rclcpp::Time &,
const std::vector<std::string> & lidar_detected_entity) -> void override;
const std::vector<std::string> & lidar_detected_entities) -> void override;
};
} // namespace simple_sensor_simulator

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,12 @@ class OccupancyGridSensorBase

/**
* @brief List all objects in range of sensor sight
* @warning `status` must contain EGO object
* @return names of objects in range of sensor sight
*/
const std::vector<std::string> getDetectedObjects(
const std::vector<traffic_simulator_msgs::EntityStatus> &) const;
const std::vector<traffic_simulator_msgs::EntityStatus> & status,
const std::vector<std::string> & lidar_detected_entities) const;

/**
* @brief Extract sensor pose from entity statuses
Expand Down Expand Up @@ -124,7 +126,7 @@ class OccupancyGridSensor : public OccupancyGridSensorBase
template <>
auto OccupancyGridSensor<nav_msgs::msg::OccupancyGrid>::getOccupancyGrid(
const std::vector<traffic_simulator_msgs::EntityStatus> & status, const rclcpp::Time & stamp,
const std::vector<std::string> & lidar_detected_entity) -> nav_msgs::msg::OccupancyGrid;
const std::vector<std::string> & lidar_detected_entities) -> nav_msgs::msg::OccupancyGrid;
} // namespace simple_sensor_simulator

#endif // SIMPLE_SENSOR_SIMULATOR__SENSOR_SIMULATION__OCCUPANCY_GRID__OCCUPANCY_GRID_SENSOR_HPP_
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include <quaternion_operation/quaternion_operation.h>

#include <algorithm>
#include <memory>
#include <nav_msgs/msg/occupancy_grid.hpp>
#include <optional>
Expand All @@ -39,11 +40,19 @@ geometry_msgs::Pose OccupancyGridSensorBase::getSensorPose(
}

const std::vector<std::string> OccupancyGridSensorBase::getDetectedObjects(
const std::vector<traffic_simulator_msgs::EntityStatus> & status) const
const std::vector<traffic_simulator_msgs::EntityStatus> & status,
const std::vector<std::string> & lidar_detected_entities) const
{
std::vector<std::string> detected_entities;
const auto pose = getSensorPose(status);
for (const auto & s : status) {
if (const auto has_detected =
std::find(lidar_detected_entities.begin(), lidar_detected_entities.end(), s.name()) !=
lidar_detected_entities.end();
!has_detected) {
continue;
}

double distance = std::hypot(
s.pose().position().x() - pose.position().x(), s.pose().position().y() - pose.position().y(),
s.pose().position().z() - pose.position().z());
Expand All @@ -57,7 +66,7 @@ const std::vector<std::string> OccupancyGridSensorBase::getDetectedObjects(
template <>
auto OccupancyGridSensor<nav_msgs::msg::OccupancyGrid>::getOccupancyGrid(
const std::vector<traffic_simulator_msgs::EntityStatus> & status, const rclcpp::Time & stamp,
const std::vector<std::string> & lidar_detected_entity) -> nav_msgs::msg::OccupancyGrid
const std::vector<std::string> & lidar_detected_entities) -> nav_msgs::msg::OccupancyGrid
{
// check if entities in `status` have unique names
{
Expand Down Expand Up @@ -96,10 +105,10 @@ auto OccupancyGridSensor<nav_msgs::msg::OccupancyGrid>::getOccupancyGrid(
auto detected_entities = std::set<std::string>();
{
if (configuration_.filter_by_range()) {
auto v = getDetectedObjects(status);
auto v = getDetectedObjects(status, lidar_detected_entities);
detected_entities.insert(v.begin(), v.end());
} else {
detected_entities.insert(lidar_detected_entity.begin(), lidar_detected_entity.end());
detected_entities.insert(lidar_detected_entities.begin(), lidar_detected_entities.end());
}
}

Expand Down
Loading