45 namespace environment {
51 ROS_WARN(
"%s: Tried to collision check without initializing.",
63 constexpr
size_t kOneNearestNeighbor = 1;
64 const std::vector<std::pair<Vector3d, double>> neighboring_obstacles =
66 for (
const auto& entry : neighboring_obstacles) {
71 const std::vector<std::pair<Vector3d, double>> neighboring_sensors =
73 for (
const auto& entry : neighboring_sensors) {
84 const TrackingBound& bound,
87 ROS_WARN(
"%s: Tried to collision check without initializing.",
102 constexpr
size_t kNumNearestNeighbors = 10;
103 const auto neighbors = kdtree.KnnSearch(p, kNumNearestNeighbors);
106 for (
const auto& entry : neighbors) {
107 const Vector3d& center = entry.first;
108 const double& radius = entry.second;
109 if (bound.OverlapsSphere(p, center, radius))
return true;
128 const fastrack_msgs::SensedSpheres::ConstPtr& msg) {
129 bool updated_env =
false;
132 const Vector3d sensor_position(msg->sensor_position.x, msg->sensor_position.y,
133 msg->sensor_position.z);
136 constexpr
size_t kOneNearestNeighbor = 1;
137 constexpr
double kSmallNumber = 1e-2;
138 const auto neighboring_fovs =
140 if (neighboring_fovs.empty() ||
141 (neighboring_fovs[0].first - sensor_position).norm() > kSmallNumber) {
147 if (msg->centers.size() != msg->radii.size())
148 ROS_WARN(
"%s: Malformed SensedSpheres msg.",
name_.c_str());
150 const size_t num_obstacles = std::min(msg->centers.size(), msg->radii.size());
153 for (
size_t ii = 0; ii < num_obstacles; ii++) {
154 const Vector3d p(msg->centers[ii].x, msg->centers[ii].y,
156 const double r = msg->radii[ii];
161 for (
const auto& entry : neighbors) {
186 const SphereSensorParams& params)
const {
187 fastrack_msgs::SensedSpheres msg;
194 for (
const auto& entry : neighbors) {
195 if ((params.position - entry.first).norm() < params.range + entry.second) {
196 geometry_msgs::Vector3 c;
197 c.x = entry.first(0);
198 c.y = entry.first(1);
199 c.z = entry.first(2);
201 msg.centers.push_back(c);
202 msg.radii.push_back(entry.second);
219 if (
vis_pub_.getNumSubscribers() <= 0)
return;
222 visualization_msgs::Marker cube;
225 cube.header.stamp = ros::Time::now();
227 cube.type = visualization_msgs::Marker::CUBE;
228 cube.action = visualization_msgs::Marker::ADD;
234 geometry_msgs::Point center;
238 center.x =
lower_(0) + 0.5 * cube.scale.x;
241 center.y =
lower_(1) + 0.5 * cube.scale.y;
244 center.z =
lower_(2) + 0.5 * cube.scale.z;
246 cube.pose.position = center;
247 cube.pose.orientation.x = 0.0;
248 cube.pose.orientation.y = 0.0;
249 cube.pose.orientation.z = 0.0;
250 cube.pose.orientation.w = 1.0;
257 for (
size_t ii = 0; ii < obstacle_registry.size(); ii++) {
258 const auto& entry = obstacle_registry[ii];
260 visualization_msgs::Marker sphere;
261 sphere.ns =
"obstacles";
263 sphere.header.stamp = ros::Time::now();
264 sphere.id =
static_cast<int>(ii);
265 sphere.type = visualization_msgs::Marker::SPHERE;
266 sphere.action = visualization_msgs::Marker::ADD;
268 sphere.scale.x = 2.0 * entry.second;
269 sphere.scale.y = 2.0 * entry.second;
270 sphere.scale.z = 2.0 * entry.second;
272 sphere.color.a = 0.9;
273 sphere.color.r = 0.7;
274 sphere.color.g = 0.5;
275 sphere.color.b = 0.5;
277 geometry_msgs::Point p;
278 p.x = entry.first(0);
279 p.y = entry.first(1);
280 p.z = entry.first(2);
282 sphere.pose.position = p;
286 ros::Duration(0.001).sleep();
291 for (
size_t ii = 0; ii < sensor_registry.size(); ii++) {
292 const auto& entry = sensor_registry[ii];
294 visualization_msgs::Marker sphere;
295 sphere.ns =
"sensors";
297 sphere.header.stamp = ros::Time::now();
298 sphere.id =
static_cast<int>(ii);
299 sphere.type = visualization_msgs::Marker::SPHERE;
300 sphere.action = visualization_msgs::Marker::ADD;
302 sphere.scale.x = 2.0 * entry.second;
303 sphere.scale.y = 2.0 * entry.second;
304 sphere.scale.z = 2.0 * entry.second;
306 sphere.color.a = 0.025;
307 sphere.color.r = 0.5;
308 sphere.color.g = 0.8;
309 sphere.color.b = 0.5;
311 geometry_msgs::Point p;
312 p.x = entry.first(0);
313 p.y = entry.first(1);
314 p.z = entry.first(2);
316 sphere.pose.position = p;
320 ros::Duration(0.001).sleep();
fastrack_msgs::SensedSpheres SimulateSensor(const SphereSensorParams ¶ms) const
std::vector< std::pair< VectorKd, V > > KnnSearch(const VectorKd &query, size_t k) const
static constexpr double kUnknownProbability
const std::vector< std::pair< VectorKd, V > > & Registry() const
ros::Publisher updated_pub_
double OccupancyProbability(const Vector3d &p, double time=std::numeric_limits< double >::quiet_NaN()) const
void SensorCallback(const typename fastrack_msgs::SensedSpheres::ConstPtr &msg)
static constexpr double kEpsilon
KdtreeMap< 3, double > sensor_fovs_
bool LoadParameters(const ros::NodeHandle &n)
static constexpr double kFreeProbability
static constexpr double kOccupiedProbability
KdtreeMap< 3, double > obstacles_
virtual bool LoadParameters(const ros::NodeHandle &n)
std::vector< std::pair< VectorKd, V > > RadiusSearch(const VectorKd &query, double r) const
bool Insert(const std::pair< VectorKd, V > &entry)
double largest_obstacle_radius_