Nav2 Navigation Stack - lyrical  lyrical
ROS 2 Navigation Stack
circle.hpp
1 // Copyright (c) 2022 Samsung R&D Institute Russia
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef NAV2_COLLISION_MONITOR__CIRCLE_HPP_
16 #define NAV2_COLLISION_MONITOR__CIRCLE_HPP_
17 
18 #include <memory>
19 #include <vector>
20 #include <string>
21 
22 #include "std_msgs/msg/float32.hpp"
23 
24 #include "nav2_collision_monitor/polygon.hpp"
25 #include "nav2_ros_common/tf2_factories.hpp"
26 
27 namespace nav2_collision_monitor
28 {
29 
35 class Circle : public Polygon
36 {
37 public:
46  Circle(
47  const nav2::LifecycleNode::WeakPtr & node,
48  const std::string & polygon_name,
49  const nav2::TransformBuffer::SharedPtr tf_buffer,
50  const std::string & base_frame_id,
51  const tf2::Duration & transform_tolerance);
55  ~Circle();
56 
62  void getPolygon(std::vector<Point> & poly) const override;
63 
71  int getPointsInside(
72  const std::vector<Point> & points,
73  std::vector<Point> & out_triggering_points) const override;
74 
82  int getPointsInside(
83  const std::vector<Point> & points,
84  std::vector<std::size_t> & out_triggering_indices) const override;
85 
90  bool isShapeSet() override;
91 
92 protected:
101  bool getParameters(
102  std::string & polygon_sub_topic,
103  std::string & polygon_pub_topic,
104  std::string & footprint_topic) override;
105 
111  void createSubscription(std::string & polygon_sub_topic) override;
112 
117  void updatePolygonFromRadius(double radius);
118 
123  void radiusCallback(std_msgs::msg::Float32::ConstSharedPtr msg);
124 
125 
126  // ----- Variables -----
127 
129  double radius_;
131  double radius_squared_ = -1.0;
133  nav2::Subscription<std_msgs::msg::Float32>::SharedPtr radius_sub_;
134 }; // class Circle
135 
136 } // namespace nav2_collision_monitor
137 
138 #endif // NAV2_COLLISION_MONITOR__CIRCLE_HPP_
Circle shape implementation. For STOP/SLOWDOWN/LIMIT model it represents zone around the robot while ...
Definition: circle.hpp:36
void updatePolygonFromRadius(double radius)
Updates polygon from radius value.
Definition: circle.cpp:159
int getPointsInside(const std::vector< Point > &points, std::vector< Point > &out_triggering_points) const override
Gets number of points inside circle.
Definition: circle.cpp:52
bool getParameters(std::string &polygon_sub_topic, std::string &polygon_pub_topic, std::string &footprint_topic) override
Supporting routine obtaining polygon-specific ROS-parameters.
Definition: circle.cpp:91
void getPolygon(std::vector< Point > &poly) const override
Gets polygon points, approximated to the circle. To be used in visualization purposes.
Definition: circle.cpp:45
double radius_squared_
(radius * radius) value. Stored for optimization.
Definition: circle.hpp:131
void radiusCallback(std_msgs::msg::Float32::ConstSharedPtr msg)
Dynamic circle radius callback.
Definition: circle.cpp:178
bool isShapeSet() override
Returns true if circle radius is set. Otherwise, prints a warning and returns false.
Definition: circle.cpp:82
nav2::Subscription< std_msgs::msg::Float32 >::SharedPtr radius_sub_
Radius subscription.
Definition: circle.hpp:133
~Circle()
Circle class destructor.
Definition: circle.cpp:40
double radius_
Radius of the circle.
Definition: circle.hpp:129
void createSubscription(std::string &polygon_sub_topic) override
Creates polygon or radius topic subscription.
Definition: circle.cpp:136
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.
Definition: circle.cpp:29
Basic polygon shape class. For STOP/SLOWDOWN/LIMIT model it represents zone around the robot while fo...
Definition: polygon.hpp:45