This project simulates the trajectory of a ball launched with a given speed and angle while incorporating the effects of gravity and bounce. The simulation also applies a Kalman Filter to estimate the ball's position from noisy observations, providing a comparison between the true trajectory and the estimated trajectory.
- Trajectory Simulation: Models the motion of a ball under the influence of gravity and includes bounce effects when the ball hits the ground.
- Kalman Filter: Implements a Kalman Filter to estimate the ball's position based on noisy measurements.
- Noise Handling: Adds Gaussian noise to the observations to simulate measurement inaccuracies.
- Performance Metrics: Calculates the Mean Squared Error (MSE) and Root Mean Squared Error (RMSE) to evaluate the Kalman Filter's performance.
- Visualization: Plots the true trajectory, noisy observations, and Kalman Filter estimates for visual comparison.
dt
: Time interval for the simulation (default: 0.1 seconds).total_time
: Total duration of the simulation (default: 10 seconds).observation_noise_cov
: Covariance matrix for observation noise.launch_params
: Dictionary containing launch position, speed, and angle.init_state_mean
: Initial state mean for the Kalman Filter, including position and velocity.init_state_cov
: Covariance matrix for the initial state estimate.transition_cov
: Process noise covariance matrix.
- Initialization: The simulation starts by setting the initial position and velocity of the ball and initializing the Kalman Filter with the given parameters.
- Simulation Loop:
- The ball's position and velocity are updated at each time step.
- If the ball hits the ground, its position is reflected, and its vertical velocity is reversed and reduced to simulate energy loss on impact.
- Noisy observations are generated based on the current position.
- The Kalman Filter uses these observations to estimate the ball's position.
- Performance Evaluation: The difference between the true and estimated positions is used to calculate MSE and RMSE, providing a quantitative measure of the filter's accuracy.
- Visualization: The results are plotted, showing the true trajectory, noisy observations, and Kalman Filter estimates.
The plot generated by this simulation illustrates:
- True Ball Trajectory: The actual path of the ball under the influence of gravity and bounce.
- Noisy Observations: The measurements with added noise, simulating real-world sensor inaccuracies.
- Kalman Filter Estimate: The estimated trajectory using the Kalman Filter, showing how well the filter tracks the true path.
The script also measures and prints the total execution time, providing insights into the computational efficiency of the simulation.