Lab 4

Arduino Code for Lab 4 Outside Track Scenario:

 

//Initial reverse of the motors to make sure the AEV goes in the correct direction

reverse(4);

 

//Set all motors at a power of 25%

motorSpeed(4,25);

 

//Tell the AEV to go to the absolute position of 400

goToAbsolutePosition(400);

 

//Brake all the motors to stop movement

brake(4);

 

 

Matlab Code for Performance Analysis:

 

%=======================================================================

% Name: Wenbo Nan, Kyle Fathauer, Jason Hahn, Ishan Taparia

% Date: 02/14/2017

% Class: 12:401:35 PM  Instructor: Kadri Parris

%

% Program title: Performance Analysis

%

% Program description: The Matlab program loads the EEPROM data, converts

% it into physical parameters and plot the power consumed by the AEV during

% the run. Then the program divides the plot into three phases and

% calculate the incremental and total energy of each phase.

%

%=======================================================================

clc

clear all

% Load EEPROM data into Matlab workspace

a = xlsread(‘aevData’);

te = a(7:280,1); % EEPROM time

ie = a(7:280,2); % EEPROM current

ve = a(7:280,3); % EEPROM voltage

marks = a(7:280,4); % EEPROM marks

pos = a(7:280,5); % EEPROM positions

% convert EEPROM data into physical parameters

t = te / 1000; % physical parameters of time

i = ie / 1024 .* 2.46 / 0.185; % physical parameters of current

v = 15 .* ve / 1024; % physical parameters of voltage

d = 0.0124 .* marks; % physical parameters of distance

s = 0.0124 .* pos; % physical parameters of position

% calculate the power consumed

p = v .* i;

% plot power vs. time

plot(t,p,‘LineWidth’,2)

xlabel(‘Time (seconds)’) % add x label to the plot

ylabel(‘Power (Watts)’) % add y label to the plot

title(‘Energy consumed during the run’) % add title to the plot

grid on % add grid to the plot

box on % add box to the plot

% Phase 1

xR = 0.36; % Right xcoordinate

xL = 0; % Left xcoordinate

iL = knnsearch(t,xL); % Element index of left point

iR = knnsearch(t,xR); % Element index of right point

P1 = p(iL:iR); % Power values of Phase 1

t1 = t(iL:iR); % Time values of Phase 1

% Compute incremental energy of Phase 1

for j = iL:iR

ej(j) = (p(j) + p(j+1)) / 2 * (t(j+1)-t(j));

end

% Compute total energy of Phase 1

e1 = sum(ej(iL:iR));

% Phase 2

xR = 13.2; % Right xcoordinate

xL = 0.36; % Left xcoordinate

iL = knnsearch(t,xL); % Element index of left point

iR = knnsearch(t,xR); % Element index of right point

P2 = p(iL:iR); % Power values of Phase 2

t2 = t(iL:iR); % Time values of Phase 2

% Compute incremental energy of Phase 2

for j = iL:iR

ej(j) = (p(j) + p(j+1)) / 2 * (t(j+1)-t(j));

end

% Compute total energy of Phase 2

e2 = sum(ej(iL:iR));

% Phase 3

xR = 16.38; % Right xcoordinate

xL = 13.2; % Left xcoordinate

iL = knnsearch(t,xL); % Element index of left point

iR = knnsearch(t,xR); % Element index of right point

P3 = p(iL:iR); % Power values of Phase 3

t3 = t(iL:iR); % Time values of Phase 3

% Compute incremental energy of Phase 3

for j = iL:iR-1

ej(j) = (p(j) + p(j+1)) / 2 * (t(j+1)-t(j));

end

% Compute total energy of Phase 3

e3 = sum(ej(iL:iR-1));