/global_costmap/clear_except_global_costmap
#
Caution
This documentation page has been auto-generated.
It may be missing some details.
/global_costmap/clear_except_global_costmap
Quick Facts
- Category
- Message type
Clears the Global Costmap EXCEPT a certain square around the robot
Quick snippets#
$ ros2 service call /global_costmap/clear_except_global_costmap nav2_msgs/srv/ClearCostmapExceptRegion
# (tip: press Tab to complete the message prototype)
How to use in your code#
1#!/usr/bin/env python
2
3import sys
4import rclpy
5from rclpy.node import Node
6
7from nav2_msgs.srv import ClearCostmapExceptRegion
8
9class ClearExceptGlobalCostmapClientAsync(Node):
10
11 def __init__(self):
12 super().__init__('global_costmap_clear_except_global_costmap_client_async')
13 self.cli = self.create_client(ClearCostmapExceptRegion, 'global_costmap_clear_except_global_costmap')
14 while not self.cli.wait_for_service(timeout_sec=1.0):
15 self.get_logger().info('service not available, waiting again...')
16 self.req = ClearCostmapExceptRegion.Request()
17
18 def send_request(self, a, b):
19 # TODO: adapt to the service's parameters
20 # self.req.a = a
21 # self.req.b = b
22 self.future = self.cli.call_async(self.req)
23 rclpy.spin_until_future_complete(self, self.future)
24 return self.future.result()
25
26
27if __name__ == '__main__':
28 rclpy.init(args=args)
29
30 srv_client = ClearExceptGlobalCostmapClientAsync()
31
32 # TODO: adapt to your parameters
33 response = srv_client.send_request(sys.argv[1], sys.argv[2])
34 srv_client.get_logger().info(
35 'Result of global_costmap_clear_except_global_costmap: %s' % response)
36
37 rclpy.shutdown()
1#include "rclcpp/rclcpp.hpp"
2#include "nav2_msgs/srv/clear_costmap_except_region.hpp"
3
4#include <chrono>
5#include <cstdlib>
6#include <memory>
7
8using namespace std::chrono_literals;
9using namespace std;
10using namespace rclcpp;
11
12int main(int argc, char **argv)
13{
14 init(argc, argv);
15
16 shared_ptr<Node> node = Node::make_shared("global_costmap/clear_except_global_costmap_client");
17 Client<nav2_msgs::srv::ClearCostmapExceptRegion>::SharedPtr client =
18 node->create_client<nav2_msgs::srv::ClearCostmapExceptRegion>("global_costmap/clear_except_global_costmap");
19
20 auto request = make_shared<nav2_msgs::srv::ClearCostmapExceptRegion::Request>();
21
22 // TODO: adapt to the service's parameters
23 // request->a = ...;
24 // request->b = ...;
25
26 while (!client->wait_for_service(1s)) {
27 if (!ok()) {
28 RCLCPP_ERROR(get_logger("rclcpp"), "Interrupted while waiting for the service. Exiting.");
29 return 0;
30 }
31 RCLCPP_INFO(get_logger("rclcpp"), "service not available, waiting again...");
32 }
33
34 auto result = client->async_send_request(request);
35 // Wait for the result.
36 if (spin_until_future_complete(node, result) == FutureReturnCode::SUCCESS)
37 {
38 // TODO: do something with the result
39 // result.get()->...;
40 } else {
41 RCLCPP_ERROR(get_logger("rclcpp"), "Failed to call service global_costmap/clear_except_global_costmap");
42 }
43
44 shutdown();
45 return 0;
46}