# AEV Code

## Lab 1

// Run motor from start to 15% power in 2.5 seconds
celerate(1,0,15,2.5);

//Keeps motor one running at 15% for 1 second and stops it
motorspeed(1,15);
goFor(1);
brake(1);

//accelerate motor 2 to 27% in 4 seconds
//then run at constant spd for 2.7 seconds
celerate(2,0,27,4);
motorspeed(2,27);
goFor(2.7);
celerate(2,27,15,1);
brake(2);
reverse(2);

celerate(4,0,31,2);
motorspeed(4,35);
goFor(1);
brake(2);
motorspeed(1,35);
brake(4);
goFor(1);

reverse(1);
celerate(1,0,19,2);
motorspeed(2,35);
motorspeed(1,19);
goFor(2);

motorspeed(2,19);
goFor(2);
celerate(4,19,0,3);
brake(4);

## Lab 2

// Program to fulfill task requirements

motorSpeed(4,25);
goFor(2);

motorSpeed(4,20);
goFor(2);

goToAbsolutePosition(295.2);
reverse(4);

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

brake(4);

}

## Lab 4

motorSpeed(4,25);
goFor(2);

motorSpeed(4,20);
goFor(2);

goToAbsolutePosition(295.2);
reverse(4);

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

brake(4);

// Tests operation of current AEV

//Motor 1, black propeller
//motorSpeed(1,25);
//goFor(5);

//brake(1);

//Motor 2, gray propeller, reverse first to go in direction of black propeller

reverse(2);

//motorSpeed(2,25);
//goFor(5);

//brake(2);

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

brake(4);

}

## Performance Test 1

//Reverse gray motor so both motors rotate in same direction
reverse(1);

motorSpeed(4,30);
goToAbsolutePosition(123);

goFor(.4);
rotateServo(30);
motorSpeed(4,0);
goFor(4);

rotateServo(0);

goFor(3.5);

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

}

## Performance Test 2

//Reverse gray motor so both motors rotate in same direction
reverse(1);

motorSpeed(4,30);
goToAbsolutePosition(125);

goFor(.4);
rotateServo(30);
motorSpeed(4,0);
goFor(4);

rotateServo(0);

goFor(3.5);

//First Gate Passage End – Servo

motorSpeed(4,30);
goToAbsolutePosition(294);

rotateServo(30);
motorSpeed(4,0);
goFor(3);
rotateServo(0);

rotateServo(30);
motorSpeed(4,0);
goFor(.5);
rotateServo(0);

brake(4);
goFor(5);

reverse(4);

motorSpeed(4,50);
goToAbsolutePosition(182);

rotateServo(30);
brake(4);

goFor(4);
rotateServo(0);
goFor(3.5);

motorSpeed(4,30);
goToAbsolutePosition(20);

goFor(.5);
brake(4);
rotateServo(30);

}

## Final Code

//2018-03-28 3rd Floor
//Battery Voltage: 8.08

//2018-03-30 2nd Floor
//Battery Voltage: 8.13

//2018-04-02 3rd Floor
//Battery Voltage: 7.96

//2018-04-09 3rd Floor
//Battery Voltage: 8.16

//2018-04-11 3rd Floor
//Battery Voltage: 8.01

//2018-04-13 2nd Floor
//Battery Voltage: 8.12

//Gray motor 2
//Black motor 1

/*
* The approach we developed for coding the whole track was to divide the track into four different legs.
*
* 1st Leg: Reach gate, trigger gate
* 2nd Leg: Move past gate and connect with the load at end of track
*/

//First Leg

//Reverse gray motor so both motors rotate in same direction
reverse(1);

motorSpeed(4,30);
goToAbsolutePosition(277);

brake(4);
rotateServo(40);
goFor(4);
rotateServo(0);

goFor(3.5);
//END First Leg

//Second Leg
motorSpeed(4,30);

goToAbsolutePosition(580);
brake(4);
rotateServo(40);
goFor(4);
rotateServo(0);

goFor(5);
//END Second Leg

//Third Leg
//Change orientation of motors to go in reverse
reverse(4);

//Was short about a wheel revolution at 320 marks
motorSpeed(4,60);
goToAbsolutePosition(387);

brake(4);
rotateServo(40);
goFor(4);
rotateServo(0);

goFor(3.5);

//END Third Leg
//Fourth leg
motorSpeed(4,60);
goToAbsolutePosition(175);

brake(4);

goToAbsolutePosition(50);

rotateServo(40);

//END Fourth leg
}

# celerate(m,p1,p2,t);

Accelerates or decelerates the motors (m) from a start speed (p1) to an end speed (p2) over (t) seconds.

m = motor id (motor 1 = 1, motor 2 = 2, all motors = 3)

p1 = start speed (%)

p2 = end speed (%)

t = duration of speed change (seconds)

### motorSpeed(m,p);

Sets the speed of motor (m) to a power percentage (p).

m = motor id (motor 1 = 1, motor 2 = 2, all motors = 3)

p = power (%)

### goFor(t);

Run motors (m) at their power settings for (t) seconds.

m = motor id (motor 1 = 1, motor 2 = 2, all motors = 3)

t = duration (seconds)

### brake(m);

Halts motors (m)

m = motor id (motor 1 = 1, motor 2 = 2, all motors = 3)

### reverse(m);

Reverse the polarity of motors (m).

m = motor id (motor 1 = 1, motor 2 = 2, all motors = 3)

### goToRelativePosition(m);

Moves the vehicle a certain amount of marks (m) either forward or backward depending on the sign of (m).

m = amount of marks to move

### goToAbsolutePosition(c);

Moves the vehicle to the specific offset of marks from the origin (m).

c = mark number to move to

Resources