15 #include "nav2_collision_monitor/circle.hpp"
21 #include "nav2_ros_common/node_utils.hpp"
22 #include "nav2_ros_common/tf2_factories.hpp"
24 #include "nav2_collision_monitor/polygon_utils.hpp"
26 namespace nav2_collision_monitor
30 const nav2::LifecycleNode::WeakPtr & node,
31 const std::string & polygon_name,
32 const nav2::TransformBuffer::SharedPtr tf_buffer,
33 const std::string & base_frame_id,
34 const tf2::Duration & transform_tolerance)
35 :
Polygon::
Polygon(node, polygon_name, tf_buffer, base_frame_id, transform_tolerance)
48 constexpr
int polygon_edges = 16;
49 poly = circleToPolygon(
radius_, polygon_edges);
53 const std::vector<Point> & points,
54 std::vector<Point> & out_triggering_points)
const
57 for (
Point point : points) {
59 out_triggering_points.push_back(point);
68 const std::vector<Point> & points,
69 std::vector<std::size_t> & out_triggering_indices)
const
72 for (std::size_t i = 0; i < points.size(); ++i) {
73 const Point & point = points[i];
75 out_triggering_indices.push_back(i);
92 std::string & polygon_sub_topic,
93 std::string & polygon_pub_topic,
94 std::string & footprint_topic)
96 auto node =
node_.lock();
98 throw std::runtime_error{
"Failed to lock node"};
102 polygon_sub_topic.clear();
104 bool use_dynamic_sub =
true;
109 use_dynamic_sub =
false;
110 }
catch (
const rclcpp::exceptions::InvalidParameterValueException &) {
113 "[%s]: Polygon circle radius is not defined. Using dynamic subscription instead.",
119 polygon_sub_topic, polygon_pub_topic, footprint_topic, use_dynamic_sub))
121 if (use_dynamic_sub && polygon_sub_topic.empty()) {
124 "[%s]: Error while getting circle parameters: static radius and sub topic both not defined",
131 footprint_topic.clear();
138 auto node =
node_.lock();
140 throw std::runtime_error{
"Failed to lock node"};
143 if (!polygon_sub_topic.empty()) {
146 "[%s]: Subscribing on %s topic for polygon",
150 polygon_qos.transient_local();
152 radius_sub_ = node->create_subscription<std_msgs::msg::Float32>(
166 std::vector<Point> poly;
169 for (
const Point & p : poly) {
170 geometry_msgs::msg::Point32 p_s;
174 polygon_.polygon.points.push_back(p_s);
182 "[%s]: Polygon circle radius update has been arrived",
A QoS profile for standard reliable topics with a history of 10 messages.
void updatePolygonFromRadius(double radius)
Updates polygon from radius value.
int getPointsInside(const std::vector< Point > &points, std::vector< Point > &out_triggering_points) const override
Gets number of points inside circle.
bool getParameters(std::string &polygon_sub_topic, std::string &polygon_pub_topic, std::string &footprint_topic) override
Supporting routine obtaining polygon-specific ROS-parameters.
void getPolygon(std::vector< Point > &poly) const override
Gets polygon points, approximated to the circle. To be used in visualization purposes.
double radius_squared_
(radius * radius) value. Stored for optimization.
void radiusCallback(std_msgs::msg::Float32::ConstSharedPtr msg)
Dynamic circle radius callback.
bool isShapeSet() override
Returns true if circle radius is set. Otherwise, prints a warning and returns false.
nav2::Subscription< std_msgs::msg::Float32 >::SharedPtr radius_sub_
Radius subscription.
~Circle()
Circle class destructor.
double radius_
Radius of the circle.
void createSubscription(std::string &polygon_sub_topic) override
Creates polygon or radius topic subscription.
Circle(const nav2::LifecycleNode::WeakPtr &node, const std::string &polygon_name, const nav2::TransformBuffer::SharedPtr tf_buffer, const std::string &base_frame_id, const tf2::Duration &transform_tolerance)
Circle class constructor.
Basic polygon shape class. For STOP/SLOWDOWN/LIMIT model it represents zone around the robot while fo...
bool getCommonParameters(std::string &polygon_sub_topic, std::string &polygon_pub_topic, std::string &footprint_topic, bool use_dynamic_sub=false)
Supporting routine obtaining ROS-parameters common for all shapes.
rclcpp::Logger logger_
Collision monitor node logger stored for further usage.
geometry_msgs::msg::PolygonStamped polygon_
Polygon, used for: 1. visualization; 2. storing latest dynamic polygon message.
bool polygon_subscribe_transient_local_
Whether the subscription to polygon topic has transient local QoS durability.
std::string polygon_name_
Name of polygon.
nav2::LifecycleNode::WeakPtr node_
Collision Monitor node.
Point with 2D collision-check coordinates and optional z from the source.