@@ -91,6 +91,29 @@ def observation_model(x):
9191
9292
9393def generate_sigma_points (xEst , PEst , gamma ):
94+ """
95+ Generate sigma points for UKF.
96+
97+ Sigma points are deterministically sampled points used to capture
98+ the mean and covariance of the state distribution.
99+
100+ Parameters
101+ ----------
102+ xEst : numpy.ndarray
103+ Current state estimate (n x 1)
104+ PEst : numpy.ndarray
105+ Current state covariance estimate (n x n)
106+ gamma : float
107+ Scaling parameter sqrt(n + lambda)
108+
109+ Returns
110+ -------
111+ sigma : numpy.ndarray
112+ Sigma points (n x 2n+1)
113+ sigma[:, 0] = xEst
114+ sigma[:, 1:n+1] = xEst + gamma * sqrt(P)
115+ sigma[:, n+1:2n+1] = xEst - gamma * sqrt(P)
116+ """
94117 sigma = xEst
95118 Psqrt = scipy .linalg .sqrtm (PEst )
96119 n = len (xEst [:, 0 ])
@@ -149,6 +172,35 @@ def calc_pxz(sigma, x, z_sigma, zb, wc):
149172
150173
151174def ukf_estimation (xEst , PEst , z , u , wm , wc , gamma ):
175+ """
176+ Unscented Kalman Filter estimation.
177+
178+ Performs one iteration of UKF state estimation using the unscented transform.
179+
180+ Parameters
181+ ----------
182+ xEst : numpy.ndarray
183+ Current state estimate [x, y, yaw, v]^T (4 x 1)
184+ PEst : numpy.ndarray
185+ Current state covariance estimate (4 x 4)
186+ z : numpy.ndarray
187+ Observation vector [x_obs, y_obs]^T (2 x 1)
188+ u : numpy.ndarray
189+ Control input [velocity, yaw_rate]^T (2 x 1)
190+ wm : numpy.ndarray
191+ Weights for calculating mean (1 x 2n+1)
192+ wc : numpy.ndarray
193+ Weights for calculating covariance (1 x 2n+1)
194+ gamma : float
195+ Sigma point scaling parameter sqrt(n + lambda)
196+
197+ Returns
198+ -------
199+ xEst : numpy.ndarray
200+ Updated state estimate (4 x 1)
201+ PEst : numpy.ndarray
202+ Updated state covariance estimate (4 x 4)
203+ """
152204 # Predict
153205 sigma = generate_sigma_points (xEst , PEst , gamma )
154206 sigma = predict_sigma_motion (sigma , u )
@@ -194,6 +246,31 @@ def plot_covariance_ellipse(xEst, PEst): # pragma: no cover
194246
195247
196248def setup_ukf (nx ):
249+ """
250+ Setup UKF parameters and weights.
251+
252+ Calculates the weights for mean and covariance computation,
253+ and the scaling parameter gamma for sigma point generation.
254+
255+ Parameters
256+ ----------
257+ nx : int
258+ Dimension of the state vector
259+
260+ Returns
261+ -------
262+ wm : numpy.ndarray
263+ Weights for calculating mean (1 x 2n+1)
264+ wm[0] = lambda / (n + lambda)
265+ wm[i] = 1 / (2(n + lambda)) for i > 0
266+ wc : numpy.ndarray
267+ Weights for calculating covariance (1 x 2n+1)
268+ wc[0] = lambda / (n + lambda) + (1 - alpha^2 + beta)
269+ wc[i] = 1 / (2(n + lambda)) for i > 0
270+ gamma : float
271+ Sigma point scaling parameter sqrt(n + lambda)
272+ where lambda = alpha^2 * (n + kappa) - n
273+ """
197274 lamb = ALPHA ** 2 * (nx + KAPPA ) - nx
198275 # calculate weights
199276 wm = [lamb / (lamb + nx )]
0 commit comments