Performance Test Code

Back to Code

Performance Test 1:

 

goToAbs(294, 40, 50);

stopAEV();

delay(8000);

goToAbs(600, 40, 20);

stopAEV();

 


Performance Test 2:

 

goToAbs(294, 40, 50);

stopAEV();

delay(8000);

goToAbs(600, 40, 20);

stopAEV();

delay(5000);

goToAbs(300, 50, 63);

stopAEV();

delay(7000);


Final Performance Test:

 

goToAbs(294, 40, 50);

stopAEV();

delay(8000);

goToAbs(630, 40, 20);

stopAEV();

delay(6000);

goToAbs(394, 50, 70);

stopAEV();

delay(7000);

goToAbs(10, 60, 30);

stopAEV();


Custom Functions:

 

void stopAEV() {

 // Direction: 1 = Forward; 0 = Reverse, 2 = No Direction.

 // the encoderPos-((dir*4)-2) will, if dir is forward, be behind the AEV, and if dir is reverse be in front of the AEV,

 // resulting in a target which is in the opposite from the velocity

 boolean didReverse = runToward(encoderPos-((dir*2)-1), 40); // Moves the motors in the opposite direction of travel

 

 // The below section waits until the AEV travels very slightly in the other direction or the gap between encoder count increments is long enough

 // If the gap between encoder count increments is high, the AEV is slow, and the propellers can stop

 int currentDir = dir; // dir is a global variable

 int delayFor = 70; // Tune this to change how slow the AEV will be, the smaller the faster

 int pastEncoder = encoderTotal; // encoderTotal is a global variable

 delay(100); // Initial delay so it doesn’t check pastEncoder to encoderTotal immediately

 while (pastEncoder!=encoderTotal && currentDir==dir){

   pastEncoder = encoderTotal;

   delay(delayFor);

 }

 

 brake(4);

 if (didReverse) reverse(4);  // reverses motors back to original if needed

}

 

// This function moves the AEV to the given position, using power for the first half and coasting for the second half

void goToAbs(int pos, int power, int runPercent) {

 boolean didReverse = runToward(pos, power); // Runs toward target direction, returns whether it had to reverse motors to do so

 int disTillStop =(int) ((runPercent/100.0) * abs(pos-encoderPos));

 if (pos>encoderTotal) {

   goToAbsolutePosition(disTillStop+encoderPos);

 }

 else {

   goToAbsolutePosition(encoderPos-disTillStop);

 }

//  goToAbsolutePosition((pos+encoderPos)/2);

 brake(4);

 goToAbsolutePosition(pos);

 if (didReverse) reverse(4); // reverses motors back to original if needed

}

 

// This function sets the motors toward the given pos, at the given power

boolean runToward(int pos, int power) {

 if (pos>encoderPos){ // Checks whether to run forward or backward

   motorSpeed(4,40);

   return false;

 }

 else {

   reverse(4);

   motorSpeed(4, 40);

   return true;

 }

}