Previous Codes and Basic Function Calls

Basic Function Calls Index

Below is a list of some of the main programming basics for the AEV:

celerate(t,p1,p2,t) – accelerates a motor or all motors for a specified time

motorSpeed(m,p) – runs a motor at a specified speed

goFor(t) – gives a time for how long the function should last

reverse(m)- switches direction on motor

brake(m) – halts motor from operating

gotoAbsolutePosition(mark) – tells the motor to go to a set location

goToReletivePosition(mark) – gives a distance for the motor to travel before stopping

reflectanceSensorTest()- Performs a test of reflectance sensors

 

Preliminary R&D

Exercise 1 – Programming Basics

// 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) in 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) in 2.7 seconds

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 one second

brake(4);

goFor(1);

// Reverse the direction of motor one

reverse(1);

// Acclerate motor on efrom start to 19% over 2 seconds

celerate(1,0,19,2);

// run motor two at 35% while simultaeneously running motor one at 19% in 2 seconds

motorSpeed(2,35);

motorSpeed(1,19);

goFor(2);

// Run both motors at a constant speed 19% for 2 seconds

motorSpeed(1,19);

goFor(2);

motorSpeed(2,19);

goFor(2);

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

celerate(1,19,0,2);

celerate(2,19,0,2);

// Brake all motors

brake(4);

 

 

 

Exercise 2- External Sensors

 

// run all motors at a constant speed25 for 2 seconds

motorSpeed(4,25);

goFor(2);

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

motorSpeed(4,20);

goToAbsolutePosition(295.3846153846154);

// Reverse motors

reverse(4);

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

motorSpeed(4,30);

goFor(1.5);

//brake all motors

brake(4);

 

 

 

Lab week 4- Design analysis tool

// accelerate  all motors from start to 25% in 3 seconds

celerate(4,0,25,3);

// run all motors at a constant speed for 1 second

goFor(1);

// run all motors at 20% power for 2 seconds

motorSpeed(4,20);

goFor(2);

// Reverse all motors

reverse(4);

// run all motors a 25% for 2 seconds

motorSpeed(4,25);

goFor(2);

// brake all motors

brake(4);

Adanced R&D Week 1: Coasting Vs. Power Braking

Coasting Code:

reverse(4);

celerate(4,0,30,2);

goFor(2);

Braking Code:

reverse(4);

celerate(4,0,30,2);

goFor(2);

reverse(4);

motorSpeed(4,30);

goFor(1);

Advanced R&D Week 2: Battery Testing

// run all motors at a constant speed25 for 2 seconds
// set in reverse because motors are on backward
reverse(4);
// accelerate from 0 t0 40 in 3 seconds
celerate(4,0,40,3);
goFor(3);
reverse(4);
motorSpeed(4,40);
goFor(2);

Lab 9A- Design selection

reverse(4);
celerate(4,0,41,3);
goFor(2);
motorSpeed(4,0);
goFor(7);
celerate(4,0,40,2);

Performance Testing code Used:

reverse(4);
celerate(4,0,41,3);
goFor(2);
motorSpeed(4,0);
goFor(10);
celerate(4,0,50,4);

Performance Test 2- Attaching to the Caboose and exiting the loading area

First Test Code used

reverse(4);
motorSpeed(4,35);
goToAbsolutePosition(101);
reverse(4);
motorSpeed(4,20);
goFor(1);
brake(4);
goFor(10);
reverse(4);
motorSpeed(4,35);
goToRelativePosition(48);

Second Test Code (meets objective)

 

reverse(4);
motorSpeed(4,35);
goToAbsolutePosition(125);
reverse(4);
motorSpeed(4,40);
goFor(1);
brake(4);
goFor(10);
reverse(4);
motorSpeed(4,35);
goToRelativePosition(48);
motorSpeed(4,0);
goFor(10);
reverse(4);
motorSpeed(4,30);
goFor(3);

Performance Test 3 (reducing energy and meeting final objective)

Test Code 1:

reverse(4);
motorSpeed(4,35);
goToAbsolutePosition(125);
reverse(4);
motorSpeed(4,40);
goFor(1);
brake(4);
goFor(9);
reverse(4);
motorSpeed(4,35);
goToRelativePosition(48);
motorSpeed(4,0);
goFor(10);
reverse(4);
motorSpeed(4,40);
goToRelativePosition(100);

Needs farther distance

Test Code 2:

reverse(4);
motorSpeed(4,35);
goToAbsolutePosition(123);
reverse(4);
motorSpeed(4,40);
goFor(1);
brake(4);
goFor(9);
reverse(4);
motorSpeed(4,35);
goToRelativePosition(48);
motorSpeed(4,0);
goFor(10);
reverse(4);
motorSpeed(4,40);
goToRelativePosition(105);
reverse(4);
motorSpeed(4,60);
goFor(1);
motorSpeed(4,0);
goFor(9);
reverse(4);
motorSpeed(4,40);
goToRelativePosition(50);
motorSpeed(4,0);
goToRelativePosition(100);
reverse(4);
motorSpeed(4,50);
goFor(1);

 

New Sensors, New code (308)

4/3 -Needed farther distance

reverse(4);
motorSpeed(4,35);
goToAbsolutePosition(252);
reverse(4);
motorSpeed(4,40);
goFor(1);
brake(4);
goFor(8);
reverse(4);
motorSpeed(4,35);
goToRelativePosition(85);
motorSpeed(4,0);
goFor(10);
reverse(4);
motorSpeed(4,40);
goToRelativePosition(-207);
reverse(4);
motorSpeed(4,60);
goFor(1);
motorSpeed(4,0);
goFor(9);
reverse(4);
motorSpeed(4,40);
goToRelativePosition(-99);
motorSpeed(4,0);
goToRelativePosition(-185);
reverse(4);

motorSpeed(4,55);

goFor(1);

reduced energy usage **Does not meet objective** **increases time**

reverse(4);
motorSpeed(4,30);
goToAbsolutePosition(262);
reverse(4);
motorSpeed(4,30);
goFor(1);
brake(4);
goFor(8);
reverse(4);
motorSpeed(4,25);
goToRelativePosition(100);
motorSpeed(4,0);
goFor(10);
reverse(4);
motorSpeed(4,40);
goToRelativePosition(-180);
reverse(4);
motorSpeed(4,40);
goFor(1);
motorSpeed(4,0);
goFor(9);
reverse(4);
motorSpeed(4,40);
goToRelativePosition(-99);
motorSpeed(4,0);
goToRelativePosition(-170);
reverse(4);
motorSpeed(4,40);
goFor(1);

Final run code:

reverse(4);
motorSpeed(4,35);
goToAbsolutePosition(245);
reverse(4);
motorSpeed(4,40);
goFor(1);
brake(4);
goFor(8);
reverse(4);
motorSpeed(4,35);
goToRelativePosition(78);
motorSpeed(4,0);
goFor(10);
reverse(4);
motorSpeed(4,40);
goToRelativePosition(-208);
reverse(4);
motorSpeed(4,60);
goFor(1);
motorSpeed(4,0);
goFor(9);
reverse(4);
motorSpeed(4,40);
goToRelativePosition(-99);
motorSpeed(4,0);
goToRelativePosition(-196);
reverse(4);
motorSpeed(4,55);
goFor(1);