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
| Field | Type | Description |
|---|---|---|
| floor_id | string | IDL compatibility field; ignored by GRW. |
| area | map_manager/msg/ForbiddenArea | Four vertices of an axis-aligned rectangle in boundary.points. |
Response
| Field | Type | Description |
|---|---|---|
| success | bool | Whether the operation succeeded. |
| message | string | Result message; invalid rectangles fail. |
| area_id | int32 | Numeric forbidden-area ID assigned on success. |
| wall_ids | int32[] | IDL response field; GRW does not create virtual walls. |
Example
Complete Environment Preparation first: the CLI examples require
ROBOT_NAMESPACEto be set; the Python and C++ examples use relative service names, so append--ros-args -r __ns:=$ROBOT_NAMESPACEwhen 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
- Vertex count: provide exactly four vertices.
- Shape constraint: the four vertices must form an axis-aligned rectangle; triangles, arbitrary polygons, and rotated rectangles are not supported.
- 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
xvalues and two distinctyvalues; pass four distinct corner points anyway to avoid ambiguity. - Floor field:
floor_idis an IDL compatibility field and is not read by GRW. - Virtual walls: this service does not create virtual walls, and
wall_idsin the response carries no usable result.