Skip to content

Commit cca72f0

Browse files
authored
modified for simulation with pedestrian detection
1 parent 8f22e76 commit cca72f0

1 file changed

Lines changed: 32 additions & 9 deletions

File tree

GEMstack/onboard/perception/agent_detection.py

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,52 @@
55
import threading
66
import copy
77

8+
import numpy as np
9+
810
class OmniscientAgentDetector(Component):
911
"""Obtains agent detections from a simulator"""
10-
def __init__(self,vehicle_interface : GEMInterface):
12+
13+
def __init__(self, vehicle_interface: GEMInterface):
1114
self.vehicle_interface = vehicle_interface
1215
self.agents = {}
1316
self.lock = threading.Lock()
1417

18+
self.start_pose = None
19+
1520
def rate(self):
1621
return 4.0
17-
22+
1823
def state_inputs(self):
19-
return []
20-
24+
return ['vehicle']
25+
2126
def state_outputs(self):
2227
return ['agents']
2328

2429
def initialize(self):
25-
self.vehicle_interface.subscribe_sensor('agent_detector',self.agent_callback, AgentState)
26-
27-
def agent_callback(self, name : str, agent : AgentState):
30+
self.vehicle_interface.subscribe_sensor('agent_detector', self.agent_callback, AgentState)
31+
32+
def agent_callback(self, name: str, agent: AgentState):
2833
with self.lock:
2934
self.agents[name] = agent
3035

31-
def update(self) -> Dict[str,AgentState]:
36+
def update(self, vehicle : VehicleState) -> Dict[str, AgentState]:
3237
with self.lock:
33-
return copy.deepcopy(self.agents)
38+
res = {}
39+
ped_num = 0
40+
41+
if self.start_pose is None:
42+
self.start_pose = vehicle.pose
43+
# print("\nVehicle start state self.start_pose:", self.start_pose)
44+
# print("\nVehicle current state:", vehicle.pose, vehicle.v)
45+
46+
for n, a in self.agents.items():
47+
# print("\nBefore to_frame: Agent:", n, a.pose, a.velocity)
48+
a = a.to_frame(ObjectFrameEnum.START, current_pose = a.pose, start_pose_abs = self.start_pose)
49+
# print("\nAfter to_frame START: Agent:", n, a.pose, a.velocity)
50+
# print('==============', a.pose.frame==ObjectFrameEnum.START)
51+
res[n] = a
52+
if a.type == AgentEnum.PEDESTRIAN:
53+
ped_num += 1
54+
if ped_num > 0:
55+
print("\nDetected", ped_num, "pedestrians")
56+
return res

0 commit comments

Comments
 (0)