asw_component/__init__.py +3−0 View file@@ -0,0 +1,3 @@
1 +
from .component import execute 2 +
3 +
__all__ = ["execute"][참조 MVP] 작업경로 생성 A-SW — 직사각형 농경지와 작업 폭으로 왕복형 커버리지 경로를 생성합니다.
https://git.agrithing.ai/kitech/path-generation-asw.git c194442 af7820a a25733b 3a25789 9560b9d 3d9ebb3 9560b9df324fa89af91903900fa510dcda2c47e1 asw_component/__init__.py +3−0 View filefrom .component import execute__all__ = ["execute"]asw_component/component.py +21−0 View filefrom __future__ import annotationsdef execute(payload: dict) -> dict: width = float(payload["width_m"]) height = float(payload["height_m"]) spacing = float(payload["lane_spacing_m"]) headland = float(payload.get("headland_m", 0)) if width <= 0 or height <= 0 or spacing <= 0 or headland < 0: raise ValueError("field dimensions and spacing must be positive") if headland * 2 >= width or headland * 2 >= height: raise ValueError("headland leaves no workable area") x0, x1 = headland, width - headland y, y1, direction = headland, height - headland, 1 points = [] while y <= y1 + 1e-9: points.extend(([x0, round(y, 3)], [x1, round(y, 3)]) if direction == 1 else ([x1, round(y, 3)], [x0, round(y, 3)])) y += spacing direction *= -1 distance = sum(((b[0]-a[0])**2 + (b[1]-a[1])**2)**0.5 for a, b in zip(points, points[1:])) return {"frame": "field_local", "waypoints": points, "path_length_m": round(distance, 3)}examples/input.json +6−0 View file{ "width_m": 20, "height_m": 12, "lane_spacing_m": 4, "headland_m": 1}pyproject.toml +8−0 View file[project]name = "path_generation_asw"version = "0.1.0"description = "직사각형 농경지와 작업 폭으로 왕복형 커버리지 경로를 생성합니다."requires-python = ">=3.11"[tool.unittest]test-path = "tests"run.py +10−0 View filefrom __future__ import annotationsimport jsonimport sysfrom asw_component import executeif __name__ == "__main__": path = sys.argv[1] if len(sys.argv) > 1 else None with open(path, encoding="utf-8") if path else sys.stdin as source: payload = json.load(source) print(json.dumps(execute(payload), ensure_ascii=False, indent=2))