diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 2dd5e134..f1a61854 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -74,6 +74,7 @@ "/home/dev-user/workspace/src/components/plan/rrt", "/home/dev-user/workspace/src/components/plan/rrt_star", "/home/dev-user/workspace/src/components/plan/rrt_star_bidirectional", + "/home/dev-user/workspace/src/components/prediction", "/home/dev-user/workspace/src/components/search/kd_tree", "/home/dev-user/workspace/src/components/sensors", "/home/dev-user/workspace/src/components/sensors/gnss", @@ -119,6 +120,7 @@ "/home/dev-user/workspace/src/simulations/path_tracking/pure_pursuit_path_tracking", "/home/dev-user/workspace/src/simulations/path_tracking/rear_wheel_feedback_tracking", "/home/dev-user/workspace/src/simulations/path_tracking/stanley_path_tracking", + "/home/dev-user/workspace/src/simulations/perception/cv_ctrv_motion_prediction", "/home/dev-user/workspace/src/simulations/perception/lidar_obstacle_sensing", "/home/dev-user/workspace/src/simulations/perception/point_cloud_rectangle_fitting", "/home/dev-user/workspace/src/simulations/perception/point_cloud_search", diff --git a/doc/object_tracking/index.md b/doc/object_tracking/index.md index 7b5c4f50..f7db16e4 100644 --- a/doc/object_tracking/index.md +++ b/doc/object_tracking/index.md @@ -6,6 +6,10 @@ This chapter is planned. This page lists what it will cover and the simulations Track the detected objects over time and estimate how they move ([#116](https://github.com/ShisatoYano/AutonomousVehicleControlBeginnersGuide/issues/116)). +## Sections + +- 11.1 CV vs CTRV motion prediction: [`cv_ctrv_motion_prediction`](/src/simulations/perception/cv_ctrv_motion_prediction) + ## Before this chapter [Chapter 6](/doc/localization/index.md), [Chapter 9](/doc/perception/index.md). diff --git a/pyrightconfig.json b/pyrightconfig.json index 61087a74..8f9c6aa4 100644 --- a/pyrightconfig.json +++ b/pyrightconfig.json @@ -39,6 +39,7 @@ "src/components/plan/rrt", "src/components/plan/rrt_star", "src/components/plan/rrt_star_bidirectional", + "src/components/prediction", "src/components/search/kd_tree", "src/components/sensors", "src/components/sensors/gnss", @@ -84,6 +85,7 @@ "src/simulations/path_tracking/pure_pursuit_path_tracking", "src/simulations/path_tracking/rear_wheel_feedback_tracking", "src/simulations/path_tracking/stanley_path_tracking", + "src/simulations/perception/cv_ctrv_motion_prediction", "src/simulations/perception/lidar_obstacle_sensing", "src/simulations/perception/point_cloud_rectangle_fitting", "src/simulations/perception/point_cloud_search", diff --git a/src/components/prediction/motion_prediction.py b/src/components/prediction/motion_prediction.py new file mode 100644 index 00000000..fb42d650 --- /dev/null +++ b/src/components/prediction/motion_prediction.py @@ -0,0 +1,126 @@ +""" +motion_prediction.py + +Author: Lenin Mookiah +""" + +import numpy as np +import numpy.typing as npt + + +YAW_RATE_EPSILON_RPS = 1.0e-6 + + +def _prediction_times(horizon_s: float, step_s: float) -> npt.NDArray[np.float64]: + """Return evenly spaced times ending exactly at ``horizon_s``. + + Both arguments must be finite and positive, and ``horizon_s`` must be a + whole multiple of ``step_s`` within a relative tolerance of ``1e-9``. + The return shape is ``(N,)``, where ``N = horizon_s / step_s``, with values + ``step_s, 2 * step_s, ..., horizon_s``. + """ + + if not np.isfinite(horizon_s): + raise ValueError("horizon_s must be finite") + if not np.isfinite(step_s): + raise ValueError("step_s must be finite") + if horizon_s <= 0.0: + raise ValueError("horizon_s must be greater than 0") + if step_s <= 0.0: + raise ValueError("step_s must be greater than 0") + ratio = horizon_s / step_s + rounded_ratio = round(ratio) + if rounded_ratio < 1 or not np.isclose( + ratio, rounded_ratio, rtol=1.0e-9, atol=0.0 + ): + raise ValueError("step_s must divide horizon_s and be <= horizon_s") + + number_steps = int(rounded_ratio) + times_s = np.arange(1, number_steps + 1, dtype=np.float64) * step_s + times_s[-1] = horizon_s + return times_s + + +def predict_cv( + x_m: float, + y_m: float, + yaw_rad: float, + speed_mps: float, + horizon_s: float, + step_s: float, +) -> tuple[npt.NDArray[np.float64], npt.NDArray[np.float64]]: + """Predict positions with the constant velocity (CV) model. + + The model keeps speed and yaw constant: + + x(t) = x_m + speed_mps * cos(yaw_rad) * t + y(t) = y_m + speed_mps * sin(yaw_rad) * t + + The returned x and y arrays both have shape ``(N,)``, where + ``N = round(horizon_s / step_s)``. ``horizon_s`` must be a whole multiple + of ``step_s`` within a relative tolerance of ``1e-9``. The arrays contain + predictions at ``step_s, 2 * step_s, ..., horizon_s``, with the last time + set exactly to ``horizon_s``; the current position at ``t=0`` is not + included. Position is in meters, yaw in radians, speed in meters per + second, and time in seconds. + + Prediction uncertainty, including propagation of track covariance, is + outside the scope of this model. + Position, yaw, and speed are not checked; NaN gives NaN predictions. + """ + + times_s = _prediction_times(horizon_s, step_s) + predicted_x_m = x_m + speed_mps * np.cos(yaw_rad) * times_s + predicted_y_m = y_m + speed_mps * np.sin(yaw_rad) * times_s + return predicted_x_m, predicted_y_m + + +def predict_ctrv( + x_m: float, + y_m: float, + yaw_rad: float, + speed_mps: float, + yaw_rate_rps: float, + horizon_s: float, + step_s: float, +) -> tuple[npt.NDArray[np.float64], npt.NDArray[np.float64]]: + """Predict positions with the constant turn rate and velocity model. + + For a nonzero yaw rate ``omega = yaw_rate_rps``, the CTRV equations are: + + x(t) = x_m + (speed_mps / omega) + * (sin(yaw_rad + omega * t) - sin(yaw_rad)) + y(t) = y_m + (speed_mps / omega) + * (cos(yaw_rad) - cos(yaw_rad + omega * t)) + + Positive yaw rate means counter-clockwise turning. When + ``abs(yaw_rate_rps) < YAW_RATE_EPSILON_RPS``, the equations can lose + numerical precision through division by a very small number, so the + function falls back to the CV model. + + The returned x and y arrays both have shape ``(N,)``, where + ``N = round(horizon_s / step_s)``. ``horizon_s`` must be a whole multiple + of ``step_s`` within a relative tolerance of ``1e-9``. The arrays contain + predictions at ``step_s, 2 * step_s, ..., horizon_s``, with the last time + set exactly to ``horizon_s``; the current position at ``t=0`` is not + included. Position is in meters, yaw in radians, speed in meters per + second, yaw rate in radians per second, and time in seconds. + + Prediction uncertainty, including propagation of track covariance, is + outside the scope of this model. + Position, yaw, speed, and yaw rate are not checked; NaN gives NaN predictions. + """ + + if abs(yaw_rate_rps) < YAW_RATE_EPSILON_RPS: + return predict_cv(x_m, y_m, yaw_rad, speed_mps, horizon_s, step_s) + + times_s = _prediction_times(horizon_s, step_s) + future_yaw_rad = yaw_rad + yaw_rate_rps * times_s + turning_radius_m = speed_mps / yaw_rate_rps + predicted_x_m = x_m + turning_radius_m * ( + np.sin(future_yaw_rad) - np.sin(yaw_rad) + ) + predicted_y_m = y_m + turning_radius_m * ( + np.cos(yaw_rad) - np.cos(future_yaw_rad) + ) + return predicted_x_m, predicted_y_m diff --git a/src/simulations/perception/cv_ctrv_motion_prediction/cv_ctrv_motion_prediction.gif b/src/simulations/perception/cv_ctrv_motion_prediction/cv_ctrv_motion_prediction.gif new file mode 100644 index 00000000..33d999c5 Binary files /dev/null and b/src/simulations/perception/cv_ctrv_motion_prediction/cv_ctrv_motion_prediction.gif differ diff --git a/src/simulations/perception/cv_ctrv_motion_prediction/cv_ctrv_motion_prediction.py b/src/simulations/perception/cv_ctrv_motion_prediction/cv_ctrv_motion_prediction.py new file mode 100644 index 00000000..d8a9dd80 --- /dev/null +++ b/src/simulations/perception/cv_ctrv_motion_prediction/cv_ctrv_motion_prediction.py @@ -0,0 +1,296 @@ +""" +cv_ctrv_motion_prediction.py + +Title: CV vs CTRV Motion Prediction +Description: Compares constant velocity and constant turn rate predictions for moving obstacles +Author: Lenin Mookiah +""" + +# import path setting +from pathlib import Path +import sys +from typing import Any + +import numpy as np +import numpy.typing as npt +from matplotlib.lines import Line2D + +abs_dir_path = str(Path(__file__).absolute().parent) +relative_path = "/../../../components/" + +sys.path.append(abs_dir_path + relative_path + "obstacle") +sys.path.append(abs_dir_path + relative_path + "prediction") +sys.path.append(abs_dir_path + relative_path + "state") +sys.path.append(abs_dir_path + relative_path + "visualization") + + +# import component modules +from global_xy_visualizer import GlobalXYVisualizer +from min_max import MinMax +from motion_prediction import predict_ctrv, predict_cv +from obstacle import Obstacle +from state import State +from time_parameters import TimeParameters + + +PREDICTION_HORIZON_S = 3.0 +SIMULATION_STEP_S = 0.1 +STOP_TURN_TARGET_YAW_RAD = np.pi / 2.0 +# Accounts for floating-point sums of yaw_rate * dt. +YAW_TOLERANCE_RAD = 1.0e-9 +ERROR_START_TIME_S = 3.5 +ERROR_HORIZONS_S = (1.0, 2.0, 3.0) +OBSTACLE_NAMES = ("Straight", "Constant turn", "Stops turning") +OBSTACLE_COLORS = ("tab:blue", "tab:orange", "tab:green") +STOP_TURNING_OBSTACLE_INDEX = OBSTACLE_NAMES.index("Stops turning") + +# flag to show plot figure +# when executed as unit test, this flag is set as false +show_plot = True + + +def create_obstacles() -> list[Obstacle]: + """Create the straight, turning, and stop-turning obstacles.""" + + return [ + Obstacle( + State( + x_m=-25.0, + y_m=22.0, + yaw_rad=0.0, + speed_mps=3.0, + color=OBSTACLE_COLORS[0], + ), + width_m=1.0, + ), + Obstacle( + State( + x_m=-18.0, + y_m=-14.0, + yaw_rad=0.0, + speed_mps=3.0, + color=OBSTACLE_COLORS[1], + ), + yaw_rate_rps=0.45, + width_m=1.0, + ), + Obstacle( + State( + x_m=10.0, + y_m=-16.0, + yaw_rad=0.0, + speed_mps=3.0, + color=OBSTACLE_COLORS[2], + ), + yaw_rate_rps=np.pi / 8.0, + width_m=1.0, + ), + ] + + +class MotionPredictionScene: + """Draw three obstacles and predictions made from their true states.""" + + def __init__(self, obstacles: list[Obstacle]) -> None: + """Initialize with a list of moving ``Obstacle`` objects.""" + + self.obstacles = obstacles + self.names = OBSTACLE_NAMES + self.colors = OBSTACLE_COLORS + + def update(self, time_s: float) -> None: + """Advance every obstacle by ``time_s`` seconds.""" + + for obstacle in self.obstacles: + obstacle.update(time_s) + + # Stop the left turn at its target heading. Using yaw rather than an + # elapsed-time counter keeps the rule correct when frame 0 is rendered + # twice by the animation machinery. + stop_turning_obstacle = self.obstacles[STOP_TURNING_OBSTACLE_INDEX] + if ( + stop_turning_obstacle.state.get_yaw_rad() + >= STOP_TURN_TARGET_YAW_RAD - YAW_TOLERANCE_RAD + ): + stop_turning_obstacle.yaw_rate_rps = 0.0 + + def draw(self, axes: Any, elems: list[Any]) -> None: + """Draw obstacles and their 3-second CV and CTRV predictions.""" + + for name, color, obstacle in zip(self.names, self.colors, self.obstacles): + obstacle.draw(axes, elems) + state = obstacle.state + x_m = state.get_x_m() + y_m = state.get_y_m() + yaw_rad = state.get_yaw_rad() + speed_mps = state.get_speed_mps() + cv_x_m, cv_y_m = predict_cv( + x_m, + y_m, + yaw_rad, + speed_mps, + PREDICTION_HORIZON_S, + SIMULATION_STEP_S, + ) + ctrv_x_m, ctrv_y_m = predict_ctrv( + x_m, + y_m, + yaw_rad, + speed_mps, + obstacle.yaw_rate_rps, + PREDICTION_HORIZON_S, + SIMULATION_STEP_S, + ) + + true_path, = axes.plot( + state.x_history, + state.y_history, + color=color, + linewidth=1.0, + alpha=0.35, + ) + path_start_x_m = np.array([x_m]) + path_start_y_m = np.array([y_m]) + cv_line, = axes.plot( + np.concatenate((path_start_x_m, cv_x_m)), + np.concatenate((path_start_y_m, cv_y_m)), + color=color, + linestyle="--", + zorder=3, + ) + ctrv_line, = axes.plot( + np.concatenate((path_start_x_m, ctrv_x_m)), + np.concatenate((path_start_y_m, ctrv_y_m)), + color=color, + linestyle="-", + zorder=2, + ) + name_label = axes.text( + x_m, + y_m + 3.0, + name, + color=color, + fontsize=8, + ha="center", + ) + elems.extend((true_path, cv_line, ctrv_line, name_label)) + + legend_handles = ( + Line2D([0], [0], color="0.35", linestyle="--", label="CV"), + Line2D([0], [0], color="0.35", linestyle="-", label="CTRV"), + Line2D([0], [0], color="0.35", alpha=0.5, label="True path"), + ) + legend = axes.legend(handles=legend_handles, loc="upper right", fontsize=8) + elems.append(legend) + + +def compute_prediction_errors() -> dict[str, dict[str, dict[float, float]]]: + """Return position errors in meters for predictions made at 3.5 seconds. + + The nested result is indexed by obstacle name, model name, and prediction + horizon in seconds. The true path uses State's discrete 0.1-second step, + which holds heading constant during each step. CTRV therefore has a small + step-size error even for the constant-turn obstacle. The stop-turning + obstacle reaches its target yaw at about 4 seconds, inside this prediction + horizon. + """ + + scene = MotionPredictionScene(create_obstacles()) + for _ in range(round(ERROR_START_TIME_S / SIMULATION_STEP_S)): + scene.update(SIMULATION_STEP_S) + + predictions: dict[ + str, + dict[ + str, + tuple[npt.NDArray[np.float64], npt.NDArray[np.float64]], + ], + ] = {} + for name, obstacle in zip(scene.names, scene.obstacles): + state = obstacle.state + predictions[name] = { + "CV": predict_cv( + state.get_x_m(), + state.get_y_m(), + state.get_yaw_rad(), + state.get_speed_mps(), + PREDICTION_HORIZON_S, + SIMULATION_STEP_S, + ), + "CTRV": predict_ctrv( + state.get_x_m(), + state.get_y_m(), + state.get_yaw_rad(), + state.get_speed_mps(), + obstacle.yaw_rate_rps, + PREDICTION_HORIZON_S, + SIMULATION_STEP_S, + ), + } + + errors: dict[str, dict[str, dict[float, float]]] = { + name: {"CV": {}, "CTRV": {}} for name in scene.names + } + horizon_steps = { + round(horizon_s / SIMULATION_STEP_S): horizon_s + for horizon_s in ERROR_HORIZONS_S + } + for future_step in range(1, round(PREDICTION_HORIZON_S / SIMULATION_STEP_S) + 1): + scene.update(SIMULATION_STEP_S) + if future_step not in horizon_steps: + continue + + horizon_s = horizon_steps[future_step] + prediction_index = future_step - 1 + for name, obstacle in zip(scene.names, scene.obstacles): + for model_name in ("CV", "CTRV"): + predicted_x_m, predicted_y_m = predictions[name][model_name] + errors[name][model_name][horizon_s] = float( + np.hypot( + predicted_x_m[prediction_index] + - obstacle.state.get_x_m(), + predicted_y_m[prediction_index] + - obstacle.state.get_y_m(), + ) + ) + + return errors + + +def main() -> tuple[list[Obstacle], dict[str, dict[str, dict[float, float]]]]: + """Run the motion prediction animation and return its obstacles and errors.""" + + x_lim, y_lim = MinMax(-30, 30), MinMax(-20, 30) + gif_path = str(Path(__file__).absolute().with_suffix(".gif")) + time_parameters = TimeParameters(span_sec=8.0, interval_sec=SIMULATION_STEP_S) + visualizer = GlobalXYVisualizer( + x_lim, + y_lim, + time_parameters, + show_zoom=False, + gif_name=gif_path, + ) + + scene = MotionPredictionScene(create_obstacles()) + visualizer.add_object(scene) + + if not show_plot: + visualizer.not_show_plot() + + visualizer.draw() + return scene.obstacles, compute_prediction_errors() + + +if __name__ == "__main__": + _, prediction_errors = main() + print("\nPrediction errors from t0 = 3.5 s (m)") + print(f"{'Obstacle':<15} {'Model':<5} {'1 s':>8} {'2 s':>8} {'3 s':>8}") + for obstacle_name in OBSTACLE_NAMES: + for model in ("CV", "CTRV"): + model_errors = prediction_errors[obstacle_name][model] + print( + f"{obstacle_name:<15} {model:<5}" + f" {model_errors[1.0]:8.4f}" + f" {model_errors[2.0]:8.4f}" + f" {model_errors[3.0]:8.4f}" + ) diff --git a/test/test_cv_ctrv_motion_prediction.py b/test/test_cv_ctrv_motion_prediction.py new file mode 100644 index 00000000..3d329b0a --- /dev/null +++ b/test/test_cv_ctrv_motion_prediction.py @@ -0,0 +1,38 @@ +""" +Test of CV and CTRV motion prediction simulation + +Author: Lenin Mookiah +""" + +from pathlib import Path +import sys + +sys.path.append( + str(Path(__file__).absolute().parent) + + "/../src/simulations/perception/cv_ctrv_motion_prediction" +) +import cv_ctrv_motion_prediction + + +def test_simulation_reports_expected_model_winners_without_plot() -> None: + cv_ctrv_motion_prediction.show_plot = False + + obstacles, errors = cv_ctrv_motion_prediction.main() + + assert len(obstacles) == 3 + assert errors["Straight"]["CV"][3.0] < 1.0e-10 + assert errors["Straight"]["CTRV"][3.0] < 1.0e-10 + assert ( + errors["Constant turn"]["CTRV"][3.0] + < errors["Constant turn"]["CV"][3.0] + ) + # State holds heading during each 0.1 s step, causing about 0.19 m error at 3 s. + assert errors["Constant turn"]["CTRV"][3.0] < 0.3 + assert ( + errors["Stops turning"]["CTRV"][1.0] + < errors["Stops turning"]["CV"][1.0] + ) + assert ( + errors["Stops turning"]["CV"][3.0] + < errors["Stops turning"]["CTRV"][3.0] + ) diff --git a/test/test_motion_prediction.py b/test/test_motion_prediction.py new file mode 100644 index 00000000..1f61c744 --- /dev/null +++ b/test/test_motion_prediction.py @@ -0,0 +1,175 @@ +""" +Unit tests of CV and CTRV motion prediction + +Author: Lenin Mookiah +""" + +from pathlib import Path +import sys + +import numpy as np +import pytest + +sys.path.append( + str(Path(__file__).absolute().parent) + "/../src/components/prediction" +) +from motion_prediction import predict_ctrv, predict_cv + + +def test_cv_values_match_hand_calculation() -> None: + predicted_x_m, predicted_y_m = predict_cv( + x_m=1.0, + y_m=2.0, + yaw_rad=np.pi / 2.0, + speed_mps=3.0, + horizon_s=2.0, + step_s=1.0, + ) + + assert np.allclose(predicted_x_m, [1.0, 1.0]) + assert np.allclose(predicted_y_m, [5.0, 8.0]) + + +def test_ctrv_with_zero_yaw_rate_equals_cv() -> None: + cv_x_m, cv_y_m = predict_cv(1.0, -2.0, 0.4, 5.0, 3.0, 0.5) + ctrv_x_m, ctrv_y_m = predict_ctrv(1.0, -2.0, 0.4, 5.0, 0.0, 3.0, 0.5) + + assert np.array_equal(ctrv_x_m, cv_x_m) + assert np.array_equal(ctrv_y_m, cv_y_m) + + +def test_ctrv_with_nonzero_yaw_rate_stays_on_circle() -> None: + x_m = 2.0 + y_m = -1.0 + yaw_rad = 0.3 + speed_mps = 6.0 + yaw_rate_rps = 0.4 + predicted_x_m, predicted_y_m = predict_ctrv( + x_m, + y_m, + yaw_rad, + speed_mps, + yaw_rate_rps, + 4.0, + 0.2, + ) + radius_m = speed_mps / yaw_rate_rps + center_x_m = x_m - radius_m * np.sin(yaw_rad) + center_y_m = y_m + radius_m * np.cos(yaw_rad) + + distances_m = np.hypot( + predicted_x_m - center_x_m, + predicted_y_m - center_y_m, + ) + assert np.allclose(distances_m, radius_m) + + +def test_ctrv_with_tiny_yaw_rate_matches_cv() -> None: + cv_x_m, cv_y_m = predict_cv(3.0, 4.0, -0.2, 7.0, 3.0, 0.1) + ctrv_x_m, ctrv_y_m = predict_ctrv( + 3.0, + 4.0, + -0.2, + 7.0, + 1.0e-9, + 3.0, + 0.1, + ) + + assert np.allclose(ctrv_x_m, cv_x_m) + assert np.allclose(ctrv_y_m, cv_y_m) + + +@pytest.mark.parametrize( + ("horizon_s", "step_s"), + [ + (0.0, 0.1), + (-1.0, 0.1), + (1.0, 0.0), + (1.0, -0.1), + (1.0, 2.0), + ], +) +def test_invalid_time_arguments_raise_value_error( + horizon_s: float, + step_s: float, +) -> None: + with pytest.raises(ValueError): + predict_cv(0.0, 0.0, 0.0, 1.0, horizon_s, step_s) + with pytest.raises(ValueError): + predict_ctrv(0.0, 0.0, 0.0, 1.0, 0.2, horizon_s, step_s) + + +@pytest.mark.parametrize("step_s", [0.4, 0.6]) +def test_non_multiple_horizon_and_step_raise_value_error(step_s: float) -> None: + with pytest.raises(ValueError, match="must divide horizon_s"): + predict_cv(0.0, 0.0, 0.0, 1.0, 1.0, step_s) + with pytest.raises(ValueError, match="must divide horizon_s"): + predict_ctrv(0.0, 0.0, 0.0, 1.0, 0.2, 1.0, step_s) + + +@pytest.mark.parametrize( + ("horizon_s", "step_s"), + [ + (np.inf, 0.1), + (-np.inf, 0.1), + (np.nan, 0.1), + (1.0, np.inf), + (1.0, -np.inf), + (1.0, np.nan), + ], +) +def test_non_finite_time_arguments_raise_value_error( + horizon_s: float, + step_s: float, +) -> None: + with pytest.raises(ValueError, match="must be finite"): + predict_cv(0.0, 0.0, 0.0, 1.0, horizon_s, step_s) + with pytest.raises(ValueError, match="must be finite"): + predict_ctrv(0.0, 0.0, 0.0, 1.0, 0.2, horizon_s, step_s) + + +def test_cv_uses_thirty_steps_and_ends_at_three_seconds() -> None: + predicted_x_m, predicted_y_m = predict_cv( + x_m=0.0, + y_m=-3.0, + yaw_rad=0.0, + speed_mps=1.0, + horizon_s=3.0, + step_s=0.1, + ) + + assert predicted_x_m.shape == (30,) + assert predicted_y_m.shape == (30,) + assert predicted_x_m[-1] == 3.0 + + +def test_step_with_rounding_above_horizon_returns_one_prediction() -> None: + predicted_x_m, predicted_y_m = predict_cv( + x_m=0.0, + y_m=0.0, + yaw_rad=0.0, + speed_mps=1.0, + horizon_s=0.3, + step_s=0.1 + 0.2, + ) + + assert predicted_x_m.shape == (1,) + assert predicted_y_m.shape == (1,) + + +def test_output_times_exclude_current_position() -> None: + predicted_x_m, predicted_y_m = predict_cv( + x_m=10.0, + y_m=-3.0, + yaw_rad=0.0, + speed_mps=2.0, + horizon_s=2.0, + step_s=0.5, + ) + + assert predicted_x_m.shape == (4,) + assert predicted_y_m.shape == (4,) + assert predicted_x_m[0] == pytest.approx(11.0) + assert predicted_x_m[-1] == pytest.approx(14.0) + assert np.all(predicted_y_m == -3.0)