From 70ad2545be724683811702360cdc0bf62e5f98a1 Mon Sep 17 00:00:00 2001 From: kristatraboulay <144058657+kristatraboulay@users.noreply.github.com> Date: Sat, 2 Nov 2024 15:51:48 -0700 Subject: [PATCH] Update Fluid Generator to Produce 2D Fluids (#454) * Update to 2D fluid vectors * Fixed indentation in README * Changed indentation in vim --- .../nodes/physics_engine/fluid_generation.py | 4 +- .../unit/nodes/physics_engine/test_fluids.py | 38 +++++++++---------- src/global_launch/config/README.md | 4 +- src/global_launch/config/globals.yaml | 8 ++-- 4 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/boat_simulator/boat_simulator/nodes/physics_engine/fluid_generation.py b/src/boat_simulator/boat_simulator/nodes/physics_engine/fluid_generation.py index f24f0eb34..c4feadcc0 100644 --- a/src/boat_simulator/boat_simulator/nodes/physics_engine/fluid_generation.py +++ b/src/boat_simulator/boat_simulator/nodes/physics_engine/fluid_generation.py @@ -12,7 +12,7 @@ class FluidGenerator: """This class provides functionality to generate velocity vectors representing fluid movements. Attributes: - `generator` (VectorGenerator): The vector generator used to generate 3D fluid velocities. + `generator` (VectorGenerator): The vector generator used to generate 2D fluid velocities. `velocity` (NDArray): The most recently generated fluid velocity vector, expressed in meters per second (m/s). It is expected to be a 3D vector. """ @@ -20,7 +20,7 @@ class FluidGenerator: def __init__(self, generator: VectorGenerator): self.__generator = generator self.__velocity = np.array(self.__generator.next()) - assert self.__velocity.shape == (3,) + assert self.__velocity.shape == (2,) def next(self) -> NDArray: """Generates the next velocity vector for the fluid simulation. diff --git a/src/boat_simulator/tests/unit/nodes/physics_engine/test_fluids.py b/src/boat_simulator/tests/unit/nodes/physics_engine/test_fluids.py index 645295a04..f7d260a99 100644 --- a/src/boat_simulator/tests/unit/nodes/physics_engine/test_fluids.py +++ b/src/boat_simulator/tests/unit/nodes/physics_engine/test_fluids.py @@ -11,9 +11,9 @@ class TestFluidGenerator: @pytest.mark.parametrize( "vector", [ - (np.array([1, 0, 1])), - (np.array([0, 1, 0])), - (np.array([1, 0, 0])), + (np.array([1, 0])), + (np.array([0, 1])), + (np.array([1, 0])), ], ) def test_velocity_constant(self, vector): @@ -26,10 +26,10 @@ def test_velocity_constant(self, vector): @pytest.mark.parametrize( "mean, cov", [ - (np.array([1, 2, 0]), np.array([[2, 1, 1], [1, 2, 0.9], [1, 0.9, 1]])), - (np.array([4, 5, 3]), np.array([[3, 1, 1], [1, 3, 1], [1, 1, 2]])), - (np.array([100, 50, 20]), np.array([[10, 5, 5], [5, 10, 4.5], [5, 4.5, 5]])), - (np.array([120, 130, 40]), np.array([[10, 5, 1], [5, 10, 2], [1, 2, 5]])), + (np.array([1, 2]), np.array([[2, 1], [1, 2]])), + (np.array([4, 5]), np.array([[3, 1], [1, 3]])), + (np.array([100, 50]), np.array([[10, 5], [5, 10]])), + (np.array([120, 130]), np.array([[10, 5], [5, 10]])), ], ) def test_velocity_random(self, mean, cov): @@ -42,12 +42,12 @@ def test_velocity_random(self, mean, cov): @pytest.mark.parametrize( "vector", [ - (np.array([1, 0, 1])), - (np.array([0, 1, 0])), - (np.array([-1, 0, 1])), - (np.array([0, -1, 0])), - (np.array([1, 1, 1])), - (np.array([-1, -1, -1])), + (np.array([1, 0])), + (np.array([0, 1])), + (np.array([-1, 0])), + (np.array([0, -1])), + (np.array([1, 1])), + (np.array([-1, -1])), ], ) def test_speed(self, vector): @@ -60,12 +60,12 @@ def test_speed(self, vector): @pytest.mark.parametrize( "vector, expected_direction", [ - (np.array([1, 0, 1]), 0), - (np.array([0, 1, -3]), 90), - (np.array([-1, 0, -1]), -180), - (np.array([0, -1, 0]), -90), - (np.array([1, 1, 4]), 45), - (np.array([-1, -1, 6]), -135), + (np.array([1, 0]), 0), + (np.array([0, 1]), 90), + (np.array([-1, 0]), -180), + (np.array([0, -1]), -90), + (np.array([1, 1]), 45), + (np.array([-1, -1]), -135), ], ) def test_direction(self, vector, expected_direction): diff --git a/src/global_launch/config/README.md b/src/global_launch/config/README.md index e547e33c1..2af78db44 100644 --- a/src/global_launch/config/README.md +++ b/src/global_launch/config/README.md @@ -262,7 +262,7 @@ specified within an array: one for the `x` component, and one for the `y` compon - _Description_: The mean value for the wind generated, expressed in kilometers per hour (km/h), for the multivariate Gaussian generator. -- _Datatype_: `double` array, length 3 +- _Datatype_: `double` array, length 2 - _Range_: `(0.0, MAX_DOUBLE)` **`wind_generation.mvgaussian_params.cov`** @@ -276,7 +276,7 @@ since ROS parameters do not support native 2D array types. - _Description_: The mean value for the current generated, expressed in kilometers per hour (km/h), for the multivariate Gaussian generator. -- _Datatype_: `double` array, length 3 +- _Datatype_: `double` array, length 2 - _Range_: `(0.0, MAX_DOUBLE)` **`current_generation.mvgaussian_params.cov`** diff --git a/src/global_launch/config/globals.yaml b/src/global_launch/config/globals.yaml index 5370d2e33..045eece39 100644 --- a/src/global_launch/config/globals.yaml +++ b/src/global_launch/config/globals.yaml @@ -62,12 +62,12 @@ physics_engine_node: value: [1.0, 0.0] wind_generation: mvgaussian_params: - mean: [5.0, 5.0, 0.0] - cov: "[[25.0, 10.0, 5.0], [10.0, 15.0, 2.0], [5.0, 2.0, 20.0]]" + mean: [5.0, 5.0] + cov: "[[25.0, 10.0], [10.0, 15.0]]" current_generation: mvgaussian_params: - mean: [1.0, 0.5, 0.0] - cov: "[[0.5, 0.1, 0.05], [0.1, 0.3, 0.02], [0.05, 0.02, 0.2]]" + mean: [1.0, 0.5] + cov: "[[0.5, 0.1], [0.1, 0.3]]" data_collection_node: ros__parameters: file_name: 'ros_data_collection'