Skip to main content

add_forbidden_area

Service type: map_manager/srv/AddForbiddenArea

Service name: /forbidden/add

Description​

Adds a forbidden area. GRW accepts only an axis-aligned rectangle with exactly four vertices. Inputs that do not meet this constraint fail. GRW ignores floor_id, assigns a numeric ID, and does not create virtual walls.

Request​

FieldTypeDescription
floor_idstringIDL compatibility field; ignored by GRW.
areamap_manager/msg/ForbiddenAreaFour vertices of an axis-aligned rectangle in boundary.points.

Response​

FieldTypeDescription
successboolWhether the operation succeeded.
messagestringResult message; invalid rectangles fail.
area_idint32Numeric forbidden-area ID assigned on success.
wall_idsint32[]IDL response field; GRW does not create virtual walls.

Example​

Complete Environment Preparation first: the CLI examples require ROBOT_NAMESPACE to be set; the Python and C++ examples use relative service names, so append --ros-args -r __ns:=$ROBOT_NAMESPACE when running them.

CLI call​

Bash
ros2 service call $ROBOT_NAMESPACE/forbidden/add map_manager/srv/AddForbiddenArea \
"{area: {boundary: {points: [{x: 0.0, y: 0.0}, {x: 2.0, y: 0.0}, {x: 2.0, y: 2.0}, {x: 0.0, y: 2.0}]}}}"

Python example​

Python
import rclpy
from geometry_msgs.msg import Point32
from map_manager.msg import ForbiddenArea
from map_manager.srv import AddForbiddenArea

rclpy.init()
node = rclpy.create_node('add_forbidden_area_client')
client = node.create_client(AddForbiddenArea, 'forbidden/add')
client.wait_for_service()

request = AddForbiddenArea.Request()
request.area = ForbiddenArea()
request.area.boundary.points = [
Point32(x=0.0, y=0.0), Point32(x=2.0, y=0.0),
Point32(x=2.0, y=2.0), Point32(x=0.0, y=2.0),
]
future = client.call_async(request)
rclpy.spin_until_future_complete(node, future)
print(future.result().success, future.result().area_id)
node.destroy_node()
rclpy.shutdown()

C++ example​

C++
#include <rclcpp/rclcpp.hpp>
#include <map_manager/srv/add_forbidden_area.hpp>

int main(int argc, char* argv[]) {
rclcpp::init(argc, argv);
auto node = std::make_shared<rclcpp::Node>("add_forbidden_area_client");
auto client = node->create_client<map_manager::srv::AddForbiddenArea>("forbidden/add");
client->wait_for_service();
auto request = std::make_shared<map_manager::srv::AddForbiddenArea::Request>();
auto& points = request->area.boundary.points;
points.resize(4);
points[0].x = 0.0; points[0].y = 0.0;
points[1].x = 2.0; points[1].y = 0.0;
points[2].x = 2.0; points[2].y = 2.0;
points[3].x = 0.0; points[3].y = 2.0;
auto future = client->async_send_request(request);
rclcpp::spin_until_future_complete(node, future);
RCLCPP_INFO(node->get_logger(), "area_id=%d", future.get()->area_id);
rclcpp::shutdown();
}

Notes​

  1. Vertex count: provide exactly four vertices.
  2. Shape constraint: the four vertices must form an axis-aligned rectangle; triangles, arbitrary polygons, and rotated rectangles are not supported.
  3. Vertex order: the current implementation derives the rectangle extent from the vertex coordinates and does not require clockwise or counter-clockwise order. It validates only that there are exactly two distinct x values and two distinct y values; pass four distinct corner points anyway to avoid ambiguity.
  4. Floor field: floor_id is an IDL compatibility field and is not read by GRW.
  5. Virtual walls: this service does not create virtual walls, and wall_ids in the response carries no usable result.