@@ -136,6 +136,12 @@ def residual(a, b):
136
136
y += 2*np.pi
137
137
return y
138
138
139
+ state_add: callable (x, y), optional, default np.add
140
+ Function that subtracts two state vectors, returning a new
141
+ state vector. Used during update to compute `x + K@y`
142
+ You will have to supply this if your state variable does not
143
+ suport addition, such as it contains angles.
144
+
139
145
Attributes
140
146
----------
141
147
@@ -278,7 +284,8 @@ def residual(a, b):
278
284
def __init__ (self , dim_x , dim_z , dt , hx , fx , points ,
279
285
sqrt_fn = None , x_mean_fn = None , z_mean_fn = None ,
280
286
residual_x = None ,
281
- residual_z = None ):
287
+ residual_z = None ,
288
+ state_add = None ):
282
289
"""
283
290
Create a Kalman filter. You are responsible for setting the
284
291
various state variables to reasonable values; the defaults below will
@@ -327,6 +334,11 @@ def __init__(self, dim_x, dim_z, dt, hx, fx, points,
327
334
else :
328
335
self .residual_z = residual_z
329
336
337
+ if state_add is None :
338
+ self .state_add = np .add
339
+ else :
340
+ self .state_add = state_add
341
+
330
342
# sigma points transformed through f(x) and h(x)
331
343
# variables for efficiency so we don't recreate every update
332
344
@@ -465,7 +477,7 @@ def update(self, z, R=None, UT=None, hx=None, **hx_args):
465
477
self .y = self .residual_z (z , zp ) # residual
466
478
467
479
# update Gaussian state estimate (x, P)
468
- self .x = self .x + dot (self .K , self .y )
480
+ self .x = self .state_add ( self . x , dot (self .K , self .y ) )
469
481
self .P = self .P - dot (self .K , dot (self .S , self .K .T ))
470
482
471
483
# save measurement and posterior state
0 commit comments