Geometric human safety enforcement for robotic workspaces — zero dependencies
Project description
cobot-safety
Geometric human safety enforcement for robotic workspaces.
Zero dependencies. Drop into any Python robotics project and get four-layer collision-free path validation in five lines of code.
pip install cobot-safety
What it does
cobot-safety validates robot pick-and-place plans against human safety
zones after any AI or heuristic planner has run. Four independent
mechanisms — no single failure can produce a dangerous path:
| Mechanism | What it checks |
|---|---|
| Point-in-polygon (ray-casting) | No destination lands inside a human zone |
| Path intersection (2D segment math) | No carry path crosses a human zone, even diagonally |
| Occupancy check | No two objects are placed at the same position |
| Safe-area computation | Candidate positions are always generated outside all zones |
Safety is enforced in Python — the AI cannot override it.
Quick start
from cobot_safety import enforce_safety, make_safety_polygon, ROBOT_BASE_ZONE
# Define where humans are (from your camera or sensor)
human_zone = {
"polygon": make_safety_polygon(
{"x_min": 0.5, "y_min": 0.6, "x_max": 0.9, "y_max": 1.0},
margin=0.05,
)
}
# Your plan (from any planner — Gemini, MoveIt, custom A*)
plan = {
"sequence": [
{"step": 1, "object_id": "bottle",
"from": {"x": 0.2, "y": 0.3}, "to": {"x": 0.8, "y": 0.8}},
{"step": 2, "object_id": "cup",
"from": {"x": 0.3, "y": 0.4}, "to": {"x": 0.1, "y": 0.1}},
],
"clusters": [],
}
zones = [ROBOT_BASE_ZONE, human_zone]
plan, relocated = enforce_safety(plan, zones)
for step in plan["sequence"]:
if step.get("skip"):
print(f"Step {step['step']} skipped — no safe path")
else:
print(f"Step {step['step']} → {step['to']}")
Try it
API
enforce_safety(plan, safety_zones, objects=None)
Main enforcement function. Mutates plan["sequence"] in place.
Parameters:
plan— dict with"sequence"(list of step dicts) and optional"clusters"safety_zones— list of zone dicts, each with a"polygon"keyobjects— optional list of{"id": str, "category": str}for cluster-aware relocation
Returns: (plan, relocated) — the mutated plan and the number of steps relocated.
Steps that could not be made safe have step["skip"] = True.
Geometry primitives
from cobot_safety import (
point_in_polygon, # ray-casting test
in_any_zone, # checks against a list of zones
segments_intersect, # p1-p2 vs p3-p4 (tuple args)
path_crosses_any_zone, # straight-line carry path check
)
Zone construction
from cobot_safety import make_safety_polygon
polygon = make_safety_polygon(
{"x_min": 0.3, "y_min": 0.6, "x_max": 0.7, "y_max": 0.9},
margin=0.05, # outward buffer, default 0.05
)
Safe-area helpers
from cobot_safety import compute_safe_area, generate_grid_positions
sx_min, sx_max, sy_min, sy_max = compute_safe_area(safety_zones)
positions = generate_grid_positions(20, sx_min, sx_max, sy_min, sy_max)
Constants
from cobot_safety import (
ROBOT_BASE_ZONE, # default robot base exclusion zone
DEFAULT_MARGIN, # 0.05 — safety polygon buffer
MIN_SPACING, # 0.11 — grid position spacing
OCCUPANCY_THRESHOLD, # 0.08 — minimum distance between objects
)
Coordinate system
All coordinates are normalized to [0, 1]. (0, 0) is the top-left corner
of the workspace, (1, 1) is the bottom-right.
Tunable constants
Override by importing and reassigning before calling enforce_safety:
import cobot_safety.enforce as se
se.MIN_SPACING = 0.15 # wider grid spacing
se.OCCUPANCY_THRESHOLD = 0.10 # larger personal space per object
Part of SafeArc
cobot-safety is extracted from the
SafeArc hackathon project — a
browser-based AI pipeline for human-safe robotic workspace sorting.
License
Apache 2.0 — see LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cobot_safety-0.1.0.tar.gz.
File metadata
- Download URL: cobot_safety-0.1.0.tar.gz
- Upload date:
- Size: 20.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
09d363a779d43134eed83de9dc26515efdab230b8455165ebde6eed8d8079d23
|
|
| MD5 |
99c903e166fa187c9fad0ae6bd78bcbf
|
|
| BLAKE2b-256 |
9bb2a43684242d24a71069a4827bdae3e2027b03cdcde7eb5657c5a324977ce5
|
File details
Details for the file cobot_safety-0.1.0-py3-none-any.whl.
File metadata
- Download URL: cobot_safety-0.1.0-py3-none-any.whl
- Upload date:
- Size: 16.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
42579a54d86675ae43e5e496a0338da15ec889a9621979dea4cfc966db2f11c3
|
|
| MD5 |
55e540bb29f835a2320f2d51ddf29c6d
|
|
| BLAKE2b-256 |
2a40dcd1176e3175f7776f6ce5155add8b9b36a1c513f5c1b8a41d54a2135c10
|