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