Nav2 Navigation Stack - humble  humble
ROS 2 Navigation Stack
photo_at_waypoint.hpp
1 // Copyright (c) 2020 Fetullah Atas
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_WAYPOINT_FOLLOWER__PLUGINS__PHOTO_AT_WAYPOINT_HPP_
16 #define NAV2_WAYPOINT_FOLLOWER__PLUGINS__PHOTO_AT_WAYPOINT_HPP_
17 
22 #define _LIBCPP_NO_EXPERIMENTAL_DEPRECATION_WARNING_FILESYSTEM
23 
24 
25 #include <filesystem>
26 #include <mutex>
27 #include <string>
28 #include <exception>
29 
30 #include "rclcpp/rclcpp.hpp"
31 #include "rclcpp_components/register_node_macro.hpp"
32 
33 #include "sensor_msgs/msg/image.hpp"
34 #include "nav2_core/waypoint_task_executor.hpp"
35 #include "opencv4/opencv2/core.hpp"
36 #include "opencv4/opencv2/opencv.hpp"
37 #include "cv_bridge/cv_bridge.h"
38 #include "image_transport/image_transport.hpp"
39 
40 
41 namespace nav2_waypoint_follower
42 {
43 
45 {
46 public:
52 
58 
65  void initialize(
66  const rclcpp_lifecycle::LifecycleNode::WeakPtr & parent,
67  const std::string & plugin_name);
68 
69 
78  bool processAtWaypoint(
79  const geometry_msgs::msg::PoseStamped & curr_pose, const int & curr_waypoint_index);
80 
86  void imageCallback(const sensor_msgs::msg::Image::SharedPtr msg);
87 
94  static void deepCopyMsg2Mat(const sensor_msgs::msg::Image::SharedPtr & msg, cv::Mat & mat);
95 
96 protected:
97  // to ensure safety when accessing global var curr_frame_
98  std::mutex global_mutex_;
99  // the taken photos will be saved under this directory
100  std::filesystem::path save_dir_;
101  // .png ? .jpg ? or some other well known format
102  std::string image_format_;
103  // the topic to subscribe in order capture a frame
104  std::string image_topic_;
105  // whether plugin is enabled
106  bool is_enabled_;
107  // current frame;
108  sensor_msgs::msg::Image::SharedPtr curr_frame_msg_;
109  // global logger
110  rclcpp::Logger logger_{rclcpp::get_logger("nav2_waypoint_follower")};
111  // ros subscriber to get camera image
112  rclcpp::Subscription<sensor_msgs::msg::Image>::SharedPtr camera_image_subscriber_;
113 };
114 } // namespace nav2_waypoint_follower
115 
116 #endif // NAV2_WAYPOINT_FOLLOWER__PLUGINS__PHOTO_AT_WAYPOINT_HPP_
Base class for creating a plugin in order to perform a specific task at waypoint arrivals.
bool processAtWaypoint(const geometry_msgs::msg::PoseStamped &curr_pose, const int &curr_waypoint_index)
Override this to define the body of your task that you would like to execute once the robot arrived t...
static void deepCopyMsg2Mat(const sensor_msgs::msg::Image::SharedPtr &msg, cv::Mat &mat)
given a shared pointer to sensor::msg::Image type, make a deep copy to inputted cv Mat
void initialize(const rclcpp_lifecycle::LifecycleNode::WeakPtr &parent, const std::string &plugin_name)
declares and loads parameters used
void imageCallback(const sensor_msgs::msg::Image::SharedPtr msg)
PhotoAtWaypoint()
Construct a new Photo At Waypoint object.
~PhotoAtWaypoint()
Destroy the Photo At Waypoint object.