Code

Week 2 Code

Code:

void myCode(){

/*

Andy Carper, Christian Meadows, Grant Centlivre, and Kody Williamson

ENGR 1182 AEV Code – Group E

myCode();

 

This is the tab where the programming of your vehicle operation is done.

lab _00_AEV_key_words contains a compiled list of functions/subroutines used         for vehicle operation.

 

Note:

(1) After running your AEV do not turn the AEV off, connect the AEV to a computer, or push the reset button on the Arduino. There is a 13 second processing period. In post processing, data is stored and battery recuperation takes place.

(2) Time, current, voltage, total marks, position traveled are recorded approximately

every 60 milliseconds. This may vary depending on the vehicles operational tasks.

It takes approximately 35-40 milliseconds for each recording. Thus when programming, code complexity may not be beneficial.

(3) Always comment your code. Debugging will be quicker and easier to do and will especially aid the instructional team in helping you.

*/

celerate(1,0,15,2.5);  //Accelerate Motor 1 from start to 15% power in 2.5s

motorSpeed(1,15);  //Set Motor 1 speed to Motor one for 15%

goFor(1);  //Run Motor 1 for 1s

celerate(2,0,27,4);  //Accelerate Motor 2 from start to 27% power in 4s

motorSpeed(2,27);  //Set Motor 2 speed to Motor one for 27%

goFor(2.7);  //Run Motor 2 for 2.7s

celerate(2,27,15,1);  //Decelerate Motor 2 from 27% battery power to 15% power in //1s

brake(2);  //Cut power to Motor 2

reverse(2);  //Reverse the direction of Motor 2

celerate(4,0,21,2);  //Accelerate all Motors from rest to 21% battery power in 2s

motorSpeed(4,35);  //Set all Motor speeds to 35% battery power

brake(2);  //Cut power to Motor 2

motorSpeed(1,35);  //Set Motor speed 1 to 35%

goFor(3);  //Run Motor 1 for 3s

brake(1);  //Cut power to Motor 1

brake(2);  //Cut power to Motor 2

reverse(1);  //Reverse the direction of Motor 1

celerate(1,0,19,2);  //Accelerate Motor 1 from rest to 19% battery power in 2s

motorSpeed(2,35);  //Set Motor 2 speed to 35% battery power

goFor(2); //Run Motor 2 for 2s

motorSpeed(1,19);  //Set Motor 1 speed to 19% battery power

goFor(2);  //Run Motor 1 for 2s

motorSpeed(4, 19);  //Set all Motor speeds to 19% battery power

goFor(2);  //Run all motors for 2s

celerate(4,19,0,3);  //Decelerate all motors from 19% battery power to 0% battery //power in 3s

brake(1);  //Cut power to Motor 1

brake(2);  //Cut power to Motor 2

}

Comments: The code seems to be executed correctly as the motors run on different power settings for different lengths of time. It was observed that power appears to be cut to the motors at the correct time. It will be essential to understand and utilize these commands moving forward to propel the AEV forward to complete the mission statement

 

Week 3 Code

reflectanceSensorTest();

/*

celerate(1,0,15,2.5);  //Accelerate Motor 1 from start to 15% power in 2.5s

motorSpeed(1,15);  //Set Motor 1 speed to Motor one for 15%

goFor(1);  //Run Motor 1 for 1s

celerate(2,0,27,4);  //Accelerate Motor 2 from start to 27% power in 4s

motorSpeed(2,27);  //Set Motor 2 speed to Motor one for 27%

goFor(2.7);  //Run Motor 2 for 2.7s

celerate(2,27,15,1);  //Decelerate Motor 2 from 27% battery power to 15% power in //1s

brake(2);  //Cut power to Motor 2

reverse(2);  //Reverse the direction of Motor 2

celerate(4,0,21,2);  //Accelerate all Motors from rest to 21% battery power in 2s

motorSpeed(4,35);  //Set all Motor speeds to 35% battery power

brake(2);  //Cut power to Motor 2

motorSpeed(1,35);  //Set Motor speed 1 to 35%

goFor(3);  //Run Motor 1 for 3s

brake(1);  //Cut power to Motor 1

brake(2);  //Cut power to Motor 2

reverse(1);  //Reverse the direction of Motor 1

celerate(1,0,19,2);  //Accelerate Motor 1 from rest to 19% battery power in 2s

motorSpeed(2,35);  //Set Motor 2 speed to 35% battery power

goFor(2); //Run Motor 2 for 2s

motorSpeed(1,19);  //Set Motor 1 speed to 19% battery power

goFor(2);  //Run Motor 1 for 2s

motorSpeed(4, 19);  //Set all Motor speeds to 19% battery power

goFor(2);  //Run all motors for 2s

celerate(4,19,0,3);  //Decelerate all motors from 19% battery power to 0% battery //power in 3s

brake(1);  //Cut power to Motor 1

brake(2);  //Cut power to Motor 2

*/

}

Comments: The code appears to be executed correctly as values of distance are obtained from the reflectance sensor test. The values are negative when the AEV travels forward suggesting that the sensors will have to be flipped to obtain positive distance values. It will be essential to understand the function calls regarding distance moving forward to program the AEV to stop at the gate.

 

Week 6 Code

reverse(1);

reverse(2);

celerate(4,0,50,1);

motorSpeed(4,50);

goToAbsolutePosition(-102);

brake(1);

brake(2);

Comments: The AEV travels forward towards the gate, power is cut to the motors before the AEV reaches the gate but it travels too far after power is cut and activates the second sensor causing the gate to remain up. A braking procedure will have to be implemented into the code to allow the AEV to come to a stop activating the first sensor while remaining in front of the second sensor.

 

Week 10 Code

Code:

void myCode()

{

reverse(1);

reverse(2);

celerate(4,0,30,2);

motorSpeed(4,30);

goToAbsolutePosition(-245);

brake(1);

brake(2);

reverse(1);

reverse(2);

celerate(4,0,45,3);

brake(1);

brake(2);

reverse(1);

reverse(2);

motorSpeed(4,0);

goFor(6);

 

celerate(4,0,40,2);

celerate(4,40,30,1);

motorSpeed(4,30);

goToAbsolutePosition(-675);

brake(1);

brake(2);

reverse(1);

reverse(2);

celerate(4,0,40,2);

celerate(4,40,0,1);

motorSpeed(4,0);

goFor(1);

brake(1);

brake(2);

reverse(1);

reverse(2);

reverse(1);

reverse(2);

celerate(4,0,50,2);

celerate(4,50,40,2);

motorSpeed(4,40);

goToRelativePosition(-300);

brake(1);

brake(2);

reverse(1);

reverse(2);

celerate(4,0,55,4);

}

Comments: The AEV travels forward towards the gate, successfully activates the first sensor, waits for the gate to open, proceeds through the gate, travels towards the caboose, picks up the caboose, and travels very slowly back towards the gate with the caboose in tow. A more forceful stop could be edited into the code before the AEV attaches to the caboose as there was a small collision between the vehicle and the caboose. In addition, the code may have to be edited to increase the power supplied to the motors of the AEV as it travels back to the gate with the caboose due to the added weight of the caboose.

 

Week 11 Code

Code:

void myCode()

{

reverse(1);

reverse(2);

celerate(4,0,30,2);

motorSpeed(4,30);

goToAbsolutePosition(-245);

brake(1);

brake(2);

reverse(1);

reverse(2);

celerate(4,0,45,3);

brake(1);

brake(2);

reverse(1);

reverse(2);

motorSpeed(4,0);

goFor(6);

celerate(4,0,40,2);

celerate(4,40,30,1);

motorSpeed(4,30);

goToAbsolutePosition(-675);

brake(1);

brake(2);

reverse(1);

reverse(2);

celerate(4,0,40,2);

celerate(4,40,0,1);

motorSpeed(4,0);

goFor(1);

brake(1);

brake(2);

reverse(1);

reverse(2);

reverse(1);

reverse(2);

celerate(4,0,50,2);

celerate(4,50,40,2);

motorSpeed(4,40);

goToRelativePosition(-300);

brake(1);

brake(2);

reverse(1);

reverse(2);

celerate(4,0,55,4);

}

Comments: The AEV Successfully traverses through the gate, comes to a smooth stop, picks up the caboose, successfully returns and passes through the gate, and finally comes to a stop near its starting point. The AEV code is almost complete as the AEV is able to navigate the course, however, the distance at which power is cut the motors on the AEV’s return to the starting will have to be adjusted as the AEV is coming to a final stop before the vehicle’s original starting point.