@@ -44,6 +44,7 @@ Polygon::~Polygon()
4444{
4545 RCLCPP_INFO (logger_, " [%s]: Destroying Polygon" , polygon_name_.c_str ());
4646 poly_.clear ();
47+ dyn_params_handler_.reset ();
4748}
4849
4950bool Polygon::configure ()
@@ -82,6 +83,10 @@ bool Polygon::configure()
8283 polygon_pub_topic, polygon_qos);
8384 }
8485
86+ // Add callback for dynamic parameters
87+ dyn_params_handler_ = node->add_on_set_parameters_callback (
88+ std::bind (&Polygon::dynamicParametersCallback, this , std::placeholders::_1));
89+
8590 return true ;
8691}
8792
@@ -109,6 +114,11 @@ ActionType Polygon::getActionType() const
109114 return action_type_;
110115}
111116
117+ bool Polygon::getEnabled () const
118+ {
119+ return enabled_;
120+ }
121+
112122int Polygon::getMaxPoints () const
113123{
114124 return max_points_;
@@ -244,6 +254,10 @@ bool Polygon::getCommonParameters(std::string & polygon_pub_topic)
244254 return false ;
245255 }
246256
257+ nav2_util::declare_parameter_if_not_declared (
258+ node, polygon_name_ + " .enabled" , rclcpp::ParameterValue (true ));
259+ enabled_ = node->get_parameter (polygon_name_ + " .enabled" ).as_bool ();
260+
247261 nav2_util::declare_parameter_if_not_declared (
248262 node, polygon_name_ + " .max_points" , rclcpp::ParameterValue (3 ));
249263 max_points_ = node->get_parameter (polygon_name_ + " .max_points" ).as_int ();
@@ -350,6 +364,26 @@ bool Polygon::getParameters(std::string & polygon_pub_topic, std::string & footp
350364 return true ;
351365}
352366
367+ rcl_interfaces::msg::SetParametersResult
368+ Polygon::dynamicParametersCallback (
369+ std::vector<rclcpp::Parameter> parameters)
370+ {
371+ rcl_interfaces::msg::SetParametersResult result;
372+
373+ for (auto parameter : parameters) {
374+ const auto & param_type = parameter.get_type ();
375+ const auto & param_name = parameter.get_name ();
376+
377+ if (param_type == rcl_interfaces::msg::ParameterType::PARAMETER_BOOL) {
378+ if (param_name == polygon_name_ + " ." + " enabled" ) {
379+ enabled_ = parameter.as_bool ();
380+ }
381+ }
382+ }
383+ result.successful = true ;
384+ return result;
385+ }
386+
353387inline bool Polygon::isPointInside (const Point & point) const
354388{
355389 // Adaptation of Shimrat, Moshe. "Algorithm 112: position of point relative to polygon."
0 commit comments