@@ -46,6 +46,31 @@ def __init__(self, mode, state_machine):
4646
4747 self .count = 0 # for test only, simulate a delay to get the gaol location
4848
49+ # Set False when omitting the webapp. TODO: add a flag to the config file
50+ self .flag_use_webapp = True
51+
52+ if self .flag_use_webapp :
53+ # Initialize the state in the server
54+ url = "http://localhost:8000/api/status"
55+ data = {
56+ "status" : "IDLE"
57+ }
58+ response = requests .post (url = url , json = data )
59+ if response .status_code == 200 :
60+ print ("Status updated successfully" )
61+ else :
62+ print ("Failed to update status:" , response .status_code )
63+ url = "http://localhost:8000/api/summon"
64+ data = {
65+ "lat" : 0 ,
66+ "lon" : 0
67+ }
68+ response = requests .post (url = url , json = data )
69+ if response .status_code == 200 :
70+ print ("Initialize goal location successfully" )
71+ else :
72+ print ("Failed to initialize goal location:" , response .status_code )
73+
4974 def state_inputs (self ):
5075 return ['all' ]
5176
@@ -64,17 +89,31 @@ def update(self, state: AllState):
6489 if self .count < 3 :
6590 return mission_plan
6691
67- # TODO: Modify to a GET request to get goal location from the server
68- # current_goal_location = self.goal_location
69- # url = ""
70- # response = requests.get(url)
71- # if response.status_code == 200:
72- # data = response.json()
73- # goal_location = data['goal_location']
74- # goal_frame = data['goal_frame']
7592
76- goal_location = [10 , 11 ] # for simulation test only
77- goal_frame = 'start'
93+ if self .flag_use_webapp :
94+ goal_location = None
95+ url = "http://localhost:8000/api/summon"
96+ response = requests .get (url )
97+ print ("GET:" , response )
98+ if response .status_code == 200 :
99+ data = response .json ()
100+ if data ['lat' ] == 0 and data ['lon' ] == 0 :
101+ print ("No goal location received" )
102+ goal_location = None
103+ goal_frame = None
104+ else :
105+ # TODO: ADD CONVERSION FROM LAT/LON TO X/Y GLOBAL COORDINATES
106+ goal_location = [data ['lat' ] , data ['lon' ]]
107+ goal_frame = 'global'
108+ print ("Goal location:" , goal_location )
109+ print ("Goal frame:" , goal_frame )
110+
111+ goal_location = [10 , 0 ] # for simlulation test only
112+ goal_frame = 'start'
113+ else :
114+ goal_location = [10 , 11 ] # for simulation test only
115+ goal_frame = 'start'
116+
78117
79118 if self .goal_location == goal_location :
80119 self .new_goal = False
@@ -128,8 +167,18 @@ def update(self, state: AllState):
128167 else :
129168 mission_plan = state .mission_plan
130169
131- # TODO: POST request to update status to the server
132- # data =
133- # response = requests.post(url=url, data=data)
170+
171+ if self .flag_use_webapp :
172+ url = "http://localhost:8000/api/status"
173+ data = {
174+ "status" : mission_plan .planner_type .name
175+ }
176+ print ("POST:" , data )
177+ response = requests .post (url = url , json = data )
178+ if response .status_code == 200 :
179+ print ("Status updated successfully" )
180+ else :
181+ print ("Failed to update status:" , response .status_code )
182+
134183
135184 return mission_plan
0 commit comments