void myCode()
{
reverse(4); // Meant to compensate backward setup
motorSpeed(4,40); // Puts AEV in gate
goToRelativePosition(259);
powerBrake(); // Power brakes
goFor(6.75); // Waits in gate
motorSpeed(4,40); // Goes to end of track
goToAbsolutePosition(392);
motorSpeed(4,0); // Confirms Stop
brake(4);
goFor(9); // Waits after connecting to the caboose
reverse(4); // Leaves with the caboose
motorSpeed(4,60);
goToRelativePosition(-267); // Goes back down some of the track
RevPowerBrake(); // Power brakes while going backwards initially
motorSpeed(4,0); // Confirms Stop
brake(4);
}
float velocity() // Method to find the velocity of the AEV
{
float startMark = getVehiclePostion(); //Takes current position
delay(100); // Waits to see change in position
float endMark = getVehiclePostion(); // Takes the new position
float markSpeed = endMark – startMark; // Finds the difference
return markSpeed; // Returns difference
}
boolean stopped() // Method to tell if the AEV slow enough to be considered stopped
{
boolean result = false; // Create new boolean
float vel = velocity(); // Finds the velocity based on user created method
if(vel > 1) // If change in marks was more than one, still moving otherwise stopped
{
result = false; // Sets the Boolean to false
}
else
{
result = true; // Sets the Boolean to true
}
return result; // returns whether AEV is stopped
}
void powerBrake() // Method that power brakes the AEV
{
reverse(4); // Reverse motors and increases their speed
motorSpeed(4, 100);
while(!stopped()) // Keeps looping until determined to be stopped
{
// Do nothing just wait for the loop to end
}
motorSpeed(4,0); // Stops all the motors
brake(4);
reverse(4); // Sets the motors back to their direction before the power brake
}
void RevPowerBrake() // Separate power brake for reverse direction to deal with any negatives
{
reverse(4); // Reverse motors and increases their speed
motorSpeed(4, 100);
while(!RevStopped()) // Keeps looping until determined to be stopped
{
// Do nothing just wait for the loop to end
}
motorSpeed(4,0); // Stops all the motors
brake(4);
reverse(4); // Sets the motors back to their direction before the power brake
}
boolean RevStopped() // Method to tell if the AEV slow enough to be considered stopped
{
boolean result = false; // Create new boolean
float vel = RevVelocity(); // Finds the velocity based on user created method
if(vel > 1) // If change in marks was more than one, still moving otherwise stopped
{
result = false; // Sets the Boolean to false
}
else
{
result = true; // Sets the Boolean to true
}
return result; // returns whether AEV is stopped
}
float RevVelocity() // Method to find the velocity of the AEV
{
float endMark = getVehiclePostion(); //Takes current position
delay(100); // Waits to see change in position
float startMark = getVehiclePostion(); // Takes the new position
float markSpeed = endMark – startMark; // Finds the difference
return markSpeed; // Returns difference
}