Day 1 Code: Getting Familiar with Arduino and Sketchbook
// Run motor one at a constant speed (15% power) for 1 second.
celerate(1,0,15,2.5);
motorSpeed(1,15);
goFor(1);
// Brake motor one.
brake(1);
//Accelerate motor two from start to 27 percent power in 4 seconds
celerate(2,0,27,4);
//Decelerate motor 2 at a constant speed in one second
celerate(2,27,15,1);
//Brake Motor 2
brake(2);
//Reverse direction for motor 2
reverse (2);
//Accelerate all motors for 2 seonds
celerate (1,0,31,2);
celerate (2,0,31,2);
Code Used to Test Reflectance Sensors:
//Accelerate all motors at 25 percent for 3 seconds
celerate (4,0,25,3);
//Run all motors at 25percent power for 1 second
motorSpeed(4,25);
goFor(1);
// Accelerate all motors at 20 percent for 2 seconds
celerate(4,0,20,2);
//Reverse all motors
reverse (4);
//Run all motors at 25 percent power for 2 seconds
motorSpeed(4,25);
goFor(2);
//Brake all 4 motors
brake(4);
Data Analysis Tool:
// (1) Motorspeed (all) set to 25% power & run for 2 seconds
motorSpeed(4, 25);
goFor(2);
// (2) Motorspeed (all) set to 20% & moved to absolute position of 12 feet (144 inches)
motorSpeed(4, 20);
goToAbsolutePosition((12.0*12.0)/.4875);
// (3) Reverse (all)
reverse(4);
// (4) Set motorspeed (all) to 30% power & run for 1.5 seconds
motorSpeed(4, 30);
goFor(1.5);
// (5) Brake (all) motors
brake(4);
Reflectance Sensor Test:
/*
* Reflectance Test
*/
// 1. Check that the battery is plugged in and the board is turned on.
// 2. Open Arduino software: Start → All Programs.
// 3. Set sketchbook preferences if needed.
// 4. Type in “reflectanceSensorTest();” into 01_myCode
reflectanceSensorTest();
// 5. Connect the Arduino controller using the USB cord provided and upload the code to the Arduino. NOTE: Keep the Arduino controller connected to the computer throughout this test.
// 6. When the code is uploaded, open the serial monitor: Tools → Serial Monitor.
// 7. Set the monitor to 115200 baud, located on the bottom of the serial monitor. Once the serial monitor is open, there should be a series of “1” scrolling.
// 8. Press the start button on the Arduino board and after 4 seconds, spin the wheel on your AEV. There should be numbers (marks) increasing or decreasing by 1 and whether the system is moving forward or reverse. If this is not what is seen, go back over Installing Reflectance Sensors and check the work. If there are problems that still occur then refer to the troubleshooting section.
// 9. Orient the sensors appropriately. If the vehicle is moving in the forward direction but the marks are decreasing, then the sensors connections on the Arduino controller need to be switched.
Performance Test 1:
/*
* Performance Test
*/
/*
* MISSION CRITICAL MEASUREMENTS:
* Distance from level_1 to slope_1: 6 ft 72 in 147.692 marks
Distance from slope_1 to level_2: N/A 48.042 in 98.548 marks
OPTIMAL STOPPING POSITION: (target – 3 inches) = 82.051 marks
Distance from level_2 to gate_stop: N/A 43 in 88.205 marks
Distance from gate_stop to slope_2: N/A 53 in 108.718 marks
Distance from slope_2 to level_3: N/A 48.01 in 98.482 marks
Distance from level_3 to end: 6 ft 72 in 147.692 marks
Inches to Marks: 0.4875in / Mark
Marks = inches/.4875in
*/
//Let’s try working with a consistant 25% power at first, maybe increase/decrease by 5% for slopes
reverse(4);
// 1. Run all motors at 25% from Beginning to base of first slope
motorSpeed(4, 30);
goToRelativePosition(147.692);
// 2. Run all motors at a constant speed of 35% (slow down on slope) for length of the slope
motorSpeed(4, 35);
goToRelativePosition(98.548);
// 3. Run motors to optimal stopping point & brake all motors
goToRelativePosition(28.051);
reverse(4);
motorSpeed(4, 40);
goFor(.75);
reverse(4);
brake(4);
goFor(8);
// 4. Run all motors at constant speed of 20% to beginning of second slope
motorSpeed(4, 25);
goToRelativePosition(40);
//108.718
Performance Test 2:
/*
* Performance Test
*/
/*
* MISSION CRITICAL MEASUREMENTS:
* Distance from level_1 to slope_1: 6 ft 72 in 147.692 marks
Distance from slope_1 to level_2: N/A 48.042 in 98.548 marks
OPTIMAL STOPPING POSITION: (target – 3 inches) = 82.051 marks
Distance from level_2 to gate_stop: N/A 43 in 88.205 marks
Distance from gate_stop to slope_2: N/A 53 in 108.718 marks
Distance from slope_2 to level_3: N/A 48.01 in 98.482 marks
Distance from level_3 to end: 6 ft 72 in 147.692 marks
Inches to Marks: 0.4875in / Mark
Marks = inches/.4875in
*/
//Let’s try working with a consistant 30% power at first, maybe increase/decrease by 5% for slopes
reverse(4);
// 1. Run all motors at 30% from Beginning to base of first slope
motorSpeed(4, 30);
goToRelativePosition(147.692);
// 2. Run all motors at a constant speed of 35% (slow down on slope) for length of the slope
motorSpeed(4, 35);
goToRelativePosition(98.548);
// 3. Run motors to optimal stopping point & brake all motors
goToRelativePosition(25.051);
reverse(4);
motorSpeed(4, 40);
goFor(.75);
reverse(4);
brake(4);
goFor(8);
// 4. Run all motors at constant speed of 25% to beginning of second slope
motorSpeed(4, 25);
goToRelativePosition(100);
//108.718
// 5. Run all motors at 15% down the slope
motorSpeed(4, 15);
goToRelativePosition(98.482);
// 6. Run motors at 20% power and stop close to end of track
motorSpeed(4, 20);
goToRelativePosition(110);
// 7. Brake to a near stop and coast to caboose pickup
reverse(4);
motorSpeed(4, 35);
goFor(.5);
brake(4);
goFor(5);
// RUN ALL PROCEEDING MOTORSPEEDS AT +5% TO COMPENSATE FOR ADDED MASS
- Run vehicle at 35% to approximate base of second slope
motorSpeed(4, 35);
goToRelativePosition(-115);
Final Performance Test Room 308:
/*
* Performance Test
*/
/*
* MISSION CRITICAL MEASUREMENTS:
* Distance from level_1 to slope_1: 6 ft 72 in 147.692 marks
Distance from slope_1 to level_2: N/A 48.042 in 98.548 marks
OPTIMAL STOPPING POSITION: (target – 3 inches) = 82.051 marks
Distance from level_2 to gate_stop: N/A 43 in 88.205 marks
Distance from gate_stop to slope_2: N/A 53 in 108.718 marks
Distance from slope_2 to level_3: N/A 48.01 in 98.482 marks
Distance from level_3 to end: 6 ft 72 in 147.692 marks
Inches to Marks: 0.4875in / Mark
Marks = inches/.4875in
*/
//Reversing the motor direction to compensate for the starting orientation of AEV.
reverse(4);
// 1. Set motor speed of all motors to 30% & run for approximately 147 marks from start to beginning of the first incline.
motorSpeed(4, 30);
goToRelativePosition(147.692);
// 2. Increase motor speed of all motors by 5% (to 35%) to compensate for incline & run for approximately 100 marks to the end of the first incline/beginning of the gate plateau.
motorSpeed(4, 35);
goToRelativePosition(100.548);
// 3. Continue running motors at same power for approximately 25 marks. Reverse all motors & increase motor speed to 40% power & run for .75 seconds to power brake the AEV.
// Reverse motor direction again to restore initial direction of movement, brake all motors & have AEV sit still for 8 seconds to allow the gate to open.
goToRelativePosition(25.051);
reverse(4);
motorSpeed(4, 40);
goFor(.75);
reverse(4);
brake(4);
goFor(8);
// 4. Increase motor speed of all motors to 25% & run for approximately 100 marks to pass through the gate to about the peak of the second incline.
motorSpeed(4, 25);
goToRelativePosition(100);
// 5. Decrease all motors speed by 10% (to 15%) to move approximately 98 marks down the second incline to its base without building too much momentum.
motorSpeed(4, 15);
goToRelativePosition(98.482);
// 6. Increase motor speed of all motors by 5% (to 20%) to move 110 marks towards the caboose carefully.
motorSpeed(4, 20);
goToRelativePosition(110);
// 7. Initiate another power brake. Reverse all motors and increase their motor speed to 35% & have it run for .5 seconds.
// Brake all motors again to end power brake & wait for 5 seconds after having attatched to the caboose.
reverse(4);
motorSpeed(4, 35);
goFor(.5);
brake(4);
goFor(5);
// 8. Increase motor speed of all motors to 35% & run for approximately -115 marks back to the base of the second incline.
motorSpeed(4, 35);
goToRelativePosition(-115);
// 9. Hold the speed of all motors by at 35% to move approximately -102 marks back up the second incline to its peak.
goToRelativePosition(-102.482);
// 10. Continue running at speed of 35% for approximately -35 marks & then initiate another power brake by reversing the direction of the motors,
// & increasing their speed to 45%, running for 1 second, correcting motor direction with another reverse, braking all motors once more & lastly waiting another 8 seconds for the gate to open.
goToRelativePosition(-35);
reverse(4);
motorSpeed(4, 45);
goFor(1);
reverse(4);
brake(4);
goFor(8);
// 11. Increase the speed of all motors to 35% and running for approximately -108 marks back to the peak of the first incline.
motorSpeed(4, 35);
goToRelativePosition(-108);
// 12. Brake all motors and allow the AEV to coast down the length of the first incline for approximately -98 marks to the base.
brake(4);
goToRelativePosition(-98.482);
// 13. Allow vehicle to coast -88 marks before initiating a powerbrake.
goToRelativePosition(-88);
// 14. Initiate the final power break; reversing all the motors, increasing motor speed to 45%, running for 1 seconds & lastly braking all motors to stop the AEV.
reverse(4);
motorSpeed(4, 45);
goFor(1.5);
brake(4);
Final Performance Test Room 224:
/*
* Performance Test
*/
/*
* MISSION CRITICAL MEASUREMENTS:
* Distance from level_1 to slope_1: 6 ft 72 in 147.692 marks
Distance from slope_1 to level_2: N/A 48.042 in 98.548 marks
OPTIMAL STOPPING POSITION: (target – 3 inches) = 82.051 marks
Distance from level_2 to gate_stop: N/A 43 in 88.205 marks
Distance from gate_stop to slope_2: N/A 53 in 108.718 marks
Distance from slope_2 to level_3: N/A 48.01 in 98.482 marks
Distance from level_3 to end: 6 ft 72 in 147.692 marks
Inches to Marks: 0.4875in / Mark
Marks = inches/.4875in
*/
//Reversing the motor direction to compensate for the starting orientation of AEV.
reverse(4);
// 1. Set motor speed of all motors to 30% & run for approximately 147 marks from start to beginning of the first incline.
motorSpeed(4, 30);
goToRelativePosition(147.692);
// 2. Increase motor speed of all motors by 5% (to 35%) to compensate for incline & run for approximately 100 marks to the end of the first incline/beginning of the gate plateau.
motorSpeed(4, 35);
goToRelativePosition(100.548);
// 3. Continue running motors at same power for approximately 25 marks. Reverse all motors & increase motor speed to 40% power & run for .75 seconds to power brake the AEV.
// Reverse motor direction again to restore initial direction of movement, brake all motors & have AEV sit still for 8 seconds to allow the gate to open.
goToRelativePosition(25.051);
reverse(4);
motorSpeed(4, 40);
goFor(.75);
reverse(4);
brake(4);
goFor(8);
// 4. Increase motor speed of all motors to 25% & run for approximately 100 marks to pass through the gate to about the peak of the second incline.
motorSpeed(4, 25);
goToRelativePosition(100);
// 5. Decrease all motors speed by 10% (to 15%) to move approximately 98 marks down the second incline to its base without building too much momentum.
motorSpeed(4, 15);
goToRelativePosition(98.482);
// 6. Increase motor speed of all motors by 5% (to 20%) to move 110 marks towards the caboose carefully.
motorSpeed(4, 20);
goToRelativePosition(112);
// 7. Initiate another power brake. Reverse all motors and increase their motor speed to 35% & have it run for .5 seconds.
// Brake all motors again to end power brake & wait for 5 seconds after having attatched to the caboose.
reverse(4);
motorSpeed(4, 35);
goFor(.5);
brake(4);
goFor(5);
// 8. Increase motor speed of all motors to 35% & run for approximately -115 marks back to the base of the second incline.
motorSpeed(4, 35);
goToRelativePosition(-115);
// 9. Hold the speed of all motors by at 35% to move approximately -102 marks back up the second incline to its peak.
goToRelativePosition(-102.482);
// 10. Continue running at speed of 35% for approximately -25 marks & then initate another power brake by reversing the direction of the motors,
// & increasing their speed to 45%, running for 1 second, correcting motor direction with another reverse, braking all motors once more & lastly waiting another 8 seconds for the gate to open.
goToRelativePosition(-25);
reverse(4);
motorSpeed(4, 45);
goFor(1);
reverse(4);
brake(4);
goFor(8);
// 11. Increase the speed of all motors to 35% and running for approximately -100 marks back to the peak of the first incline.
motorSpeed(4, 35);
goToRelativePosition(-100);
// 12. Brake all motors and allow the AEV to coast down the length of the first incline for approximately -98 marks to the base.
brake(4);
goToRelativePosition(-98.482);
// 13. Allow vehicle to coast -84 marks before initiating a powerbrake.
goToRelativePosition(-84);
// 14. Initiate the final power break; reversing all the motors, increasing motor speed to 45%, running for 1 seconds & lastly braking all motors to stop the AEV.
reverse(4);
motorSpeed(4, 45);
goFor(1.5);
brake(4);