Vous êtes sur la page 1sur 13

ENGG100

PROJECT
GROUP H

Sean Kurian George (5485927)


Umm Kulsoom Emad Ul Mukhtar (5529657)
Hamdah Abdul Ghafoor (5539092)
Table of contents

Introduction Background Information about the


Software.
Problem and the Approach.

Procedure Solving the problem.


Mathematical and dynamics
concepts.

Top-Level Flowchart Main Process flow.


Detailed Flowchart (including team
contributions).

Output plots Plot of the racetrack.


Plots for different data with respect to
time.

Conclusion Comparison with tracks given in


database.

Appendix Scripts and functions.


Introduction
Background Information about the Software
MATLAB (matrix-laboratory) is a fourth era programming language used for
technical computation. With the help of matrix, we can plot functions and data,
implement algorithms, create GUIs and do much more analysis. The
programming environment of MATLAB is primarily optimized for solving
engineering and scientific problems.

Problem and the Approach


For this project, we had to produce a MATLAB code for generating a plot of the
race track with the given raw track data of a race car. By calculating the
dynamics; like acceleration, distance, velocity and displacement, of the racing
car, we could determine the path traversed by the race car.

Solving the Problem


Reading the data
To start with, the data given in the .txt format had to be imported by using
the MATLAB generated import function, which reads data from the start row
value to the end row value of the text file. (The end row value was found after
the function was generated, given as an example code.)

Information and separation of data

After importing the data file given, the data read had to be separated so that
it could be used for further analysis. The default function of MATLAB, numel
was used to return the number of elements in the data. The longitudinal G-
force, latitudinal G-force and ground speed, of the race car, were given at
time intervals of 0.02s. The units of ground speed had to be changed from
km/hr to m/s by multiplying the ground speed with 5/18. As 1 g-force is 9.81
m/s2, we have to multiply the g-force data in each time interval with 9.81.

Dynamics of the race car

1.1.Determining the Acceleration


Change of velocity with respect to time is called acceleration.
The magnitude of acceleration of the race car depends on the latitudinal
G-force (GF_Lat) and longitudinal G-force (GF_Lng), and is found by
adding the squares of both values and square-rooting it.
1.2.Determining the Distance
Distance is the total distance measured from initial position to the final
position
The distance of the race car depends on the speed and time. By
multiplying the ground speed value given with the time interval, the
distance for the first interval was found. With the use of function numel
in for-loop , the distance from the subsequent time intervals was
calculated one by one, which kept adding to the previous distances until
the last value of ground speed was reached.

1.3.Determining the Velocity


The change of position of an object with respect to time is velocity. It is a
vector quantity and it is always tangential to the path of traversal.
The velocity depends on the acceleration and time. Since velocity is
tangential to the path, we consider only longitudinal acceleration
(longitudinal G-force) instead of using acceleration, therefore longitudinal
G-force is multiplied by the time interval, and first velocity value is found.
With the use of function numel in for-loop, the velocity for second time
interval till the last values of longitudinal G-force is calculated.

1.4.Determining the Displacement


Displacement is a vector quantity that defines the shortest distance
between two points.
We use this formula to calculate displacement of the race car. Here, x is
the displacement in x co-ordinate and y is the displacement in y
coordinate.

S=
1.5. Determining the Position
Each measurement of velocity (or ground speed) and lateral acceleration
(or g-force) at different times is separated by a finite t. In our case, t is
0.02s.
To track the forward position of our car, we can use the velocity of the car:

s(n+1) - s(n) =
v(n).t,
s(n+1) = s(n) +

Where the distance traveled is given by s, velocity is v and time is t. n


denotes nth data point. This will give you the distance traveled along the
track.

The angle between the final direction and initial direction can be
expressed as follows:

(n+1) - (n) =
(a(n).t)/v(n),
(n+1) = (n) +
Using the formulas stated we can calculate the displacement in x
direction and displacement in y direction. The basic formula is:

x(n+1) = x(n) +
v(n).t.cos(n+1)
y(n+1) = y(n) +

Plotting graphs
To plot the graphs of longitudinal G-force and latitudinal G-force vs time,
acceleration vs time, velocity vs time, ground speed vs time, displacement vs
time and distance vs time in the same window, the function subplot was
used; having three rows and two columns with six different positions.
For each graph, the x and y labels, the title, axis properties, position was
entered separately. Since longitudinal G-force and latitudinal G-force are on
the same graph, so the function legend is used to identify each data set.

Flowcharts
Main Process Flow
Detailed fl owchart
Output Plots
Plot of the Race Track

Plots of the dynamics


Conclusion
In conclusion, our track closely resembles Thruxton, England. However, we have to
multiple the x and y coordinates with -1 to obtain the track that resembles closely to the
one given in database.

Appendix
Documentation
%--------------------------------------------------------------------------
% Input: Text File containing data:
% 1. Time (T)
% 2. Ground Speed (G_Speed)
% 3. Longitudinal G-Force (GF_Lng)
% 4. Lateral G-Force (GF_Lat)
%
% Outputs: 1. Position coordinates for the race car over one lap
% 2. Graphs:
% 2.a.Longitudinal and lateral G?forces w.r.t time
% 2.b.Acceleration vs Time
% 2.c.Velocity vs Time
% 2.d.Ground Speed vs Time
% 2.e.Displacement vs Time
% 2.f.Distance vs Time
%
%
% Author(s): Sean Kurian George
% Umm Kulsoom Emad Ul Mukhtar
% Hamdah Abdul Ghafoor
%
% Date: December 07, 2016
%-------------------------------------------------------------------------

Importing the file.


%We use the matlab generated import function
%
%DATA = IMPORTFILE(FILENAME, STARTROW, ENDROW) Reads data from rows
%STARTROW through ENDROW of text file FILENAME.
%
%We get to know the ENDROW value after the function is generated.
%It's given as an example code.
%
DATA = importfile('Track-P08.txt',1, 14232);
%The function description for 'importfile' is at the end.
Separating Data so it can be used further for analysis
n = numel(DATA);%n = numel(A) returns the number of elements, n, in array A.
T = DATA(1:4:n);%Time in s
G_Speed = DATA(2:4:n) * (5/18);%Speed in ms^-1
GF_Lng = DATA(3:4:n) * 9.81;%LongitudinalGForce in ms^-2
GF_Lat = DATA(4:4:n) * 9.81;%LatitudinalGForce in ms^-2
clear n %Clearing unwanted variables from workspace

Calculating acceleration
%Note that the '.' operator does elementwise operation.
A = sqrt((GF_Lng .^ 2) + (GF_Lat .^ 2));%Acceleartion in ms^-2

Calculating distance
%DISTANCE = SPEED x TIME
dt = 0.02; %Since each time interval is 0.02s
D(1) = G_Speed(1) * dt; % We calculate the first element of D
for i=2:numel(G_Speed)
dx = G_Speed(i) * dt;%Distance = Speed x Time (distance in 0.02s)
D(i) = D(i-1) + dx;%Adding up the distance covered in time interval
end
clear i dx dt% Clearing unwanted variables from workspace

Calculating velocity
%VELOCITY = ACCELERATION x TIME
%V = U + A*T ( V=final velocity, U=initial velocity, A=Acceleration)
dt = 0.02; %Since each time interval is 0.02s
V(1) = GF_Lng(1) * dt; % We calculate the first element of V
for i=2:numel(GF_Lng)
V(i) = V(i-1) + GF_Lng(i) * dt;%V = U + A*T
end
clear i dt % Clearing unwanted variables from workspace

Calculating Position
dt = 0.02; %time interval of 0.02s
Alpha(1) = 0; % Angle
x(1) = 0; % x position
y(1) = 0; % y position
Ddt = G_Speed * dt;% Distance covered in 0.02s
n = numel(T);
for i = 2:n
% Formula to calculate the angles
Alpha(i) = Alpha(i-1) + (GF_Lat(i-1) * dt) / G_Speed(i-1);
x(i) = (x(i-1) + Ddt(i) * cos(Alpha(i))); %x displacement
y(i) = (y(i-1) + Ddt(i) * sin(Alpha(i))); %y displacement
end
clear i n dt %clearing unwanted variables from workspace

Calculating displacement
S = sqrt((x.^2 + y.^2));%Formula for displacement

Plotting racetrack
figure
%multiplying x and y with -1 closely resembles
%Thruxton, England racetrack from dataabase.
plot(-1.*x,-1.*y,'*')
title('Race Track (Thruxton, England)')

Plotting GForce-t, s-t, v-t, a-t graphs.


figure

%Plotting g-forces against time


subplot1 = subplot(3,2,1);%Create subplot
plot(T, GF_Lng, T, GF_Lat);%Create plot
xlabel('Time (s)');% Create xlabel
title('Longitudinal and lateral G-Forces w.r.t Time');% Create title
ylabel('G-Forces (m/s^2)');% Create ylabel
legend1 = legend(subplot1,'Longitudinal','Latitudinal');% Create legend
%Set remaining axis properties
set(subplot1,'FontSize',5);
set(legend1,'Orientation','horizontal','FontSize',5,'Location','best');

%Plotting acceleration against time


subplot2 = subplot(3,2,2);
plot(T, A);
xlabel('Time (s)');% Create xlabel
title('Acceleration vs Time');% Create title
ylabel('Acceleration (m/s^2)');% Create ylabel
% Set the remaining axes properties
set(subplot2,'FontSize',5);

%Plotting velocity against time


subplot3 = subplot(3,2,3);
plot(T, V);
xlabel('Time (s)');% Create xlabel
title('Velocity vs Time');% Create title
ylabel('Velocity (m/s^1)');% Create ylabel
% Set the remaining axes properties
set(subplot3,'FontSize',5);

%Plotting Ground-Speed against time


subplot4 = subplot(3,2,4);
plot(T, G_Speed);
xlabel('Time (s)');% Create xlabel
title('Ground Speed vs Time');% Create title
ylabel('Ground Speed (m/s^1)');% Create ylabel
% Set the remaining axes properties
set(subplot4,'FontSize',5);

%Plotting Displacement against time


subplot5 = subplot(3,2,5);
plot(T, S);
xlabel('Time (s)'); % Create xlabel
title('Displacement vs Time');% Create title
ylabel('Displacement (m)');% Create ylabel
% Set the remaining axes properties
set(subplot5,'FontSize',5);

%Plotting Distance against time


subplot6 = subplot(3,2,6);
plot(T, D);
xlabel('Time (s)');% Create xlabel
title('Distance vs Time');% Create title
ylabel('Distance (m)');% Create ylabel
% Set the remaining axes properties
set(subplot6,'FontSize',5);

clear subplot1 subplot2 subplot3 subplot4 subplot5 subplot6 legend1

importfile function.
function DATA = importfile(filename, startRow, endRow)

%IMPORTFILE Import numeric data from a text file as column vectors.


% DATA = IMPORTFILE(FILENAME) Reads data from text file FILENAME for the
% default selection.
%
% DATA = IMPORTFILE(FILENAME, STARTROW, ENDROW) Reads data from rows
% STARTROW through ENDROW of text file FILENAME.
%
% Example:
% DATA = importfile('Track-P08.txt',1, 14232);
%
% See also TEXTSCAN.

% Auto-generated by MATLAB on 2016/12/01 18:22:27

Initialize variables.
delimiter = ':';
if nargin<=2
startRow = 1;
endRow = inf;
end

Format for each line of text:


column2: double (%f)
For more information, see the TEXTSCAN documentation.

formatSpec = '%*s%f%[^\n\r]';

Open the text file.


fileID = fopen(filename,'r');

Read columns of data according to the format.


This call is based on the structure of the file used to generate this code. If an
error occurs for a different file, try regenerating the code from the Import Tool.

textscan(fileID, '%[^\n\r]', startRow(1)-1, 'WhiteSpace', '', 'ReturnOnError', false);


dataArray = textscan(fileID, formatSpec, endRow(1)-startRow(1)+1, 'Delimiter', delimiter,
'MultipleDelimsAsOne', true, 'EmptyValue' ,NaN,'ReturnOnError', false, 'EndOfLine', '\r\n');
for block=2:length(startRow)
frewind(fileID);
textscan(fileID, '%[^\n\r]', startRow(block)-1, 'WhiteSpace', '', 'ReturnOnError', false);
dataArrayBlock = textscan(fileID, formatSpec, endRow(block)-startRow(block)+1, 'Delimiter', delimiter,
'MultipleDelimsAsOne', true, 'EmptyValue' ,NaN,'ReturnOnError', false, 'EndOfLine', '\r\n');
dataArray{1} = [dataArray{1};dataArrayBlock{1}];
end

Close the text file.


fclose(fileID);
Post processing for unimportable data.
No unimportable data rules were applied during the import, so no post
processing code is included. To generate code which works for unimportable
data, select unimportable cells in a file and regenerate the script.

Allocate imported array to column variable names


DATA = dataArray{:, 1};

end

Published with MATLAB R2016b

Vous aimerez peut-être aussi