Skip to content

Commit 9c1f04d

Browse files
committed
1st working version of background map
add dependency to smopy #249
1 parent 0eab7ad commit 9c1f04d

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

src/sailing_robot/scripts/debugging_2D_plot_matplot

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ from sensor_msgs.msg import NavSatFix
1010
import numpy as np
1111
from matplotlib.transforms import blended_transform_factory
1212

13+
import smopy
1314

1415
# color palette definition (V2 from https://matplotlib.org/users/dflt_style_changes.html#colors-color-cycles-and-color-maps)
1516
C = ['#1f77b4', '#ff7f0e', '#2ca02c', '#d62728',
@@ -60,6 +61,7 @@ class Debugging_2D_matplot():
6061
rospy.Subscriber('position', NavSatFix, self.update_position)
6162
self.position = [1,1]
6263

64+
self.window = [0,0,0,0]
6365
self.init_plot()
6466
self.update_plot()
6567

@@ -204,6 +206,37 @@ class Debugging_2D_matplot():
204206
miny = - dist * scale_dy
205207
maxy = + dist * scale_dy
206208
self.ax.axis([minx, maxx, miny, maxy])
209+
210+
if self.window == [minx, maxx, miny, maxy]:
211+
return
212+
213+
self.window = [minx, maxx, miny, maxy]
214+
215+
216+
SO_corner = self.nav.utm_to_latlon(self.origin[0] + minx, self.origin[1] + miny)
217+
NE_corner = self.nav.utm_to_latlon(self.origin[0] + maxx, self.origin[1] + maxy)
218+
219+
image_map = smopy.Map((float(SO_corner.lat),
220+
float(SO_corner.lon),
221+
float(NE_corner.lat),
222+
float(NE_corner.lon)), )
223+
224+
mapminx, mapminy = image_map.to_pixels((float(SO_corner.lat),
225+
float(SO_corner.lon)), )
226+
227+
mapmaxx, mapmaxy = image_map.to_pixels((float(NE_corner.lat),
228+
float(NE_corner.lon)), )
229+
230+
mapminx = int(mapminx)
231+
mapminy = int(mapminy)
232+
mapmaxx = int(mapmaxx)
233+
mapmaxy = int(mapmaxy)
234+
image = image_map.to_numpy()[mapmaxy:mapminy, mapminx:mapmaxx, :]
235+
236+
self.ax.imshow(image, extent=(minx, maxx, miny, maxy))
237+
238+
239+
207240

208241

209242
def update_plot(self):

0 commit comments

Comments
 (0)