Skip to content

Commit 5420aa4

Browse files
author
Tony Najjar
committed
Revert "Merge pull request #20 from logivations/collision-monitor-add-publish-action"
This reverts commit 8996e15, reversing changes made to 617f60a.
1 parent 5ec9c35 commit 5420aa4

File tree

5 files changed

+1
-124
lines changed

5 files changed

+1
-124
lines changed

nav2_collision_monitor/include/nav2_collision_monitor/collision_monitor_node.hpp

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,6 @@ class CollisionMonitor : public nav2_util::LifecycleNode
141141
*/
142142
void process(const Velocity & cmd_vel_in);
143143

144-
/**
145-
* @brief Timer callback for actions not requiring vel
146-
*/
147-
void process_without_vel();
148-
149144
/**
150145
* @brief Processes the polygon of STOP and SLOWDOWN action type
151146
* @param polygon Polygon to process
@@ -174,18 +169,6 @@ class CollisionMonitor : public nav2_util::LifecycleNode
174169
const Velocity & velocity,
175170
Action & robot_action) const;
176171

177-
/**
178-
* @brief Processes Publish action type
179-
* @param polygon Polygon to process
180-
* @param collision_points Array of 2D obstacle points
181-
* @param velocity Desired robot velocity
182-
* @param robot_action Output processed robot action
183-
* @return True if returned action is caused by current polygon, otherwise false
184-
*/
185-
bool processPublish(
186-
const std::shared_ptr<Polygon> polygon,
187-
const std::vector<Point> & collision_points) const;
188-
189172
/**
190173
* @brief Prints robot action and polygon caused it (if it was)
191174
* @param robot_action Robot action to print
@@ -217,8 +200,6 @@ class CollisionMonitor : public nav2_util::LifecycleNode
217200
rclcpp::Subscription<geometry_msgs::msg::Twist>::SharedPtr cmd_vel_in_sub_;
218201
/// @brief Output cmd_vel publisher
219202
rclcpp_lifecycle::LifecyclePublisher<geometry_msgs::msg::Twist>::SharedPtr cmd_vel_out_pub_;
220-
rclcpp::TimerBase::SharedPtr timer_;
221-
222203

223204
/// @brief Whether main routine is active
224205
bool process_active_;

nav2_collision_monitor/include/nav2_collision_monitor/polygon.hpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#include "rclcpp/rclcpp.hpp"
2323
#include "geometry_msgs/msg/polygon_stamped.hpp"
2424
#include "geometry_msgs/msg/polygon.hpp"
25-
#include "std_msgs/msg/bool.hpp"
2625

2726
#include "tf2/time.h"
2827
#include "tf2_ros/buffer.h"
@@ -136,11 +135,6 @@ class Polygon
136135
const std::vector<Point> & collision_points,
137136
const Velocity & velocity) const;
138137

139-
/**
140-
* @brief Publishes detection message
141-
*/
142-
bool publish_detection(std::vector<Point> collision_points) const;
143-
144138
/**
145139
* @brief Publishes polygon message into a its own topic
146140
*/
@@ -199,10 +193,6 @@ class Polygon
199193
double simulation_time_step_;
200194
/// @brief Footprint subscriber
201195
std::unique_ptr<nav2_costmap_2d::FootprintSubscriber> footprint_sub_;
202-
/// @brief Detection topic
203-
std::string detection_topic_;
204-
/// @brief Detection publisher
205-
rclcpp_lifecycle::LifecyclePublisher<std_msgs::msg::Bool>::SharedPtr detection_pub_;
206196

207197
// Global variables
208198
/// @brief TF buffer

nav2_collision_monitor/include/nav2_collision_monitor/types.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ enum ActionType
6565
DO_NOTHING = 0, // No action
6666
STOP = 1, // Stop the robot
6767
SLOWDOWN = 2, // Slowdown in percentage from current operating speed
68-
APPROACH = 3, // Keep constant time interval before collision
69-
PUBLISH = 4 // Publish to a topic
68+
APPROACH = 3 // Keep constant time interval before collision
7069
};
7170

7271
/// @brief Action for robot

nav2_collision_monitor/src/collision_monitor_node.cpp

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424

2525
#include "nav2_collision_monitor/kinematics.hpp"
2626

27-
using namespace std::chrono_literals;
28-
2927
namespace nav2_collision_monitor
3028
{
3129

@@ -69,15 +67,6 @@ CollisionMonitor::on_configure(const rclcpp_lifecycle::State & /*state*/)
6967
cmd_vel_out_pub_ = this->create_publisher<geometry_msgs::msg::Twist>(
7068
cmd_vel_out_topic, 1);
7169

72-
for (std::shared_ptr<Polygon> polygon : polygons_) {
73-
if (polygon->getActionType() == PUBLISH) {
74-
timer_ = this->create_wall_timer(
75-
100ms,
76-
std::bind(&CollisionMonitor::process_without_vel, this));
77-
break;
78-
}
79-
}
80-
8170
return nav2_util::CallbackReturn::SUCCESS;
8271
}
8372

@@ -394,34 +383,6 @@ void CollisionMonitor::process(const Velocity & cmd_vel_in)
394383
robot_action_prev_ = robot_action;
395384
}
396385

397-
void CollisionMonitor::process_without_vel()
398-
{
399-
// Current timestamp for all inner routines prolongation
400-
rclcpp::Time curr_time = this->now();
401-
402-
// Do nothing if main worker in non-active state
403-
if (!process_active_) {
404-
return;
405-
}
406-
407-
// Points array collected from different data sources in a robot base frame
408-
std::vector<Point> collision_points;
409-
410-
// Fill collision_points array from different data sources
411-
for (std::shared_ptr<Source> source : sources_) {
412-
source->getData(curr_time, collision_points);
413-
}
414-
415-
for (std::shared_ptr<Polygon> polygon : polygons_) {
416-
const ActionType at = polygon->getActionType();
417-
if (at == PUBLISH) {
418-
// Process PUBLISH for the selected polygon
419-
processPublish(polygon, collision_points);
420-
}
421-
}
422-
publishPolygons();
423-
}
424-
425386
bool CollisionMonitor::processStopSlowdown(
426387
const std::shared_ptr<Polygon> polygon,
427388
const std::vector<Point> & collision_points,
@@ -477,13 +438,6 @@ bool CollisionMonitor::processApproach(
477438
return false;
478439
}
479440

480-
bool CollisionMonitor::processPublish(
481-
const std::shared_ptr<Polygon> polygon,
482-
const std::vector<Point> & collision_points) const
483-
{
484-
return polygon->publish_detection(collision_points);
485-
}
486-
487441
void CollisionMonitor::printAction(
488442
const Action & robot_action, const std::shared_ptr<Polygon> action_polygon) const
489443
{
@@ -503,10 +457,6 @@ void CollisionMonitor::printAction(
503457
get_logger(),
504458
"Robot to approach for %f seconds away from collision",
505459
action_polygon->getTimeBeforeCollision());
506-
} else if (robot_action.action_type == PUBLISH) {
507-
RCLCPP_INFO(
508-
get_logger(),
509-
"Robot to publish to configured topic collision detection");
510460
} else { // robot_action.action_type == DO_NOTHING
511461
RCLCPP_INFO(
512462
get_logger(),

nav2_collision_monitor/src/polygon.cpp

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,6 @@ bool Polygon::configure()
7373
base_frame_id_, tf2::durationToSec(transform_tolerance_));
7474
}
7575

76-
if (!detection_topic_.empty()) {
77-
detection_pub_ = node->create_publisher<std_msgs::msg::Bool>(
78-
detection_topic_, rclcpp::SystemDefaultsQoS());
79-
}
80-
8176
if (visualize_) {
8277
// Fill polygon_ points for future usage
8378
std::vector<Point> poly;
@@ -103,19 +98,13 @@ void Polygon::activate()
10398
if (visualize_) {
10499
polygon_pub_->on_activate();
105100
}
106-
if (!detection_topic_.empty()) {
107-
detection_pub_->on_activate();
108-
}
109101
}
110102

111103
void Polygon::deactivate()
112104
{
113105
if (visualize_) {
114106
polygon_pub_->on_deactivate();
115107
}
116-
if (!detection_topic_.empty()) {
117-
detection_pub_->on_deactivate();
118-
}
119108
}
120109

121110
std::string Polygon::getName() const
@@ -233,27 +222,6 @@ void Polygon::publish() const
233222
polygon_pub_->publish(std::move(poly_s));
234223
}
235224

236-
bool Polygon::publish_detection(std::vector<Point> collision_points) const
237-
{
238-
if (detection_topic_.empty()) {
239-
return false;
240-
}
241-
242-
auto node = node_.lock();
243-
if (!node) {
244-
throw std::runtime_error{"Failed to lock node"};
245-
}
246-
bool detected = getPointsInside(collision_points) > getMaxPoints();
247-
248-
std::unique_ptr<std_msgs::msg::Bool> detection =
249-
std::make_unique<std_msgs::msg::Bool>();
250-
detection->data = detected;
251-
// Publish polygon
252-
253-
detection_pub_->publish(std::move(detection));
254-
return detected;
255-
}
256-
257225
bool Polygon::getCommonParameters(std::string & polygon_pub_topic)
258226
{
259227
auto node = node_.lock();
@@ -274,8 +242,6 @@ bool Polygon::getCommonParameters(std::string & polygon_pub_topic)
274242
action_type_ = SLOWDOWN;
275243
} else if (at_str == "approach") {
276244
action_type_ = APPROACH;
277-
} else if (at_str == "publish") {
278-
action_type_ = PUBLISH;
279245
} else { // Error if something else
280246
RCLCPP_ERROR(logger_, "[%s]: Unknown action type: %s", polygon_name_.c_str(), at_str.c_str());
281247
return false;
@@ -350,15 +316,6 @@ bool Polygon::getParameters(std::string & polygon_pub_topic, std::string & footp
350316
footprint_topic.clear();
351317
}
352318

353-
if (action_type_ == PUBLISH) {
354-
nav2_util::declare_parameter_if_not_declared(
355-
node, polygon_name_ + ".detection_topic", rclcpp::ParameterValue(polygon_name_));
356-
detection_topic_ =
357-
node->get_parameter(polygon_name_ + ".detection_topic").as_string();
358-
} else {
359-
detection_topic_.clear();
360-
}
361-
362319
// Leave it not initialized: the will cause an error if it will not set
363320
nav2_util::declare_parameter_if_not_declared(
364321
node, polygon_name_ + ".points", rclcpp::PARAMETER_DOUBLE_ARRAY);

0 commit comments

Comments
 (0)