Skip to content

Commit 0d57387

Browse files
fixed incorrect true wind calculation in mock_gps
1 parent ce1596e commit 0d57387

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

src/local_pathfinding/local_pathfinding/mock_nodes/node_mock_gps.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,12 @@ def wind_sensor_callback(self, msg: ci.WindSensor):
137137

138138
self._logger.debug(f"Received data from {self.__mock_wind_sensor_sub.topic}: {msg}")
139139
aw_speed_kmph: float = msg.speed.speed
140-
aw_direction_deg: float = msg.direction
140+
aw_dir_boat_coord_deg: float = msg.direction
141+
aw_dir_global_coord_deg: float = wcs.boat_to_global_coordinate(
142+
self.__heading_deg.heading, aw_dir_boat_coord_deg
143+
)
141144
tw_dir_rad, tw_speed_kmph = wcs.get_true_wind(
142-
aw_direction_deg,
145+
aw_dir_global_coord_deg,
143146
aw_speed_kmph,
144147
self.__heading_deg.heading,
145148
self.__mean_speed_kmph.speed,

src/local_pathfinding/test/test_wind_coord_systems.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import math
2+
23
import pytest
4+
35
import local_pathfinding.wind_coord_systems as wcs
46

57

@@ -20,8 +22,8 @@
2022
],
2123
)
2224
def test_boat_to_global_coordinate(boat_heading: float, wind_direction: float, expected: float):
23-
assert (
24-
wcs.boat_to_global_coordinate(boat_heading, wind_direction) == pytest.approx(expected)
25+
assert wcs.boat_to_global_coordinate(boat_heading, wind_direction) == pytest.approx(
26+
expected
2527
), "incorrect angle conversion"
2628

2729

@@ -56,6 +58,16 @@ def test_global_to_boat_coordinate(
5658
(180, 17, 179, 9, 179.65, 26),
5759
(140, 17, 45, 9, 111.06, 18.52),
5860
(80, 5, -70, 8, -35.74, 4.44),
61+
(70, 10.579, 180.0, 3.452, 89.04, 9.94),
62+
(70, 10.600, 180.0, 3.518, 89.38, 9.96),
63+
(70, 10.601, -79.198, 3.518, 56.64, 7.79),
64+
(-8, 13.044, -79.198, 3.085, -19.75, 14.34),
65+
(-8, 13.451, -52.021, 3.497, -16.65, 16.15),
66+
(-31, 11.693, -52.021, 2.060, -34.10, 13.64),
67+
(-37, 10.100, -71.758, 0.127, -37.40, 10.20),
68+
(-16, 10.745, -71.758, 0.782, -19.31, 11.20),
69+
(-15, 11.958, -71.765, 2.044, -22.45, 13.19),
70+
(-14, 12.370, -71.765, 2.470, -22.67, 13.85),
5971
],
6072
)
6173
def test_get_true_wind_direction(
@@ -74,8 +86,8 @@ def test_get_true_wind_direction(
7486
tw_dir_deg = math.degrees(tw_dir_rad)
7587

7688
assert tw_dir_deg == pytest.approx(
77-
expected=expected_direction, abs=1e-2
78-
) and tw_speed_kmph == pytest.approx(expected=expected_speed, abs=1e-2)
89+
expected=expected_direction, abs=1e-1
90+
) and tw_speed_kmph == pytest.approx(expected=expected_speed, abs=1e-1)
7991

8092

8193
@pytest.mark.parametrize(
@@ -137,7 +149,7 @@ def test_mock_wind_sensor_pipeline(
137149

138150
assert aw_dir_boat_coord_deg == pytest.approx(
139151
expected=expected_aw_boat_dir_deg, abs=1
140-
), f"Apparent wind direction in boat frame mismatch: {aw_dir_boat_coord_deg} != {expected_aw_boat_dir_deg}" # noqa
152+
), f"Apparent wind direction in boat frame mismatch: {aw_dir_boat_coord_deg} != {expected_aw_boat_dir_deg}" # noqa
141153
assert aw_speed_kmph == pytest.approx(
142154
expected=expected_aw_speed, abs=1
143155
), f"Apparent wind speed mismatch: {aw_speed_kmph} != {expected_aw_speed}"

0 commit comments

Comments
 (0)