Академический Документы
Профессиональный Документы
Культура Документы
(MTS-315)
Category NS NS NS ASC
Name Talha Zubair Taaha Jawad Noman Saad
Khan Bashir Salahuddin
Reg No. 199253
Degree 38A
Date 12-06-2019
1. Introduction
In this assignment, the task was to estimate values for the roll angle and
pitch angle of a quadrotor UAV, given the time steps, the gyroscope outputs (the
angular velocities about the x,y, and z axes respectively), the accelerometer outputs
(accelerations in the x,y, and z axes), and the true values of the roll and pitch
angles. In this assignment, this data was used to estimate the roll and pitch angles,
using an Extended Kalman Filter, and the estimated and true values were plotted to
visualize the accuracy of the Kalman estimates.
2. Procedure
The following steps were followed in determining the Kalman estimates:
1. The State Space variables (in this case: the roll angle (phi), and the pitch
angle(theta)) were defined as a variable x. This vector was given an initial
value of 0.
2. The Eular angle rate variables for the gyroscope outputs (phi dot and theta
dot) were declared and initialized as zero.
3. The required matrices, i.e. Q , R ,P_initial , were initialized using values
given in the data set.
4. The required data was extracted from the given table and assigned
appropriate vector variables.
5. Then, the main part of the filter was written inside a for loop, since the EKF
is an iterative process.
6. The operation of the EKF can be split into two parts. The Prediction step,
and the Correction step.
7. The Prediction Step:
a. Phi dot and Theta dot were calculated using the given transfer
function, which converts the gyroscope outputs (p, q ,r) into Euler
angle rates. This was computed using the initial values for the state
variables.
b. Then, the values of the state variables (phi and theta) were predicted
using the following equations:
𝜑𝑘 − 𝜑𝑘−1
𝜑̇ =
∆𝑡
The equation above was re arranged for 𝜑𝑘 , i.e. the value of the roll
angle in the next time step. 𝜑𝑘 was then determined as all the other
values were known (using the initial values of 𝜑𝑘−1 . A similar
procedure was repeated for 𝜃𝑘
c. Then, the state transformation matrix, F, was determined by taking the
Jacobian of the transfer function of the gyroscope. This was adjusted
with the time step, and the identity matrix.
d. The error covariance matrix was then calculated
8.
a. The measurement model used for the accelerometer was:
ℎ(𝑥) = [tan(𝜑) , 𝑔𝑠𝑖𝑛(𝜃)]𝑇
b. The C matrix was then calculated, which is the Jacobian of h(x)
c. The Kalman gain was then calculated. The measurement of tan(𝜑),
and 𝑔𝑠𝑖𝑛(𝜃) was then determined from the accelerometer outputs.
This was the compared with h(x), and the Kalman gain to produce a
corrected value of x. Thus, the corrected state variables were
calculated, followed by the corrected error covariance matrix.
d. These values of the state variables were stored in an array.
e. Once the loop terminated, the true values, and estimated values were
plotted on a graph.
3. Results
Fig. 1 shows the true and estimated values of the pitch angle, against time.
Fig. 2 shows the true and estimated values of the roll angle, against time. In both
figures, the blue line represents the true value of the corresponding angle, while the
red line represents the value estimated by the Extended Kalman Filter.
Figure 1 Pitch angle vs Time
5. Conclusion
phi = x(1,1);
theta = x(2,1);
phi_dot = 0;
theta_dot = 0;
dt = 0.002; %Timestep
%---------------------------Initialization of Matrices-------------------
P = [1e-9,0;0,1e-9]; %Values from given dataset
Q = [1e-15,0;0,1e-15];
R = [1e-8,0;0,1e-6];
I = [1,0;0,1]; %Identity matrix
p = zeros(1,44676);
q = zeros(1,44676);
r = zeros(1,44676);
ax = zeros(1,44676);
ay = zeros(1,44676);
az = zeros(1,44676);
true_phi = zeros(1,44676);
true_theta = zeros(1,44676);
end
%---------------------------The EKF-------------------
for j = 1:44676
%Prediction step
phi = x(1,1);
theta = x(2,1);
phi_dot = p(j) + (q(j) * sin(phi) * tan(theta)) + (r(j) * cos(phi) *
tan(theta)); %from gyro
theta_dot = (q(j) * cos(phi)) - (r(j) * sin(phi));%from gyro
F = I + (F * dt);
P1 = F * P * F' + Q;
C = [((sec(phi))^2),0;0,(9.81*cos(theta))];
%Correction Step