@@ -206,15 +206,13 @@ void ObstacleLayer::onInitialize()
206206
207207 // create an observation buffer
208208 observation_buffers_.push_back (
209- std::shared_ptr<ObservationBuffer
210- >(
211- new ObservationBuffer (
212- node, topic, observation_keep_time, expected_update_rate,
209+ std::make_shared<ObservationBuffer>(node, topic, observation_keep_time,
210+ expected_update_rate,
213211 min_obstacle_height,
214212 max_obstacle_height, obstacle_max_range, obstacle_min_range, raytrace_max_range,
215213 raytrace_min_range, *tf_,
216214 global_frame_,
217- sensor_frame, tf2::durationFromSec (transform_tolerance)))) ;
215+ sensor_frame, tf2::durationFromSec (transform_tolerance)));
218216
219217 // check if we'll add this buffer to our marking observation buffers
220218 if (marking) {
@@ -399,7 +397,7 @@ ObstacleLayer::dynamicParametersCallback(
399397void
400398ObstacleLayer::laserScanCallback (
401399 sensor_msgs::msg::LaserScan::ConstSharedPtr message,
402- const std::shared_ptr<nav2_costmap_2d:: ObservationBuffer> & buffer)
400+ const std::shared_ptr<ObservationBuffer> & buffer)
403401{
404402 // project the laser into a point cloud
405403 sensor_msgs::msg::PointCloud2 cloud;
@@ -433,7 +431,7 @@ ObstacleLayer::laserScanCallback(
433431void
434432ObstacleLayer::laserScanValidInfCallback (
435433 sensor_msgs::msg::LaserScan::ConstSharedPtr raw_message,
436- const std::shared_ptr<nav2_costmap_2d:: ObservationBuffer> & buffer)
434+ const std::shared_ptr<ObservationBuffer> & buffer)
437435{
438436 // Filter positive infinities ("Inf"s) to max_range.
439437 float epsilon = 0.0001 ; // a tenth of a millimeter
@@ -499,7 +497,7 @@ ObstacleLayer::updateBounds(
499497 useExtraBounds (min_x, min_y, max_x, max_y);
500498
501499 bool current = true ;
502- std::vector<Observation> observations, clearing_observations;
500+ std::vector<Observation::ConstSharedPtr > observations, clearing_observations;
503501
504502 // get the marking observations
505503 current = current && getMarkingObservations (observations);
@@ -511,17 +509,15 @@ ObstacleLayer::updateBounds(
511509 current_ = current;
512510
513511 // raytrace freespace
514- for (unsigned int i = 0 ; i < clearing_observations. size (); ++i ) {
515- raytraceFreespace (clearing_observations[i] , min_x, min_y, max_x, max_y);
512+ for (const auto & clearing_observation : clearing_observations) {
513+ raytraceFreespace (*clearing_observation , min_x, min_y, max_x, max_y);
516514 }
517515
518516 // place the new obstacles into a priority queue... each with a priority of zero to begin with
519- for (std::vector<Observation>::const_iterator it = observations.begin ();
520- it != observations.end (); ++it)
521- {
522- const Observation & obs = *it;
517+ for (const auto & observation : observations) {
518+ const Observation & obs = *observation;
523519
524- const sensor_msgs::msg::PointCloud2 & cloud = *( obs.cloud_ ) ;
520+ const sensor_msgs::msg::PointCloud2 & cloud = obs.cloud_ ;
525521
526522 double sq_obstacle_max_range = obs.obstacle_max_range_ * obs.obstacle_max_range_ ;
527523 double sq_obstacle_min_range = obs.obstacle_min_range_ * obs.obstacle_min_range_ ;
@@ -632,14 +628,15 @@ ObstacleLayer::updateCosts(
632628
633629void
634630ObstacleLayer::addStaticObservation (
635- nav2_costmap_2d::Observation & obs,
631+ nav2_costmap_2d::Observation obs,
636632 bool marking, bool clearing)
637633{
634+ const auto observation = Observation::make_shared (std::move (obs));
638635 if (marking) {
639- static_marking_observations_.push_back (obs );
636+ static_marking_observations_.push_back (observation );
640637 }
641638 if (clearing) {
642- static_clearing_observations_.push_back (obs );
639+ static_clearing_observations_.push_back (observation );
643640 }
644641}
645642
@@ -655,15 +652,18 @@ ObstacleLayer::clearStaticObservations(bool marking, bool clearing)
655652}
656653
657654bool
658- ObstacleLayer::getMarkingObservations (std::vector<Observation> & marking_observations) const
655+ ObstacleLayer::getMarkingObservations (
656+ std::vector<Observation::ConstSharedPtr> & marking_observations) const
659657{
660658 bool current = true ;
661659 // get the marking observations
662- for (unsigned int i = 0 ; i < marking_buffers_.size (); ++i) {
663- marking_buffers_[i]->lock ();
664- marking_buffers_[i]->getObservations (marking_observations);
665- current = marking_buffers_[i]->isCurrent () && current;
666- marking_buffers_[i]->unlock ();
660+ for (const auto & marking_buffer : marking_buffers_) {
661+ if (marking_buffer) {
662+ marking_buffer->lock ();
663+ marking_buffer->getObservations (marking_observations);
664+ current = marking_buffer->isCurrent () && current;
665+ marking_buffer->unlock ();
666+ }
667667 }
668668 marking_observations.insert (
669669 marking_observations.end (),
@@ -672,15 +672,18 @@ ObstacleLayer::getMarkingObservations(std::vector<Observation> & marking_observa
672672}
673673
674674bool
675- ObstacleLayer::getClearingObservations (std::vector<Observation> & clearing_observations) const
675+ ObstacleLayer::getClearingObservations (
676+ std::vector<Observation::ConstSharedPtr> & clearing_observations) const
676677{
677678 bool current = true ;
678679 // get the clearing observations
679- for (unsigned int i = 0 ; i < clearing_buffers_.size (); ++i) {
680- clearing_buffers_[i]->lock ();
681- clearing_buffers_[i]->getObservations (clearing_observations);
682- current = clearing_buffers_[i]->isCurrent () && current;
683- clearing_buffers_[i]->unlock ();
680+ for (const auto & clearing_buffer : clearing_buffers_) {
681+ if (clearing_buffer) {
682+ clearing_buffer->lock ();
683+ clearing_buffer->getObservations (clearing_observations);
684+ current = clearing_buffer->isCurrent () && current;
685+ clearing_buffer->unlock ();
686+ }
684687 }
685688 clearing_observations.insert (
686689 clearing_observations.end (),
@@ -697,7 +700,7 @@ ObstacleLayer::raytraceFreespace(
697700{
698701 double ox = clearing_observation.origin_ .x ;
699702 double oy = clearing_observation.origin_ .y ;
700- const sensor_msgs::msg::PointCloud2 & cloud = *( clearing_observation.cloud_ ) ;
703+ const sensor_msgs::msg::PointCloud2 & cloud = clearing_observation.cloud_ ;
701704
702705 // get the map coordinates of the origin of the sensor
703706 unsigned int x0, y0;
@@ -833,9 +836,9 @@ ObstacleLayer::reset()
833836void
834837ObstacleLayer::resetBuffersLastUpdated ()
835838{
836- for (unsigned int i = 0 ; i < observation_buffers_. size (); ++i ) {
837- if (observation_buffers_[i] ) {
838- observation_buffers_[i] ->resetLastUpdated ();
839+ for (const auto & observation_buffer : observation_buffers_) {
840+ if (observation_buffer ) {
841+ observation_buffer ->resetLastUpdated ();
839842 }
840843 }
841844}
0 commit comments