Lab Code

This page contains the code from Labs 1, 2, 4, and 5, in ascending order, below.

Lab 1:

Scenario 1
Line 1 celerate(1, 0, 15, 2.5);
Line 2 goFor(1);
Line 3 brake(1);
Line 4 celerate(2, 0, 27, 4);
Line 5 goFor(2.7);
Line 6 celerate(2, 27, 15, 1);
Line 7 brake(1);
Line 8 reverse(2);
Line 9 celerate(4, 0, 31, 2);
Line 10 goFor(1);
Line 11 brake(2);
Line 12 goFor(3);
Line 13 brake(4);
Line 14 goFor(1);
Line 15 reverse(1);
Line 16 celerate(1, 0, 19, 2);
Line 17 motorSpeed(2, 35);
Line 18 goFor(2);
Line 19 motorSpeed(2, 19);
Line 20 goFor(2);
Line 21 celerate(4, 19, 0, 3);
Line 22 brake(4);
Scenario 2
Line 1 reverse(4);
Line 2 motorSpeed(4,25);
Line 3 goFor(0.5);
Line 4 brake(4);
Line 5 goFor(0.1);
Line 6 motorSpeed(4,25);
Line 7 goFor(0.5);
Line 8 brake(4);
Line 9 goFor(0.1);
Line 10 motorSpeed(4,25);
Line 11 goFor(0.5);
Line 12 brake(4);
Line 13 goFor(0.1);
Line 14 motorSpeed(4,15);
Line 15 goFor(0.3);
Line 16 brake(4);
Line 17 goFor(0.05);
Line 18 motorSpeed(4,40);
Line 19 goFor(0.3);
Line 20 motorSpeed(4,25);
Line 21 goFor(0.5);
Line 22 motorSpeed(4,15);
Line 23 goFor(0.3);
Line 24 brake(4);
Line 25 goFor(0.05);
Line 26 motorSpeed(4,40);
Line 27 goFor(0.3);
Line 28 motorSpeed(4,25);
Line 29 goFor(0.5);
Line 30 brake(4);
Line 31 goFor(0.5);
Line 32 motorSpeed(4,55);
Line 33 goFor(0.5);
Line 34 brake(4);
Line 35 goFor(0.1);
Line 36 motorSpeed(4,55);
Line 37 goFor(0.5);
Line 38 brake(4);
Line 39 goFor(0.1);
Line 40 motorSpeed(4,55);
Line 41 goFor(0.5);
Line 42 brake(4);
Line 43 goFor(0.1);
Line 44 motorSpeed(4,65);
Line 45 goFor(0.05);
Line 46 motorSpeed(4,40);
Line 47 goFor(0.3);
Line 48 motorSpeed(4,25);
Line 49 goFor(0.5);
Line 50 motorSpeed(4,15);
Line 51 goFor(0.3);
Line 52 brake(4);
Line 53 goFor(0.05);
Line 54 motorSpeed(4,40);
Line 55 goFor(0.3);
Line 56 motorSpeed(4,25);
Line 57 goFor(0.5);
Line 58 brake(4);

 

Lab 2:

Line Numbers Code
Line 1 motorSpeed(4, 25);
Line 2 goFor(2);
Line 3 motorSpeed(4, 20);
Line 4 goToAbsolutePosition( (int) (16 * 12 * 0.4875))
Line 5 reverse(4);
Line 6 motorSpeed(4, 30);
Line 7 goFor(1.5);
Line 8 break(4);

 

Lab 4:

Table 01-Phase Analysis and Arduino Code
Phase Arduino Code Distance

(m)

Time (seconds)

From Data

Total Energy in Joules for that Phase
1  reverse(4);

 // going to the gate

 motorSpeed(4, 25);

 goFor(5);

 //goToRelativePosition ((int) (10 * 12) / (0.4875));

 brake(4);

0 0–4.983 30.504
2 goFor(10); // wait at gate 1st time 0 5.043–15.063 0.936
3  motorSpeed(4, 25); //load cargo

 goFor(5);

 //goToRelativePosition ((int) (10 * 12) / (0.4875));

 brake(4);

0 15.123–20.043 30.403
4 goFor(8); // wait for loading 0 20.103–28.023 0.204
5   reverse(4); // go back to gate

  motorSpeed(4, 25);

  goFor(5);

 //goToRelativePosition ((int) (10 * 12) / (0.4875));

0 28.083–33.003 27.398
6 //wait at gate 2rn time

 brake(4);

 goFor(10);

0 33.063–43.023 0.215
7 //go back

  motorSpeed(4, 25);

  goFor(5);

 //goToRelativePosition ((int) (10 * 12) / (0.4875));

 brake(4); // at gate

0 43.083–48.063 27.882
Total Energy Used: 117.542 Joules

 

Lab 5:

 reverse(1);  

 motorSpeed(4,25);

 goFor(5);    

 brake(4);

Lab 8:

void myCode()

{

 // Define all Constants

 float IN_PER_MARK = (0.4875);

 //Measurements for track

 float ftToGate = 16; // lab man said 19

 float ftToR2 = 16;

 float ftBackToGate = 16;

 float ftBackToStart = 16;

 //waiting times

 float timeToWait = 9;

 float timeToWait2 = 8;

 float timeAtR2 = 6;

 //Clalcualtions for marks

 int marksToGate = (int) ((ftToGate * 12) / IN_PER_MARK);

 int marksToR2 =(int) ((ftToR2 * 12) / IN_PER_MARK);

 int marksBackToGate = (int) ((ftBackToGate * 12) / IN_PER_MARK);

 int marksBackToStart = (int) ((ftBackToStart * 12) / IN_PER_MARK);

 //UNLIMITED POWER!!!!!

 int mSpeed = 25;

 //Code starts here

 reverse(4);

 moveToPosition(mSpeed, marksToGate, timeToWait);

 moveToPosition(mSpeed, marksToR2, timeAtR2);

 

 reverse(4);

 

 moveToPosition(mSpeed, marksBackToGate, timeToWait2);

 moveToPosition(mSpeed,marksBackToStart, 0);

 

} // DO NOT REMOVE. end of void myCode()+

void moveToPosition(int mSpeed, int distance, float time2Wait){

 motorSpeed(4, mSpeed);

 goToRelativePosition(distance);

 brake(4);

 goFor(time2Wait);

}