Team E Codes

TABLE OF CONTENTS:

Glossary

Exercise 1

Exercise 2

Exercise 4

ARD1 (coasting)

ARDWBRK1/2

ARDPWRBRK

E­_EFF1

E­_EFF2

E­_EFF3

Performance Test 1

Performance Test 2

Code Comparison

Performance Test 3

 

 

GLOSSARY:

Basic Function Calls Function Call  Function  Example 
celerate(m,p1,p2,t);  Accelerates or decelerates motor(s) m from start speed (%) p1 to end speed (%) p2 over a duration of t seconds celerate(1,20,45,2); 

Accelerates motor 1 from 20% to 45% power in 2 seconds

motorSpeed(m,p);  Initializes motor(s) m at percent power motorSpeed(2,16); 

Sets motor 2 speed to 16% power

goFor(t);  Runs the motor(s) at their initialized state for t seconds goFor(5); 

Runs the motor(s) at their initialized state for 5 seconds

brake(m);  Brakes motor(s) m. Note: This does NOT brake the AEV, just stops the motors from spinning brake(4); 

Cuts the power to all motors

reverse(m);  Reverses the polarity of motor(s) reverse(1); 

Reverses polarity of motor 1

goToRelativePosition(n);  Continues the previous command for n marks from the vehicle’s current position. n can be positive or negative, with positive meaning the vehicle is moving forward, negative meaning the vehicle is moving backward motorSpeed(4,20); 

goToRelativePosition(30); 

All motors are set to 20% power, and they will continue to run at 20% power until the AEV reaches 30 marks from its current position

goToAbsolutePosition(n);  Continues the previous command for n marks relative to the overall starting position of the AEV motorSpeed(4,20); 

goToAbsolutePosition(300); 

All motors are set to 20% power, and they will continue to run at 20% power until the AEV reaches 300 marks from its starting position

goToRelativePosition(m); 

 One Argument; works specifically with reflectance sensor

 m: Number of wheel marks (from current position)

 The goToRelativePosition function continues the previous command for m marks from the vehicles current position. m can be a positive or negative value. A positive values indicates the vehicle is moving forward from its current position. A negative value indicates the vehicle is moving backward from its current position.

goToAbsolutePosition(c); 

 One Argument; works specifically with reflectance sensor

 c: Number of wheel counts (from current position)

 The goToAbsolutePosition function continues the previous command until the vehicle

*(from user manual):
The Arduino will record 8 marks for one full wheel revolution. This is due to four voltage changes (from light to dark to light and back to dark or vice versa) and there are two sensors so therefore there are 8 marks recorded for one full wheel revolution. The wheel has a circumference of ~3.9 inches. Therefore, the conversion from marks to distance traveled is 3.9 inches per 8 marks or 0.4875 inches/mark. This will be useful when converting the marks to engineering units of inches.

 

 

Exercise 1:

//Accelerate motor one from start to 15% power in 2.5 seconds.

celerate(1,0,15,2.5);

//Run motor one at a constant speed (15% power) for 1 second.

motorSpeed(1,15);

goFor(1);

//Brake motor one.

brake(1);

//Accelerate motor two from start to 27% power in 4 seconds.

celerate(2,0,27,4);

//Run motor two at a constant speed (27% power) for 2.7 seconds.

motorSpeed(2,27);

goFor(2.7);

//Decelerate motor two to 15% power in 1 second.

celerate(2,27,15,1);

//Brake motor two.

brake(2);

//Reverse the direction of only motor 2.

reverse(2);

//Accelerate all motors from start to 31% power in 2 seconds.

celerate(4,0,31,2);

//Run all motors at a constant speed of 35% power for 1 second.

motorSpeed(4,35);

goFor(1);

//Brake motor two but keep motor one running at a constant speed (35% power) for 3 seconds.

brake(2);

motorSpeed(1,35);

goFor(3);

//Brake all motors for 1 second.

brake(4);

goFor(1);

//Reverse the direction of motor one.

reverse(1);

//Accelerate motor one from start to 19% power over 2 seconds.

celerate(1,0,19,2);

//Run motor two at 35% power while simultaneously running motor one at 19% power for 2 seconds.

motorSpeed(2,35);

motorSpeed(1,19);

goFor(2);

//Run both motors at a constant speed (19% power) for 2 seconds.

motorSpeed(4,19);

goFor(2);

//Decelerate both motors to 0% power in 3 seconds.

celerate(4,19,0,3);

//Brake all motors.

brake(4);

 

Exercise 2:

//Run all motors at a constant speed of 25% power for 2 seconds.

motorSpeed(4,25);

goFor(2);

//Run all motors at a constant speed of 20% to travel a total distance of 12 feet

motorSpeed(4,20);

goToAbsolutePosition(296);

//Reverse motors.

reverse(4);

//Run all motors at a constant speed of 30% power for 1.5 second.

motorSpeed(4,30);

//Run all motors at a constant speed of 30% power for 1.5 second.

goFor(1.5);

//Brake all motors.

brake(4);

 

Exercise 4:

//starts the program

celerate(4,0,25,3); 

//Runs all motors at a constant 25% speed

motorSpeed(4,25); 

//Runs motors for 1 second at this speed

goFor(1); 

//Runs all motors at a constant 25% speed

motorSpeed(4,20); 

//Runs motors for 2 seconds at this speed

goFor(2); 

//Reverses all motors

reverse(4);

//Runs all motors at a constant 25% speed

motorSpeed(4,25); 

//Runs motors for 2 seconds at this speed

goFor(2);  

//Brake all motors.

brake(4);

ARD1 (coasting)

//Reverses motor 2

‘reverse(2);  

//Sets all motor speeds to 30% power and runs for 2 seconds

   ‘motorSpeed(4,30);’

‘goFor(2);    

//Stops all motors

‘motorSpeed(4,0); ‘

‘goFor(2);    

‘brake(4);    

 

ARDWBRK1/2

‘//Power Brake   

//Sets arm into starting position

   ‘rotateServo(90);  ‘

   ‘celerate(4,0,0,6);’

//Reverses motor 2

   ‘reverse(2);   

//Runs all motors at 30% power for 5 seconds

   ‘motorSpeed(4,30); ‘

‘goFor(5);     

//Stops the motors

   ‘motorSpeed(4,0);  ‘

‘goFor(2);     

‘brake(4);     

//Rotates the arm to stop the AEV

   ‘rotateServo(10);  ‘

 

ARDPWRBRK

//Reverses motor 2

  ‘reverse(2);    

//Accelerates all motors to 50% power for 2 seconds

   ‘celerate(4,0,50,2);’

//Runs all motors at 50% for 2 seconds

‘motorSpeed(4,50);  ‘

‘goFor(2);      

//Reverses all motors

‘reverse(4);    

//Accelerates all motors to 40% for 2 seconds

   ‘celerate(4,0,40,2);’

//Stops all motors

‘brake(4);      

E­_EFF1

‘//Energy effiency’

//Reverses motor 2

‘reverse(2);  

//Puts the servo arm into the starting position

‘rotateServo(90); ‘

//Sets all motor speeds to 30% for 4 seconds

   ‘motorSpeed(4,30);’

‘goFor(4);    

//Stops all motors

‘motorSpeed(4,0); ‘

‘goFor(10);      

 

E­_EFF2

‘//Energy effiency’

//Reverses motor 2

‘reverse(2);  

//Sets the motor power to 50% for 5 seconds

   ‘motorSpeed(4,50);’

‘goFor(5);    

//Stops all motors

‘motorSpeed(4,0); ‘

‘goFor(10);   

 

E­_EFF3

‘//Energy effiency’

//Reverses motor 2

‘reverse(2);   ‘

//Sets the motor power to 50% for 5 seconds

‘motorSpeed(4,50);’

‘goFor(5);     ‘

//Stops all motors

‘motorSpeed(4,0); ‘

‘goFor(10);    ‘

 

Performance Test 1

//reverse one motor

reverse(2);

//set motor power to 30% for both

motorSpeed(4,30);

//stop  and coast into stop sign

goToAbsolutePosition(200);

//rotate servo to brake

rotateServo(85);

//brake motors

brake(4);

//wait for stop sign to move

celerate(4,0,0,12);

//travel through gate

motorSpeed(4,40);

//travel for 2 seconds

goFor(2);

//brake

brake(4);

 

Performance Test 1

////to stop sign

//reverse one motor

reverse(2);

//set motor power to 30% for both

motorSpeed(4,30);

//stop at stop sign

goToAbsolutePosition(259);

//rotate servo to brake

rotateServo(87);

//brake motors

brake(4);

//wait for stop sign to move

celerate(4,0,0,8.5);

////to caboose

//rotate servo from brake position

rotateServo(0);

//set motor power to 25% for both

motorSpeed(4,25);

//go short of caboose

goToAbsolutePosition(520);

//brake servo

rotateServo(82);

//brake motors

brake(4);

//wait for 7 seconds

celerate(4,0,0,7);

////back down track

//reverse both motors

reverse(4);

//rotate servo from brake position

rotateServo(0);

//set motor power to 45% for both

motorSpeed(4,45);

//go for 2 seconds

goFor(2);

//brake motors

brake(4);

 

Performance Test 2

////to stop sign

//reverse one motor

reverse(2);

//set motor power to 30% for both

motorSpeed(4,30);

//stop at stop sign

goToAbsolutePosition(259);

//rotate servo to brake

rotateServo(87);

//brake motors

brake(4);

//wait for stop sign to move

celerate(4,0,0,8.5);

////to caboose

//rotate servo from brake position

rotateServo(0);

//set motor power to 25% for both

motorSpeed(4,25);

//go short of caboose

goToAbsolutePosition(520);

//brake servo

rotateServo(82);

//brake motors

brake(4);

//wait for 7 seconds

celerate(4,0,0,7);

////back down track

//reverse both motors

reverse(4);

//rotate servo from brake position

rotateServo(0);

//set motor power to 45% for both

motorSpeed(4,45);

//go for 2 seconds

goFor(2);

//brake motors

brake(4);

 

Code Comparison

////NonCoasting to stop sign

//reverse one motor

reverse(1);

//set motor speed to 30%

motorSpeed(4,30);

//travel 262 marks

goToAbsolutePosition(-262);

//rotate servo to brake position

rotateServo(75);

//brake motors

brake(4);

 

//// Coasting to stop sign

//to stop sign

//reverse one motor

reverse(1);

//set motor speed to 30%

motorSpeed(4,30);

//travel 200 marks

goToAbsolutePosition(-200);

//brake motors and coast AVE

brake(4);

//travel 262 marks

goToAbsolutePosition(-262);

//rotate servo to brake position

rotateServo(75);

 

Performance Test 3

////to stop sign

//reverse one motor

reverse(2);

//set both motor speeds to 30%

motorSpeed(4,30);

//travel to 262 marks

goToAbsolutePosition(262);

//rotate servo to brake AEV

rotateServo(75);

//brake motors

brake(4);

//wait at gate

celerate(4,0,0,8.5);

////to caboose

//rotate servo out of brake position

rotateServo(0);

//set both motor speeds to 25%

motorSpeed(4,25);

//travel to 573 marks

goToAbsolutePosition(573); 

//rotate servo to brake position

rotateServo(67);

//brake motors

brake(4);

//wait with caboose

celerate(4,0,0,5);

////back down track

//reverse both motors

reverse(4);

//rotate servo out of brake position

rotateServo(0);

//set both motor speeds to 45%

motorSpeed(4,45);

//travel to 396 marks

goToAbsolutePosition(396);

//rotate servo to brake position

rotateServo(75);

//brake motors

brake(4);

//wait at gate

celerate(4,0,0,8.5);

////back through stop sign to end

//rotate servo out of brake position

rotateServo(0);

//set both motor speeds to 45%

motorSpeed(4,45);

//travel to 209 marks

goToAbsolutePosition(209);

//brake motors

brake(4);

//coast for .8 seconds

goFor(.8);

//rotate servo to brake position

rotateServo(69);