The final code was designed to be as modular as possible. There were many functions that were re-purposed repeatedly in order to keep the code efficient and allow for faster debugging when issues arrived in the process. The functions were mostly navigational and there were several functions that were used in order to check that the robot was on track. The final code also had a part of it in the int main that allowed the user to assign RPS coordinates in front of important tasks before the run. This allowed the robot to work the same regardless of any difference in RPS coordinates from course to course.
Below is a list of all of the functions in the final code:
–Starting Light: The robot reads the CDS Cell every couple of milliseconds and if the value is below a certain threshold then the robot starts the course.
–Forward: This function made the robot drive forward. It set the motor percentages and allowed them to run for the amount of time that made the robot drive the input distance.
–Backward: The backward function is set up exactly the same as the forward function, however the motor percentages become the opposite of what they were in the forward function. The positive percentages are set to negative and the negative to positive.
–ForwardBump: The robot moves forward until the bump switch on the front of the lift is triggered. After the switch is hit the function end and the code moves on.
–LeftTurn/RightTurn: These function have no input. They set the motors to run in opposite directions so that the robot turns in place. The amount of time that the motors run was tested to find the time such that the turn is ninety degrees.
–LeverTurn: The robot hooks around the lever and turns back in order to pull the lever down. In order to do this a separate turn function to turn left the smaller amount and get in position to pull the lever.
–Check_Heading: An RPS heading is input and the robot pulses clockwise and counterclockwise until the heading that the RPS reads matches the input heading. This was used to check turns and make sure that the robot was heading in the desired direction.
–Check_x_(minus/plus): The desired X-Coordinate is input so that the robot knows which coordinate to navigate to. The motors pulse on and off in order to move closer to the coordinate, but also allow the robot time to read the RPS coordinate. If the RPS coordinate is greater than the input coordinate then the robot pulses its motors to move towards the correct coordinate. Check_x_minus means that the robot is moving in the negative x direction so the robot moves forward when the coordinate is greater than desired and backwards when it is less. Check_x_plus means that the robot is moving in the positive x direction so the robot moves forward when the coordinate is less than desired and backwards when it is greater.
–Check_y_(minus/plus): These functions are the same as the check_x function, except that the y coordinate is input and checked. The motors pulse the exact same way, and minus and plus both still have the same respective differences.