Skip to content

Commit 913d0a5

Browse files
Fix compilation
1 parent 8cdccdf commit 913d0a5

File tree

12 files changed

+191
-34
lines changed

12 files changed

+191
-34
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
cmake_minimum_required(VERSION 3.8)
2+
project(task_behavior_tree)
3+
4+
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
5+
add_compile_options(-Wall -Wextra -Wpedantic)
6+
endif()
7+
8+
find_package(geometry_msgs REQUIRED)
9+
find_package(nav2_behavior_tree REQUIRED)
10+
find_package(task_msgs REQUIRED)
11+
12+
include_directories(
13+
include
14+
)
15+
16+
set(library_name ${PROJECT_NAME})
17+
18+
set(dependencies
19+
geometry_msgs
20+
nav2_behavior_tree
21+
task_msgs
22+
)
23+
24+
add_library(task_initialize_navigation_action_bt_node SHARED plugins/src/action/initialize_navigation.cpp)
25+
list(APPEND plugin_libs task_initialize_navigation_action_bt_node)
26+
27+
foreach(bt_plugin ${plugin_libs})
28+
ament_target_dependencies(${bt_plugin} ${dependencies})
29+
target_compile_definitions(${bt_plugin} PRIVATE BT_PLUGIN_EXPORT)
30+
endforeach()
31+
32+
install(TARGETS ${plugin_libs}
33+
ARCHIVE DESTINATION lib
34+
LIBRARY DESTINATION lib
35+
RUNTIME DESTINATION bin
36+
)
37+
38+
install(DIRECTORY include/
39+
DESTINATION include/
40+
)
41+
42+
if(BUILD_TESTING)
43+
find_package(ament_lint_auto REQUIRED)
44+
# the following line skips the linter which checks for copyrights
45+
set(ament_cmake_copyright_FOUND TRUE)
46+
set(ament_cmake_cpplint_FOUND TRUE)
47+
ament_lint_auto_find_test_dependencies()
48+
endif()
49+
50+
ament_export_include_directories(
51+
include
52+
)
53+
54+
ament_export_libraries(
55+
${plugin_libs}
56+
)
57+
58+
ament_export_dependencies(${dependencies})
59+
60+
ament_package()

src/task_behavior_tree/plugins/include/actions/initialize_navigation.hpp renamed to src/task_behavior_tree/include/action/initialize_navigation.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
1-
21
#ifndef BEHAVIOR_TREE__PLUGINS__ACTION__INITIALIZE_NAVIGATION_ACTION_HPP_
32
#define BEHAVIOR_TREE__PLUGINS__ACTION__INITIALIZE_NAVIGATION_ACTION_HPP_
43

54
#include <string>
65

6+
#include "geometry_msgs/msg/pose_stamped.hpp"
77
#include "nav2_behavior_tree/bt_action_node.hpp"
8+
#include "task_msgs/action/initialize_navigation.hpp"
89

910
namespace behavior_tree {
1011
namespace action {
1112

1213
/**
1314
* @brief A nav2_behavior_tree::BtActionNode class that wraps behavior_tree::action::InitializeNavigation
1415
*/
15-
class InitializeNavigation : public BtActionNode<task_msgs::action::InitializeNavigation>
16+
class InitializeNavigation : public nav2_behavior_tree::BtActionNode<task_msgs::action::InitializeNavigation>
1617
{
1718
public:
1819
/**

src/task_behavior_tree/package.xml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0"?>
2+
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
3+
<package format="3">
4+
<name>task_behavior_tree</name>
5+
<version>0.0.0</version>
6+
<description>TODO: Package description</description>
7+
<maintainer email="[email protected]">luis</maintainer>
8+
<license>TODO: License declaration</license>
9+
10+
<buildtool_depend>ament_cmake</buildtool_depend>
11+
12+
<build_depend>geometry_msgs</build_depend>
13+
<build_depend>nav2_behavior_tree</build_depend>
14+
<build_depend>task_msgs</build_depend>
15+
16+
<exec_depend>geometry_msgs</exec_depend>
17+
<exec_depend>nav2_behavior_tree</exec_depend>
18+
<exec_depend>task_msgs</exec_depend>
19+
20+
<test_depend>ament_lint_auto</test_depend>
21+
<test_depend>ament_lint_common</test_depend>
22+
23+
<export>
24+
<build_type>ament_cmake</build_type>
25+
</export>
26+
</package>

src/task_behavior_tree/plugins/src/actions/initialize_navigation.cpp renamed to src/task_behavior_tree/plugins/src/action/initialize_navigation.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include <memory>
22
#include <string>
33

4-
#include "actions/initialize_navigation.hpp"
4+
#include "action/initialize_navigation.hpp"
55

66
namespace behavior_tree {
77
namespace action {
@@ -40,10 +40,10 @@ BT_REGISTER_NODES(factory)
4040
BT::NodeBuilder builder =
4141
[](const std::string & name, const BT::NodeConfiguration & config)
4242
{
43-
return std::make_unique<behavior_tree::InitializeNavigation>(
43+
return std::make_unique<behavior_tree::action::InitializeNavigation>(
4444
name, "initialize_navigation", config);
4545
};
4646

47-
factory.registerBuilder<behavior_tree::InitializeNavigation>(
47+
factory.registerBuilder<behavior_tree::action::InitializeNavigation>(
4848
"InitializeNavigation", builder);
4949
}

src/task_monitor/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,16 @@ if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
55
add_compile_options(-Wall -Wextra -Wpedantic)
66
endif()
77

8+
find_package(ament_cmake REQUIRED)
89
find_package(types REQUIRED)
910
find_package(geometry_msgs REQUIRED)
1011
find_package(rclcpp REQUIRED)
12+
find_package(nav2_util REQUIRED)
13+
find_package(task_behavior_tree REQUIRED)
14+
find_package(task_msgs REQUIRED)
1115
find_package(tf2 REQUIRED)
1216
find_package(tf2_geometry_msgs REQUIRED)
17+
find_package(tf2_ros REQUIRED)
1318

1419
include_directories(
1520
include
@@ -33,8 +38,12 @@ set(dependencies
3338
types
3439
geometry_msgs
3540
rclcpp
41+
nav2_util
42+
task_behavior_tree
43+
task_msgs
3644
tf2
3745
tf2_geometry_msgs
46+
tf2_ros
3847
)
3948

4049
ament_target_dependencies(${library_name}
Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#include "rclcpp/rclcpp.hpp"
22

33
#include "geometry_msgs/msg/pose_with_covariance_stamped.hpp"
4+
#include "nav2_util/simple_action_server.hpp"
5+
#include "task_msgs/action/initialize_navigation.hpp"
6+
#include "rclcpp_lifecycle/lifecycle_node.hpp"
47

58
namespace brain {
69

@@ -16,40 +19,39 @@ class TaskMonitor : public rclcpp::Node {
1619
~TaskMonitor();
1720

1821
private:
19-
const double pose_distance_tolerance_;
20-
const double pose_distance_angle_;
21-
const double timeout_s_;
22-
const geometry_msgs::msg::PoseWithCovarianceStamped initial_pose_;
23-
24-
rclcpp::Publisher<geometry_msgs::msg::PoseWithCovarianceStamped>::SharedPtr initial_pose_pub_;
25-
rclcpp::Subscription<geometry_msgs::msg::PoseWithCovarianceStamped>::SharedPtr robot_pose_sub_;
26-
27-
// Action server that implements the InitializeNavigation action
28-
using task_msgs::action::InitializeNavigation InitializeNavigationAction;
29-
using nav2_util::SimpleActionServer<InitializeNavigationAction> InitializeNavigationActionServer;
30-
std::unique_ptr<nav2_util::SimpleActionServer<task_msgs::action::InitializeNavigation>> initialize_navigation_action_server_;
31-
3222
/**
3323
* @brief Get the initial pose from a param or initialize to {0.0, 0.0, 0.0, 0.0}
3424
* @return geometry_msgs::msg::PoseWithCovarianceStamped with the initial pose
3525
*/
3626
geometry_msgs::msg::PoseWithCovarianceStamped GetInitialPose();
3727
/**
3828
* @brief Set the initial pose as initial_pose
39-
* @return bool with the result of the action
4029
*/
41-
bool SetInitialPose();
30+
void SetInitialPose();
4231
/**
4332
* @brief Get the robot pose from AMCL
4433
*/
45-
void AmclPoseCallback (const geometry_msgs::msg::PoseWithCovarianceStamped::SharedPtr msg)
34+
void AmclPoseCallback (const geometry_msgs::msg::PoseWithCovarianceStamped::SharedPtr msg);
4635
/**
4736
* @brief Check if the robot is close to the desired pose
4837
* @param desired_pose the pose where we want the robot at
4938
* @return bool with the comparation result
5039
*/
5140
bool IsRobotAtPose(geometry_msgs::msg::PoseWithCovarianceStamped desired_pose);
5241

42+
double pose_distance_tolerance_;
43+
double pose_angle_tolerance_;
44+
double timeout_s_;
45+
geometry_msgs::msg::PoseWithCovarianceStamped initial_pose_;
46+
geometry_msgs::msg::PoseWithCovarianceStamped robot_pose_;
47+
48+
rclcpp::Publisher<geometry_msgs::msg::PoseWithCovarianceStamped>::SharedPtr initial_pose_pub_;
49+
rclcpp::Subscription<geometry_msgs::msg::PoseWithCovarianceStamped>::SharedPtr robot_pose_sub_;
50+
51+
// Action server that implements the InitializeNavigation action
52+
using InitializeNavigationAction = task_msgs::action::InitializeNavigation;
53+
using InitializeNavigationActionServer = nav2_util::SimpleActionServer<InitializeNavigationAction>;
54+
std::unique_ptr<InitializeNavigationActionServer> initialize_navigation_action_server_;
5355
};
5456

5557
} // namespace brain

src/task_monitor/package.xml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,22 @@
1212
<build_depend>rclcpp</build_depend>
1313
<build_depend>types</build_depend>
1414
<build_depend>geometry_msgs</build_depend>
15+
<build_depend>nav2_util</build_depend>
16+
<build_depend>task_behavior_tree</build_depend>
17+
<build_depend>task_msgs</build_depend>
1518
<build_depend>tf2</build_depend>
1619
<build_depend>tf2_geometry_msgs</build_depend>
20+
<build_depend>tf2_ros</build_depend>
1721

1822
<exec_depend>rclcpp</exec_depend>
1923
<exec_depend>types</exec_depend>
2024
<exec_depend>geometry_msgs</exec_depend>
25+
<exec_depend>nav2_util</exec_depend>
26+
<exec_depend>task_behavior_tree</exec_depend>
27+
<exec_depend>task_msgs</exec_depend>
2128
<exec_depend>tf2</exec_depend>
22-
<build_depend>tf2_geometry_msgs</build_depend>
29+
<exec_depend>tf2_geometry_msgs</exec_depend>
30+
<exec_depend>tf2_ros</exec_depend>
2331

2432
<test_depend>ament_lint_auto</test_depend>
2533
<test_depend>ament_lint_common</test_depend>

src/task_monitor/src/main.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ int main(int argc, char * argv[])
77
// Need to wait some time for the publisher to stablish connection, bug ?
88
std::chrono::seconds sleep_time_sec(1);
99
rclcpp::sleep_for(std::chrono::duration_cast<std::chrono::nanoseconds>(sleep_time_sec));
10-
task_monitor_node->Start();
1110
rclcpp::spin_some(task_monitor_node->get_node_base_interface());
1211
RCLCPP_INFO(task_monitor_node->get_logger(), "Spin");
1312
rclcpp::shutdown();

src/task_monitor/src/task_monitor.cpp

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
#include "nav2_util/simple_action_server.hpp"
44
#include "pose_3d.hpp"
5+
#include "tf2/LinearMath/Matrix3x3.h"
6+
#include "tf2_ros/transform_broadcaster.h"
7+
#include "tf2_ros/transform_listener.h"
8+
#include "tf2/convert.h"
9+
#include "tf2_geometry_msgs/tf2_geometry_msgs.h"
510

611
#define LOG(level, ...) RCLCPP_##level(this->get_logger(), __VA_ARGS__)
712

@@ -26,11 +31,11 @@ TaskMonitor::TaskMonitor() : Node("task_monitor") {
2631
// Subscriber to get the robot pose from amcl node
2732
robot_pose_sub_ = this->create_subscription<geometry_msgs::msg::PoseWithCovarianceStamped>(
2833
"amcl_pose", rclcpp::QoS(rclcpp::KeepLast(1)).transient_local().reliable(),
29-
std::bind(&TaskMonitor::AmclPoseCallback(), this, std::placeholders::_1));
34+
std::bind(&TaskMonitor::AmclPoseCallback, this, std::placeholders::_1));
3035

3136
// Action server to initialize navigation properly
3237
initialize_navigation_action_server_ = std::make_unique<InitializeNavigationActionServer>(
33-
rclcpp_node_, "initialize_navigation", std::bind(&TaskMonitor::SetInitialPose, this));
38+
this->create_sub_node("action_sub_node"), "initialize_navigation", std::bind(&TaskMonitor::SetInitialPose, this));
3439

3540
initial_pose_ = GetInitialPose();
3641
}
@@ -56,25 +61,29 @@ geometry_msgs::msg::PoseWithCovarianceStamped TaskMonitor::GetInitialPose() {
5661
return initial_pose_with_covariance_msg;
5762
}
5863

59-
void TaskMonitor::AmclPoseCallback(const geometry_msgs::msg::PoseWithCovarianceStamped::SharedPtr msg)
60-
robot_pose_ = msg->pose;
64+
void TaskMonitor::AmclPoseCallback(const geometry_msgs::msg::PoseWithCovarianceStamped::SharedPtr msg) {
65+
if (msg) {
66+
robot_pose_ = *msg;
67+
}
6168
}
6269

6370
bool TaskMonitor::IsRobotAtPose(geometry_msgs::msg::PoseWithCovarianceStamped desired_pose) {
6471
// Get the relative tf from the actual robot pose to the desired pose
65-
tf2::Transform robot_pose_tf = tf2::fromMsg(robot_pose_);
66-
tf2::Transform desired_pose_tf = tf2::fromMsg(desired_pose);
72+
tf2::Stamped<tf2::Transform> robot_pose_tf, desired_pose_tf;
73+
tf2::fromMsg(robot_pose_, robot_pose_tf);
74+
tf2::fromMsg(desired_pose, desired_pose_tf);
6775
tf2::Transform relative_tf = robot_pose_tf.inverseTimes(desired_pose_tf);
6876

6977
// Check that location coordinates are lower than the distance tolerance
7078
auto relative_translation = relative_tf.getOrigin();
71-
for (auto& coordinate : relative_translation) {
79+
std::vector<double> relative_translation_vector{relative_translation.getX(), relative_translation.getY(), relative_translation.getZ()};
80+
for (auto &coordinate : relative_translation_vector) {
7281
if (coordinate > pose_distance_tolerance_)
7382
return false;
7483
}
7584

7685
// Check that the RPY angles are lower than the angle tolerance
77-
tf2::Matrix3x3 relative_orientation_matrix(relative_tf.getOrientation());
86+
tf2::Matrix3x3 relative_orientation_matrix(relative_tf.getRotation());
7887
std::vector<double> relative_orientation_vector;
7988
relative_orientation_vector.reserve(3);
8089
relative_orientation_matrix.getRPY(relative_orientation_vector[0], relative_orientation_vector[1], relative_orientation_vector[2]);
@@ -88,13 +97,13 @@ bool TaskMonitor::IsRobotAtPose(geometry_msgs::msg::PoseWithCovarianceStamped de
8897

8998
void TaskMonitor::SetInitialPose() {
9099
LOG(INFO, "Initialize navigation service called");
91-
auto start_time = rclcpp::Time::now();
100+
auto start_time = this->now();
92101
initial_pose_ = initialize_navigation_action_server_->get_current_goal()->pose;
93102
timeout_s_ = initialize_navigation_action_server_->get_current_goal()->timeout_s;
94103
initial_pose_pub_->publish(initial_pose_);
95104

96105
// Check that the robot is at the desired pose
97-
while ((rclcpp::Time::now() - start_time).seconds() < timeout_s_) {
106+
while ((this->now() - start_time).seconds() < timeout_s_) {
98107
if (IsRobotAtPose(initial_pose_)) {
99108
LOG(INFO, "Robot is at initial pose");
100109
initialize_navigation_action_server_->succeeded_current();

src/task_msgs/CMakeLists.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
cmake_minimum_required(VERSION 3.8)
2+
project(task_msgs)
3+
4+
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
5+
add_compile_options(-Wall -Wextra -Wpedantic)
6+
endif()
7+
8+
find_package(builtin_interfaces REQUIRED)
9+
find_package(geometry_msgs REQUIRED)
10+
find_package(std_msgs REQUIRED)
11+
find_package(action_msgs REQUIRED)
12+
13+
rosidl_generate_interfaces(${PROJECT_NAME}
14+
"action/InitializeNavigation.action"
15+
DEPENDENCIES builtin_interfaces geometry_msgs std_msgs action_msgs
16+
)
17+
18+
ament_export_dependencies(rosidl_default_runtime)
19+
20+
ament_package()

0 commit comments

Comments
 (0)