sistemato aggiornamento display target simulati in base al movimento dell'ownship

This commit is contained in:
VALLONGOL 2025-11-05 15:54:37 +01:00
parent f9c609bd64
commit 0a3afcaf61
2 changed files with 14 additions and 16 deletions

View File

@ -2,7 +2,7 @@
"general": {
"scan_limit": 60,
"max_range": 100,
"geometry": "1305x929+159+354",
"geometry": "1409x1110+159+173",
"last_selected_scenario": "corto",
"connection": {
"target": {

View File

@ -37,27 +37,30 @@ def build_display_data(
if not history:
continue
# --- Process Simulated Data (assumed to be relative) ---
# --- Process Simulated Data (transforming from absolute to relative) ---
if history.get("simulated"):
# Simulated data is generated relative to (0,0), so no transformation is needed.
last_sim_state = history["simulated"][-1]
# Unpack the state tuple, now expecting velocities
if len(last_sim_state) >= 6:
_ts, x_ft, y_ft, z_ft, vel_fps, vert_vel_fps = last_sim_state[:6]
else: # Fallback for old data format
else:
_ts, x_ft, y_ft, z_ft = last_sim_state
vel_fps, vert_vel_fps = 0.0, 0.0
# Convert absolute simulation coordinates to relative-to-ownship coordinates
rel_x_ft, rel_y_ft = x_ft, y_ft
if ownship_pos_xy_ft:
rel_x_ft = x_ft - ownship_pos_xy_ft[0]
rel_y_ft = y_ft - ownship_pos_xy_ft[1]
sim_target = Target(target_id=tid, trajectory=[])
setattr(sim_target, "_pos_x_ft", x_ft)
setattr(sim_target, "_pos_y_ft", y_ft)
setattr(sim_target, "_pos_z_ft", z_ft)
setattr(sim_target, "_pos_x_ft", rel_x_ft)
setattr(sim_target, "_pos_y_ft", rel_y_ft)
setattr(sim_target, "_pos_z_ft", z_ft) # Altitude is handled relative to ground
sim_target.current_velocity_fps = vel_fps
sim_target.current_vertical_velocity_fps = vert_vel_fps
sim_target._update_current_polar_coords()
# Preserve heading information from the engine/scenario if available
try:
heading = None
if engine and getattr(engine, "scenario", None):
@ -73,7 +76,6 @@ def build_display_data(
except Exception:
pass
# Preserve active flag
sim_target.active = True
if engine and getattr(engine, "scenario", None):
t_engine = engine.scenario.get_target(tid)
@ -89,12 +91,9 @@ def build_display_data(
rel_x_ft, rel_y_ft = abs_x_ft, abs_y_ft
if ownship_pos_xy_ft:
# Calculate position relative to the ownship
rel_x_ft = abs_x_ft - ownship_pos_xy_ft[0]
rel_y_ft = abs_y_ft - ownship_pos_xy_ft[1]
# The z-coordinate (altitude) is typically absolute, but for display
# we can treat it as relative to the ownship's altitude.
ownship_alt_ft = ownship_state.get("altitude_ft", 0.0)
rel_z_ft = abs_z_ft - ownship_alt_ft
@ -104,7 +103,6 @@ def build_display_data(
setattr(real_target, "_pos_z_ft", rel_z_ft)
real_target._update_current_polar_coords()
# Copy last-known heading if hub provides it
hdg = simulation_hub.get_real_heading(tid)
if hdg is not None:
real_target.current_heading_deg = float(hdg) % 360
@ -119,4 +117,4 @@ def build_display_data(
len(real_targets_for_ppi),
)
return {"simulated": simulated_targets_for_ppi, "real": real_targets_for_ppi}
return {"simulated": simulated_targets_for_ppi, "real": real_targets_for_ppi}