@@ -31,7 +31,6 @@ using namespace std::chrono; // NOLINT
3131SmacPlanner::SmacPlanner ()
3232: _a_star(nullptr ),
3333 _smoother (nullptr ),
34- _node(nullptr ),
3534 _costmap(nullptr ),
3635 _costmap_downsampler(nullptr )
3736{
@@ -40,7 +39,7 @@ SmacPlanner::SmacPlanner()
4039SmacPlanner::~SmacPlanner ()
4140{
4241 RCLCPP_INFO (
43- _node-> get_logger () , " Destroying plugin %s of type SmacPlanner" ,
42+ _logger , " Destroying plugin %s of type SmacPlanner" ,
4443 _name.c_str ());
4544}
4645
@@ -49,7 +48,9 @@ void SmacPlanner::configure(
4948 std::string name, std::shared_ptr<tf2_ros::Buffer>/* tf*/ ,
5049 std::shared_ptr<nav2_costmap_2d::Costmap2DROS> costmap_ros)
5150{
52- _node = parent.lock ();
51+ auto node = parent.lock ();
52+ _logger = node->get_logger ();
53+ _clock = node->get_clock ();
5354 _costmap = costmap_ros->getCostmap ();
5455 _name = name;
5556 _global_frame = costmap_ros->getGlobalFrameID ();
@@ -64,77 +65,77 @@ void SmacPlanner::configure(
6465
6566 // General planner params
6667 nav2_util::declare_parameter_if_not_declared (
67- _node , name + " .tolerance" , rclcpp::ParameterValue (0.125 ));
68- _tolerance = static_cast <float >(_node ->get_parameter (name + " .tolerance" ).as_double ());
68+ node , name + " .tolerance" , rclcpp::ParameterValue (0.125 ));
69+ _tolerance = static_cast <float >(node ->get_parameter (name + " .tolerance" ).as_double ());
6970 nav2_util::declare_parameter_if_not_declared (
70- _node , name + " .downsample_costmap" , rclcpp::ParameterValue (true ));
71- _node ->get_parameter (name + " .downsample_costmap" , _downsample_costmap);
71+ node , name + " .downsample_costmap" , rclcpp::ParameterValue (true ));
72+ node ->get_parameter (name + " .downsample_costmap" , _downsample_costmap);
7273 nav2_util::declare_parameter_if_not_declared (
73- _node , name + " .downsampling_factor" , rclcpp::ParameterValue (1 ));
74- _node ->get_parameter (name + " .downsampling_factor" , _downsampling_factor);
74+ node , name + " .downsampling_factor" , rclcpp::ParameterValue (1 ));
75+ node ->get_parameter (name + " .downsampling_factor" , _downsampling_factor);
7576
7677 nav2_util::declare_parameter_if_not_declared (
77- _node , name + " .angle_quantization_bins" , rclcpp::ParameterValue (1 ));
78- _node ->get_parameter (name + " .angle_quantization_bins" , angle_quantizations);
78+ node , name + " .angle_quantization_bins" , rclcpp::ParameterValue (1 ));
79+ node ->get_parameter (name + " .angle_quantization_bins" , angle_quantizations);
7980 _angle_bin_size = 2.0 * M_PI / angle_quantizations;
8081 _angle_quantizations = static_cast <unsigned int >(angle_quantizations);
8182
8283 nav2_util::declare_parameter_if_not_declared (
83- _node , name + " .allow_unknown" , rclcpp::ParameterValue (true ));
84- _node ->get_parameter (name + " .allow_unknown" , allow_unknown);
84+ node , name + " .allow_unknown" , rclcpp::ParameterValue (true ));
85+ node ->get_parameter (name + " .allow_unknown" , allow_unknown);
8586 nav2_util::declare_parameter_if_not_declared (
86- _node , name + " .max_iterations" , rclcpp::ParameterValue (-1 ));
87- _node ->get_parameter (name + " .max_iterations" , max_iterations);
87+ node , name + " .max_iterations" , rclcpp::ParameterValue (-1 ));
88+ node ->get_parameter (name + " .max_iterations" , max_iterations);
8889 nav2_util::declare_parameter_if_not_declared (
89- _node , name + " .smooth_path" , rclcpp::ParameterValue (false ));
90- _node ->get_parameter (name + " .smooth_path" , smooth_path);
90+ node , name + " .smooth_path" , rclcpp::ParameterValue (false ));
91+ node ->get_parameter (name + " .smooth_path" , smooth_path);
9192
9293 nav2_util::declare_parameter_if_not_declared (
93- _node , name + " .minimum_turning_radius" , rclcpp::ParameterValue (0.2 ));
94- _node ->get_parameter (name + " .minimum_turning_radius" , search_info.minimum_turning_radius );
94+ node , name + " .minimum_turning_radius" , rclcpp::ParameterValue (0.2 ));
95+ node ->get_parameter (name + " .minimum_turning_radius" , search_info.minimum_turning_radius );
9596
9697 nav2_util::declare_parameter_if_not_declared (
97- _node , name + " .reverse_penalty" , rclcpp::ParameterValue (2.0 ));
98- _node ->get_parameter (name + " .reverse_penalty" , search_info.reverse_penalty );
98+ node , name + " .reverse_penalty" , rclcpp::ParameterValue (2.0 ));
99+ node ->get_parameter (name + " .reverse_penalty" , search_info.reverse_penalty );
99100 nav2_util::declare_parameter_if_not_declared (
100- _node , name + " .change_penalty" , rclcpp::ParameterValue (0.5 ));
101- _node ->get_parameter (name + " .change_penalty" , search_info.change_penalty );
101+ node , name + " .change_penalty" , rclcpp::ParameterValue (0.5 ));
102+ node ->get_parameter (name + " .change_penalty" , search_info.change_penalty );
102103 nav2_util::declare_parameter_if_not_declared (
103- _node , name + " .non_straight_penalty" , rclcpp::ParameterValue (1.05 ));
104- _node ->get_parameter (name + " .non_straight_penalty" , search_info.non_straight_penalty );
104+ node , name + " .non_straight_penalty" , rclcpp::ParameterValue (1.05 ));
105+ node ->get_parameter (name + " .non_straight_penalty" , search_info.non_straight_penalty );
105106 nav2_util::declare_parameter_if_not_declared (
106- _node , name + " .cost_penalty" , rclcpp::ParameterValue (1.2 ));
107- _node ->get_parameter (name + " .cost_penalty" , search_info.cost_penalty );
107+ node , name + " .cost_penalty" , rclcpp::ParameterValue (1.2 ));
108+ node ->get_parameter (name + " .cost_penalty" , search_info.cost_penalty );
108109 nav2_util::declare_parameter_if_not_declared (
109- _node , name + " .analytic_expansion_ratio" , rclcpp::ParameterValue (2.0 ));
110- _node ->get_parameter (name + " .analytic_expansion_ratio" , search_info.analytic_expansion_ratio );
110+ node , name + " .analytic_expansion_ratio" , rclcpp::ParameterValue (2.0 ));
111+ node ->get_parameter (name + " .analytic_expansion_ratio" , search_info.analytic_expansion_ratio );
111112
112113 nav2_util::declare_parameter_if_not_declared (
113- _node , name + " .max_planning_time_ms" , rclcpp::ParameterValue (5000.0 ));
114- _node ->get_parameter (name + " .max_planning_time_ms" , _max_planning_time);
114+ node , name + " .max_planning_time_ms" , rclcpp::ParameterValue (5000.0 ));
115+ node ->get_parameter (name + " .max_planning_time_ms" , _max_planning_time);
115116
116117 nav2_util::declare_parameter_if_not_declared (
117- _node , name + " .motion_model_for_search" , rclcpp::ParameterValue (std::string (" DUBIN" )));
118- _node ->get_parameter (name + " .motion_model_for_search" , motion_model_for_search);
118+ node , name + " .motion_model_for_search" , rclcpp::ParameterValue (std::string (" DUBIN" )));
119+ node ->get_parameter (name + " .motion_model_for_search" , motion_model_for_search);
119120 MotionModel motion_model = fromString (motion_model_for_search);
120121 if (motion_model == MotionModel::UNKNOWN) {
121122 RCLCPP_WARN (
122- _node-> get_logger () ,
123+ _logger ,
123124 " Unable to get MotionModel search type. Given '%s', "
124125 " valid options are MOORE, VON_NEUMANN, DUBIN, REEDS_SHEPP." ,
125126 motion_model_for_search.c_str ());
126127 }
127128
128129 if (max_on_approach_iterations <= 0 ) {
129130 RCLCPP_INFO (
130- _node-> get_logger () , " On approach iteration selected as <= 0, "
131+ _logger , " On approach iteration selected as <= 0, "
131132 " disabling tolerance and on approach iterations." );
132133 max_on_approach_iterations = std::numeric_limits<int >::max ();
133134 }
134135
135136 if (max_iterations <= 0 ) {
136137 RCLCPP_INFO (
137- _node-> get_logger () , " maximum iteration selected as <= 0, "
138+ _logger , " maximum iteration selected as <= 0, "
138139 " disabling maximum iterations." );
139140 max_iterations = std::numeric_limits<int >::max ();
140141 }
@@ -153,22 +154,23 @@ void SmacPlanner::configure(
153154
154155 if (smooth_path) {
155156 _smoother = std::make_unique<Smoother>();
156- _optimizer_params.get (_node .get (), name);
157- _smoother_params.get (_node .get (), name);
157+ _optimizer_params.get (node .get (), name);
158+ _smoother_params.get (node .get (), name);
158159 _smoother_params.max_curvature = 1 .0f / minimum_turning_radius_global_coords;
159160 _smoother->initialize (_optimizer_params);
160161 }
161162
162163 if (_downsample_costmap && _downsampling_factor > 1 ) {
163164 std::string topic_name = " downsampled_costmap" ;
164- _costmap_downsampler = std::make_unique<CostmapDownsampler>(_node);
165- _costmap_downsampler->initialize (_global_frame, topic_name, _costmap, _downsampling_factor);
165+ _costmap_downsampler = std::make_unique<CostmapDownsampler>();
166+ _costmap_downsampler->on_configure (
167+ node, _global_frame, topic_name, _costmap, _downsampling_factor);
166168 }
167169
168- _raw_plan_publisher = _node ->create_publisher <nav_msgs::msg::Path>(" unsmoothed_plan" , 1 );
170+ _raw_plan_publisher = node ->create_publisher <nav_msgs::msg::Path>(" unsmoothed_plan" , 1 );
169171
170172 RCLCPP_INFO (
171- _node-> get_logger () , " Configured plugin %s of type SmacPlanner with "
173+ _logger , " Configured plugin %s of type SmacPlanner with "
172174 " tolerance %.2f, maximum iterations %i, "
173175 " max on approach iterations %i, and %s. Using motion model: %s." ,
174176 _name.c_str (), _tolerance, max_iterations, max_on_approach_iterations,
@@ -179,32 +181,33 @@ void SmacPlanner::configure(
179181void SmacPlanner::activate ()
180182{
181183 RCLCPP_INFO (
182- _node-> get_logger () , " Activating plugin %s of type SmacPlanner" ,
184+ _logger , " Activating plugin %s of type SmacPlanner" ,
183185 _name.c_str ());
184186 _raw_plan_publisher->on_activate ();
185187 if (_costmap_downsampler) {
186- _costmap_downsampler->activatePublisher ();
188+ _costmap_downsampler->on_activate ();
187189 }
188190}
189191
190192void SmacPlanner::deactivate ()
191193{
192194 RCLCPP_INFO (
193- _node-> get_logger () , " Deactivating plugin %s of type SmacPlanner" ,
195+ _logger , " Deactivating plugin %s of type SmacPlanner" ,
194196 _name.c_str ());
195197 _raw_plan_publisher->on_deactivate ();
196198 if (_costmap_downsampler) {
197- _costmap_downsampler->deactivatePublisher ();
199+ _costmap_downsampler->on_deactivate ();
198200 }
199201}
200202
201203void SmacPlanner::cleanup ()
202204{
203205 RCLCPP_INFO (
204- _node-> get_logger () , " Cleaning up plugin %s of type SmacPlanner" ,
206+ _logger , " Cleaning up plugin %s of type SmacPlanner" ,
205207 _name.c_str ());
206208 _a_star.reset ();
207209 _smoother.reset ();
210+ _costmap_downsampler->on_cleanup ();
208211 _costmap_downsampler.reset ();
209212 _raw_plan_publisher.reset ();
210213}
@@ -251,7 +254,7 @@ nav_msgs::msg::Path SmacPlanner::createPlan(
251254
252255 // Setup message
253256 nav_msgs::msg::Path plan;
254- plan.header .stamp = _node ->now ();
257+ plan.header .stamp = _clock ->now ();
255258 plan.header .frame_id = _global_frame;
256259 geometry_msgs::msg::PoseStamped pose;
257260 pose.header = plan.header ;
@@ -282,7 +285,7 @@ nav_msgs::msg::Path SmacPlanner::createPlan(
282285
283286 if (!error.empty ()) {
284287 RCLCPP_WARN (
285- _node-> get_logger () ,
288+ _logger ,
286289 " %s: failed to create plan, %s." ,
287290 _name.c_str (), error.c_str ());
288291 return plan;
@@ -304,7 +307,7 @@ nav_msgs::msg::Path SmacPlanner::createPlan(
304307 }
305308
306309 // Publish raw path for debug
307- if (_node-> count_subscribers ( _raw_plan_publisher->get_topic_name () ) > 0 ) {
310+ if (_raw_plan_publisher->get_subscription_count ( ) > 0 ) {
308311 _raw_plan_publisher->publish (plan);
309312 }
310313
@@ -328,7 +331,7 @@ nav_msgs::msg::Path SmacPlanner::createPlan(
328331 // Smooth plan
329332 if (!_smoother->smooth (path_world, costmap, _smoother_params)) {
330333 RCLCPP_WARN (
331- _node-> get_logger () ,
334+ _logger ,
332335 " %s: failed to smooth plan, Ceres could not find a usable solution to optimize." ,
333336 _name.c_str ());
334337 return plan;
0 commit comments