General Programming Strategy



Function Examples


Gyro Turn

The Gyro Turn function uses the gyro sesnsor to help increase the accuracy of turns. It compares the current angle with the target angle, and turns until the target angle is reached. We start by turning at a very high power, causing the gyro sensor to overcorrect. We then make it turn back at a slower power until it reaches the target angle. This method allows for very accurate turns. However, since we use a very high power, it will cause the robot to overcorrect a large amount, so we programmed the sensor to look for a value less than the target angle, requiring less correction, as it will stop closer to its target value.




Proportional Integral Derivative Line Following

Our Proportional Integral Derivative Line Following program is a smoother way to line follow that adjusts the power levels of motors B and C proportionally to the distance from the edge of the line, which would have a light value of 50. It takes into account the error (the difference between the optimal and current light sensor reading), the integral (the sum of all errors), and the derivative (the difference between the current error and last error). Those values are scaled to an appropriate value for use in motor power levels based on three user-inputted coefficients in our constants.py module: kp, ki, and kd.




Main Selection Program

This selection program allows us to quickly and efficiently switch programs/missions during the two-and-a-half minute match. Our selection program contains functions, each containing one of our missions. The user of the robot simply starts the selection program and clicks the centre button to start the first mission. Then, when the mission finishes, the robot automatically advances to the next mission and waits for the user to click the centre button to run the appropriate mission. In case one needs to go backwards or forwards through the list of missions, the program accommodates that by allowing the user to navigate with the left and right arrow buttons.




Error-Corrected Move Block

For straighter and more accurate movements, our program continuously measures the distances travelled by each drive motor and constantly adjusts their speeds to maintain the predetermined ratio of the distance to be travelled by each drive motor. This functions also allows for more accurate robot arc turns, acceleration at the beginning of the movement and deceleration at the end.



Square Up

We have created a function that makes the robot completely perpendicular to the edge of a black line. Each light sensor corresponds with a motor. The robot drives up to the line and has the light sensor check the reflected light values. If the light sensor sees a value of less than 50 (black), it will tell the motor to move towards a value greater than 50 (white). It does this for both motors while for a set amount of time while slowly decreasing in power, until the robot becomes completely perpendicular to the edge of the line.




Full Programming Documentation (Click to See Full Code!)