Skip to content

Commit b7953db

Browse files
RBT22Tony Najjar
andauthored
FIXME Add collision_detector (ros-navigation#12)
Co-authored-by: Tony Najjar <[email protected]>
1 parent 7de75f4 commit b7953db

17 files changed

+755
-2417
lines changed

nav2_collision_monitor/CMakeLists.txt

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,12 @@ set(dependencies
3737
nav2_costmap_2d
3838
)
3939

40-
set(executable_name collision_monitor)
41-
set(library_name ${executable_name}_core)
40+
set(monitor_executable_name collision_monitor)
41+
set(detector_executable_name collision_detector)
42+
set(monitor_library_name ${monitor_executable_name}_core)
43+
set(detector_library_name ${detector_executable_name}_core)
4244

43-
add_library(${library_name} SHARED
45+
add_library(${monitor_library_name} SHARED
4446
src/collision_monitor_node.cpp
4547
src/polygon.cpp
4648
src/circle.cpp
@@ -50,34 +52,59 @@ add_library(${library_name} SHARED
5052
src/range.cpp
5153
src/kinematics.cpp
5254
)
55+
add_library(${detector_library_name} SHARED
56+
src/collision_detector_node.cpp
57+
src/polygon.cpp
58+
src/circle.cpp
59+
src/source.cpp
60+
src/scan.cpp
61+
src/pointcloud.cpp
62+
src/range.cpp
63+
src/kinematics.cpp
64+
)
5365

54-
add_executable(${executable_name}
55-
src/main.cpp
66+
add_executable(${monitor_executable_name}
67+
src/collision_monitor_main.cpp
68+
)
69+
add_executable(${detector_executable_name}
70+
src/collision_detector_main.cpp
5671
)
5772

58-
ament_target_dependencies(${library_name}
73+
ament_target_dependencies(${monitor_library_name}
74+
${dependencies}
75+
)
76+
ament_target_dependencies(${detector_library_name}
5977
${dependencies}
6078
)
6179

62-
target_link_libraries(${executable_name}
63-
${library_name}
80+
target_link_libraries(${monitor_executable_name}
81+
${monitor_library_name}
82+
)
83+
target_link_libraries(${detector_executable_name}
84+
${detector_library_name}
85+
)
86+
87+
ament_target_dependencies(${monitor_executable_name}
88+
${dependencies}
6489
)
6590

66-
ament_target_dependencies(${executable_name}
91+
ament_target_dependencies(${detector_executable_name}
6792
${dependencies}
6893
)
6994

70-
rclcpp_components_register_nodes(${library_name} "nav2_collision_monitor::CollisionMonitor")
95+
rclcpp_components_register_nodes(${monitor_library_name} "nav2_collision_monitor::CollisionMonitor")
96+
97+
rclcpp_components_register_nodes(${detector_library_name} "nav2_collision_monitor::CollisionDetector")
7198

7299
### Install ###
73100

74-
install(TARGETS ${library_name}
101+
install(TARGETS ${monitor_library_name} ${detector_library_name}
75102
ARCHIVE DESTINATION lib
76103
LIBRARY DESTINATION lib
77104
RUNTIME DESTINATION bin
78105
)
79106

80-
install(TARGETS ${executable_name}
107+
install(TARGETS ${monitor_executable_name} ${detector_executable_name}
81108
RUNTIME DESTINATION lib/${PROJECT_NAME}
82109
)
83110

@@ -98,13 +125,12 @@ if(BUILD_TESTING)
98125
ament_lint_auto_find_test_dependencies()
99126

100127
find_package(ament_cmake_gtest REQUIRED)
101-
add_subdirectory(test)
102128
endif()
103129

104130
### Ament stuff ###
105131

106132
ament_export_include_directories(include)
107-
ament_export_libraries(${library_name})
133+
ament_export_libraries(${monitor_library_name} ${detector_library_name})
108134
ament_export_dependencies(${dependencies})
109135

110136
ament_package()
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
// Copyright (c) 2022 Samsung R&D Institute Russia
2+
// Copyright (c) 2023 Pixel Robotics GmbH
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
#ifndef NAV2_COLLISION_MONITOR__COLLISION_DETECTOR_NODE_HPP_
17+
#define NAV2_COLLISION_MONITOR__COLLISION_DETECTOR_NODE_HPP_
18+
19+
#include <string>
20+
#include <vector>
21+
#include <memory>
22+
23+
#include "rclcpp/rclcpp.hpp"
24+
25+
#include "tf2/time.h"
26+
#include "tf2_ros/buffer.h"
27+
#include "tf2_ros/transform_listener.h"
28+
29+
#include "nav2_util/lifecycle_node.hpp"
30+
#include "nav2_msgs/msg/collision_detector_state.hpp"
31+
32+
#include "nav2_collision_monitor/types.hpp"
33+
#include "nav2_collision_monitor/polygon.hpp"
34+
#include "nav2_collision_monitor/circle.hpp"
35+
#include "nav2_collision_monitor/source.hpp"
36+
#include "nav2_collision_monitor/scan.hpp"
37+
#include "nav2_collision_monitor/pointcloud.hpp"
38+
#include "nav2_collision_monitor/range.hpp"
39+
40+
namespace nav2_collision_monitor
41+
{
42+
43+
/**
44+
* @brief Collision Monitor ROS2 node
45+
*/
46+
class CollisionDetector : public nav2_util::LifecycleNode
47+
{
48+
public:
49+
/**
50+
* @brief Constructor for the nav2_collision_monitor::CollisionDetector
51+
* @param options Additional options to control creation of the node.
52+
*/
53+
explicit CollisionDetector(const rclcpp::NodeOptions & options = rclcpp::NodeOptions());
54+
/**
55+
* @brief Destructor for the nav2_collision_monitor::CollisionDetector
56+
*/
57+
~CollisionDetector();
58+
59+
protected:
60+
/**
61+
* @brief: Initializes and obtains ROS-parameters, creates main subscribers and publishers,
62+
* creates polygons and data sources objects
63+
* @param state Lifecycle Node's state
64+
* @return Success or Failure
65+
*/
66+
nav2_util::CallbackReturn on_configure(const rclcpp_lifecycle::State & state) override;
67+
/**
68+
* @brief: Activates LifecyclePublishers, polygons and main processor, creates bond connection
69+
* @param state Lifecycle Node's state
70+
* @return Success or Failure
71+
*/
72+
nav2_util::CallbackReturn on_activate(const rclcpp_lifecycle::State & state) override;
73+
/**
74+
* @brief: Deactivates LifecyclePublishers, polygons and main processor, destroys bond connection
75+
* @param state Lifecycle Node's state
76+
* @return Success or Failure
77+
*/
78+
nav2_util::CallbackReturn on_deactivate(const rclcpp_lifecycle::State & state) override;
79+
/**
80+
* @brief: Resets all subscribers/publishers, polygons/data sources arrays
81+
* @param state Lifecycle Node's state
82+
* @return Success or Failure
83+
*/
84+
nav2_util::CallbackReturn on_cleanup(const rclcpp_lifecycle::State & state) override;
85+
/**
86+
* @brief Called in shutdown state
87+
* @param state Lifecycle Node's state
88+
* @return Success or Failure
89+
*/
90+
nav2_util::CallbackReturn on_shutdown(const rclcpp_lifecycle::State & state) override;
91+
92+
protected:
93+
/**
94+
* @brief Supporting routine obtaining all ROS-parameters
95+
* @return True if all parameters were obtained or false in failure case
96+
*/
97+
bool getParameters();
98+
/**
99+
* @brief Supporting routine creating and configuring all polygons
100+
* @param base_frame_id Robot base frame ID
101+
* @param transform_tolerance Transform tolerance
102+
* @return True if all polygons were configured successfully or false in failure case
103+
*/
104+
bool configurePolygons(
105+
const std::string & base_frame_id,
106+
const tf2::Duration & transform_tolerance);
107+
/**
108+
* @brief Supporting routine creating and configuring all data sources
109+
* @param base_frame_id Robot base frame ID
110+
* @param odom_frame_id Odometry frame ID. Used as global frame to get
111+
* source->base time interpolated transform.
112+
* @param transform_tolerance Transform tolerance
113+
* @param source_timeout Maximum time interval in which data is considered valid
114+
* @param base_shift_correction Whether to correct source data towards to base frame movement,
115+
* considering the difference between current time and latest source time
116+
* @return True if all sources were configured successfully or false in failure case
117+
*/
118+
bool configureSources(
119+
const std::string & base_frame_id,
120+
const std::string & odom_frame_id,
121+
const tf2::Duration & transform_tolerance,
122+
const rclcpp::Duration & source_timeout,
123+
const bool base_shift_correction);
124+
125+
/**
126+
* @brief Main processing routine
127+
*/
128+
void process();
129+
130+
/**
131+
* @brief Polygons publishing routine. Made for visualization.
132+
*/
133+
void publishPolygons() const;
134+
135+
// ----- Variables -----
136+
137+
/// @brief TF buffer
138+
std::shared_ptr<tf2_ros::Buffer> tf_buffer_;
139+
/// @brief TF listener
140+
std::shared_ptr<tf2_ros::TransformListener> tf_listener_;
141+
142+
/// @brief Polygons array
143+
std::vector<std::shared_ptr<Polygon>> polygons_;
144+
/// @brief Data sources array
145+
std::vector<std::shared_ptr<Source>> sources_;
146+
147+
/// @brief collision monitor state publisher
148+
rclcpp_lifecycle::LifecyclePublisher<nav2_msgs::msg::CollisionDetectorState>::SharedPtr
149+
state_pub_;
150+
/// @brief timer that runs actions
151+
rclcpp::TimerBase::SharedPtr timer_;
152+
153+
/// @brief main loop frequency
154+
double frequency_;
155+
}; // class CollisionDetector
156+
157+
} // namespace nav2_collision_monitor
158+
159+
#endif // NAV2_COLLISION_MONITOR__COLLISION_DETECTOR_NODE_HPP_

nav2_collision_monitor/include/nav2_collision_monitor/collision_monitor_node.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ class CollisionMonitor : public nav2_util::LifecycleNode
4747
{
4848
public:
4949
/**
50-
* @brief Constructor for the nav2_collision_safery::CollisionMonitor
50+
* @brief Constructor for the nav2_collision_monitor::CollisionMonitor
5151
* @param options Additional options to control creation of the node.
5252
*/
5353
explicit CollisionMonitor(const rclcpp::NodeOptions & options = rclcpp::NodeOptions());
5454
/**
55-
* @brief Destructor for the nav2_collision_safery::CollisionMonitor
55+
* @brief Destructor for the nav2_collision_monitor::CollisionMonitor
5656
*/
5757
~CollisionMonitor();
5858

@@ -125,7 +125,7 @@ class CollisionMonitor : public nav2_util::LifecycleNode
125125
* @brief Supporting routine creating and configuring all data sources
126126
* @param base_frame_id Robot base frame ID
127127
* @param odom_frame_id Odometry frame ID. Used as global frame to get
128-
* source->base time inerpolated transform.
128+
* source->base time interpolated transform.
129129
* @param transform_tolerance Transform tolerance
130130
* @param source_timeout Maximum time interval in which data is considered valid
131131
* @param base_shift_correction Whether to correct source data towards to base frame movement,

0 commit comments

Comments
 (0)