Division P- Preliminary Software

The code used to run the AEV as a a basic programming exercise (scenario 1) is as follows:

celerate(1,0,15,2.5);
goFor(1);
brake(1);
celerate(2,0,27,4);
goFor(2.7);
celerate(2,27,15,1);
brake(2);
reverse(2);
celerate(4,0,31,2);
motorSpeed(4,35);
goFor(1);
brake(2);
goFor(3);
brake(4);
goFor(1);
reverse(1);
celerate(1,0,19,2);
motorSpeed(2,35);
goFor(2);
motorSpeed(4,19);
goFor(2);
celerate(4,19,0,3);
brake(4);

Code Design Take Away(for wheel)

In the past few weeks, the team put the focus on code development for AEV performance. The task is to operate AEV, perform a certain routine automatically, safly and consistently, in both time and energy conserved fashion. Before the team put the concern on energy efficiency, the AEV need to be assured for its consistency in terms of  reach certain position and be able to stop to avoid potential crashes. Hence the team developed three version of code to gradually improve the adaptability, adjustability and consistency.

 

Code Version 1

const int mark1st = 260;

const int mark2nd = 580;

const int mark3rd = 380;

const int mark4th = 0;

 

 // GO TO THE GATE

 motorSpeed(4,20);

 goToAbsolutePosition(mark1st);

 brakeStop();

 goFor(7);

 

//GO TO THE LOADING ZONE

 motorSpeed(4,20);

 goToAbsolutePosition(mark2nd);

 brakeStop();

 goFor(5);

 

//BACK TO GATE

 reverse(4);

 motorSpeed(4,20);

 goToAbsolutePosition(mark3rd);

 brakeStop();

 goFor(7);

 

//GET OUT

/* motorSpeed(4,20);

 goToAbsolutePosition(mark4th);

 brakeStop();

*/

 

}

// BRAKE FUNCTION

void brakeStop() {

 const Int breakingPower =15;

 int iniDir = getVehicleDirection();

 int finDir =iniDir;

 reverse(4);

 do {

   int currentPosition = getVehiclePostion();

      motorSpeed(4,breakingPower);

 goFor(minTimeLapse/1000.0);

 finDir = getVehicleDirection();

 } while (finDir == iniDir);

 reverse(4);

 brake(4);

}

The focus of this code is to put all the important marks in the beginning of the code for easy adjustment, followed by the good coding practice. And an approach to reach for consistency is the breakStop() function which can reverse the motor to stop the AEV until it change its direction.

Code Version 2

// BRAKE FUNCTION

void brakeStopAt(int brakingPower,int stopMark) {

 int iniDir = getVehicleDirection();

 int finDir =iniDir;

 reverse(4);

 do {

   

//adjust brake power according to the distance between target mark and current mark

//using 10 as range for adjust at two stop of braking power

   if (currentPosition<stopMark+10&&currentPosition>stopMark-10) {

 motorSpeed(4,brakingPower);

 goFor(minTimeLapse/1000.0);

   } else {

     motorSpeed(4,brakingPower-5);

 goFor(minTimeLapse/1000.0);

   }

 finDir = getVehicleDirection();

 

 } while (finDir == iniDir);

 reverse(4);

 brake(4);

}

This version of code only change the brakeStop() function to brakeWithPowerStopAt(int brakePower, int stopMark). Introducing a parameter “brakePower” to adjust the reverse power for each stage allow the AEV to adapt the weight change after picking up the caboose. After the total weight increase, the AEV need to increase braking power to stop properly. Another change to the code is adding “stopMark” to the braking function, allow it adjust the braking power itself according to AEV’s current location.

Other than the braking function, the team also added underlined code to change running power in 2nd and 3rd stage to adapt to the hump on the track.

//GO TO THE LOADING ZONE

 motorSpeed(4,20);

 goFor(2);

 motorSpeed(4,15);

 goToAbsolutePosition(mark2nd);

 brakeStop();

 goFor(5);

 

//BACK TO GATE

 reverse(4);

 motorSpeed(4,20);

 goFor(1);

 motorSpeed(4,25);

 goToAbsolutePosition(mark3rd);

 brakeStop();

 goFor(7);

 

Figure.2 V2 code results summery 

Code Version 3

// BRAKE FUNCTION

//@breakingPower = power of break @stopMark is the targeted stopping pos

void brakeStopAt(int breakingPower,int stopMark) {

 const int STOP_TIME = 4;

 int iniPos = getVehiclePostion();

 int posCountTime = 0;

 int iniDir = getVehicleDirection();

 int finDir =iniDir;

 reverse(4);

 do {

//check position of the AEV

   int currentPosition = getVehiclePostion();

//compare current pos and past pos, if same, count time +1

   if (currentPosition == iniPos) {

     posCountTime++;

   }

//update the pos

   iniPos = currentPosition;

   

//adjust break power according to the distance between target mark and current mark

//using 10 as range for adjust at two stop of breaking power

   if (currentPosition<stopMark+10&&currentPosition>stopMark-10) {

 motorSpeed(4,breakingPower+5);

 goFor(minTimeLapse/1000.0);

   } else {

     motorSpeed(4,breakingPower);

 goFor(minTimeLapse/1000.0);

   }

 finDir = getVehicleDirection();

 

 } while ((finDir == iniDir)&&(posCountTime<STOP_TIME));

 reverse(4);

 brake(4);

}

This version of code only fine tuned the braking function by adding one more condition check to determine when to stop the brake, that is to check whether the AEV is stopped(position no longer change). And this code lead to our successful final run.

Figure.2 Final performance test run