From 67bbd8f1b915ea3252a74f9ca15a4ef34bdc0b8d Mon Sep 17 00:00:00 2001 From: James Pace Date: Sat, 7 Mar 2026 16:07:24 -0500 Subject: [PATCH] Get lat long. --- am_i_up/Api.py | 13 +++++++++++++ am_i_up/Facts.py | 7 +++++++ am_i_up/Ros.py | 5 +++++ 3 files changed, 25 insertions(+) diff --git a/am_i_up/Api.py b/am_i_up/Api.py index ca5cc70..31c71bb 100644 --- a/am_i_up/Api.py +++ b/am_i_up/Api.py @@ -29,6 +29,7 @@ class Api: web.get('/api/env', self.env), web.get('/api/status', self.status), web.get('/api/costmap_image', self.costmap_image), + web.get("/api/position", self.position), web.static("/assets", ui_static_directory), # we're not actually using key anywhere, but doing this allows react router # to work correctly. @@ -91,3 +92,15 @@ class Api: raise web.HTTPUnsupportedMediaType() resp = web.Response(body=image_data, content_type='image/{}'.format(image_format)) return resp + + async def position(self, request): + resp = {} + (lat, lon) = self._facts.get_lat_long() + if not lat or not lon: + resp["status"] = False + return web.json_response(resp) + resp["status"] = True + resp["latitude"] = lat + resp["longitude"] = lon + return web.json_response(resp) + diff --git a/am_i_up/Facts.py b/am_i_up/Facts.py index 4b9d193..2e91a2c 100644 --- a/am_i_up/Facts.py +++ b/am_i_up/Facts.py @@ -21,6 +21,13 @@ class Facts: self._status_string = None self._costmap_image_format = None self._costmap_image_data = None + self._lat_lon = (None, None) + + def set_lat_long(self, lat, lon): + self._lat_lon = (lat, lon) + + def get_lat_long(self): + return self._lat_lon def set_costmap_image(self, image_format, image_data): self._costmap_image_format = image_format diff --git a/am_i_up/Ros.py b/am_i_up/Ros.py index 4443d77..167fca2 100644 --- a/am_i_up/Ros.py +++ b/am_i_up/Ros.py @@ -11,6 +11,7 @@ import rclpy from std_msgs.msg import String from sensor_msgs.msg import CompressedImage +from sensor_msgs.msg import NavSatFix import asyncio class Ros: @@ -21,10 +22,14 @@ class Ros: self._node.create_subscription(String, "status", self.status_sub, 1) self._node.create_subscription(CompressedImage, "image/compressed", self.image_sub, 1) + self._node.create_subscription(NavSatFix, "navsatfix", self.navsat_sub, 1) def status_sub(self, msg): self._facts.set_status_string(msg.data) + def navsat_sub(self, msg): + self._facts.set_lat_long(msg.latitude, msg.longitude) + def image_sub(self, msg): if msg.format != "jpg" and msg.format != "png": # I don't know what to do with this image....