Final Tested Code


motorSpeed(4,25);
while (getVehiclePostion() < 335) {
  if (getVehiclePostion() > 283 && getVehicleDirection() == 1) {
    reverse(4);
    while(getVehicleDirection() > 0) {
        motorSpeed(4,30);
    }
  }
}
brake(4);
goFor(7);
motorSpeed(4,25);
if (getVehicleDirection() == 0) {
  reverse(4);
  motorSpeed(4,25);
}
while (getVehiclePostion() < 775) {
  if (getVehiclePostion() > 712 && getVehicleDirection() == 1) {
    reverse(4);
    while(getVehicleDirection() > 0) {
        motorSpeed(4,35);
    }
  }
}

brake(4);
goFor(5);
motorSpeed(4,50);
if (getVehicleDirection() != 0) {
  reverse(4);
  motorSpeed(4,50);
}
while (getVehiclePostion() > 484) {
  if (getVehiclePostion() < 527 && getVehicleDirection() == 0) {
    reverse(4);
    while(getVehicleDirection() == 0) {
        motorSpeed(4,35);
    }
  }
}

brake(4);
goFor(7);
motorSpeed(4,55);
if (getVehicleDirection() != 0) {
  reverse(4);
  motorSpeed(4,55);
}
while (getVehiclePostion() > 30) {
  if (getVehiclePostion() < 105 && getVehicleDirection() == 0) {
    reverse(4);
    while(getVehicleDirection() == 0) {
        motorSpeed(4,60);
    }
  }
}
brake(4);

Inside Track Glide

  motorSpeed(4,25); 
  goToAbsolutePosition(250); 
  brake(4); 
  goFor(7); 
   
  motorSpeed(4,25); 
  goToAbsolutePosition(700); 
  brake(4); 
  goFor(5); 
   
  motorSpeed(4,50); 
  gotoAbsolutePosition(480); 
  brake(4); 
  goFor(7); 
   
  motorSpeed(4,50); 
  goToAbsolutePosition(60); 
  brake(4);

Inside Track V2

motorSpeed(4,25); 
  while (getVehiclePostion() < 335) { 
    if (getVehiclePostion() > 290 && getVehicleDirection() == 1) { 
      reverse(4); 
      while(getVehicleDirection() > 0) { 
          motorSpeed(4,30); 
      } 
    } 
  } 
  brake(4); 
  goFor(7); 
  motorSpeed(4,25); 
  if (getVehicleDirection() == 0) { 
    reverse(4); 
    motorSpeed(4,25); 
  } 
  while (getVehiclePostion() < 775) { 
    if (getVehiclePostion() > 715 && getVehicleDirection() == 1) { 
      reverse(4); 
      while(getVehicleDirection() > 0) { 
          motorSpeed(4,35); 
      } 
    } 
  } 
 
  brake(4); 
  goFor(5); 
  motorSpeed(4,50); 
  if (getVehicleDirection() != 0) { 
    reverse(4); 
    motorSpeed(4,50); 
  } 
  while (getVehiclePostion() > 495) { 
    if (getVehiclePostion() < 545 && getVehicleDirection() == 0) { 
      reverse(4); 
      while(getVehicleDirection() == 0) { 
          motorSpeed(4,40); 
      } 
    } 
  } 
 
  brake(4); 
  goFor(7); 
  motorSpeed(4,55); 
  if (getVehicleDirection() != 0) { 
    reverse(4); 
    motorSpeed(4,55); 
  } 
  while (getVehiclePostion() > 10) { 
    if (getVehiclePostion() < 50 && getVehicleDirection() == 0) { 
      reverse(4); 
      while(getVehicleDirection() == 0) { 
          motorSpeed(4,55); 
      } 
    } 
  } 
  brake(4); 

Performance Analysis & Incremental Energy

%=============================================================== 
% Name: Ashwin Rajgopal, Blake Kanoy, Alex Beutel & Daniel Fahmi 
% Date: 2/09/17 
% Class: ENGR 1182.01 
% 
% Program Title: Performance Analysis 
% 
% Program description: Convert Excel data and analyze it. 
% 
%================================================================ 
  
% Load EEPROM data into MATLAB workspace 
  
data = xlsread('lab04data.xlsx'); 
t = data(:,1); 
i = data(:,2); 
v = data(:,3); 
cwc = data(:,4); 
pwc = data(:,5); 
  
t = t / 1000; 
i = (i/1024)*2.46*(1/.185); 
v = 15*v/1024; 
cwc = cwc * .0124; 
pwc = pwc * .0124; 
p = v .* i; 
  
figure(1); 
plot(t, p, 'LineWidth', 2); 
grid on 
box on 
title('AEV Power Usage of Time'); 
xlabel('Time (s)'); 
ylabel('Power (Watts)'); 
  
  
% Phase 1 
xL = 0; % Right x-coordinate 
xR = .18; % Left x-coordinate 
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 
ph1 = []; 
for i=1:size(P1)-1 
    ph1(i) = ((P1(i) + P1(i+1))/2) * (t1(i+1)-t1(i)); 
end 
% Compute total energy of Phase 1 
ph1tot = sum(ph1) 
  
% Phase 2 
xL = .18; % Right x-coordinate 
xR = 6.93; % Left x-coordinate 
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 
ph2 = []; 
for i=1:size(P2)-1 
    ph2(i) = ((P2(i) + P2(i+1))/2) * (t2(i+1)-t2(i)); 
end 
% Compute total energy of Phase 2 
ph2tot = sum(ph2) 
  
% Phase 3 
xL = 6.93; % Right x-coordinate 
xR = 6.963; % Left x-coordinate 
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 
ph3 = []; 
for i=1:size(P3)-1 
    ph3(i) = ((P3(i) + P3(i+1))/2) * (t3(i+1)-t3(i)); 
end 
% Compute total energy of Phase 3 
ph3tot = sum(ph3) 
  
% Phase 4 
xL = 6.963; % Right x-coordinate 
xR = 9.903; % Left x-coordinate 
iL = knnsearch(t,xL); % Element index of left point 
iR = knnsearch(t,xR); % Element index of right point 
P4 = p(iL:iR); % Power values of Phase 4 
t4 = t(iL:iR); % Time values of Phase 4 
  
% Compute incremental energy of Phase 4 
ph4 = []; 
for i=1:size(P4)-1 
    ph4(i) = ((P4(i) + P4(i+1))/2) * (t4(i+1)-t4(i)); 
end 
% Compute total energy of Phase 4 
ph4tot = sum(ph4)

Reaching the Gate: Inner Track

motorSpeed(4, 50); // Run all motors at a constant speed of 25% power  
goFor(2); // For 2 seconds 
motorSpeed(4, 50); // Run all motors at a constant speed of 25% power  
goToAbsolutePosition(332); // Travel a total distance of 13.5 feet (from the starting point).  
reverse(4); // Reverse the motors. 
motorSpeed(4, 60); // Run all motors at a constant speed of 30% power  
goFor(1); // For 1 second. 
brake(4); // Brake all motors.

AEV Introduction Scenario 1

celerate(1,0,15,2.5); // Accelerate motor one from start to 15% power in 2.5 seconds. 
goFor(1); // Run motor one at a constant speed (15% power) for 1 second. 
brake(1); // Brake motor one. 
celerate(2,0,27,4); // Accelerate motor two from start to 27% power in 4 seconds. 
goFor(2.7); // Run motor two at a constant speed (27% power) for 2.7 seconds. 
celerate(2,27,15,1); // Decelerate motor two to 15% power in 1 second. 
brake(2); // Brake motor two. 
reverse(2); // Reverse the direction of only motor 2. 
celerate(4,0,31,2); // Accelerate all motors from start to 31% power in 2 seconds. 
motorSpeed(4,35); // Run all motors at a constant speed of 35% power 
goFor(1); // For 1 second. 
brake(2); // Brake motor two  
goFor(3); // Keep motor one running at a constant speed (35% power) for 3 seconds. 
brake(4); // Brake all motors  
goFor(1); // For 1 second. 
reverse(1); // Reverse the direction of motor one. 
celerate(1,0,19,2); // Accelerate motor one from start to 19% power over 2 seconds. 
motorSpeed(2,35); // Run motor two at 35% power  
goFor(2); // While simultaneously running motor one at 19% power for 2 seconds. 
motorSpeed(4,19); // Run both motors at a constant speed (19% power)  
goFor(2); //For 2 seconds. 
celerate(4,19,0,3); // Decelerate both motors to 0% power in 3 seconds. 
brake(4); // Brake all motors.