Skip to content

Commit 1c69d1d

Browse files
authored
Fix memory growth issue in isPoseOccupied (#5715)
Signed-off-by: mini-1235 <mauricepurnawan@gmail.com>
1 parent d93fead commit 1c69d1d

File tree

3 files changed

+26
-14
lines changed

3 files changed

+26
-14
lines changed

nav2_behavior_tree/include/nav2_behavior_tree/plugins/condition/is_pose_occupied_condition.hpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ class IsPoseOccupiedCondition : public BT::ConditionNode
6060
*/
6161
void initialize();
6262

63+
/**
64+
* @brief Function to create ROS interfaces
65+
*/
66+
void createROSInterfaces();
67+
6368
/**
6469
* @brief Creates list of BT ports
6570
* @return BT::PortsList Containing node-specific ports
@@ -72,7 +77,8 @@ class IsPoseOccupiedCondition : public BT::ConditionNode
7277

7378
return {
7479
BT::InputPort<geometry_msgs::msg::PoseStamped>("pose", "Pose to check if occupied"),
75-
BT::InputPort<std::string>("service_name", "global_costmap/get_cost_global_costmap"),
80+
BT::InputPort<std::string>("service_name", "global_costmap/get_cost_global_costmap",
81+
"The service name to call GetCosts"),
7682
BT::InputPort<double>(
7783
"cost_threshold", 254.0,
7884
"Cost threshold for considering a pose occupied"),

nav2_behavior_tree/plugins/condition/is_path_valid_condition.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,11 @@ IsPathValidCondition::IsPathValidCondition(
3131
node_->create_client<nav2_msgs::srv::IsPathValid>(
3232
"is_path_valid",
3333
false /* Does not create and spin an internal executor*/);
34-
35-
server_timeout_ = config().blackboard->template get<std::chrono::milliseconds>("server_timeout");
3634
}
3735

3836
void IsPathValidCondition::initialize()
3937
{
40-
getInput<std::chrono::milliseconds>("server_timeout", server_timeout_);
38+
getInputOrBlackboard("server_timeout", server_timeout_);
4139
getInput<unsigned int>("max_cost", max_cost_);
4240
getInput<bool>("consider_unknown_as_obstacle", consider_unknown_as_obstacle_);
4341
}

nav2_behavior_tree/plugins/condition/is_pose_occupied_condition.cpp

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,32 @@ IsPoseOccupiedCondition::IsPoseOccupiedCondition(
2424
const std::string & condition_name,
2525
const BT::NodeConfiguration & conf)
2626
: BT::ConditionNode(condition_name, conf),
27-
use_footprint_(true), consider_unknown_as_obstacle_(false), cost_threshold_(254),
28-
service_name_("global_costmap/get_cost_global_costmap")
27+
use_footprint_(true), consider_unknown_as_obstacle_(false), cost_threshold_(254)
2928
{
30-
node_ = config().blackboard->get<nav2::LifecycleNode::SharedPtr>("node");
31-
server_timeout_ = config().blackboard->template get<std::chrono::milliseconds>("server_timeout");
29+
initialize();
3230
}
3331

3432
void IsPoseOccupiedCondition::initialize()
3533
{
36-
getInput<std::string>("service_name", service_name_);
3734
getInput<double>("cost_threshold", cost_threshold_);
3835
getInput<bool>("use_footprint", use_footprint_);
3936
getInput<bool>("consider_unknown_as_obstacle", consider_unknown_as_obstacle_);
40-
getInput<std::chrono::milliseconds>("server_timeout", server_timeout_);
41-
client_ =
42-
node_->create_client<nav2_msgs::srv::GetCosts>(
43-
service_name_,
44-
false /* Does not create and spin an internal executor*/);
37+
getInputOrBlackboard("server_timeout", server_timeout_);
38+
createROSInterfaces();
39+
}
40+
41+
void IsPoseOccupiedCondition::createROSInterfaces()
42+
{
43+
std::string service_new;
44+
getInput<std::string>("service_name", service_new);
45+
if (service_new != service_name_ || !client_) {
46+
service_name_ = service_new;
47+
node_ = config().blackboard->get<nav2::LifecycleNode::SharedPtr>("node");
48+
client_ =
49+
node_->create_client<nav2_msgs::srv::GetCosts>(
50+
service_name_,
51+
false /* Does not create and spin an internal executor*/);
52+
}
4553
}
4654

4755
BT::NodeStatus IsPoseOccupiedCondition::tick()

0 commit comments

Comments
 (0)