sistemati i problemi su heding diverso da 0
This commit is contained in:
parent
4fed8dc983
commit
b58d7f1022
@ -3,7 +3,7 @@
|
||||
"scan_limit": 60,
|
||||
"max_range": 100,
|
||||
"geometry": "1492x992+113+61",
|
||||
"last_selected_scenario": "scenario3",
|
||||
"last_selected_scenario": "scenario_dritto",
|
||||
"connection": {
|
||||
"target": {
|
||||
"type": "sfp",
|
||||
|
||||
@ -70,28 +70,17 @@ def build_display_data(
|
||||
|
||||
# Default to identity transformation if origin is not set
|
||||
x_origin_ft, y_origin_ft = 0.0, 0.0
|
||||
heading_origin_rad = 0.0
|
||||
|
||||
if simulation_origin:
|
||||
origin_pos = simulation_origin.get("position_xy_ft", (0.0, 0.0))
|
||||
x_origin_ft, y_origin_ft = origin_pos
|
||||
heading_origin_rad = math.radians(
|
||||
simulation_origin.get("heading_deg", 0.0)
|
||||
)
|
||||
# NOTE: heading_origin_rad is intentionally not used for position anymore
|
||||
|
||||
# 1. Rotate the simulated position by the initial heading of the ownship.
|
||||
# This aligns the simulation frame with the world frame (North-up).
|
||||
cos_h = math.cos(heading_origin_rad)
|
||||
sin_h = math.sin(heading_origin_rad)
|
||||
x_rotated = x_sim_ft * cos_h - y_sim_ft * sin_h
|
||||
y_rotated = x_sim_ft * sin_h + y_sim_ft * cos_h
|
||||
# 1. Translate by the initial position of the ownship to get absolute world position.
|
||||
x_abs_ft = x_sim_ft + x_origin_ft
|
||||
y_abs_ft = y_sim_ft + y_origin_ft
|
||||
|
||||
# 2. Translate by the initial position of the ownship.
|
||||
# This gives the absolute world position of the simulated target.
|
||||
x_abs_ft = x_rotated + x_origin_ft
|
||||
y_abs_ft = y_rotated + y_origin_ft
|
||||
|
||||
# 3. Convert absolute world coordinates to coordinates relative to current ownship.
|
||||
# 2. Convert absolute world coordinates to coordinates relative to current ownship.
|
||||
rel_x_ft, rel_y_ft = x_abs_ft, y_abs_ft
|
||||
if ownship_pos_xy_ft:
|
||||
rel_x_ft = x_abs_ft - ownship_pos_xy_ft[0]
|
||||
@ -106,26 +95,20 @@ def build_display_data(
|
||||
sim_target._update_current_polar_coords()
|
||||
|
||||
try:
|
||||
# --- START OF HEADING CORRECTION ---
|
||||
# The heading from the simulation engine is already in the "world"
|
||||
# frame (North-Up). No further rotation is needed.
|
||||
heading = None
|
||||
if engine and getattr(engine, "scenario", None):
|
||||
t = engine.scenario.get_target(tid)
|
||||
if t:
|
||||
# The target's heading is also in the simulation frame.
|
||||
# It must be rotated by the origin heading to be in the world frame.
|
||||
sim_heading_deg = getattr(t, "current_heading_deg", 0.0)
|
||||
world_heading_deg = (
|
||||
sim_heading_deg + math.degrees(heading_origin_rad)
|
||||
) % 360
|
||||
heading = world_heading_deg
|
||||
heading = getattr(t, "current_heading_deg", 0.0)
|
||||
|
||||
if heading is None and scenario:
|
||||
t2 = scenario.get_target(tid)
|
||||
if t2:
|
||||
sim_heading_deg = getattr(t2, "current_heading_deg", 0.0)
|
||||
world_heading_deg = (
|
||||
sim_heading_deg + math.degrees(heading_origin_rad)
|
||||
) % 360
|
||||
heading = world_heading_deg
|
||||
heading = getattr(t2, "current_heading_deg", 0.0)
|
||||
# --- END OF HEADING CORRECTION ---
|
||||
|
||||
if heading is not None:
|
||||
sim_target.current_heading_deg = float(heading)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user