Skip to content

Commit 43c810b

Browse files
david-wbDavid Brown
authored andcommitted
new param to disable collision checking in DriveOnHeading and BackUp actions (ros-navigation#4785)
* add parameter to the DriveOnHeading and BackUp actions to disable collision checking Signed-off-by: David Brown <david.brown@inria.fr> * update commander api Signed-off-by: David Brown <david.brown@inria.fr> * use a less verbose param name Signed-off-by: David Brown <davewbrwn@gmail.com> * fix flake8 error Signed-off-by: David Brown <davewbrwn@gmail.com> * rename param Signed-off-by: David Brown <davewbrwn@gmail.com> * set defaults in action messages and popular instance field for param Signed-off-by: David Brown <davewbrwn@gmail.com> * populate field in backup action as well Signed-off-by: David Brown <davewbrwn@gmail.com> * also add the new param to the spin action Signed-off-by: David Brown <davewbrwn@gmail.com> * fix incorrect type Signed-off-by: David Brown <davewbrwn@gmail.com> --------- Signed-off-by: David Brown <david.brown@inria.fr> Signed-off-by: David Brown <davewbrwn@gmail.com> Co-authored-by: David Brown <david.brown@inria.fr>
1 parent a42dc34 commit 43c810b

File tree

18 files changed

+48
-8
lines changed

18 files changed

+48
-8
lines changed

nav2_behavior_tree/include/nav2_behavior_tree/plugins/action/back_up_action.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ class BackUpAction : public BtActionNode<nav2_msgs::action::BackUp>
8080
BT::InputPort<double>("backup_dist", 0.15, "Distance to backup"),
8181
BT::InputPort<double>("backup_speed", 0.025, "Speed at which to backup"),
8282
BT::InputPort<double>("time_allowance", 10.0, "Allowed time for reversing"),
83+
BT::InputPort<bool>("disable_collision_checks", false, "Disable collision checking"),
8384
BT::OutputPort<ActionResult::_error_code_type>(
8485
"error_code_id", "The back up behavior server error code")
8586
});

nav2_behavior_tree/include/nav2_behavior_tree/plugins/action/drive_on_heading_action.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class DriveOnHeadingAction : public BtActionNode<nav2_msgs::action::DriveOnHeadi
5959
BT::InputPort<double>("dist_to_travel", 0.15, "Distance to travel"),
6060
BT::InputPort<double>("speed", 0.025, "Speed at which to travel"),
6161
BT::InputPort<double>("time_allowance", 10.0, "Allowed time for driving on heading"),
62+
BT::InputPort<bool>("disable_collision_checks", false, "Disable collision checking"),
6263
BT::OutputPort<Action::Result::_error_code_type>(
6364
"error_code_id", "The drive on heading behavior server error code")
6465
});

nav2_behavior_tree/include/nav2_behavior_tree/plugins/action/spin_action.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ class SpinAction : public BtActionNode<nav2_msgs::action::Spin>
6464
BT::InputPort<double>("spin_dist", 1.57, "Spin distance"),
6565
BT::InputPort<double>("time_allowance", 10.0, "Allowed time for spinning"),
6666
BT::InputPort<bool>("is_recovery", true, "True if recovery"),
67+
BT::InputPort<bool>("disable_collision_checks", false, "Disable collision checking"),
6768
BT::OutputPort<ActionResult::_error_code_type>(
6869
"error_code_id", "The spin behavior error code")
6970
});

nav2_behavior_tree/nav2_tree_nodes.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
<input_port name="time_allowance">Allowed time for reversing</input_port>
1414
<input_port name="server_name">Server name</input_port>
1515
<input_port name="server_timeout">Server timeout</input_port>
16+
<input_port name="disable_collision_checks">Disable collision checking</input_port>
1617
<output_port name="error_code_id">"Back up error code"</output_port>
1718
</Action>
1819

@@ -22,6 +23,7 @@
2223
<input_port name="time_allowance">Allowed time for reversing</input_port>
2324
<input_port name="server_name">Server name</input_port>
2425
<input_port name="server_timeout">Server timeout</input_port>
26+
<input_port name="disable_collision_checks">Disable collision checking</input_port>
2527
<output_port name="error_code_id">"Drive on heading error code"</output_port>
2628
</Action>
2729

@@ -193,6 +195,7 @@
193195
<input_port name="time_allowance">Allowed time for spinning</input_port>
194196
<input_port name="server_name">Server name</input_port>
195197
<input_port name="server_timeout">Server timeout</input_port>
198+
<input_port name="disable_collision_checks">Disable collision checking</input_port>
196199
<output_port name="error_code_id">Spin error code</output_port>
197200
</Action>
198201

nav2_behavior_tree/plugins/action/back_up_action.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,16 @@ void nav2_behavior_tree::BackUpAction::initialize()
3636
getInput("backup_speed", speed);
3737
double time_allowance;
3838
getInput("time_allowance", time_allowance);
39+
bool disable_collision_checks;
40+
getInput("disable_collision_checks", disable_collision_checks);
3941

4042
// Populate the input message
4143
goal_.target.x = dist;
4244
goal_.target.y = 0.0;
4345
goal_.target.z = 0.0;
4446
goal_.speed = speed;
4547
goal_.time_allowance = rclcpp::Duration::from_seconds(time_allowance);
48+
goal_.disable_collision_checks = disable_collision_checks;
4649
}
4750

4851
void BackUpAction::on_tick()

nav2_behavior_tree/plugins/action/drive_on_heading_action.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,16 @@ void DriveOnHeadingAction::initialize()
3737
getInput("speed", speed);
3838
double time_allowance;
3939
getInput("time_allowance", time_allowance);
40+
bool disable_collision_checks;
41+
getInput("disable_collision_checks", disable_collision_checks);
4042

4143
// Populate the input message
4244
goal_.target.x = dist;
4345
goal_.target.y = 0.0;
4446
goal_.target.z = 0.0;
4547
goal_.speed = speed;
4648
goal_.time_allowance = rclcpp::Duration::from_seconds(time_allowance);
49+
goal_.disable_collision_checks = disable_collision_checks;
4750
initalized_ = true;
4851
}
4952

nav2_behavior_tree/test/plugins/action/test_back_up_action.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,18 +131,20 @@ TEST_F(BackUpActionTestFixture, test_ports)
131131
tree_ = std::make_shared<BT::Tree>(factory_->createTreeFromText(xml_txt, config_->blackboard));
132132
EXPECT_EQ(tree_->rootNode()->getInput<double>("backup_dist"), 0.15);
133133
EXPECT_EQ(tree_->rootNode()->getInput<double>("backup_speed"), 0.025);
134+
EXPECT_EQ(tree_->rootNode()->getInput<bool>("disable_collision_checks"), false);
134135

135136
xml_txt =
136137
R"(
137138
<root BTCPP_format="4">
138139
<BehaviorTree ID="MainTree">
139-
<BackUp backup_dist="2" backup_speed="0.26" />
140+
<BackUp backup_dist="2" backup_speed="0.26" disable_collision_checks="true" />
140141
</BehaviorTree>
141142
</root>)";
142143

143144
tree_ = std::make_shared<BT::Tree>(factory_->createTreeFromText(xml_txt, config_->blackboard));
144145
EXPECT_EQ(tree_->rootNode()->getInput<double>("backup_dist"), 2.0);
145146
EXPECT_EQ(tree_->rootNode()->getInput<double>("backup_speed"), 0.26);
147+
EXPECT_EQ(tree_->rootNode()->getInput<bool>("disable_collision_checks"), true);
146148
}
147149

148150
TEST_F(BackUpActionTestFixture, test_tick)

nav2_behavior_tree/test/plugins/action/test_drive_on_heading_action.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,18 +128,20 @@ TEST_F(DriveOnHeadingActionTestFixture, test_ports)
128128
EXPECT_EQ(tree_->rootNode()->getInput<double>("dist_to_travel"), 0.15);
129129
EXPECT_EQ(tree_->rootNode()->getInput<double>("speed"), 0.025);
130130
EXPECT_EQ(tree_->rootNode()->getInput<double>("time_allowance"), 10.0);
131+
EXPECT_EQ(tree_->rootNode()->getInput<bool>("disable_collision_checks"), false);
131132

132133
xml_txt =
133134
R"(
134135
<root BTCPP_format="4">
135136
<BehaviorTree ID="MainTree">
136-
<DriveOnHeading dist_to_travel="2" speed="0.26" />
137+
<DriveOnHeading dist_to_travel="2" speed="0.26" disable_collision_checks="true" />
137138
</BehaviorTree>
138139
</root>)";
139140

140141
tree_ = std::make_shared<BT::Tree>(factory_->createTreeFromText(xml_txt, config_->blackboard));
141142
EXPECT_EQ(tree_->rootNode()->getInput<double>("dist_to_travel"), 2.0);
142143
EXPECT_EQ(tree_->rootNode()->getInput<double>("speed"), 0.26);
144+
EXPECT_EQ(tree_->rootNode()->getInput<bool>("disable_collision_checks"), true);
143145
}
144146

145147
TEST_F(DriveOnHeadingActionTestFixture, test_tick)

nav2_behavior_tree/test/plugins/action/test_spin_action.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,17 +130,19 @@ TEST_F(SpinActionTestFixture, test_ports)
130130

131131
tree_ = std::make_shared<BT::Tree>(factory_->createTreeFromText(xml_txt, config_->blackboard));
132132
EXPECT_EQ(tree_->rootNode()->getInput<double>("spin_dist"), 1.57);
133+
EXPECT_EQ(tree_->rootNode()->getInput<bool>("disable_collision_checks"), false);
133134

134135
xml_txt =
135136
R"(
136137
<root BTCPP_format="4">
137138
<BehaviorTree ID="MainTree">
138-
<Spin spin_dist="3.14" />
139+
<Spin spin_dist="3.14" disable_collision_checks="true" />
139140
</BehaviorTree>
140141
</root>)";
141142

142143
tree_ = std::make_shared<BT::Tree>(factory_->createTreeFromText(xml_txt, config_->blackboard));
143144
EXPECT_EQ(tree_->rootNode()->getInput<double>("spin_dist"), 3.14);
145+
EXPECT_EQ(tree_->rootNode()->getInput<bool>("disable_collision_checks"), true);
144146
}
145147

146148
TEST_F(SpinActionTestFixture, test_tick)

nav2_behaviors/include/nav2_behaviors/plugins/drive_on_heading.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class DriveOnHeading : public TimedBehavior<ActionT>
4747
feedback_(std::make_shared<typename ActionT::Feedback>()),
4848
command_x_(0.0),
4949
command_speed_(0.0),
50+
command_disable_collision_checks_(false),
5051
simulate_ahead_time_(0.0)
5152
{
5253
}
@@ -76,6 +77,7 @@ class DriveOnHeading : public TimedBehavior<ActionT>
7677
command_x_ = command->target.x;
7778
command_speed_ = command->speed;
7879
command_time_allowance_ = command->time_allowance;
80+
command_disable_collision_checks_ = command->disable_collision_checks;
7981

8082
end_time_ = this->clock_->now() + command_time_allowance_;
8183

@@ -168,6 +170,10 @@ class DriveOnHeading : public TimedBehavior<ActionT>
168170
const geometry_msgs::msg::Twist & cmd_vel,
169171
geometry_msgs::msg::Pose2D & pose2d)
170172
{
173+
if (command_disable_collision_checks_) {
174+
return true;
175+
}
176+
171177
// Simulate ahead by simulate_ahead_time_ in this->cycle_frequency_ increments
172178
int cycle_count = 0;
173179
double sim_position_change;
@@ -229,6 +235,7 @@ class DriveOnHeading : public TimedBehavior<ActionT>
229235
geometry_msgs::msg::PoseStamped initial_pose_;
230236
double command_x_;
231237
double command_speed_;
238+
bool command_disable_collision_checks_;
232239
rclcpp::Duration command_time_allowance_{0, 0};
233240
rclcpp::Time end_time_;
234241
double simulate_ahead_time_;

0 commit comments

Comments
 (0)