Skip to main content

AddDangerousArea

Service type: map_manager/srv/AddDangerousArea

Service name: ${MM}/add_dangerous_area

Description

Add a new speed-restricted area.

Request

FieldTypeDescription
floor_idstringUnique floor identifier.
areamap_manager/msg/DangerousAreaArea data.

Response

FieldTypeDescription
successboolWhether the operation succeeded.
messagestringResult details or an error message.
area_idint32Unique area identifier.

Examples

Example 1

Bash
# Add a rectangular speed-restricted area with a 0.5 m/s limit
ros2 service call ${MM}/add_dangerous_area map_manager/srv/AddDangerousArea \
"{floor_id: '1F', area: {id: 1, boundary: {points: [{x: 0.0, y: 0.0, z: 0.0}, {x: 3.0, y: 0.0, z: 0.0}, {x: 3.0, y: 3.0, z: 0.0}, {x: 0.0, y: 3.0, z: 0.0}]}, speed_limit: 0.5}}"

# Add a corridor speed-restricted area with a 0.3 m/s limit
ros2 service call ${MM}/add_dangerous_area map_manager/srv/AddDangerousArea \
"{floor_id: '1F', area: {id: 2, boundary: {points: [{x: 10.0, y: 0.0, z: 0.0}, {x: 15.0, y: 0.0, z: 0.0}, {x: 15.0, y: 2.0, z: 0.0}, {x: 10.0, y: 2.0, z: 0.0}]}, speed_limit: 0.3}}"

Example 2

Python
from map_manager.srv import AddDangerousArea
from map_manager.msg import DangerousArea
from geometry_msgs.msg import Polygon, Point32
import rclpy
from rclpy.node import Node

class DangerousAreaManager(Node):
def __init__(self):
super().__init__('dangerous_area_manager')
self.client = self.create_client(
AddDangerousArea, '/add_dangerous_area')
self.client.wait_for_service()
self.next_id = 1

def add_area(self, floor_id: str, points: list, speed_limit: float,
area_id: int = None):
if area_id is None:
area_id = self.next_id
self.next_id += 1

polygon = Polygon(points=[
Point32(x=float(p[0]), y=float(p[1]), z=0.0)
for p in points
])

request = AddDangerousArea.Request()
request.floor_id = floor_id
request.area = DangerousArea(
id=area_id,
boundary=polygon,
speed_limit=speed_limit
)

future = self.client.call_async(request)
rclpy.spin_until_future_complete(self, future)
result = future.result()

if result.success:
print(f"Speed-restricted area added successfully: ID={result.area_id}, speed limit={speed_limit} m/s")
else:
print(f"Failed to add: {result.message}")
return result

def add_rectangle(self, floor_id: str, x1: float, y1: float,
x2: float, y2: float, speed_limit: float,
area_id: int = None):
"""Add a rectangular speed-restricted area"""
points = [(x1, y1), (x2, y1), (x2, y2), (x1, y2)]
return self.add_area(floor_id, points, speed_limit, area_id)

rclpy.init()
manager = DangerousAreaManager()

# Add a rectangular speed-restricted area with a 0.5 m/s limit
manager.add_rectangle('1F', 0.0, 0.0, 3.0, 3.0, speed_limit=0.5)

# Add a custom polygonal speed-restricted area
manager.add_area('1F',
[(5.0, 5.0), (8.0, 5.0), (8.0, 8.0), (5.0, 8.0)],
speed_limit=0.3)

rclpy.shutdown()

Example 3

C++
#include <rclcpp/rclcpp.hpp>
#include <map_manager/srv/add_dangerous_area.hpp>
#include <map_manager/msg/dangerous_area.hpp>

class DangerousAreaManager : public rclcpp::Node {
public:
DangerousAreaManager() : Node("dangerous_area_manager"), next_id_(1) {
client_ = create_client<map_manager::srv::AddDangerousArea>(
"/add_dangerous_area");
client_->wait_for_service();
}

bool add_rectangle(const std::string& floor_id,
double x1, double y1, double x2, double y2,
float speed_limit, int area_id = -1) {
if (area_id < 0) area_id = next_id_++;

auto request = std::make_shared<map_manager::srv::AddDangerousArea::Request>();
request->floor_id = floor_id;
request->area.id = area_id;
request->area.speed_limit = speed_limit;

geometry_msgs::msg::Point32 p1, p2, p3, p4;
p1.x = x1; p1.y = y1; p1.z = 0;
p2.x = x2; p2.y = y1; p2.z = 0;
p3.x = x2; p3.y = y2; p3.z = 0;
p4.x = x1; p4.y = y2; p4.z = 0;

request->area.boundary.points = {p1, p2, p3, p4};

auto future = client_->async_send_request(request);
if (rclcpp::spin_until_future_complete(shared_from_this(), future) ==
rclcpp::FutureReturnCode::SUCCESS) {
auto result = future.get();
RCLCPP_INFO(get_logger(), "Speed-restricted area %s: ID=%d, speed limit=%.2f m/s",
result->success ? "Added successfully" : "Failed to add",
result->area_id, speed_limit);
return result->success;
}
return false;
}

private:
rclcpp::Client<map_manager::srv::AddDangerousArea>::SharedPtr client_;
int next_id_;
};

Speed-Restricted Areas vs. Forbidden Areas

PropertyForbidden AreaSpeed-Restricted Area
Robot may enterNoYes
Costmap effectLethal obstacleHigh-cost but traversable area
Speed limitNot applicableConfigurable
Typical useUnsafe or prohibited spaceCrowded areas and narrow passages
ScenarioRecommended Limit (m/s)Rationale
Crowded area0.3Prioritize safety.
Narrow corridor0.5Reduce collision risk.
Doorway0.4Allow safe door traversal.
Ramp0.3Reduce loss-of-control risk.
In front of a glass door0.2Account for sensor blind spots.