11from typing import List , Union
22from klampt .vis import scene
33from ..component import Component
4- from ...utils import serialization
54from ...state import Route , ObjectFrameEnum , AllState , VehicleState , Roadgraph , MissionObjective , MissionEnum , ObjectPose
65import numpy as np
76import requests
8- import json
97import time
8+ import yaml
109
1110
1211def check_distance (goal_pose : Union [ObjectPose , list ], current_pose : ObjectPose ):
@@ -37,7 +36,7 @@ def next_state(self):
3736class SummoningMissionPlanner (Component ):
3837 def __init__ (self , use_webapp , webapp_url , goal = None , state_machine = None ):
3938 self .state_machine = StateMachine ([eval (s ) for s in state_machine ])
40-
39+
4140 # if use_webapp is True, goal should be None
4241 self .goal_location = goal ['location' ] if not use_webapp else None
4342 self .goal_frame = goal ['frame' ] if not use_webapp else None
@@ -46,6 +45,7 @@ def __init__(self, use_webapp, webapp_url, goal=None, state_machine=None):
4645 self .start_pose = None
4746 self .start_time = time .time ()
4847 self .end_of_driving_route = None
48+ self .search_count = 0
4949
5050 self .flag_use_webapp = use_webapp
5151 self .url_status = f"{ webapp_url } /api/status"
@@ -113,6 +113,8 @@ def update(self, state: AllState):
113113 goal_location = self .goal_location
114114 goal_frame = self .goal_frame
115115
116+ start_vehicle_pose = state .start_vehicle_pose
117+
116118 if goal_frame == 'global' :
117119 self .goal_pose = ObjectPose (t = time .time (), x = goal_location [0 ], y = goal_location [1 ],
118120 frame = ObjectFrameEnum .GLOBAL )
@@ -128,11 +130,15 @@ def update(self, state: AllState):
128130 raise ValueError ("Invalid frame argument" )
129131
130132 if self .goal_pose :
131- # self.goal_pose = self.goal_pose.to_frame(ObjectFrameEnum.START, start_pose_abs=state.start_vehicle_pose)
132-
133- # For global map test in simulation only
134- start_pose_global = ObjectPose (frame = ObjectFrameEnum .GLOBAL , t = time .time (), x = - 88.235252 , y = 40.0927516 , yaw = - 1.57079633 )
135- self .goal_pose = self .goal_pose .to_frame (ObjectFrameEnum .START , start_pose_abs = start_pose_global )
133+ if start_vehicle_pose .frame == ObjectFrameEnum .ABSOLUTE_CARTESIAN and goal_frame == 'global' :
134+ # For global map simulation test
135+ with open ("scenes/summoning_map_sim_setting.yaml" , "r" ) as f :
136+ data = yaml .safe_load (f )
137+ start = data ['start_pose_global' ]
138+ start_pose_global = ObjectPose (frame = ObjectFrameEnum .GLOBAL , t = start_vehicle_pose .t , x = start [0 ], y = start [1 ], yaw = start [2 ])
139+ self .goal_pose = self .goal_pose .to_frame (ObjectFrameEnum .START , start_pose_abs = start_pose_global )
140+ else :
141+ self .goal_pose = self .goal_pose .to_frame (ObjectFrameEnum .START , start_pose_abs = start_vehicle_pose )
136142 print ("Goal pose:" , self .goal_pose )
137143
138144 # Initiate state
@@ -159,6 +165,8 @@ def update(self, state: AllState):
159165 mission .type = self .state_machine .next_state ()
160166 print ("============== Next state:" , mission .type )
161167 self .end_of_driving_route = route .points [- 1 ]
168+ else :
169+ self .search_count += 1
162170
163171 # Finish parking, back to idle and wait for the next goal location
164172 elif mission .type == MissionEnum .PARALLEL_PARKING :
@@ -171,12 +179,24 @@ def update(self, state: AllState):
171179 mission .type = self .state_machine .next_state ()
172180 self .new_goal = False
173181 self .goal_pose = None
182+ self .goal_location = None
183+ self .goal_frame = None
174184 mission .goal_pose = self .goal_pose
175185 print ("============== Next state:" , mission .type )
186+ else :
187+ self .search_count += 1
176188
177189 else :
178190 raise ValueError ("Invalid mission type" )
179191
192+ # Can not find a path, stop mission.
193+ if self .search_count > 10 :
194+ mission .type = MissionEnum .IDLE
195+ self .goal_pose = None
196+ self .goal_location = None
197+ self .goal_frame = None
198+ self .search_count = 0
199+
180200
181201 if self .flag_use_webapp :
182202 data = {
0 commit comments