AddDangerousArea
Service type: map_manager/srv/AddDangerousArea
Service name: ${MM}/add_dangerous_area
Description
Add a new speed-restricted area.
Request
| Field | Type | Description |
|---|---|---|
floor_id | string | Unique floor identifier. |
area | map_manager/msg/DangerousArea | Area data. |
Response
| Field | Type | Description |
|---|---|---|
success | bool | Whether the operation succeeded. |
message | string | Result details or an error message. |
area_id | int32 | Unique 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
| Property | Forbidden Area | Speed-Restricted Area |
|---|---|---|
| Robot may enter | No | Yes |
| Costmap effect | Lethal obstacle | High-cost but traversable area |
| Speed limit | Not applicable | Configurable |
| Typical use | Unsafe or prohibited space | Crowded areas and narrow passages |
Recommended Speed Limits
| Scenario | Recommended Limit (m/s) | Rationale |
|---|---|---|
| Crowded area | 0.3 | Prioritize safety. |
| Narrow corridor | 0.5 | Reduce collision risk. |
| Doorway | 0.4 | Allow safe door traversal. |
| Ramp | 0.3 | Reduce loss-of-control risk. |
| In front of a glass door | 0.2 | Account for sensor blind spots. |