Program Listing for File polygon_source.hpp

Return to documentation for file (include/nav2_collision_monitor/polygon_source.hpp)

// Copyright (c) 2023 Pixel Robotics GmbH
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef NAV2_COLLISION_MONITOR__POLYGON_SOURCE_HPP_
#define NAV2_COLLISION_MONITOR__POLYGON_SOURCE_HPP_

#include <memory>
#include <vector>
#include <string>

#include "geometry_msgs/msg/polygon_instance_stamped.hpp"
#include "geometry_msgs/msg/polygon_stamped.hpp"

#include "nav2_collision_monitor/source.hpp"

namespace nav2_collision_monitor
{

class PolygonSource : public Source
{
public:
  PolygonSource(
    const nav2_util::LifecycleNode::WeakPtr & node,
    const std::string & source_name,
    const std::shared_ptr<tf2_ros::Buffer> tf_buffer,
    const std::string & base_frame_id,
    const std::string & global_frame_id,
    const tf2::Duration & transform_tolerance,
    const rclcpp::Duration & source_timeout,
    const bool base_shift_correction);
  ~PolygonSource();

  void configure();

  bool getData(
    const rclcpp::Time & curr_time,
    std::vector<Point> & data);

  void convertPolygonStampedToPoints(
    const geometry_msgs::msg::PolygonStamped & polygon,
    std::vector<Point> & data) const;

protected:
  void getParameters(std::string & source_topic);

  void dataCallback(geometry_msgs::msg::PolygonInstanceStamped::ConstSharedPtr msg);

  // ----- Variables -----

  rclcpp::Subscription<geometry_msgs::msg::PolygonInstanceStamped>::SharedPtr data_sub_;

  std::vector<geometry_msgs::msg::PolygonInstanceStamped> data_;

  double sampling_distance_;
};  // class PolygonSource

}  // namespace nav2_collision_monitor

#endif  // NAV2_COLLISION_MONITOR__POLYGON_SOURCE_HPP_