Skip to content

Commit 6cbef08

Browse files
committed
use tf2's .hpp includes
Signed-off-by: rayferric <[email protected]>
1 parent 4e3c80d commit 6cbef08

File tree

55 files changed

+3612
-3953
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+3612
-3953
lines changed

nav2_amcl/src/amcl_node.cpp

+439-491
Large diffs are not rendered by default.

nav2_behavior_tree/include/nav2_behavior_tree/ros_topic_logger.hpp

+19-30
Original file line numberDiff line numberDiff line change
@@ -15,40 +15,36 @@
1515
#ifndef NAV2_BEHAVIOR_TREE__ROS_TOPIC_LOGGER_HPP_
1616
#define NAV2_BEHAVIOR_TREE__ROS_TOPIC_LOGGER_HPP_
1717

18-
#include <vector>
1918
#include <memory>
2019
#include <utility>
20+
#include <vector>
2121

2222
#include "behaviortree_cpp/loggers/abstract_logger.h"
23-
#include "rclcpp/rclcpp.hpp"
2423
#include "nav2_msgs/msg/behavior_tree_log.hpp"
2524
#include "nav2_msgs/msg/behavior_tree_status_change.h"
26-
#include "tf2/time.h"
25+
#include "rclcpp/rclcpp.hpp"
26+
#include "tf2/time.hpp"
2727
#include "tf2_ros/buffer_interface.h"
2828

29-
namespace nav2_behavior_tree
30-
{
29+
namespace nav2_behavior_tree {
3130

3231
/**
3332
* @brief A class to publish BT logs on BT status change
3433
*/
35-
class RosTopicLogger : public BT::StatusChangeLogger
36-
{
34+
class RosTopicLogger : public BT::StatusChangeLogger {
3735
public:
3836
/**
3937
* @brief A constructor for nav2_behavior_tree::RosTopicLogger
4038
* @param ros_node Weak pointer to parent rclcpp::Node
4139
* @param tree BT to monitor
4240
*/
43-
RosTopicLogger(const rclcpp::Node::WeakPtr & ros_node, const BT::Tree & tree)
44-
: StatusChangeLogger(tree.rootNode())
45-
{
41+
RosTopicLogger(const rclcpp::Node::WeakPtr &ros_node, const BT::Tree &tree)
42+
: StatusChangeLogger(tree.rootNode()) {
4643
auto node = ros_node.lock();
4744
clock_ = node->get_clock();
4845
logger_ = node->get_logger();
4946
log_pub_ = node->create_publisher<nav2_msgs::msg::BehaviorTreeLog>(
50-
"behavior_tree_log",
51-
rclcpp::QoS(10));
47+
"behavior_tree_log", rclcpp::QoS(10));
5248
}
5349

5450
/**
@@ -58,36 +54,29 @@ class RosTopicLogger : public BT::StatusChangeLogger
5854
* @param prev_status Previous status of the node
5955
* @param status Current status of the node
6056
*/
61-
void callback(
62-
BT::Duration timestamp,
63-
const BT::TreeNode & node,
64-
BT::NodeStatus prev_status,
65-
BT::NodeStatus status) override
66-
{
57+
void callback(BT::Duration timestamp, const BT::TreeNode &node,
58+
BT::NodeStatus prev_status, BT::NodeStatus status) override {
6759
nav2_msgs::msg::BehaviorTreeStatusChange event;
6860

69-
// BT timestamps are a duration since the epoch. Need to convert to a time_point
70-
// before converting to a msg.
61+
// BT timestamps are a duration since the epoch. Need to convert to a
62+
// time_point before converting to a msg.
7163
event.timestamp = tf2_ros::toMsg(tf2::TimePoint(timestamp));
7264
event.node_name = node.name();
7365
event.uid = node.UID();
7466
event.previous_status = toStr(prev_status, false);
7567
event.current_status = toStr(status, false);
7668
event_log_.push_back(std::move(event));
7769

78-
RCLCPP_DEBUG(
79-
logger_, "[%.3f]: %25s %s -> %s",
80-
std::chrono::duration<double>(timestamp).count(),
81-
node.name().c_str(),
82-
toStr(prev_status, true).c_str(),
83-
toStr(status, true).c_str() );
70+
RCLCPP_DEBUG(logger_, "[%.3f]: %25s %s -> %s",
71+
std::chrono::duration<double>(timestamp).count(),
72+
node.name().c_str(), toStr(prev_status, true).c_str(),
73+
toStr(status, true).c_str());
8474
}
8575

8676
/**
8777
* @brief Clear log buffer if any
8878
*/
89-
void flush() override
90-
{
79+
void flush() override {
9180
if (!event_log_.empty()) {
9281
auto log_msg = std::make_unique<nav2_msgs::msg::BehaviorTreeLog>();
9382
log_msg->timestamp = clock_->now();
@@ -104,6 +93,6 @@ class RosTopicLogger : public BT::StatusChangeLogger
10493
std::vector<nav2_msgs::msg::BehaviorTreeStatusChange> event_log_;
10594
};
10695

107-
} // namespace nav2_behavior_tree
96+
} // namespace nav2_behavior_tree
10897

109-
#endif // NAV2_BEHAVIOR_TREE__ROS_TOPIC_LOGGER_HPP_
98+
#endif // NAV2_BEHAVIOR_TREE__ROS_TOPIC_LOGGER_HPP_

nav2_behavior_tree/plugins/action/remove_in_collision_goals_action.cpp

+19-28
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,23 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
#include <string>
16-
#include <memory>
1715
#include <limits>
16+
#include <memory>
17+
#include <string>
1818

19-
#include "nav2_behavior_tree/plugins/action/remove_in_collision_goals_action.hpp"
2019
#include "nav2_behavior_tree/bt_utils.hpp"
21-
#include "tf2/utils.h"
20+
#include "nav2_behavior_tree/plugins/action/remove_in_collision_goals_action.hpp"
21+
#include "tf2/utils.hpp"
2222
#include "tf2_geometry_msgs/tf2_geometry_msgs.hpp"
2323

24-
namespace nav2_behavior_tree
25-
{
24+
namespace nav2_behavior_tree {
2625

2726
RemoveInCollisionGoals::RemoveInCollisionGoals(
28-
const std::string & service_node_name,
29-
const BT::NodeConfiguration & conf)
30-
: BtServiceNode<nav2_msgs::srv::GetCosts>(service_node_name, conf,
31-
"/global_costmap/get_cost_global_costmap")
32-
{}
33-
27+
const std::string &service_node_name, const BT::NodeConfiguration &conf)
28+
: BtServiceNode<nav2_msgs::srv::GetCosts>(
29+
service_node_name, conf, "/global_costmap/get_cost_global_costmap") {}
3430

35-
void RemoveInCollisionGoals::on_tick()
36-
{
31+
void RemoveInCollisionGoals::on_tick() {
3732
getInput("use_footprint", use_footprint_);
3833
getInput("cost_threshold", cost_threshold_);
3934
getInput("input_goals", input_goals_);
@@ -47,44 +42,40 @@ void RemoveInCollisionGoals::on_tick()
4742
request_ = std::make_shared<nav2_msgs::srv::GetCosts::Request>();
4843
request_->use_footprint = use_footprint_;
4944

50-
for (const auto & goal : input_goals_) {
45+
for (const auto &goal : input_goals_) {
5146
request_->poses.push_back(goal);
5247
}
5348
}
5449

5550
BT::NodeStatus RemoveInCollisionGoals::on_completion(
56-
std::shared_ptr<nav2_msgs::srv::GetCosts::Response> response)
57-
{
51+
std::shared_ptr<nav2_msgs::srv::GetCosts::Response> response) {
5852
if (!response->success) {
59-
RCLCPP_ERROR(
60-
node_->get_logger(),
61-
"GetCosts service call failed");
53+
RCLCPP_ERROR(node_->get_logger(), "GetCosts service call failed");
6254
setOutput("output_goals", input_goals_);
6355
return BT::NodeStatus::FAILURE;
6456
}
6557

6658
Goals valid_goal_poses;
6759
for (size_t i = 0; i < response->costs.size(); ++i) {
6860
if ((response->costs[i] == 255 && !consider_unknown_as_obstacle_) ||
69-
response->costs[i] < cost_threshold_)
70-
{
61+
response->costs[i] < cost_threshold_) {
7162
valid_goal_poses.push_back(input_goals_[i]);
7263
}
7364
}
7465
// Inform if all goals have been removed
7566
if (valid_goal_poses.empty()) {
7667
RCLCPP_INFO(
77-
node_->get_logger(),
78-
"All goals are in collision and have been removed from the list");
68+
node_->get_logger(),
69+
"All goals are in collision and have been removed from the list");
7970
}
8071
setOutput("output_goals", valid_goal_poses);
8172
return BT::NodeStatus::SUCCESS;
8273
}
8374

84-
} // namespace nav2_behavior_tree
75+
} // namespace nav2_behavior_tree
8576

8677
#include "behaviortree_cpp/bt_factory.h"
87-
BT_REGISTER_NODES(factory)
88-
{
89-
factory.registerNodeType<nav2_behavior_tree::RemoveInCollisionGoals>("RemoveInCollisionGoals");
78+
BT_REGISTER_NODES(factory) {
79+
factory.registerNodeType<nav2_behavior_tree::RemoveInCollisionGoals>(
80+
"RemoveInCollisionGoals");
9081
}

nav2_behavior_tree/plugins/action/truncate_path_local_action.cpp

+46-43
Original file line numberDiff line numberDiff line change
@@ -24,27 +24,23 @@
2424
#include "nav2_util/robot_utils.hpp"
2525
#include "nav_msgs/msg/path.hpp"
2626
#include "rclcpp/rclcpp.hpp"
27-
#include "tf2/LinearMath/Quaternion.h"
27+
#include "tf2/LinearMath/Quaternion.hpp"
2828
#include "tf2_ros/buffer.h"
2929
#include "tf2_ros/create_timer_ros.h"
3030

3131
#include "nav2_behavior_tree/plugins/action/truncate_path_local_action.hpp"
3232

33-
namespace nav2_behavior_tree
34-
{
33+
namespace nav2_behavior_tree {
3534

36-
TruncatePathLocal::TruncatePathLocal(
37-
const std::string & name,
38-
const BT::NodeConfiguration & conf)
39-
: BT::ActionNodeBase(name, conf)
40-
{
35+
TruncatePathLocal::TruncatePathLocal(const std::string &name,
36+
const BT::NodeConfiguration &conf)
37+
: BT::ActionNodeBase(name, conf) {
4138
tf_buffer_ =
42-
config().blackboard->template get<std::shared_ptr<tf2_ros::Buffer>>(
43-
"tf_buffer");
39+
config().blackboard->template get<std::shared_ptr<tf2_ros::Buffer>>(
40+
"tf_buffer");
4441
}
4542

46-
inline BT::NodeStatus TruncatePathLocal::tick()
47-
{
43+
inline BT::NodeStatus TruncatePathLocal::tick() {
4844
setStatus(BT::NodeStatus::RUNNING);
4945

5046
double distance_forward, distance_backward;
@@ -76,70 +72,77 @@ inline BT::NodeStatus TruncatePathLocal::tick()
7672

7773
auto closest_pose_detection_end = path_.poses.end();
7874
if (path_pruning) {
79-
closest_pose_detection_end = nav2_util::geometry_utils::first_after_integrated_distance(
80-
closest_pose_detection_begin_, path_.poses.end(), max_robot_pose_search_dist);
75+
closest_pose_detection_end =
76+
nav2_util::geometry_utils::first_after_integrated_distance(
77+
closest_pose_detection_begin_, path_.poses.end(),
78+
max_robot_pose_search_dist);
8179
}
8280

8381
// find the closest pose on the path
8482
auto current_pose = nav2_util::geometry_utils::min_by(
85-
closest_pose_detection_begin_, closest_pose_detection_end,
86-
[&pose, angular_distance_weight](const geometry_msgs::msg::PoseStamped & ps) {
87-
return poseDistance(pose, ps, angular_distance_weight);
88-
});
83+
closest_pose_detection_begin_, closest_pose_detection_end,
84+
[&pose,
85+
angular_distance_weight](const geometry_msgs::msg::PoseStamped &ps) {
86+
return poseDistance(pose, ps, angular_distance_weight);
87+
});
8988

9089
if (path_pruning) {
9190
closest_pose_detection_begin_ = current_pose;
9291
}
9392

9493
// expand forwards to extract desired length
95-
auto forward_pose_it = nav2_util::geometry_utils::first_after_integrated_distance(
96-
current_pose, path_.poses.end(), distance_forward);
94+
auto forward_pose_it =
95+
nav2_util::geometry_utils::first_after_integrated_distance(
96+
current_pose, path_.poses.end(), distance_forward);
9797

9898
// expand backwards to extract desired length
99-
// Note: current_pose + 1 is used because reverse iterator points to a cell before it
100-
auto backward_pose_it = nav2_util::geometry_utils::first_after_integrated_distance(
101-
std::reverse_iterator(current_pose + 1), path_.poses.rend(), distance_backward);
99+
// Note: current_pose + 1 is used because reverse iterator points to a cell
100+
// before it
101+
auto backward_pose_it =
102+
nav2_util::geometry_utils::first_after_integrated_distance(
103+
std::reverse_iterator(current_pose + 1), path_.poses.rend(),
104+
distance_backward);
102105

103106
nav_msgs::msg::Path output_path;
104107
output_path.header = path_.header;
105108
output_path.poses = std::vector<geometry_msgs::msg::PoseStamped>(
106-
backward_pose_it.base(), forward_pose_it);
109+
backward_pose_it.base(), forward_pose_it);
107110
setOutput("output_path", output_path);
108111

109112
return BT::NodeStatus::SUCCESS;
110113
}
111114

112-
inline bool TruncatePathLocal::getRobotPose(
113-
std::string path_frame_id, geometry_msgs::msg::PoseStamped & pose)
114-
{
115+
inline bool
116+
TruncatePathLocal::getRobotPose(std::string path_frame_id,
117+
geometry_msgs::msg::PoseStamped &pose) {
115118
if (!getInput("pose", pose)) {
116119
std::string robot_frame;
117120
if (!getInput("robot_frame", robot_frame)) {
118-
RCLCPP_ERROR(
119-
config().blackboard->get<rclcpp::Node::SharedPtr>("node")->get_logger(),
120-
"Neither pose nor robot_frame specified for %s", name().c_str());
121+
RCLCPP_ERROR(config()
122+
.blackboard->get<rclcpp::Node::SharedPtr>("node")
123+
->get_logger(),
124+
"Neither pose nor robot_frame specified for %s",
125+
name().c_str());
121126
return false;
122127
}
123128
double transform_tolerance;
124129
getInput("transform_tolerance", transform_tolerance);
125-
if (!nav2_util::getCurrentPose(
126-
pose, *tf_buffer_, path_frame_id, robot_frame, transform_tolerance))
127-
{
128-
RCLCPP_WARN(
129-
config().blackboard->get<rclcpp::Node::SharedPtr>("node")->get_logger(),
130-
"Failed to lookup current robot pose for %s", name().c_str());
130+
if (!nav2_util::getCurrentPose(pose, *tf_buffer_, path_frame_id,
131+
robot_frame, transform_tolerance)) {
132+
RCLCPP_WARN(config()
133+
.blackboard->get<rclcpp::Node::SharedPtr>("node")
134+
->get_logger(),
135+
"Failed to lookup current robot pose for %s", name().c_str());
131136
return false;
132137
}
133138
}
134139
return true;
135140
}
136141

137142
double
138-
TruncatePathLocal::poseDistance(
139-
const geometry_msgs::msg::PoseStamped & pose1,
140-
const geometry_msgs::msg::PoseStamped & pose2,
141-
const double angular_distance_weight)
142-
{
143+
TruncatePathLocal::poseDistance(const geometry_msgs::msg::PoseStamped &pose1,
144+
const geometry_msgs::msg::PoseStamped &pose2,
145+
const double angular_distance_weight) {
143146
double dx = pose1.pose.position.x - pose2.pose.position.x;
144147
double dy = pose1.pose.position.y - pose2.pose.position.y;
145148
// taking angular distance into account in addition to spatial distance
@@ -152,10 +155,10 @@ TruncatePathLocal::poseDistance(
152155
return std::sqrt(dx * dx + dy * dy + da * da);
153156
}
154157

155-
} // namespace nav2_behavior_tree
158+
} // namespace nav2_behavior_tree
156159

157160
#include "behaviortree_cpp/bt_factory.h"
158161
BT_REGISTER_NODES(factory) {
159162
factory.registerNodeType<nav2_behavior_tree::TruncatePathLocal>(
160-
"TruncatePathLocal");
163+
"TruncatePathLocal");
161164
}

0 commit comments

Comments
 (0)