Nav2 Navigation Stack - kilted  kilted
ROS 2 Navigation Stack
costmap_cost_tool.hpp
1 // Copyright (c) 2024 Jatin Patil
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_RVIZ_PLUGINS__COSTMAP_COST_TOOL_HPP_
16 #define NAV2_RVIZ_PLUGINS__COSTMAP_COST_TOOL_HPP_
17 
18 #include <memory>
19 
20 #include <nav2_msgs/srv/get_costs.hpp>
21 #include <rviz_common/ros_integration/ros_node_abstraction_iface.hpp>
22 #include <rviz_common/tool.hpp>
23 #include <rviz_common/properties/bool_property.hpp>
24 #include <rviz_common/properties/qos_profile_property.hpp>
25 #include <rclcpp/rclcpp.hpp>
26 #include "nav2_util/service_client.hpp"
27 
28 namespace nav2_rviz_plugins
29 {
30 class CostmapCostTool : public rviz_common::Tool
31 {
32  Q_OBJECT
33 
34 public:
36  virtual ~CostmapCostTool();
37 
38  void onInitialize() override;
39  void activate() override;
40  void deactivate() override;
41 
42  int processMouseEvent(rviz_common::ViewportMouseEvent & event) override;
43 
44  void callCostService(float x, float y);
45 
46  void handleLocalCostResponse(rclcpp::Client<nav2_msgs::srv::GetCosts>::SharedFuture);
47  void handleGlobalCostResponse(rclcpp::Client<nav2_msgs::srv::GetCosts>::SharedFuture);
48 
49 private Q_SLOTS:
50 
51 private:
52  nav2_util::ServiceClient<nav2_msgs::srv::GetCosts>::SharedPtr local_cost_client_;
53  nav2_util::ServiceClient<nav2_msgs::srv::GetCosts>::SharedPtr global_cost_client_;
54  // The Node pointer that we need to keep alive for the duration of this plugin.
55  std::shared_ptr<rviz_common::ros_integration::RosNodeAbstractionIface> node_ptr_;
56 
57  QCursor std_cursor_;
58  QCursor hit_cursor_;
59  rviz_common::properties::BoolProperty * auto_deactivate_property_;
60  rviz_common::properties::QosProfileProperty * qos_profile_property_;
61 
62  rclcpp::QoS qos_profile_;
63 };
64 
65 } // namespace nav2_rviz_plugins
66 
67 #endif // NAV2_RVIZ_PLUGINS__COSTMAP_COST_TOOL_HPP_