Arduino Code
Reference Code:
celerate(m,p1,p2,t); This accelerates or decelerates motors m from speeds p1 to p2 for t seconds
motorSpeed(m,p); This starts the motor m at p percent power
goFor(t); This runs the motors for t seconds
brake(m); This stops the motor m from running
reverse(m); This reverses motor m (spins in a different direction)
goToRelativePosition(n); This runs the AEV until it’s at position, n, relative to where it is at that moment.
goToAbsolutePosition(n); This runs the AEV until it’s at position, n, relative to the starting point.
Our code:
// Accelerating motors
celerate(4,0,25,3);
//Run motors atr constant speed 25
motorSpeed(4,25);
goFor(1);
//Run motors at constant speed 20
motorSpeed(4,20);
goFor(2);
//REVERSE
reverse(4);
// //Run motors at constant speed 25
motorSpeed(4,25);
goFor(2);
//brake
brake(4);
} // DO NOT REMOVE. end of void myCode()
EXERCISE 2:
//Run both motors at constant speed at 25% power
motorSpeed(4,25);
GoFor(2);
// Run all motors- constant speed- 20%- travel 12 feet (144 inches).
motorSpeed(4,20);
GoToAbsolutePosition(295.233);
// Reverse motors.
reverse(4);
// Run all motors- 30% power- 1.5s
motorSpeed(4,30);
GoFor(1.5);
// Brake
Brake(4);
} // DO NOT REMOVE. end of void myCode()
EXERCISE 4:
// Accelerate motor one from start to 15% power in 2.5 seconds
celerate(1,0,15,2.5);
// Run motor one at constant speed at 15% power for 1 second
motorspeed(15);
goForit(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(27);
goForit(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(1,0,31,2);
celerate(2,0,31,2);
// Run mtors at a constant speed of 35% for 1 second
motorspeed(1,35);
goForit(1);
motorspeed(2,35);
goForit(1);
// Brake motor two but keep motor one running at a constant speed (35% power) for 3 seconds.
brake(2);
motorspeed(1,35);
goForit(3);
// Brake all motors
brake(1);
// Reverse direction of motor 1
reverse(1);
//Accelerate motor one from start to 19% in 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);
goForit(2);
motorspeed(1,19);
goForit(2);
// Run mtors at a constant speed of 19% for 2 second
motorspeed(1,19);
goForit(2);
motorspeed(2,19);
goForit(2);
// Decelerate both motors to 0% power in 3 seconds.
celerate(1,19,0,3);
celerate(2,19,0,3);
// Brake all motors
brake(1);
brake(2);
} // DO NOT REMOVE. end of void myCode()
PERFORMANCE TEST 1:
// Accelerate both motors from 0 to 10
motorSpeed(4,35);
goToAbsolutePosition(-247);
reverse(4);
// decelerate motors
motorSpeed(4,60);
goFor(1);
//cut power to motors
brake(4);
goFor(8);
//reverse motors to move forward
reverse(4);
//Move ahead again to the end of track
motorSpeed(4,20);
goFor(2);
PERFORMANCE TEST 2:
// Accelerate both motors from 0 to 10
motorSpeed(4,35);
goToAbsolutePosition(-257);
reverse(4);
// decelerate motors
motorSpeed(4,60);
goFor(1);
//cut power to motors
brake(4);
goFor(10);
//reverse motors to move forward
reverse(4);
//Move ahead again to the end of track
motorSpeed(4,33);
goFor(2.5);
//brake motors
brake(4);
goFor(10);
//start moving the other way
reverse(4);
motorSpeed(4,55);
goFor(4);
brake(4);
Final Performance Test
goToAbsolutePosition(-257);
motorSpeed(4,60);
goFor(1);
brake(4);
goFor(10);
reverse(4);
motorSpeed(4,33);
goFor(2.5);
brake(4);
goFor(10);
//start moving the other way
reverse(4);
motorSpeed(4,55);
goToRelativePosition(244);
reverse(4);
motorSpeed(4,60);
goFor(1);
brake(4);
goFor(9);
reverse(4);
motorSpeed(4,60);
goFor(2.2);
motorSpeed(4,15);
goToRelativePosition(245);
reverse(4);
motorSpeed(4,55);
goFor(1);
brake(4);