Arduino Code

Glossary of Arduino Functions


  • celerate(m,p1,p2,t) – Changes the speed of the motor(s) m from p1 to p2 over a duration t.
  • motorSpeed(m,p) – Initializes motor(s) m at a percent power p.
  • goFor(t) – Runs the motor(s) at their initialized state for t second
  • brake(m) – Brakes motor(s) m.
  • reverse(m) – Reverses the polarity of motor(s) m.
  • goToRelativePosition(n) – Continues the previous command for n marks from the vehicle’s current position. n can be positive of negative (forward or backward) respectively.
  • goToAbsolutePosition(n) – Continues the previous command for n marks relative to the overall starting position of the AEV.

 

*Note that every line beginning with “//” is a comment and has no functionality in AEV performance*

 

Preliminary R&D Code


Exercise #1:

Programming Basics

//start

//begins to move forward on motor 1

celerate(1,0,15,2.5);

motorSpeed(1,15);

goFor(1);

 

//brake motor 1 only

brake(1);

 

//begins to move motor 2 forward

celerate(2,0,27,4);

motorSpeed(2,27);

goFor(2.7);

celerate(2,27,15,1);

 

//brake motor 2 only

brake(2);

 

//run both motors in reverse

reverse(2);

celerate(4,0,31,2);

motorSpeed(4,35);

goFor(1);

 

//brakes both motors

brake(2);

 

//run motor 1

motorSpeed(1,35);

goFor(3);

 

//brakes motors

brake(4);

goFor(1);

 

//run both motors in opposite directions

reverse(1);

celerate(1,0,19,2);

motorSpeed(2,35);

motorSpeed(1,19);

goFor(2);

motorSpeed(4,19);

celerate(4,19,0,3);

 

//brakes motors

brake(4);

//stop

Exercise #2:

External Sensors Outside Program: Reflective Sensor Test

//start

//run both motors

motorSpeed(4,25);

go for(2);

motorSpeed(4,20);

goToAbsolutePosition(70.2);

 

//reverse both motors  and run

reverse(4);

motorSpeed(4,30);

goFor(1.5);

 

//brake both motors

brake(4);

//stop

 Exercise #4:

Design Analysis Tool

//start

//run both motors

celerate(4,0,25,3);

motorSpeed(4,25);

goFor(1);

motorSpeed(4,20);

goFor(2);

 

//reverse both motors and run

reverse(4);

motorSpeed(4,25);

goFor(2);

 

//brake both motors

brake(4);

//stop

 

Advanced R&D Code


Exercise #1:

Battery Testing Code

//start

//run both motors

reverse(4);

celerate(4,0,25,3);

motorSpeed(4,25);

goFor(1);

motorSpeed(4,20);

goFor(2);

 

//power braking for both motors

reverse(4);

motorSpeed(4,25);

goFor(2);

brake(4);

//stop

 

  • This is the secondary code we used when testing with one motor only

//start

//run the motor

reverse(1);

celerate(1,0,30,3);

motorSpeed(1,30);

goFor(1);

motorSpeed(1,25);

goFor(2);

 

//power braking for the motor

reverse(1);

motorSpeed(1,35);

goFor(2);

brake(1);

//stop

Exercise #2:

Energy Analysis

//start

//run both motors

motorSpeed(4,25);

goFor(4);

 

//sets motor speed to zero on both motors

motorSpeed(4,0);

goFor(10);

//stop

 

Performance Test #1:


//start

//run both motors

reverse(4);

celerate(4,0,25,1);

motorSpeed(4,25);
goToRelativePosition(247);

motorSpeed(4,10);
goToRelativePosition(30);

 

//power braking before first stop

reverse(4);

motorSpeed(4,40);
goFor(1);

 

//waits for sign to raise

brake(4);
goFor(8);

 

//runs motors to the end to pick up load

reverse(4);

motorSpeed(4,20);
goToRelativePosition(280);

 

//leaves the landing zone

reverse(4);

motorSpeed(4,10);
goFor(1);

//stop

 

Performance Test #2:


//start

//runs motors to first stop sign

reverse(4);

celerate(4,0,25,1);

motorSpeed(4,30);
goToRelativePosition(220);

motorSpeed(4,10);
goToRelativePosition(30);

 

//power braking

reverse(4);

motorSpeed(4,40);
goFor(1);

brake(4);
goFor(8);

 

//after first stopsign
reverse(4);

motorSpeed(4,20);
goToRelativePosition(240);

 

//power braking

reverse(4);

motorSpeed(4,30);
goFor(1);

 

//waits to leave landing

brake(4);
goFor(5);

motorSpeed(4,45);
goToRelativePosition(-220);

 

//power braking

reverse(4);

motorSpeed(4,40);
goFor(1);

brake(4);
goFor(8);

 

// second stopsign

reverse(4);

motorSpeed(4,60);
goToRelativePosition(-150);

 

//power braking at the end of the run

reverse(4);

motorSpeed(4,40);
goFor(1);

//stop

 

Performance Test #3 (Final):


  • This is the code that all energy and time costs is based on.

//start

//runs motors to first stop sign

reverse(4);

celerate(4,0,25,1);

motorSpeed(4,28);
goToRelativePosition(220);

motorSpeed(4,15);
goToRelativePosition(30);

 

//power braking

reverse(4);

motorSpeed(4,35);
goFor(1.5);

 

//waits at stop sing

brake(4);
goFor(7.5);

 

//after first stop sign move down incline
reverse(4);

motorSpeed(4,25);
goToRelativePosition(180);

 

//power braking

reverse(4);

motorSpeed(4,30);
goFor(1.5);

 

//wait to move after attached to cargo load and return to stop sign

brake(4);
goFor(5);

motorSpeed(4,45);
goToRelativePosition(-260);

 

//power braking

reverse(4);

motorSpeed(4,30);
goFor(1.5);

 

//wait for second stop and then goes back down incline

brake(4);
goFor(8);

reverse(4);

motorSpeed(4,60);
goToRelativePosition(-55);

 

//wait and then power brake

reverse(4);

motorSpeed(4,0);
goToRelativePosition(-175);

motorSpeed(4,28);
goFor(1.5);

//stop