estimator_kalman
Kalman filter estimators.
KalmanFilter(dt, model='so_rpy', config='cf2x_L250', filter_type='UKF', estimate_rotor_vel=False, estimate_dist_f=False, estimate_dist_t=False, initial_obs=None, batch_shape=(), jit=False)
¶
Bases: Estimator
Extended or unscented Kalman Filter class that wraps the filterPY toolbox.
Initialize basic parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dt
|
float
|
Time step between callings. |
required |
model
|
str
|
The name of the model that is to be used. |
'so_rpy'
|
config
|
str
|
The setup configuration of the drone. |
'cf2x_L250'
|
filter_type
|
Literal['EKF', 'UKF']
|
The type of Kalman filter, "EKF" or "UKF". The EKF uses the Jacobian of the dynamics at hover. |
'UKF'
|
estimate_rotor_vel
|
bool
|
If the rotor speeds should be estimated, defaults to False. |
False
|
estimate_dist_f
|
bool
|
If the disturbance forces should be estimated, defaults to False. |
False
|
estimate_dist_t
|
bool
|
If the disturbance torques should be estimated, defaults to False. |
False
|
initial_obs
|
dict[str, Array] | None
|
Optional, the initial observation of the environment's state. See the environment's observation space for details. |
None
|
batch_shape
|
tuple[int, ...]
|
The batch dimensions, e.g., (n_drones,). All arrays have leading batch dimensions. |
()
|
jit
|
bool
|
If the filter should be jit compiled with jax. |
False
|
Source code in drone_estimators/estimator_kalman.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | |
correct(pos, quat, command=None, mask=None)
¶
Correct the state with the latest observation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pos
|
Array
|
Latest observation of the position. |
required |
quat
|
Array
|
Latest observation of the quaternion. |
required |
command
|
Array | None
|
Optional, latest input to the system. |
None
|
mask
|
Array | None
|
Optional, only batch elements where mask is True are corrected. |
None
|
Returns:
| Type | Description |
|---|---|
EstimatorData
|
New state estimate. |
Source code in drone_estimators/estimator_kalman.py
create_covariance_matrices(dim_x, dim_z, varQ_pos, varQ_quat, varQ_rotor_vel, varR_pos, varR_quat, dt, varQ_dist_f=1e-08, varQ_dist_t=1e-13)
¶
Creates sophisticated covariance matrices based on a paper.
We assume that the linear elements (pos, vel) are correlated and the rotational elements (quat, ang_vel) are. For more information consult the filterpy library.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dim_x
|
int
|
The dimension of the state. |
required |
dim_z
|
int
|
The dimension of the measurement. |
required |
varQ_pos
|
float
|
The variance of the position and velocity process noise. |
required |
varQ_quat
|
float
|
The variance of the quaternion and angular velocity process noise. |
required |
varQ_rotor_vel
|
float
|
The variance of the rotor velocity process noise, if estimated. |
required |
varR_pos
|
float
|
The variance of the position measurement noise. |
required |
varR_quat
|
float
|
The variance of the quaternion measurement noise. |
required |
dt
|
float
|
The time step. |
required |
varQ_dist_f
|
float
|
The variance of the disturbance force process noise, if estimated. |
1e-08
|
varQ_dist_t
|
float
|
The variance of the disturbance torque process noise, if estimated. |
1e-13
|
Returns:
| Type | Description |
|---|---|
Array
|
The process noise covariance Q of shape (dim_x, dim_x) and the measurement noise |
Array
|
covariance R of shape (dim_z, dim_z). |
Source code in drone_estimators/estimator_kalman.py
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 | |
predict(dt, command=None)
¶
Predict the state by one time step. Only batch elements with a positive dt are updated.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dt
|
float
|
Time step size. |
required |
command
|
Array | None
|
Optional, latest input to the system. |
None
|
Returns:
| Type | Description |
|---|---|
EstimatorData
|
New state prediction. |
Source code in drone_estimators/estimator_kalman.py
set_state(pos, quat)
¶
Sets pos and quat of the state to the given values and reduces the covariance value.
With aggressive Q and R values, this needs to be called in the beginning. Otherwise the estimator might fail.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pos
|
Array
|
The position the state is set to. |
required |
quat
|
Array
|
The quaternion the state is set to. |
required |
Source code in drone_estimators/estimator_kalman.py
step(pos, quat, dt, command=None)
¶
Steps the filter by one. Doing one prediction and correction step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pos
|
Array
|
Latest observation of the position. |
required |
quat
|
Array
|
Latest observation of the quaternion. |
required |
dt
|
float
|
Time step size. Only batch elements with a positive dt are updated. |
required |
command
|
Array | None
|
Optional, latest input to the system. |
None
|
Returns:
| Type | Description |
|---|---|
EstimatorData
|
New state estimate. |