� �g�Uc @` s� d Z d d l m Z m Z m Z m Z d d l Z d d l j Z d d l m Z m Z m Z m Z d d l m Z m Z m Z m Z d e f d � � YZ d S( u4 Copyright 2015 Roger R Labbe Jr. FilterPy library. http://github.com/rlabbe/filterpy Documentation at: https://filterpy.readthedocs.org Supporting book at: https://github.com/rlabbe/Kalman-and-Bayesian-Filters-in-Python This is licensed under an MIT license. See the readme.MD file for more information. i ( t absolute_importt divisiont print_functiont unicode_literalsN( t dott zerost eyet isscalar( t settert setter_1dt setter_scalart dot3t KalmanFilterc B` sj e Z d Z d d � Z d d d � Z d � Z d d � Z d e d � Z d d � Z d d � Z d � Z d � Z e d � � Z e j d � � Z e d � � Z e j d � � Z e d � � Z e j d � � Z e d � � Z e j d � � Z e d � � Z e j d � � Z e d � � Z e j d � � Z e d � � Z e d � � Z e d � � Z RS( ui Implements a Kalman filter. You are responsible for setting the various state variables to reasonable values; the defaults will not give you a functional filter. You will have to set the following attributes after constructing this object for the filter to perform properly. Please note that there are various checks in place to ensure that you have made everything the 'correct' size. However, it is possible to provide incorrectly sized arrays such that the linear algebra can not perform an operation. It can also fail silently - you can end up with matrices of a size that allows the linear algebra to work, but are the wrong shape for the problem you are trying to solve. **Attributes** x : numpy.array(dim_x, 1) state estimate vector P : numpy.array(dim_x, dim_x) covariance estimate matrix R : numpy.array(dim_z, dim_z) measurement noise matrix Q : numpy.array(dim_x, dim_x) process noise matrix F : numpy.array() State Transition matrix H : numpy.array(dim_x, dim_x) You may read the following attributes. **Readable Attributes** y : numpy.array Residual of the update step. K : numpy.array(dim_x, dim_z) Kalman gain of the update step S : numpy.array Systen uncertaintly projected to measurement space i c C` s� | d k s t � | d k s$ t � | d k s6 t � | | _ | | _ | | _ t | d f � | _ t | � | _ t | � | _ d | _ d | _ d | _ t | � | _ d | _ d | _ t | d f � | _ d | _ t j | � | _ d S( u" Create a Kalman filter. You are responsible for setting the various state variables to reasonable values; the defaults below will not give you a functional filter. **Parameters** dim_x : int Number of state variables for the Kalman filter. For example, if you are tracking the position and velocity of an object in two dimensions, dim_x would be 4. This is used to set the default size of P, Q, and u dim_z : int Number of of measurement inputs. For example, if the sensor provides you with position in (x,y), dim_z would be 2. dim_u : int (optional) size of the control input, if it is being used. Default value of 0 indicates it is not used. i i g �?N( t AssertionErrort dim_xt dim_zt dim_uR t _xR t _Pt _Qt _Bt _Ft Ht Rt _alpha_sqt _Kt _yt _St npt _I( t selfR R R ( ( s"