Question: Vehicle Dynamics model [ x v ] = [ 0 1 0 0 ] [ x v ] + [ 0 a t r u

Vehicle Dynamics model
[xv]=[0100][xv]+[0atrue(t)]+[0(t)]
Acceleration measurement model
ameas(t)=atrue+b+a(t)
Measurement model
Range from the ith station
ri(k)=(xi-x)2+hi22+
u(k)
where xi,hi are the position and the height of the ith radar. The position and altitude of each radar are provided in the table below
The truck accelerates from 0ms2 to 0.05ms2 in first 100s, remains at 0.05ms2 acceleration for next 100s and deccelerates to 0ms2 in the next
Simulate the measured acceleration and the measured ranges based on the above specifications for 300s at every 1 second. Develop an EKF estimator to
estimate the position, velocity and the accelerometer bias. Show the performance of the implemented EKF using proper figures with error, standard
deviations and residuals.100s
"""_summary_
This module contains the classes used to implement various estimation algorithms.
"""
import numpy as np
from scipy.linalg import expm, inv
from scipy.integrate import odeint
class state:
"""_summary_
This class is used to store the state of the system at a given time.
x - state vector
P - state covariance matrix
t - time
z - predicted observation
res - residual
innovation_cov - innovation covariance matrix
"""
def __init__(self,**kwargs):
if len(kwargs)==0:
self.x = None
self.P = None
self.t = None
self.z = None
elif len(kwargs)==3:
self.x = kwargs['x']
self.P = kwargs['P']
self.t = kwargs['t']
else:
self.x = kwargs['x']
self.P = kwargs['P']
self.t = kwargs['t']
self.z = kwargs['z']
self.res = kwargs['res']
self.innovation_cov = kwargs['innovation_cov']
class kalman_filter:
"""_summary_
This class is used to implement the Kalman filter algorithm.
model - model of the system
Q - process noise covariance matrix
R - measurement noise covariance matrix
state0- initial state of the system
"""
def __init__(self, model, Q, R, state0, dT):
"""_summary_
Args:
model (_structure_):
model.dynamics (_function_): _system model_, dynamics needs to be compatible with odeint
model.Phi (_function_): _system jacobian_
model.h (_function_): _observation model_
model.H (_function_): _observation jacobian_
Q (_ndarray_): _process noise covariance_
R (_ndarray_): _measurement noise covariance_
state0(_state_): _Initial state information_
dT (_scalar_): _time step_
"""
self.model = model
self.Q = Q
self.R = R
self.state_post = state0
self.state_priori = state()
self.dt = dT
def KF_prediction(self):
"""_summary_
Kalman filter prediction step
"""
x = self.state_post.x
P = self.state_post.P
t = self.state_post.t
Phi = self.model.Phi
x_priori = odeint(self.model.dynamics, x,[t, t+ self.dt])[-1,:] #state propagation
P_priori = Phi.dot(P).dot(Phi.T)+ self.Q #covariance propagation
z_priori = self.model.h(x_priori) #observation prediction
self.state_priori.x = x_priori
self.state_priori.P = P_priori
self.state_priori.z = z_priori
self.state_priori.t = t+1
return
def KF_correction(self, observation):
"""_summary_
Args:
observation (_vector_): _Observation_
"""
x_priori = self.state_priori.x
P_priori = self.state_priori.P
z_priori = self.state_priori.z
H = self.model.H
residue = observation - z_priori
R = self.R
if len(R.shape)>2:
K = P_priori.dot(H.T).dot(inv(H.dot(P_priori).dot(H.T)+R))
self.state_post.x = x_priori + K.dot(residue)
self.state_post.P =(np.identity(2)-K.dot(H)).dot(P_priori).dot((np.identity(2)-K.dot(H)).T)\
+ K.dot(R).dot(K.T)
else:
K = P_priori.dot(H.T)*((H.dot(P_priori).dot(H.T)+R)**-1)
K = K.reshape(K.shape[0],1)
#pdb.set_trace()
self.state_post.x = x_priori +(K*residue).reshape(len(x_priori)) #state update
self.state_post.P =(np.identity(2)-K.do

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!