Arduino Programming Basics Arduino Code
-This code was created in order to familiarize the team with all possible commands available to control the AEV with.
celerate(1,0,15,2.5); // Increase motor 1 from 0 to 15% in 2.5 sec.
motorSpeed(1,15); // Run motor 1 at 15% power for 1 sec.
goFor(1);
brake(1); // Brake motor 1
celerate(2,0,27,4); // Accelerate motor 2 from start to 27% power in 4 sec.
motorSpeed(2,27); // Run motor 2 at 27% power for 2.7 sec.
goFor(2.7);
celerate(2,27,15,1); // Decelerate motor 2 to 15% power in 1 sec.
brake(2); // Brake motor 2
reverse(2); // Reverse direction of motor 2
celerate(4,0,31,2); // Accelerate all motors from start to 31% power in 2 sec.
motorSpeed(4,,35);
goFor(1); // Run all motors at 35% for 1 sec.
brake(2); // Brake motor 2 but keep motor
motorSpeed(1,35) 1 running at 35% power for 3 sec.
goFor(3);
brake(4); // Brake all motors for 1 sec.
goFor(1);
reverse(1); // Reverse motor 1
celerate(1,0,19,2); // Accelerate motor 1 from start to 19% power over 2 sec.
motorSpeed(2,35); // Run motor 2 at 35% and run motor 1 at 19% for 3 sec.
goFor(2);
motorSpeed(1,19);
goFor(2);
motorSpeed(4,19); // Run both motors at 19% power for 2 seconds
goFor(2);
celerate(4,19,0,3); //Decelerate both motors to 0% in 3 sec.
brake(4); // Brake all motors
Arduino Code for Performance Test 1
-This code was created so that two AEV designs could be tested with it on the track to determine which vehicle completed the program most efficiently
reverse(4); // reverse all motors so that the AEV runs in
push configuration
motorSpeed(4,20); // run all motors at 20% power until the AEV
goToAbsolutePosition(-430); reaches an absolute position of -430 marks
reverse(4); // reverse all motors so that the AEV runs in
pull configuration
motorSpeed(4,15); // run all motors at 15% power for 3 seconds
goFor(3); .
brake(4); // brake all motors
Arduino Code #1 for Performance Tests 2 and 3
-This code was created to utilize coasting and a low motor speed
reverse(4); //Reverse all motors
celerate(4,0,23,2); //Accelerate all motors from 0 to 23% power in 2 sec
motorSpeed(4,23); //Run all motors at 23% power.
goToAbsolutePosition(-362); //Go to an absolute position of -362 marks.
reverse(4); //Reverse all motors.
celerate(4,23,0,5); //Accelerate all motors from 23 to 0% power in 5 sec
brake(4); //Brake all motors
goFor(7); //Go for 7 seconds
//Stop at gate
reverse(4); //Reverse all motors
motorSpeed(4,23); //Run all motors at 23 % power
goToRelativePosition(-338); //Go to a relative position of of -338 marks
brake(4); //Brake all motors
goFor(10); //Go for 10 seconds
//Pick-up Cargo
reverse(4); //Reverse all motors.
celerate(4,0,35,2); //Accelerate all motors from 0 to 35% power in 2 sec
motorSpeed(4,35); //Run all motors at 35% power
goToRelativePosition(355); //Go to a relative position of 355.
brake(4); //Brake all motors
goFor(8); //Go for 8 seconds
//Stop at gate
celerate(4,0,35,2); //Accelerate all motors from 0 to 35% power in 2 sec
motorSpeed(4,35); //Run all motors at 35% power
goToRelativePosition(355); //Go to a relative position of 355 marks
brake(4); //Brake all motors
Arduino Code #2 for Performance Tests 2 and 3
-This code was created to utilize a reverse thrust braking method and a higher overall motor speed
reverse(4); //Reverse all motors.
celerate(4,0,30,2); //Accelerate all motors from 0 to 30% in 2 sec
motorSpeed(4,30); //Run all motors at 30% power
goToAbsolutePosition(-368); //Go to an absolute position of -240
//Brake for gate.
reverse(4); //Reverse all motors
motorSpeed(4,30); //Run all motors from 30 power for 2 seconds
goFor(2);
//Stop at Gate First Time
brake(4); //Brake all motors
goFor(9); //Go for 9 seconds
reverse(4); //Reverse all motors
motorSpeed(4,30); //Run all motors at 30 % power
goToRelativePosition(-390); //Go to a relative position of of -350
//Brake for Cargo.
reverse(4); //Reverse all motors
motorSpeed(4,30); //Run all motors at 30 power for 2 seconds
goFor(2);
brake(4); //Brake all motors for 7 seconds.
goFor(7);
//Pick Up Cargo
celerate(4,0,45,2); //Accelerate all motors from 0 to 45 % in 2 sec
motorSpeed(4,45); //Run all motors at 45% power
goToRelativePosition(330); //Go to a relative position of 355
//Brake for gate second time
reverse(4); //Reverse all motors.
motorSpeed(4,45); //Set all motors to run at 45% power for 3 sec
goFor(3);
brake(4); //Brake all motors for 8 seconds
goFor(8);
//Stopped at gate second time.
reverse(4);
celerate(4,0,45,2); //Accelerate all motors from 0 to 45% in 2 sec
motorSpeed(4,45); //Run all motors at 45% power
goToRelativePosition(345); //Go to a relative position of 360.
//Brake for final stop.
reverse(4); //Reverse all motors
motorSpeed(4,45); //Run all motors at 45% power for 3 sec
goFor(3);
brake(4); //Brake all motors.
Final Arduino Code
-This code was written to complete the MCR
reverse(4); //Reverse all motors.
celerate(4,0,23,2); //Accelerate all motors from 0 power to 23 in 2
seconds.
motorSpeed(4,23); //Run all motors at 23% power.
goToAbsolutePosition(-394); //Go to an absolute position of -394 marks.
reverse(4); //Reverse all motors.
celerate(4,23,0,5); //Accelerate all motors from 23 to 0% power in 5 seconds.
brake(4); //Brake all motors.
goFor(6.5); //Go for 6.5 seconds.
//Stopped at Gate First Time
reverse(4); //Reverse all motors.
motorSpeed(4,23); //Run all motors at 23 % power.
goToRelativePosition(-317); //Go to a relative position of of -317 marks.
brake(4); //Brake all motors.
goFor(10); //Go for 10 seconds
//Pick-Up Cargo
reverse(4); //Reverse all motors.
celerate(4,0,35,2); //Accelerate all motors from 0 to 35 power in 2 seconds.
motorSpeed(4,35); //Run all motors at 35% power.
goToRelativePosition(336); //Go to a relative position of 336 marks.
reverse(4); //Reverse all motors.
celerate(4,40,0,2.5); //Accelerate all motors from 40 to 0% power in 2.5 seconds.
brake(4); //Brake all motors.
goFor(7.5); //Go for 7.5 seconds.
//Stopped at Gate Second Time
reverse(4); //Reverse all motors.
celerate(4,0,40,2); //Accelerate all motors from 0 to 40% power in 2 seconds.
motorSpeed(4,35); //Run all motors at 35% power.
goToRelativePosition(330); //Go to a relative position of 330 marks.
reverse(4); //Reverse all motors
celerate(4,23,0,3); //Accelerate all motors from 23 to 0% power in 3 seconds
brake(4); //Brake all motors.
//Run Finished