@@ -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
3432void 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
4755BT::NodeStatus IsPoseOccupiedCondition::tick ()
0 commit comments