Arduino Codes

This page contains a list of all the Arduino Codes used for the various tests and activities conducted during lab.

Basic Call Functions:
______________________________________________________________________

  • // Accelerate or decelerate motor(s)
    • celerate(M,P1,P2,T);
  • // Initialize motor at percent power
    • motorSpeed(M,P);
  • // Run motor at set speed for T seconds
    • goFor(T);
  • // Brake the motors
    • brake(M);
  • // Reverse the polarity of the motor(s)
    • reverse(M);
  • // Continues previous command for the relative marks
    • goToRelativePosition(N);
  • // Continues previous command for the marks relative to overall start
    • goToAbsolutePosition(N);

Programming Basics: Scenario 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 two.
    • brake(2);
  • // Reverse the direction of only 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);
  • // Reverse the direction of motor one.
    • 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);

Reflectance Sensors
______________________________________________________________________ 

  • // Run all motors at a constant speed (25% power) for 2 seconds.
    • motorSpeed(4,25);
    • goFor(2);
  • // Run all motors at a constant speed of 20% for a distance of 12 feet.
    • motorSpeed(4,20);
    • goToAbsolutePosition(295);
  • // Reverse Motors & run at a constant speed of 30% power for 1.5 seconds.
    • reverse(4);
    • motorSpeed(4,30);
    • goFor(1.5);
  • //Brake all motors
    • brake(4);

Design Analysis Tool
______________________________________________________________________ 

  • //AEV went backwards.
    • reverse(4);
  • //Accelerate all motors from start to 25% in 3 seconds.
    • celerate(4,0,25,3);
  • //Run all motors at a constant speed for 1 second.
    • motorSpeed(4,25);
    • goFor(1);
  • //Run all motors at 20% power for 2 seconds.
    • motorSpeed(4,20);
    • goFor(2);
  • //Reverse all motors and run at a constant speed 25% power for 2 seconds.
    • reverse(4);
    • motorSpeed(4,25);
    • goFor(2);
  • //Brake all motors.
    • brake(4);

Track Variance
______________________________________________________________________ 

  • //Motor went backwards.
    • reverse(4);
  • //Accelerate all motors from start to 25% in 3 seconds.
    • celerate(4,0,30,3);
  • //Run all motors at a constant speed for 160 inches.
    • motorSpeed(4,30);
    • goToAbsolutePosition(185);
  • //Brake all motors.
    • brake(4);

Performance Test 1: Design A
 ______________________________________________________________________ 

  • //Motor went backwards.
    • reverse(4);
  • //Accelerate all motors from start to 25% in 3 seconds.
    • celerate(4,0,30,3);
  • //Run all motors at a constant speed for 160 inches.
    • motorSpeed(4,30);
    • goToAbsolutePosition(174);
  • //Brake all motors.
    • brake(4);
  • //Stop at the gate for 7 seconds
    • goFor(13);
  • //Run all motors to loading gate
    • motorSpeed(4,30);
    • goFor(2);
  • //Brake all motors.
    • brake(4);

Performance Test 1: Design B
______________________________________________________________________ 

  • //Motor went backwards.
    • reverse(4);
  • //Accelerate all motors from start to 25% in 3 seconds.
    • celerate(4,0,30,3);
  • //Run all motors at a constant speed for 160 inches.
    • motorSpeed(4,30);
    • goToAbsolutePosition(198);
  • //Brake all motors.
    • brake(4);
  • //Stop at the gate for 7 seconds
    • goFor(11);
  • //Run all motors to loading gate
    • motorSpeed(4,30);
    • goFor(2);
  • //Brake all motors.
    • brake(4);

Performance Test 2: Code A
______________________________________________________________________ 

  • //Motor went backwards.
    • reverse(4);
  • //Accelerate all motors from start to 25% in 3 seconds.
    • celerate(4,0,30,3);
  • //Run all motors at a constant speed up the first incline.
    • motorSpeed(4,30);
    • goToAbsolutePosition(194);
  • //Brake all motors.
    • brake(4);
    • goFor(1);
  • //Decelerate the AEV to stop at the gate
    • reverse(4);
    • celerate(4,30,0,2);
  • //Wait at the gate for 7 seconds
    • brake(4);
    • goFor(8);
  • //Run all motors to loading gate
    • reverse(4);
    • motorSpeed(4,32);
    • goFor(2);
  • //Brake all motors and pickup load.
    • brake(4);
    • goFor(10);
  • //Accelerate back with the caboose after loading.
    • reverse(4);
    • celerate(4,0,50,7);
  • //Run motors back up the second incline to the gate.
    • motorSpeed(4,50);
    • goFor(5);
  • //Brake all motors
    • brake(4);

Performance Test 2: Code B
______________________________________________________________________ 

  • //Motor went backwards.
    • reverse(4);
  • //Accelerate all motors from start to 25% in 3 seconds.
    • celerate(4,0,30,3);
  • //Run all motors at a constant speed up the first incline.
    • motorSpeed(4,30);
    • goToAbsolutePosition(190);
  • //Brake all motors.
    • brake(4);
    • goFor(1);
  • //Stop at the gate for 7 seconds
    • brake(4);
    • goFor(11);
  • //Run all motors to loading gate
    • reverse(4);
    • motorSpeed(4,30);
    • goFor(2);
  • //Brake all motors and attach to pickup load.
    • brake(4);
    • goFor(7);
  • //Return up track with load
    • reverse(4);
    • celerate(4,0,50,7);
    • motorSpeed(4,50);
    • goFor(3);
    • brake(4);

Performance Test Final:
______________________________________________________________________

  • //Motor went backwards.
    • reverse(4);
  • //Accelerate all motors from start to 25% in 3 seconds.
    • celerate(4,0,30,3);
  • //Run all motors at a constant speed up the first incline.
    • motorSpeed(4,30);
    • goToAbsolutePosition(193);
  • //Brake all motors.
    • brake(4);
    • goFor(1);
  • //Decelerate the AEV to stop at the gate
    • reverse(4);
    • celerate(4,30,0,2);
  • //Wait at the gate for 7 seconds
    • brake(4);
    • goFor(8);
  • //Run all motors to loading gate
    • reverse(4);
    • motorSpeed(4,30);
    • goFor(2);
  • //Brake all motors and pickup load.
    • brake(4);
    • goFor(10);
  • //Accelerate back with the caboose after loading.
    • reverse(4);
    • celerate(4,0,50,6);
  • //Run motors back up the second incline to the gate.
    • motorSpeed(4,50);
    • goToRelativePosition(-156);
  • //Decelerate to stop at gate
    • reverse(4);
    • celerate(4,50,0,2.5);
  • //Wait at the gate for 7 seconds
    • brake(4);
    • goFor(5);
  • //Brake all motors
    • brake(4);
  • //Run all motors through the gate
    • reverse(4);
    • celerate(4,0,50,6);
    • motorSpeed(4,50);
    • goFor(2.25);
  • //Cut Power to motors
    • brake(4);
    • goFor(1.75);
  • //Slow the Caboose to rest
    • reverse(4);
    • celerate(4,56,0,2);