Skip to content

Commit 3913408

Browse files
naiveHoboSteveMacenski
authored andcommitted
Add unit tests for follow path, compute path to pose, and navigate to pose BT action nodes (#1844)
* Add compute path to pose unit tests Signed-off-by: Sarthak Mittal <[email protected]> * Add follow path action unit tests Signed-off-by: Sarthak Mittal <[email protected]> * Add navigate to pose action unit tests Signed-off-by: Sarthak Mittal <[email protected]>
1 parent 28be30e commit 3913408

File tree

10 files changed

+810
-131
lines changed

10 files changed

+810
-131
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Copyright (c) 2018 Intel Corporation
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#ifndef NAV2_BEHAVIOR_TREE__PLUGINS__ACTION__COMPUTE_PATH_TO_POSE_ACTION_HPP_
16+
#define NAV2_BEHAVIOR_TREE__PLUGINS__ACTION__COMPUTE_PATH_TO_POSE_ACTION_HPP_
17+
18+
#include <string>
19+
20+
#include "nav2_msgs/action/compute_path_to_pose.hpp"
21+
#include "nav_msgs/msg/path.h"
22+
#include "nav2_behavior_tree/bt_action_node.hpp"
23+
24+
namespace nav2_behavior_tree
25+
{
26+
27+
class ComputePathToPoseAction : public BtActionNode<nav2_msgs::action::ComputePathToPose>
28+
{
29+
public:
30+
ComputePathToPoseAction(
31+
const std::string & xml_tag_name,
32+
const std::string & action_name,
33+
const BT::NodeConfiguration & conf);
34+
35+
void on_tick() override;
36+
37+
BT::NodeStatus on_success() override;
38+
39+
static BT::PortsList providedPorts()
40+
{
41+
return providedBasicPorts(
42+
{
43+
BT::OutputPort<nav_msgs::msg::Path>("path", "Path created by ComputePathToPose node"),
44+
BT::InputPort<geometry_msgs::msg::PoseStamped>("goal", "Destination to plan to"),
45+
BT::InputPort<std::string>("planner_id", ""),
46+
});
47+
}
48+
49+
private:
50+
bool first_time_{true};
51+
};
52+
53+
} // namespace nav2_behavior_tree
54+
55+
#endif // NAV2_BEHAVIOR_TREE__PLUGINS__ACTION__COMPUTE_PATH_TO_POSE_ACTION_HPP_
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Copyright (c) 2018 Intel Corporation
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#ifndef NAV2_BEHAVIOR_TREE__PLUGINS__ACTION__FOLLOW_PATH_ACTION_HPP_
16+
#define NAV2_BEHAVIOR_TREE__PLUGINS__ACTION__FOLLOW_PATH_ACTION_HPP_
17+
18+
#include <string>
19+
20+
#include "nav2_msgs/action/follow_path.hpp"
21+
#include "nav2_behavior_tree/bt_action_node.hpp"
22+
23+
namespace nav2_behavior_tree
24+
{
25+
26+
class FollowPathAction : public BtActionNode<nav2_msgs::action::FollowPath>
27+
{
28+
public:
29+
FollowPathAction(
30+
const std::string & xml_tag_name,
31+
const std::string & action_name,
32+
const BT::NodeConfiguration & conf);
33+
34+
void on_tick() override;
35+
36+
void on_wait_for_result() override;
37+
38+
static BT::PortsList providedPorts()
39+
{
40+
return providedBasicPorts(
41+
{
42+
BT::InputPort<nav_msgs::msg::Path>("path", "Path to follow"),
43+
BT::InputPort<std::string>("controller_id", ""),
44+
});
45+
}
46+
};
47+
48+
} // namespace nav2_behavior_tree
49+
50+
#endif // NAV2_BEHAVIOR_TREE__PLUGINS__ACTION__FOLLOW_PATH_ACTION_HPP_
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Copyright (c) 2018 Intel Corporation
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#ifndef NAV2_BEHAVIOR_TREE__PLUGINS__ACTION__NAVIGATE_TO_POSE_ACTION_HPP_
16+
#define NAV2_BEHAVIOR_TREE__PLUGINS__ACTION__NAVIGATE_TO_POSE_ACTION_HPP_
17+
18+
#include <string>
19+
20+
#include "geometry_msgs/msg/point.hpp"
21+
#include "geometry_msgs/msg/quaternion.hpp"
22+
#include "nav2_msgs/action/navigate_to_pose.hpp"
23+
#include "nav2_behavior_tree/bt_action_node.hpp"
24+
25+
namespace nav2_behavior_tree
26+
{
27+
28+
class NavigateToPoseAction : public BtActionNode<nav2_msgs::action::NavigateToPose>
29+
{
30+
public:
31+
NavigateToPoseAction(
32+
const std::string & xml_tag_name,
33+
const std::string & action_name,
34+
const BT::NodeConfiguration & conf);
35+
36+
void on_tick() override;
37+
38+
// Any BT node that accepts parameters must provide a requiredNodeParameters method
39+
static BT::PortsList providedPorts()
40+
{
41+
return providedBasicPorts(
42+
{
43+
BT::InputPort<geometry_msgs::msg::Point>("position", "Position"),
44+
BT::InputPort<geometry_msgs::msg::Quaternion>("orientation", "Orientation")
45+
});
46+
}
47+
};
48+
49+
} // namespace nav2_behavior_tree
50+
51+
#endif // NAV2_BEHAVIOR_TREE__PLUGINS__ACTION__NAVIGATE_TO_POSE_ACTION_HPP_

nav2_behavior_tree/plugins/action/compute_path_to_pose_action.cpp

Lines changed: 21 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -12,61 +12,39 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
#ifndef NAV2_BEHAVIOR_TREE__COMPUTE_PATH_TO_POSE_ACTION_HPP_
16-
#define NAV2_BEHAVIOR_TREE__COMPUTE_PATH_TO_POSE_ACTION_HPP_
17-
1815
#include <memory>
1916
#include <string>
2017

21-
#include "nav2_msgs/action/compute_path_to_pose.hpp"
22-
#include "nav_msgs/msg/path.h"
23-
#include "nav2_behavior_tree/bt_action_node.hpp"
18+
#include "nav2_behavior_tree/plugins/action/compute_path_to_pose_action.hpp"
2419

2520
namespace nav2_behavior_tree
2621
{
2722

28-
class ComputePathToPoseAction : public BtActionNode<nav2_msgs::action::ComputePathToPose>
23+
ComputePathToPoseAction::ComputePathToPoseAction(
24+
const std::string & xml_tag_name,
25+
const std::string & action_name,
26+
const BT::NodeConfiguration & conf)
27+
: BtActionNode<nav2_msgs::action::ComputePathToPose>(xml_tag_name, action_name, conf)
2928
{
30-
public:
31-
ComputePathToPoseAction(
32-
const std::string & xml_tag_name,
33-
const std::string & action_name,
34-
const BT::NodeConfiguration & conf)
35-
: BtActionNode<nav2_msgs::action::ComputePathToPose>(xml_tag_name, action_name, conf)
36-
{
37-
}
38-
39-
void on_tick() override
40-
{
41-
getInput("goal", goal_.pose);
42-
getInput("planner_id", goal_.planner_id);
43-
}
29+
}
4430

45-
BT::NodeStatus on_success() override
46-
{
47-
setOutput("path", result_.result->path);
31+
void ComputePathToPoseAction::on_tick()
32+
{
33+
getInput("goal", goal_.pose);
34+
getInput("planner_id", goal_.planner_id);
35+
}
4836

49-
if (first_time_) {
50-
first_time_ = false;
51-
} else {
52-
config().blackboard->set("path_updated", true);
53-
}
54-
return BT::NodeStatus::SUCCESS;
55-
}
37+
BT::NodeStatus ComputePathToPoseAction::on_success()
38+
{
39+
setOutput("path", result_.result->path);
5640

57-
static BT::PortsList providedPorts()
58-
{
59-
return providedBasicPorts(
60-
{
61-
BT::OutputPort<nav_msgs::msg::Path>("path", "Path created by ComputePathToPose node"),
62-
BT::InputPort<geometry_msgs::msg::PoseStamped>("goal", "Destination to plan to"),
63-
BT::InputPort<std::string>("planner_id", ""),
64-
});
41+
if (first_time_) {
42+
first_time_ = false;
43+
} else {
44+
config().blackboard->set("path_updated", true);
6545
}
66-
67-
private:
68-
bool first_time_{true};
69-
};
46+
return BT::NodeStatus::SUCCESS;
47+
}
7048

7149
} // namespace nav2_behavior_tree
7250

@@ -83,5 +61,3 @@ BT_REGISTER_NODES(factory)
8361
factory.registerBuilder<nav2_behavior_tree::ComputePathToPoseAction>(
8462
"ComputePathToPose", builder);
8563
}
86-
87-
#endif // NAV2_BEHAVIOR_TREE__COMPUTE_PATH_TO_POSE_ACTION_HPP_

nav2_behavior_tree/plugins/action/follow_path_action.cpp

Lines changed: 24 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -12,59 +12,42 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
#ifndef NAV2_BEHAVIOR_TREE__FOLLOW_PATH_ACTION_HPP_
16-
#define NAV2_BEHAVIOR_TREE__FOLLOW_PATH_ACTION_HPP_
17-
1815
#include <memory>
1916
#include <string>
2017

21-
#include "nav2_msgs/action/follow_path.hpp"
22-
#include "nav2_behavior_tree/bt_action_node.hpp"
18+
#include "nav2_behavior_tree/plugins/action/follow_path_action.hpp"
2319

2420
namespace nav2_behavior_tree
2521
{
2622

27-
class FollowPathAction : public BtActionNode<nav2_msgs::action::FollowPath>
23+
FollowPathAction::FollowPathAction(
24+
const std::string & xml_tag_name,
25+
const std::string & action_name,
26+
const BT::NodeConfiguration & conf)
27+
: BtActionNode<nav2_msgs::action::FollowPath>(xml_tag_name, action_name, conf)
2828
{
29-
public:
30-
FollowPathAction(
31-
const std::string & xml_tag_name,
32-
const std::string & action_name,
33-
const BT::NodeConfiguration & conf)
34-
: BtActionNode<nav2_msgs::action::FollowPath>(xml_tag_name, action_name, conf)
35-
{
36-
config().blackboard->set("path_updated", false);
37-
}
38-
39-
void on_tick() override
40-
{
41-
getInput("path", goal_.path);
42-
getInput("controller_id", goal_.controller_id);
43-
}
29+
config().blackboard->set("path_updated", false);
30+
}
4431

45-
void on_wait_for_result() override
46-
{
47-
// Check if the goal has been updated
48-
if (config().blackboard->get<bool>("path_updated")) {
49-
// Reset the flag in the blackboard
50-
config().blackboard->set("path_updated", false);
32+
void FollowPathAction::on_tick()
33+
{
34+
getInput("path", goal_.path);
35+
getInput("controller_id", goal_.controller_id);
36+
}
5137

52-
// Grab the new goal and set the flag so that we send the new goal to
53-
// the action server on the next loop iteration
54-
getInput("path", goal_.path);
55-
goal_updated_ = true;
56-
}
57-
}
38+
void FollowPathAction::on_wait_for_result()
39+
{
40+
// Check if the goal has been updated
41+
if (config().blackboard->get<bool>("path_updated")) {
42+
// Reset the flag in the blackboard
43+
config().blackboard->set("path_updated", false);
5844

59-
static BT::PortsList providedPorts()
60-
{
61-
return providedBasicPorts(
62-
{
63-
BT::InputPort<nav_msgs::msg::Path>("path", "Path to follow"),
64-
BT::InputPort<std::string>("controller_id", ""),
65-
});
45+
// Grab the new goal and set the flag so that we send the new goal to
46+
// the action server on the next loop iteration
47+
getInput("path", goal_.path);
48+
goal_updated_ = true;
6649
}
67-
};
50+
}
6851

6952
} // namespace nav2_behavior_tree
7053

@@ -81,5 +64,3 @@ BT_REGISTER_NODES(factory)
8164
factory.registerBuilder<nav2_behavior_tree::FollowPathAction>(
8265
"FollowPath", builder);
8366
}
84-
85-
#endif // NAV2_BEHAVIOR_TREE__FOLLOW_PATH_ACTION_HPP_

0 commit comments

Comments
 (0)