@@ -43,7 +43,7 @@ PLUGINLIB_EXPORT_CLASS(nav2_costmap_2d::DepthLayer, nav2_costmap_2d::Layer)
4343namespace nav2_costmap_2d
4444{
4545
46- static const rclcpp::Logger LOGGER = rclcpp::get_logger (" basic_grasping_perception " );
46+ static const rclcpp::Logger LOGGER = rclcpp::get_logger (" depth_layer " );
4747
4848DepthLayer::DepthLayer ()
4949{
@@ -67,14 +67,14 @@ void DepthLayer::onInitialize()
6767 declareParameter (" max_obstacle_height" , rclcpp::ParameterValue (2.0 ));
6868 declareParameter (" min_clearing_height" , rclcpp::ParameterValue (-std::numeric_limits<double >::infinity ()));
6969 declareParameter (" max_clearing_height" , rclcpp::ParameterValue (std::numeric_limits<double >::infinity ()));
70- declareParameter (" observation_range " , rclcpp::ParameterValue (2.5 ));
70+ declareParameter (" obstacle_range " , rclcpp::ParameterValue (2.5 ));
7171 declareParameter (" raytrace_range" , rclcpp::ParameterValue (3.0 ));
7272
7373 // Skipping of potentially noisy rays near the edge of the image
74- declareParameter (" skip_rays_bottom" , rclcpp::ParameterValue (20 ));
75- declareParameter (" skip_rays_top" , rclcpp::ParameterValue (20 ));
76- declareParameter (" skip_rays_left" , rclcpp::ParameterValue (20 ));
77- declareParameter (" skip_rays_right" , rclcpp::ParameterValue (20 ));
74+ declareParameter (" skip_rays_bottom" , rclcpp::ParameterValue (10 ));
75+ declareParameter (" skip_rays_top" , rclcpp::ParameterValue (10 ));
76+ declareParameter (" skip_rays_left" , rclcpp::ParameterValue (10 ));
77+ declareParameter (" skip_rays_right" , rclcpp::ParameterValue (10 ));
7878
7979 // Should skipped edge rays be used for clearing?
8080 declareParameter (" clear_with_skipped_rays" , rclcpp::ParameterValue (false ));
@@ -117,20 +117,17 @@ void DepthLayer::onInitialize()
117117 node_->get_parameter (name_ + " .obstacle_range" , obstacle_range);
118118 node_->get_parameter (name_ + " .raytrace_range" , raytrace_range);
119119
120- std::string topic = " " ;
121120 std::string sensor_frame = " " ;
122121
123122 marking_buf_ = std::make_shared<nav2_costmap_2d::ObservationBuffer>(
124- node_, topic , observation_keep_time, expected_update_rate,
123+ node_, name_ , observation_keep_time, expected_update_rate,
125124 min_obstacle_height, max_obstacle_height, obstacle_range, raytrace_range,
126125 *tf_, global_frame_, sensor_frame, transform_tolerance);
127126 marking_buffers_.push_back (marking_buf_);
128127 observation_buffers_.push_back (marking_buf_);
129128
130- min_obstacle_height = 0.0 ;
131-
132- clearing_buf_ = std::make_shared<nav2_costmap_2d::ObservationBuffer>(
133- node_, topic, observation_keep_time, expected_update_rate,
129+ clearing_buf_ = std::make_shared<nav2_costmap_2d::ObservationBuffer>(
130+ node_, name_, observation_keep_time, expected_update_rate,
134131 min_clearing_height, max_clearing_height, obstacle_range, raytrace_range,
135132 *tf_, global_frame_, sensor_frame, transform_tolerance);
136133 clearing_buffers_.push_back (clearing_buf_);
@@ -142,12 +139,14 @@ void DepthLayer::onInitialize()
142139 {
143140 clearing_pub_ = node_->create_publisher <sensor_msgs::msg::PointCloud2>(" clearing_obs" , points_qos);
144141 marking_pub_ = node_->create_publisher <sensor_msgs::msg::PointCloud2>(" marking_obs" , points_qos);
142+ clearing_pub_->on_activate ();
143+ marking_pub_->on_activate ();
145144 }
146145
147146 // Subscribe to camera/info topics
148147 std::string camera_depth_topic, camera_info_topic;
149- node_->get_parameter (" depth_topic" , camera_depth_topic);
150- node_->get_parameter (" info_topic" , camera_info_topic);
148+ node_->get_parameter (name_ + " . depth_topic" , camera_depth_topic);
149+ node_->get_parameter (name_ + " . info_topic" , camera_info_topic);
151150
152151 camera_info_sub_ = node_->create_subscription <sensor_msgs::msg::CameraInfo>(
153152 camera_info_topic,
@@ -208,7 +207,7 @@ void DepthLayer::depthImageCallback(sensor_msgs::msg::Image::ConstSharedPtr msg)
208207
209208 if (K_.empty ())
210209 {
211- RCLCPP_DEBUG (LOGGER, " Camera info not yet received." );
210+ RCLCPP_WARN (LOGGER, " Camera info not yet received." );
212211 return ;
213212 }
214213
@@ -233,6 +232,9 @@ void DepthLayer::depthImageCallback(sensor_msgs::msg::Image::ConstSharedPtr msg)
233232 }
234233 }
235234
235+ // Filter noise
236+ cv::medianBlur (cv_ptr->image , cv_ptr->image , 5 );
237+
236238 // Convert to 3d
237239 cv::Mat points3d;
238240 depthTo3d (cv_ptr->image , K_, points3d);
@@ -284,7 +286,7 @@ void DepthLayer::depthImageCallback(sensor_msgs::msg::Image::ConstSharedPtr msg)
284286 if (ground_plane[0 ] == 0.0 && ground_plane[1 ] == 0.0 &&
285287 ground_plane[2 ] == 0.0 && ground_plane[3 ] == 0.0 )
286288 {
287- RCLCPP_DEBUG (LOGGER, " Invalid ground plane." );
289+ RCLCPP_WARN (LOGGER, " Invalid ground plane." );
288290 return ;
289291 }
290292
@@ -321,7 +323,6 @@ void DepthLayer::depthImageCallback(sensor_msgs::msg::Image::ConstSharedPtr msg)
321323 for (size_t j = 0 ; j < points3d.cols ; j++)
322324 {
323325 // Get next point
324- geometry_msgs::msg::Point32 current_point;
325326 float x = channels[0 ].at <float >(i, j);
326327 float y = channels[1 ].at <float >(i, j);
327328 float z = channels[2 ].at <float >(i, j);
@@ -331,9 +332,9 @@ void DepthLayer::depthImageCallback(sensor_msgs::msg::Image::ConstSharedPtr msg)
331332 z != 0.0 && !std::isnan (z))
332333 {
333334 // Check if point is part of the ground plane
334- if (fabs (ground_plane[0 ] * current_point. x +
335- ground_plane[1 ] * current_point. y +
336- ground_plane[2 ] * current_point. z +
335+ if (fabs (ground_plane[0 ] * x +
336+ ground_plane[1 ] * y +
337+ ground_plane[2 ] * z +
337338 ground_plane[3 ]) <= observations_threshold_)
338339 {
339340 if (clear_with_skipped_rays_)
@@ -377,46 +378,17 @@ void DepthLayer::depthImageCallback(sensor_msgs::msg::Image::ConstSharedPtr msg)
377378 continue ;
378379 }
379380
380- // Check for outliers, mark non-outliers as obstacles.
381- int num_valid = 0 ;
382- for (int x = -1 ; x < 2 ; x++)
383- {
384- for (int y = -1 ; y < 2 ; y++)
385- {
386- if (x == 0 && y == 0 )
387- {
388- continue ;
389- }
390- float px = channels[0 ].at <float >(i+x, j+y);
391- float py = channels[1 ].at <float >(i+x, j+y);
392- float pz = channels[2 ].at <float >(i+x, j+y);
393- if (px != 0.0 && py != 0.0 && pz != 0.0 &&
394- !std::isnan (px) && !std::isnan (py) && !std::isnan (pz))
395- {
396- if ( fabs (px - current_point.x ) < 0.1 &&
397- fabs (py - current_point.y ) < 0.1 &&
398- fabs (pz - current_point.z ) < 0.1 )
399- {
400- num_valid++;
401- }
402- }
403- } // for y
404- } // for x
405-
406- if (num_valid >= 7 )
407- {
408- *marking_x = x;
409- *marking_y = y;
410- *marking_z = z;
411- ++marking_points;
412- ++marking_x;
413- ++marking_y;
414- ++marking_z;
415- }
381+ *marking_x = x;
382+ *marking_y = y;
383+ *marking_z = z;
384+ ++marking_points;
385+ ++marking_x;
386+ ++marking_y;
387+ ++marking_z;
416388 }
417- } // for j (y)
418- } // for i (x )
419- }
389+ }
390+ } // for j (y )
391+ } // for i (x)
420392
421393 clearing_mod.resize (clearing_points);
422394 marking_mod.resize (marking_points);
@@ -425,19 +397,14 @@ void DepthLayer::depthImageCallback(sensor_msgs::msg::Image::ConstSharedPtr msg)
425397 if (publish_observations_)
426398 {
427399 clearing_pub_->publish (clearing_msg);
400+ marking_pub_->publish (marking_msg);
428401 }
429402
430- // buffer the ground plane observation
403+ // buffer the observations
431404 clearing_buf_->lock ();
432405 clearing_buf_->bufferCloud (clearing_msg);
433406 clearing_buf_->unlock ();
434407
435- // Publish and buffer our marking point cloud
436- if (publish_observations_)
437- {
438- marking_pub_->publish (marking_msg);
439- }
440-
441408 marking_buf_->lock ();
442409 marking_buf_->bufferCloud (marking_msg);
443410 marking_buf_->unlock ();
0 commit comments