# Code Archive

## Lab 1:

// Accelerate motor one from start to 15% power in 2.5 seconds.
celerate(1,0,15,2.5);

// Run motor one at a constant speed (15% power) for 1 second.
motorSpeed(1,15);
goFor(1);

// Brake motor one.
brake(1);

// Accelerate motor two from start to 27% power in 4 seconds
celerate(2,0,27,4);

//Run motor two at a constant speed (27% power) for 2.7 seconds.
motorSpeed(2,27);
goFor(2.7);

// Decelerate motor two to 15% power in 1 second.
celerate(2,27,15,1);

// Brake motor 2.
brake(2);

// Reverse direction of motor 2
reverse(2);

//Accelerate all motors from start to 31% power in 2 seconds.
celerate(4,0,31,2);

// Run all motors at a constant speed of 35% power for 1 second.
motorSpeed(4,35);
goFor(1);

// Brake motor two but keep motor one running at a constant speed (35% power) for 3
seconds.
brake(2);
motorSpeed(1,35);
goFor(3);

// Brake all motors for 1 second.
brake(4);
goFor(1);

// Brake all motors for 1 second.
reverse(1);

//Accelerate motor one from start to 19% power over 2 seconds.
celerate(1,0,19,2);

// Run motor two at 35% power while simultaneously running motor one at 19% power
for 2 seconds.
motorSpeed(2,35);
motorSpeed(1,19);
goFor(2);

// Run both motors at a constant speed (19% power) for 2 seconds.
motorSpeed(4,19);
goFor(2);

// Decelerate both motors to 0% power in 3 seconds.
celerate(4,19,0,3);

// Brake all motors.
brake(4);

## Lab 2:

// Run all motors at a constant speed of 25% power for 2 seconds.
motorSpeed(4,25);
goFor(2);

// Run all motors at a constant speed of 20% and travel a total distance of 12 feet from the starting point.
motorSpeed(4,20);
goToAbsolutePosition(296);

// Reverse all motors.
reverse(4);

// Run all motors at a constant speed of 30% power for 1.5 second
motorSpeed(4,30);
goFor(1.5);

// Brake all motors.
brake(4);

## Lab 3:

// accelerate vehicle

celerate(4,0,25,3);
motorSpeed(4, 25);
goFor(1);

// decelerate vehicle for 2 seconds
motorSpeed(4, 20);
goFor(2);
reverse(4);

// accelerate vehicle for 2 seconds by 5%

motorSpeed(4, 25);
goFor(2);

// cut power for all motors

brake(4);

## Coasting Test

reverse(4);

motorSpeed(4,25);

goToAbsolutePosition(200);

brake(4);

## Power Braking Test

reverse(4);

motorSpeed(4,25);

goToAbsolutePosition(200);

reverse(4);

motorSpeed(4,30);

goFor(2);

## Energy Analysis

reverse(4);

motorSpeed(4,30);

goFor(4);

motorSpeed(4,0);

goFor(10);

## Performance Test 1

int phase;

phase == 1;

reverse(4);

// initial acceleration example values

motorSpeed(4, 25);

goToAbsolutePosition(214);

brake(4);

//208 8.44

//214 8.33

while (phase == 1) {

// not far enough

// if <= 280 and stopped

if (getForwardsTotal() <= 280 && getVehicleDirection == 2) {

motorSpeed(1, 25);

goFor(.5);

phase ++;

}

// too far

// if at 315 and moving

else if (getForwardsTotal() >= 315 && getVehicleDirection == 1) {

reverse(1);

motorSpeed(1, 30);

goFor(1);

brake(1);

reverse(1);

phase ++;

}

// if stopped in range

else if (getVehicleDirection == 2) {

phase ++;

}

} // end phase 1

// stop at gate for 7 seconds

motorSpeed(4, 0);

goFor(10);

// leave gate

motorSpeed(4, 25);

goFor(3);

## Performance Test 2

int phase;
phase = 1;

reverse(4);

// initial acceleration example values
motorSpeed(4, 25);
goToAbsolutePosition(201);
brake(4);

///////////////////////////////////
//208 8.44 Lecture
//214 8.33 Lecture
//208 8.38 Lecture after power brake (hot)
//206 8.32 Lab
//226 weird day
//////////////////////////////////////

while (phase == 1) {

// if stopped in range
if (getForwardsTotal() >= 307 && getForwardsTotal() <= 314 && getVehicleDirection == 2 ) {
phase ++;
}

// too far
//315
else if ( getForwardsTotal() >= 290 ) {
reverse(4);
motorSpeed(4, 30);
goFor(1.5);
brake(4);
reverse(4);
phase ++;
}

} // end phase 1

// stop at gate for 7 seconds
motorSpeed(4, 0);
goFor(7.25);

// leave gate
motorSpeed(4, 25);
goFor(2.45);

// phase 2– docking and leaving

// wait
motorSpeed(4, 0);
goFor(12.25);

reverse(4);
motorSpeed(4,45);
goFor(3.5);

## Performance Test 3

///////////////////////////////////
//208 8.44 Lecture
//214 8.33 Lecture
//208 8.38 Lecture after power brake (hot)
//206 8.32 Lab
//226 weird day

//213 8.42 213 power break
//223 8.45 Lecture
//////////////////////////////////////

int phase;
phase = 1;
reverse(4);

// initial acceleration
motorSpeed(4, 25);
goToAbsolutePosition(227);
brake(4);

while (phase == 1) {

// if stopped in range
if (getForwardsTotal() >= 307 && getForwardsTotal() <= 314 && getVehicleDirection == 2 ) { // fix range
phase ++;
}

// too far
//315 //290
else if ( getForwardsTotal() >= 297 ) {
reverse(4);
motorSpeed(4, 30);
goFor(1);
brake(4);
reverse(4);
phase ++;
}

} // end phase 1

// stop at gate for 7 seconds
motorSpeed(4, 0);
goFor(7);

// leave gate
//25
motorSpeed(4, 25);
goFor(3.12);
// 2.45 //
// marks 308

//goToAbsolutePosition(308);
// weird power wait thing
motorSpeed(4, 0);
goFor(3.5);

// phase 2————————– docking and leaving——————————

while (phase == 2) {

while (getTotalMarks() >= 630 && phase == 2) {

if (getVehicleDirection() == 2) {
phase++;
}
// 646
else if (getTotalMarks() >= 637 && getVehicleDirection() == 1) {

reverse(1);
motorSpeed(1, 25);
goFor(1);
brake(1);
reverse(1);
phase ++;

}

}

} //////////////////////////////////////////// end phase 2

// wait
motorSpeed(4, 0);
goFor(6);

reverse(4);
motorSpeed(4, 42);

//375 378
goToAbsolutePosition(382);

// brake at gate
brake(4);
reverse(4);
motorSpeed(4, 32);
goFor(1.5);
brake(4);
reverse(4);

// stop at gate for 7 seconds
motorSpeed(4, 0);
goFor(7);

// leave gate for starting zone
motorSpeed(4, 40);
goToAbsolutePosition(222);
brake(4);

// phase 3 brake at the start w load———————————————————
while (phase == 3) {

// brake at 78 absolute //1250
if (getTotalMarks() >= 1230) {

//brake
reverse(4);
motorSpeed(4, 40);
goFor(1.75);
brake(4);
reverse(4);
phase++;

}

}
//////——————————————————————————————

//590k