-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlector_vf.py
More file actions
80 lines (68 loc) · 3.64 KB
/
lector_vf.py
File metadata and controls
80 lines (68 loc) · 3.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# controllers/drive_Vf/lector_vf.py
import owlready2
from owlready2 import get_ontology, sync_reasoner
# fuerza el ejecutable de Java para HermiT
owlready2.JAVA_EXE = r"C:\Program Files\Eclipse Adoptium\jdk-21.0.7.6-hotspot\bin\java.exe"
import os
ONTOLOGY_FILE = "ONTOLOGIA_vf.owl"
def get_robot_attributes():
# 1) Cargo la ontología y razono con HermiT
onto_path = os.path.abspath(ONTOLOGY_FILE)
onto = get_ontology(f"file://{onto_path}").load()
with onto:
sync_reasoner(infer_property_values=True)
# 2) Encuentro la clase Robot
Robot = next((c for c in onto.classes() if c.name.lower() == "robot"), None)
if Robot is None:
print("[ERROR] No hay clase Robot en la ontología.")
return []
robot_data = []
for r in Robot.instances():
# Extraigo atributos básicos...
id_val = float(r.id[0]) if getattr(r, "id", None) else None
xpos = float(r.xpos[0]) if getattr(r, "xpos", None) else 0.0
ypos = float(r.ypos[0]) if getattr(r, "ypos", None) else 0.0
angle = float(r.angle[0]) if getattr(r, "angle", None) else 0.0
# Batería (sigue manual en el controlador)
bat = r.has_battery[0] if getattr(r, "has_battery", None) else None
battery_charge = float(bat.charge[0]) if bat and getattr(bat, "charge", None) else None
# Motor
eng = r.uses_engine[0] if getattr(r, "uses_engine", None) else None
engine_name = eng.name[0] if eng and getattr(eng, "name", None) else None
max_speed = float(eng.max_speed[0]) if eng and getattr(eng, "max_speed", None) else None
consumption = float(eng.consumption[0]) if eng and getattr(eng, "consumption", None) else None
engine_type = eng.type[0] if eng and getattr(eng, "type", None) else None
# Task config (patrol / navigate)
patrol_ind = r.has_patrol_config[0] if getattr(r, "has_patrol_config", None) else None
patrol_time = float(patrol_ind.patrol_time[0]) if patrol_ind and getattr(patrol_ind, "patrol_time", None) else None
move_distance = float(patrol_ind.move_distance[0]) if patrol_ind and getattr(patrol_ind, "move_distance", None) else None
patrol_speed = float(patrol_ind.patrol_speed[0]) if patrol_ind and getattr(patrol_ind, "patrol_speed", None) else None
nav_ind = r.has_navigate_config[0] if getattr(r, "has_navigate_config", None) else None
target_x = float(nav_ind.target_x[0]) if nav_ind and getattr(nav_ind, "target_x", None) else None
target_y = float(nav_ind.target_y[0]) if nav_ind and getattr(nav_ind, "target_y", None) else None
navigation_speed = float(nav_ind.navigation_speed[0]) if nav_ind and getattr(nav_ind, "navigation_speed", None) else None
# 3) Extraigo el resultado del razonamiento
behavior = None
if getattr(r, "behaves", None) and r.behaves:
# tomo el nombre del estado inferido
behavior = r.behaves[0].name
# 4) Construyo el registro
robot_data.append({
"id": id_val,
"xpos": xpos,
"ypos": ypos,
"angle": angle,
"battery_charge": battery_charge,
"engine_name": engine_name,
"max_speed": max_speed,
"consumption": consumption,
"engine_type": engine_type,
"patrol_time": patrol_time,
"move_distance": move_distance,
"patrol_speed": patrol_speed,
"target_x": target_x,
"target_y": target_y,
"navigation_speed": navigation_speed,
"behavior": behavior
})
return robot_data