Skip to content

Commit c1cd575

Browse files
committed
fix linting and fixed other nodes
1 parent ea21535 commit c1cd575

21 files changed

+111
-88
lines changed

nav2_behavior_tree/include/nav2_behavior_tree/plugins/action/goal_checker_selector_node.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class GoalCheckerSelector : public BT::SyncActionNode
8282
* @param msg the message with the id of the goal_checker_selector
8383
*/
8484
void callbackGoalCheckerSelect(const std_msgs::msg::String::SharedPtr msg);
85-
85+
bool first_time;
8686
rclcpp::Subscription<std_msgs::msg::String>::SharedPtr goal_checker_selector_sub_;
8787

8888
std::string last_selected_goal_checker_;

nav2_behavior_tree/include/nav2_behavior_tree/plugins/action/planner_selector_node.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class PlannerSelector : public BT::SyncActionNode
8383
*/
8484
void callbackPlannerSelect(const std_msgs::msg::String::SharedPtr msg);
8585

86-
86+
bool first_time;
8787
rclcpp::Subscription<std_msgs::msg::String>::SharedPtr planner_selector_sub_;
8888

8989
std::string last_selected_planner_;

nav2_behavior_tree/include/nav2_behavior_tree/plugins/action/remove_passed_goals_action.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ class RemovePassedGoals : public BT::ActionNodeBase
5252
void halt() override {}
5353
BT::NodeStatus tick() override;
5454

55+
bool first_time;
5556
double viapoint_achieved_radius_;
5657
double transform_tolerance_;
5758
std::shared_ptr<tf2_ros::Buffer> tf_;

nav2_behavior_tree/plugins/action/assisted_teleop_action.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ void AssistedTeleopAction::on_tick()
3636

3737
// Populate the input message
3838
goal_.time_allowance = rclcpp::Duration::from_seconds(time_allowance);
39-
39+
4040
if (is_recovery_) {
4141
increment_recovery_count();
4242
}

nav2_behavior_tree/plugins/action/back_up_action.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ void BackUpAction::on_tick()
4343
goal_.target.z = 0.0;
4444
goal_.speed = speed;
4545
goal_.time_allowance = rclcpp::Duration::from_seconds(time_allowance);
46-
46+
4747
increment_recovery_count();
4848
}
4949

nav2_behavior_tree/plugins/action/controller_selector_node.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,30 +30,30 @@ using std::placeholders::_1;
3030
ControllerSelector::ControllerSelector(
3131
const std::string & name,
3232
const BT::NodeConfiguration & conf)
33-
: BT::SyncActionNode(name, conf)
33+
: BT::SyncActionNode(name, conf),
34+
first_time(true)
3435
{
3536
node_ = config().blackboard->get<rclcpp::Node::SharedPtr>("node");
3637
callback_group_ = node_->create_callback_group(
3738
rclcpp::CallbackGroupType::MutuallyExclusive,
3839
false);
3940
callback_group_executor_.add_callback_group(callback_group_, node_->get_node_base_interface());
41+
}
4042

43+
BT::NodeStatus ControllerSelector::tick()
44+
{
4145
getInput("topic_name", topic_name_);
4246

4347
rclcpp::QoS qos(rclcpp::KeepLast(1));
4448
qos.transient_local().reliable();
45-
4649
rclcpp::SubscriptionOptions sub_option;
4750
sub_option.callback_group = callback_group_;
4851
controller_selector_sub_ = node_->create_subscription<std_msgs::msg::String>(
4952
topic_name_,
5053
qos,
5154
std::bind(&ControllerSelector::callbackControllerSelect, this, _1),
5255
sub_option);
53-
}
5456

55-
BT::NodeStatus ControllerSelector::tick()
56-
{
5757
callback_group_executor_.spin_some();
5858

5959
// This behavior always use the last selected controller received from the topic input.

nav2_behavior_tree/plugins/action/goal_checker_selector_node.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,25 @@ using std::placeholders::_1;
3030
GoalCheckerSelector::GoalCheckerSelector(
3131
const std::string & name,
3232
const BT::NodeConfiguration & conf)
33-
: BT::SyncActionNode(name, conf)
33+
: BT::SyncActionNode(name, conf),
34+
first_time(true)
3435
{
3536
node_ = config().blackboard->get<rclcpp::Node::SharedPtr>("node");
36-
37-
getInput("topic_name", topic_name_);
38-
39-
rclcpp::QoS qos(rclcpp::KeepLast(1));
40-
qos.transient_local().reliable();
41-
42-
goal_checker_selector_sub_ = node_->create_subscription<std_msgs::msg::String>(
43-
topic_name_, qos, std::bind(&GoalCheckerSelector::callbackGoalCheckerSelect, this, _1));
4437
}
4538

4639
BT::NodeStatus GoalCheckerSelector::tick()
4740
{
41+
if (first_time) {
42+
first_time = false;
43+
getInput("topic_name", topic_name_);
44+
45+
rclcpp::QoS qos(rclcpp::KeepLast(1));
46+
qos.transient_local().reliable();
47+
48+
goal_checker_selector_sub_ = node_->create_subscription<std_msgs::msg::String>(
49+
topic_name_, qos, std::bind(&GoalCheckerSelector::callbackGoalCheckerSelect, this, _1));
50+
}
51+
4852
rclcpp::spin_some(node_);
4953

5054
// This behavior always use the last selected goal checker received from the topic input.

nav2_behavior_tree/plugins/action/planner_selector_node.cpp

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,30 +30,35 @@ using std::placeholders::_1;
3030
PlannerSelector::PlannerSelector(
3131
const std::string & name,
3232
const BT::NodeConfiguration & conf)
33-
: BT::SyncActionNode(name, conf)
33+
: BT::SyncActionNode(name, conf),
34+
first_time(true)
3435
{
3536
node_ = config().blackboard->get<rclcpp::Node::SharedPtr>("node");
36-
callback_group_ = node_->create_callback_group(
37-
rclcpp::CallbackGroupType::MutuallyExclusive,
38-
false);
39-
callback_group_executor_.add_callback_group(callback_group_, node_->get_node_base_interface());
40-
41-
getInput("topic_name", topic_name_);
42-
43-
rclcpp::QoS qos(rclcpp::KeepLast(1));
44-
qos.transient_local().reliable();
45-
46-
rclcpp::SubscriptionOptions sub_option;
47-
sub_option.callback_group = callback_group_;
48-
planner_selector_sub_ = node_->create_subscription<std_msgs::msg::String>(
49-
topic_name_,
50-
qos,
51-
std::bind(&PlannerSelector::callbackPlannerSelect, this, _1),
52-
sub_option);
5337
}
5438

5539
BT::NodeStatus PlannerSelector::tick()
5640
{
41+
if (first_time) {
42+
first_time = false;
43+
callback_group_ = node_->create_callback_group(
44+
rclcpp::CallbackGroupType::MutuallyExclusive,
45+
false);
46+
callback_group_executor_.add_callback_group(callback_group_, node_->get_node_base_interface());
47+
48+
getInput("topic_name", topic_name_);
49+
50+
rclcpp::QoS qos(rclcpp::KeepLast(1));
51+
qos.transient_local().reliable();
52+
53+
rclcpp::SubscriptionOptions sub_option;
54+
sub_option.callback_group = callback_group_;
55+
planner_selector_sub_ = node_->create_subscription<std_msgs::msg::String>(
56+
topic_name_,
57+
qos,
58+
std::bind(&PlannerSelector::callbackPlannerSelect, this, _1),
59+
sub_option);
60+
}
61+
5762
callback_group_executor_.spin_some();
5863

5964
// This behavior always use the last selected planner received from the topic input.

nav2_behavior_tree/plugins/action/remove_passed_goals_action.cpp

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,24 +29,29 @@ RemovePassedGoals::RemovePassedGoals(
2929
const std::string & name,
3030
const BT::NodeConfiguration & conf)
3131
: BT::ActionNodeBase(name, conf),
32-
viapoint_achieved_radius_(0.5)
32+
viapoint_achieved_radius_(0.5),
33+
first_time(true)
3334
{
34-
getInput("radius", viapoint_achieved_radius_);
35-
36-
tf_ = config().blackboard->get<std::shared_ptr<tf2_ros::Buffer>>("tf_buffer");
37-
auto node = config().blackboard->get<rclcpp::Node::SharedPtr>("node");
38-
node->get_parameter("transform_tolerance", transform_tolerance_);
39-
40-
global_frame_ = BT::deconflictPortAndParamFrame<std::string, RemovePassedGoals>(
41-
node, "global_frame", this);
42-
robot_base_frame_ = BT::deconflictPortAndParamFrame<std::string, RemovePassedGoals>(
43-
node, "robot_base_frame", this);
4435
}
4536

4637
inline BT::NodeStatus RemovePassedGoals::tick()
4738
{
4839
setStatus(BT::NodeStatus::RUNNING);
4940

41+
if (first_time) {
42+
first_time = false;
43+
getInput("radius", viapoint_achieved_radius_);
44+
45+
tf_ = config().blackboard->get<std::shared_ptr<tf2_ros::Buffer>>("tf_buffer");
46+
auto node = config().blackboard->get<rclcpp::Node::SharedPtr>("node");
47+
node->get_parameter("transform_tolerance", transform_tolerance_);
48+
49+
global_frame_ = BT::deconflictPortAndParamFrame<std::string, RemovePassedGoals>(
50+
node, "global_frame", this);
51+
robot_base_frame_ = BT::deconflictPortAndParamFrame<std::string, RemovePassedGoals>(
52+
node, "robot_base_frame", this);
53+
}
54+
5055
Goals goal_poses;
5156
getInput("input_goals", goal_poses);
5257

nav2_behavior_tree/plugins/action/smoother_selector_node.cpp

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,30 +31,34 @@ using std::placeholders::_1;
3131
SmootherSelector::SmootherSelector(
3232
const std::string & name,
3333
const BT::NodeConfiguration & conf)
34-
: BT::SyncActionNode(name, conf)
34+
: BT::SyncActionNode(name, conf),
35+
first_time(true)
3536
{
3637
node_ = config().blackboard->get<rclcpp::Node::SharedPtr>("node");
3738
callback_group_ = node_->create_callback_group(
3839
rclcpp::CallbackGroupType::MutuallyExclusive,
3940
false);
4041
callback_group_executor_.add_callback_group(callback_group_, node_->get_node_base_interface());
41-
42-
getInput("topic_name", topic_name_);
43-
44-
rclcpp::QoS qos(rclcpp::KeepLast(1));
45-
qos.transient_local().reliable();
46-
47-
rclcpp::SubscriptionOptions sub_option;
48-
sub_option.callback_group = callback_group_;
49-
smoother_selector_sub_ = node_->create_subscription<std_msgs::msg::String>(
50-
topic_name_,
51-
qos,
52-
std::bind(&SmootherSelector::callbackSmootherSelect, this, _1),
53-
sub_option);
5442
}
5543

5644
BT::NodeStatus SmootherSelector::tick()
5745
{
46+
if (first_time) {
47+
first_time = false;
48+
getInput("topic_name", topic_name_);
49+
50+
rclcpp::QoS qos(rclcpp::KeepLast(1));
51+
qos.transient_local().reliable();
52+
53+
rclcpp::SubscriptionOptions sub_option;
54+
sub_option.callback_group = callback_group_;
55+
smoother_selector_sub_ = node_->create_subscription<std_msgs::msg::String>(
56+
topic_name_,
57+
qos,
58+
std::bind(&SmootherSelector::callbackSmootherSelect, this, _1),
59+
sub_option);
60+
}
61+
5862
callback_group_executor_.spin_some();
5963

6064
// This behavior always use the last selected smoother received from the topic input.

0 commit comments

Comments
 (0)