Nav2 Navigation Stack - lyrical  lyrical
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/client.hpp"
26 #include "rclcpp/qos.hpp"
27 #include "nav2_ros_common/service_client.hpp"
28 
29 namespace nav2_rviz_plugins
30 {
31 class CostmapCostTool : public rviz_common::Tool
32 {
33  Q_OBJECT
34 
35 public:
37  virtual ~CostmapCostTool();
38 
39  void onInitialize() override;
40  void activate() override;
41  void deactivate() override;
42 
43  int processMouseEvent(rviz_common::ViewportMouseEvent & event) override;
44 
45  void callCostService(float x, float y);
46  // nosemgrep
47  void handleLocalCostResponse(rclcpp::Client<nav2_msgs::srv::GetCosts>::SharedFuture);
48  // nosemgrep
49  void handleGlobalCostResponse(rclcpp::Client<nav2_msgs::srv::GetCosts>::SharedFuture);
50 
51 private Q_SLOTS:
52 
53 private:
54  nav2::ServiceClient<nav2_msgs::srv::GetCosts>::SharedPtr local_cost_client_;
55  nav2::ServiceClient<nav2_msgs::srv::GetCosts>::SharedPtr global_cost_client_;
56  // The Node pointer that we need to keep alive for the duration of this plugin.
57  std::shared_ptr<rviz_common::ros_integration::RosNodeAbstractionIface> node_ptr_;
58 
59  QCursor std_cursor_;
60  QCursor hit_cursor_;
61  rviz_common::properties::BoolProperty * auto_deactivate_property_;
62  rviz_common::properties::QosProfileProperty * qos_profile_property_;
63 
64  rclcpp::QoS qos_profile_;
65 };
66 
67 } // namespace nav2_rviz_plugins
68 
69 #endif // NAV2_RVIZ_PLUGINS__COSTMAP_COST_TOOL_HPP_