Program Listing for File source.hpp

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

// Copyright (c) 2022 Samsung R&D Institute Russia
//
// 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__SOURCE_HPP_
#define NAV2_COLLISION_MONITOR__SOURCE_HPP_

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

#include "rclcpp/rclcpp.hpp"

#include "tf2/time.h"
#include "tf2_ros/buffer.h"

#include "nav2_util/lifecycle_node.hpp"

#include "nav2_collision_monitor/types.hpp"

namespace nav2_collision_monitor
{

class Source
{
public:
  Source(
    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);
  virtual ~Source();

  virtual void getData(
    const rclcpp::Time & curr_time,
    std::vector<Point> & data) const = 0;

  bool getEnabled() const;

protected:
  bool configure();

  void getCommonParameters(std::string & source_topic);

  bool sourceValid(
    const rclcpp::Time & source_time,
    const rclcpp::Time & curr_time) const;

  rcl_interfaces::msg::SetParametersResult dynamicParametersCallback(
    std::vector<rclcpp::Parameter> parameters);

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

  nav2_util::LifecycleNode::WeakPtr node_;
  rclcpp::Logger logger_{rclcpp::get_logger("collision_monitor")};
  rclcpp::node_interfaces::OnSetParametersCallbackHandle::SharedPtr dyn_params_handler_;

  // Basic parameters
  std::string source_name_;

  // Global variables
  std::shared_ptr<tf2_ros::Buffer> tf_buffer_;
  std::string base_frame_id_;
  std::string global_frame_id_;
  tf2::Duration transform_tolerance_;
  rclcpp::Duration source_timeout_;
  bool base_shift_correction_;
  bool enabled_;
};  // class Source

}  // namespace nav2_collision_monitor

#endif  // NAV2_COLLISION_MONITOR__SOURCE_HPP_