|
15 | 15 | Call the `dash_app` function with a multiprocessing shared Manager.queue to start the Dash app.
|
16 | 16 | """
|
17 | 17 |
|
| 18 | +import math |
18 | 19 | from multiprocessing import Queue
|
19 | 20 | from typing import List, Optional, Tuple
|
20 | 21 |
|
@@ -190,32 +191,49 @@ def live_update_plot(state: VisualizerState) -> go.Figure:
|
190 | 191 | name="Intermediate",
|
191 | 192 | )
|
192 | 193 |
|
| 194 | + goal_x = [state.final_local_wp_x[-1]] |
| 195 | + goal_y = [state.final_local_wp_y[-1]] |
| 196 | + boat_x = [state.sailbot_pos_x[-1]] |
| 197 | + boat_y = [state.sailbot_pos_y[-1]] |
| 198 | + angle_from_boat = math.atan2(goal_x[0] - boat_x[0], goal_y[0] - boat_y[0]) |
| 199 | + angle_degrees = math.degrees(angle_from_boat) |
| 200 | + |
193 | 201 | # goal local waypoint
|
194 | 202 | goal_trace = go.Scatter(
|
195 |
| - x=[state.final_local_wp_x[-1]], |
196 |
| - y=[state.final_local_wp_y[-1]], |
| 203 | + x=goal_x, |
| 204 | + y=goal_y, |
197 | 205 | mode="markers",
|
198 | 206 | marker=dict(color="red", size=10),
|
199 | 207 | name="Goal",
|
| 208 | + hovertemplate="X: %{x:.2f} <br>" |
| 209 | + + "Y: %{y:.2f} <br>" |
| 210 | + + "Angle from the boat: " |
| 211 | + + f"{angle_degrees:.1f}°" |
| 212 | + + "<extra></extra>", |
200 | 213 | )
|
201 | 214 |
|
202 |
| - # boat marker (current position) |
203 | 215 | boat_trace = go.Scatter(
|
204 | 216 | x=[state.sailbot_pos_x[-1]],
|
205 | 217 | y=[state.sailbot_pos_y[-1]],
|
206 | 218 | mode="markers",
|
207 |
| - marker_symbol="arrow", |
208 |
| - marker_line_color="darkseagreen", |
209 |
| - marker_color="lightgreen", |
210 |
| - marker_line_width=2, |
211 |
| - marker_size=15, |
212 | 219 | name="Boat",
|
213 |
| - hovertemplate="<b>🚢 Sailbot Current Position</b><br>" + |
214 |
| - "X: %{x:.2f} meters<br>" + |
215 |
| - "Y: %{y:.2f} meters<br>" + |
216 |
| - "Heading: " + f"{state.sailbot_gps[-1].heading.heading:.1f}°<br>" + |
217 |
| - "Speed: " + f"{state.sailbot_gps[-1].speed.speed:.1f}<br>" + |
218 |
| - "<extra></extra>" |
| 220 | + hovertemplate=( |
| 221 | + "<b>🚢 Sailbot Current Position</b><br>" |
| 222 | + "X: %{x:.2f} <br>" |
| 223 | + "Y: %{y:.2f} <br>" |
| 224 | + "Heading: " + f"{state.sailbot_gps[-1].heading.heading:.1f}°<br>" |
| 225 | + f"Speed: {state.sailbot_gps[-1].speed.speed:.1f}<br>" |
| 226 | + "<extra></extra>" |
| 227 | + ), |
| 228 | + marker=dict( |
| 229 | + symbol="arrow-wide", |
| 230 | + line_color="darkseagreen", |
| 231 | + color="lightgreen", |
| 232 | + line_width=2, |
| 233 | + size=15, |
| 234 | + angleref="up", |
| 235 | + angle=cs.true_bearing_to_plotly_cartesian(state.sailbot_gps[-1].heading.heading), |
| 236 | + ), |
219 | 237 | )
|
220 | 238 |
|
221 | 239 | # Add all traces to the figure
|
@@ -265,12 +283,14 @@ def animated_update_plot(state: VisualizerState) -> go.Figure:
|
265 | 283 | marker_size=15,
|
266 | 284 | text=["Boat"],
|
267 | 285 | name="Boat",
|
268 |
| - hovertemplate="<b>🚢 Sailbot Current Position</b><br>" + |
269 |
| - "X: %{x:.2f} meters<br>" + |
270 |
| - "Y: %{y:.2f} meters<br>" + |
271 |
| - "Heading: " + f"{state.sailbot_gps[0].heading.heading:.1f}°<br>" + |
272 |
| - "Speed: " + f"{state.sailbot_gps[0].speed.speed:.1f}<br>" + |
273 |
| - "<extra></extra>" |
| 286 | + hovertemplate="<b>🚢 Sailbot Current Position</b><br>" |
| 287 | + + "X: %{x:.2f} meters<br>" |
| 288 | + + "Y: %{y:.2f} meters<br>" |
| 289 | + + "Heading: " |
| 290 | + + f"{state.sailbot_gps[0].heading.heading:.1f}°<br>" |
| 291 | + + "Speed: " |
| 292 | + + f"{state.sailbot_gps[0].speed.speed:.1f}<br>" |
| 293 | + + "<extra></extra>", |
274 | 294 | )
|
275 | 295 | initial_state = [
|
276 | 296 | go.Scatter(
|
@@ -338,12 +358,14 @@ def animated_update_plot(state: VisualizerState) -> go.Figure:
|
338 | 358 | marker_size=15,
|
339 | 359 | text=["Boat"],
|
340 | 360 | name="Boat",
|
341 |
| - hovertemplate="<b>🚢 Sailbot Current Position</b><br>" + |
342 |
| - "X: %{x:.2f} meters<br>" + |
343 |
| - "Y: %{y:.2f} meters<br>" + |
344 |
| - "Heading: " + f"{state.sailbot_gps[i].heading.heading:.1f}°<br>" + |
345 |
| - "Speed: " + f"{state.sailbot_gps[i].speed.speed:.1f}<br>" + |
346 |
| - "<extra></extra>" |
| 361 | + hovertemplate="<b>🚢 Sailbot Current Position</b><br>" |
| 362 | + + "X: %{x:.2f} meters<br>" |
| 363 | + + "Y: %{y:.2f} meters<br>" |
| 364 | + + "Heading: " |
| 365 | + + f"{state.sailbot_gps[i].heading.heading:.1f}°<br>" |
| 366 | + + "Speed: " |
| 367 | + + f"{state.sailbot_gps[i].speed.speed:.1f}<br>" |
| 368 | + + "<extra></extra>", |
347 | 369 | )
|
348 | 370 | ],
|
349 | 371 | name=f"Boat {i}",
|
|
0 commit comments