Happy Pi Day! To celebrate π today, I am going to share how pi was used this past week in my robotics classes.

I was teaching students to use motor encoders with the LEGO EV3 robots. Previously we had been using the wait1Msec command to keep the motors running (pause and wait before moving on in the program) for a specific duration. This works, but requires a great deal of trial and error to complete tasks. Using the motor encoders allows the programmer to tell the motors how many rotations to make.

On the EV3 motors, there are 360 encoder counts for every revolution. That means there is an encoder count for every degree. This is where pi became important. Students measured the diameter of the wheel on the robot. Using the formula for finding circumference (C=D*π), students multiplied π * D to get C. This gave us the circumference of the wheel. We found the wheel to be about 2 1/8 or 2.125 inches. If you multiply 2.125 inches by π you get 6.67 inches. Students then divided the circumference by 360 to get the distance the robot would travel for every encoder count. We found this to be 0.0185 inches. So when a student wants the robot to travel a specific distance, let’s say two feet or twenty-four inches, they can mathematically calculate what encoder count to enter. All you have to do is take the desired distance and divide by 0.0185. That would give you the encoder count required to go the desired distance.

I led my students through this activity. I was pleased that I had integrated geometry in a real and relevant way. What I didn’t expect was what one group did to calculate the encoder count for a 90 degree turn. While most students used trial and error to find the encoder count that would make the 90 degree turn, one group decided to once again asked π for help. This group realized that when using a swing turn, the distance between the wheels would be the radius of a circle. So they multiplied the radius by 2 and multiplied by π to find the circumference of yet another circle. If you want to make a 90 turn, you just have to divide the circumference by 4 since 90 degrees is 1/4 of the circle. They took that distance and divided by the distance for each encoder count and you have the encoder count for a 90 turn.

This group found the distance between the wheels to be 4.75 inches. This doubled is 9.5 inches. Multiply 9.5 by π and you get 29.85 inches. Take 29.85 inches and divide by 0.0185 inches, the number found before, and you get 1613. Divide 1613 by 4 and you have the encoder count needed to make a 90 degree turn. You end up around 403. We have found that there is some tweaking needed, but the calculations get you very close if not absolutely accurate.

We used the following code using ROBOTC.

**//we used the motor sync because EV3 won’t go straight without syncing motors**

** //we have not started naming motors yet, so we used motorB and motorC**

** setMotorSyncEncoder(motorB, motorC, 50, 403, 25); //50 is the ratio for a swing turn, 403 is the encoder count and 25 is the motor power**

** waitUntilMotorStop(motorB);**

That is true learning. These students used their knowledge of geometry to solve a real problem. This was one of those days that will remember for a very long time!