1- from ...state import AllState , VehicleState , ObjectPose , ObjectFrameEnum , AgentState , AgentEnum , AgentActivityEnum
1+ from ...state import AllState , VehicleState , ObjectPose , ObjectFrameEnum , AgentState , AgentEnum , AgentActivityEnum , ObstacleState , Obstacle , ObstacleStateEnum , ObstacleMaterialEnum
22from ..interface .gem import GEMInterface
33from ..component import Component
44from ultralytics import YOLO
@@ -707,9 +707,12 @@ def update(self, vehicle: VehicleState) -> Dict[str, AgentState]:
707707
708708class FakConeDetector (Component ):
709709 def __init__ (self , vehicle_interface : GEMInterface ):
710+ """
711+ Initializes the FakeConeDetector with two parking spots:
712+ - One standard 2x2 rectangular spot
713+ - One wider mouth for easier entry
714+ """
710715 self .vehicle_interface = vehicle_interface
711- self .times = [(5.0 , 20.0 ), (30.0 , 35.0 )]
712- self .t_start = None
713716
714717 def rate (self ):
715718 return 4.0
@@ -718,27 +721,71 @@ def state_inputs(self):
718721 return ['vehicle' ]
719722
720723 def state_outputs (self ):
721- return ['agents ' ]
724+ return ['obstacles ' ]
722725
723- def update (self , vehicle : VehicleState ) -> Dict [str , AgentState ]:
724- if self .t_start is None :
725- self .t_start = self .vehicle_interface .time ()
726- t = self .vehicle_interface .time () - self .t_start
726+ def update (self , vehicle : VehicleState ) -> Dict [str , ObstacleState ]:
727+ """
728+ Called every simulation step, updates the timestamp and publishes the obstacle states.
729+ """
730+
731+ current_time = self .vehicle_interface .time ()
732+
733+ # === Standard Parking Spot ===
734+ # cones_standard = {
735+ # 'cone0': (5.0, 5.0, 0.5, 0.5), # Front Left
736+ # 'cone1': (5.0, 7.0, 0.5, 0.5), # Back Left
737+ # 'cone2': (7.0, 5.0, 0.5, 0.5), # Front Right
738+ # 'cone3': (7.0, 7.0, 0.5, 0.5) # Back Right
739+ # }
740+
741+ # === Wider Mouth Parking Spot ===
742+ cones_wide = {
743+ 'cone4' : (6.0 , 9.0 , 0.5 , 0.5 ), # Front Left (wide)
744+ 'cone5' : (10.0 , 9.0 , 0.5 , 0.5 ), # Back Left
745+ 'cone6' : (3.0 , 4.0 , 0.5 , 0.5 ), # Front Right (wide)
746+ 'cone7' : (7.0 , 4.0 , 0.5 , 0.5 ) # Back Right
747+ }
748+
749+ # Populate the obstacle states
727750 res = {}
728- for time_range in self .times :
729- if t >= time_range [0 ] and t <= time_range [1 ]:
730- res ['cone0' ] = box_to_fake_agent ((0 , 0 , 0 , 0 ))
731- rospy .loginfo ("Detected a Cone (simulated)" )
732- return res
751+ for name , box in {** cones_wide }.items ():
752+ res [name ] = box_to_fake_obstacle (box , current_time )
753+
754+ # Update timestamp
755+ for obstacle in res .values ():
756+ obstacle .pose .t = current_time
733757
758+ rospy .loginfo (f"[FakeConeDetector] Simulated Two Parking Spots Detected" )
759+ return res
734760
735- def box_to_fake_agent (box ):
761+ def box_to_fake_obstacle (box , current_time ):
762+ """
763+ Helper function to create a fake obstacle (cone) from bounding box coordinates.
764+ """
736765 x , y , w , h = box
737- pose = ObjectPose (t = 0 , x = x + w / 2 , y = y + h / 2 , z = 0 , yaw = 0 , pitch = 0 , roll = 0 , frame = ObjectFrameEnum .CURRENT )
738- dims = (w , h , 0 )
739- return AgentState (pose = pose , dimensions = dims , outline = None ,
740- type = AgentEnum .CONE , activity = AgentActivityEnum .MOVING ,
741- velocity = (0 , 0 , 0 ), yaw_rate = 0 )
766+ pose = ObjectPose (
767+ t = current_time ,
768+ x = x ,
769+ y = y ,
770+ z = 0.0 ,
771+ yaw = 0.0 ,
772+ pitch = 0.0 ,
773+ roll = 0.0 ,
774+ frame = ObjectFrameEnum .START
775+ )
776+
777+ dims = (w , h , 1.0 )
778+
779+ new_obstacle = Obstacle (
780+ pose = pose ,
781+ dimensions = dims ,
782+ outline = None ,
783+ material = ObstacleMaterialEnum .TRAFFIC_CONE ,
784+ collidable = True
785+ )
786+ print ("Obstacles made" )
787+ return new_obstacle
788+
742789
743790
744791if __name__ == '__main__' :
0 commit comments