Arduino Code

EXERCISE 1 (SCENARIO 1):

celerate(1,0,15,2.5);//accelerate motor 1 to 15 speed over 2.5 seconds

goFor(1);//run for 1 second

brake(1);//stop motor 1

celerate(2,0,27,4);//accelerate motor 2 to 27 speed over 4 seconds

goFor(2.7);//run for 2.7 seconds

celerate(2,27,15,1);//decelerate motor 2 from 27 to 15 speed over 1 second

brake(2);//stop motor 2

reverse(2);//change direction of motor 2

celerate(4,0,31,1);//accelerate all motors to 31 speed over 1 second

motorSpeed(4,35);//set all motors to 35 speed

brake(2);//brake motor 2

goFor(3);//go for 3 seconds

brake(1);//stop motor 1

goFor(1);//go for 1 second

reverse(1);//change the direction of motor 1

motorSpeed(1,35);//set motor 1 to 35 speed

motorSpeed(2,19);//set motor 2 to 19 speed

goFor(2);//run for 2 seconds

motorSpeed(1,19);//set motor 1 to 19 speed

goFor(2);//run motors for 2 seconds

celerate(4,19,0,3);//decelerate all motors from 19 to 0 speed over 3 seconds

brake(4);//brake all motors

 

EXERCISE 2:

//All motors running at 25% power for 2 seconds

motorSpeed(4,25);

goFor(2);

//Travel a distance of 12 feet at a constant speed with motors at 20%

motorSpeed(4,20);

goToAbsolutePosition(295.2);

//Reverse the motors

reverse(4);

//All motors running at 30% power for 1.5 seconds

motorSpeed(4,30);

goFor(1.5);

//Braking

brake(4);

 

EXERCISE 4:

celerate(4,0,25,3); //accelerate both motors to 25% in 3 seconds

motorSpeed (4,25);//both motors are at 25%

goFor(1);//all motors go for 1 second

motorSpeed(4,20);//set all motors to 20 speed

goFor(2);//all motors go for 2 seconds

reverse(4);//change direction of motors

motorSpeed(4,25);//set all motors to 25%

goFor(2);//run for 2 seconds

brake(4);//stop all motors

 

COASTING:

celerate(4,0,35,2);  //speed all motors up to 35 percent power over a period of 2 seconds

goFor(3);  //Allow motor to run for 3 seconds

brake(4);  //Stops motors

 

POWER BRAKING:

celerate(4,0,35,2); );  //speed all motors up to 35 percent power over a period of 2 seconds

goFor(4); //Allow motors to run for 4 seconds

reverse(4); //Change the direction of all motors

motorSpeed(4,30); //Initialize all motors to 30 percent speed

goFor(3);  //run initialized state for 3 seconds

 

ONE MOTOR:

motorSpeed(1,35); //Initialize motor 1 to 35 percent speed

goFor(2); //run initialized state for 2 seconds

brake(1); //brake motor 1

 

TWO MOTORS:

motorSpeed(2,35); //Initialize motor 2 to 35 percent speed

goFor(2); //run initialized state for 2 seconds

brake(2); //brake motor 2

 

1st PERFORMANCE TEST:

motorSpeed(4,30);  //set both motors to 30 power

goToRelativePosition(-185); //travel 185 marks

brake(4);

reverse(4);

motorSpeed(4,22);  //stop, change direction, and set both motors to 22 power

goToRelativePosition(-110); //travel 110 marks

brake(4);

goFor(9); //stop and wait for 9 sec

reverse(4);

motorSpeed(4,30); //reverse both motors and set speed to 30

goFor(2.5); //travel for 2.5 seconds

 

2nd PERFORMANCE TEST (DISTANCE):

motorSpeed(4,30);  //set both motors to 30 power

goToRelativePosition(-185); //travel 185 marks

brake(4);

reverse(4);

motorSpeed(4,22);  //stop, change direction, and set both motors to 22 power

goToRelativePosition(-110); //travel 110 marks

brake(4);

goFor(9); //stop and wait for 9 sec

reverse(4);

motorSpeed(4,30); //reverse both motors and set speed to 30

goFor(2.5); //travel for 2.5 seconds

brake(4);

goFor(10); //stop motors and wait for 10 seconds

reverse(4);

motorSpeed(4,59); //set motors to 59 speed

goFor(3); //run motors for 3 seconds

 

2nd PERFORMANCE TEST (TIME):

motorSpeed(4,30);  //set both motors to 30 power

goToRelativePosition(-185); //travel 185 marks

brake(4);

reverse(4);

motorSpeed(4,60); //stop, change direction and set both motors to 60 power

goFor(1);

brake(4); //run for 1 second and then stop

goFor(9); //stop and wait for 9 sec

reverse(4);

motorSpeed(4,30); //reverse both motors and set speed to 30

goFor(2.5); //travel for 2.5 seconds

brake(4);

goFor(10); //stop motors and wait for 10 seconds

reverse(4);

motorSpeed(4,59); //set motors to 59 speed

goFor(3); //run motors for 3 seconds

 

FINAL PERFORMANCE TEST:

motorSpeed(4,40);

goToRelativePosition(-186); //185 for 308, 180 for 224

brake(4);

reverse(4);

motorSpeed(4,61);

goFor(1);

brake(4);

goFor(11);

reverse(4);

motorSpeed(4,28); //28 for 224

goFor(2.5);

brake(4);

goFor(11);

reverse(4);

motorSpeed(4,77); //75 for 224

goFor(3);

brake(4);

goFor(1.15);

reverse(4);

motorSpeed(4,62); //54 for 224

goFor(1.3);

brake(4);

goFor(9);

reverse(4);

motorSpeed(4,71);

goFor(2); //2 for 224

brake(4);

goFor(3.92);

reverse(4);

motorSpeed(4,45);

goFor(1.5);