A simple VEX motor test. Make sure your motors aren’t sabotaging your code.

Here is a summer project we came up with. A quick and easy system to test our motors. I’m involved with an elementary school program and the gear goes through A LOT of use and abuse so we have realized how different performances our motors are displaying so we decided to build a way to test them. I think a test like this (or maybe a bit more advanced one day) should be a core element of every team to regularly check their motors, and at least make sure to pair motors up with even performance.

First to test a motor we need force to work against the motor. Evil forces of the dark to challenge our motors. And the evil force I pick is: “Gravity!”. And what better resistance is there available to us than that! We built a very simple system for a motor to spin a beam with weight on the tip. Then we needed to measure the speed the motor turns this beam, we used our favorite way for that, light sensors. VEX calls them color sensors, we could use one sensor to detect when our object’s color passes by it but these sensors are pretty sensitive and they can read objects all around you and can get annoying. Cleanest way is to have one color sensor emit light, the other sensor to be right across from it, measure the light and if there is a reduction in brightness we can tell an object blocked the light. Nice and easy. So this is what we ended up with:

Note: Make sure you always have use charged battery while doing this test. We like to have batteries returning 8.0 volts or above for accurate results.

It would have been much better to support the sensor on the right side with a beam also but this was a quick project and we didn’t have that beam. You be sure to add that because the sensors have to line up perfectly, looking at each other.

Then this is the code to run as a first test.

We have 2 color sensors, one called “Light” and the other called “Sensor” and a motor called “Motor1” set up in the devices. When the program is started, we set light to 100%. Set the speed, torque, stopping to hold and start spinning. Then the loop on the right will always check if the light is being blocked. You might have to play around with the number “70” based on the brightness level in your room but “50” or so should pretty much always work. So every time the arm spins and passes in front of the sensor the brain will beep to let you know. I also created a variable called “howmany”, I increase it by 1 every time the arm passes by the sensor and after 18 revolutions I end my test. Yeah, I could use a repeat loop but anyway, same result…

Now that our system is running well, let’s improve this. Now I want to measure the time it takes to complete each revolution and print it on the brain. If we had a v2 brain I could print it on the VEX console but we don’t so we have to manage with our tiny brain screen. And these measurements will be pretty sensitive so I want 2 decimals to get accurate numbers. So below I’m adding “clear all rows” first to empty the screen, then I set print precision to 0.01 for numbers to come with 2 decimals, and then I add 2 print lines in our forever loop. And after printing we reset the timer so that we can accurately measure the next revolution.

But now I only see like 5 lines on the brain after the code completes, and I want my 18 lines. So let’s use our space better.

Follow the comments on the screenshot above for a better understanding. But now we are printing the numbers on one line separated by a comma and every 3 numbers we go to the next line. So now we get all the numbers on the screen.

Why do I have those 2.56 type numbers? You’re correct, the code above will not make numbers like this. This is because, next addition to my test was to put a stop every 3 revolutions. Anybody can spin something around easily, right? But a better test is to stop and then continue. That’s why I set the motor to “hold” which is the type of stop that arrests the movement completely and then I continue spinning. I felt a little bad for the motor, it looked tough on it to handle this abrupt stop but then I think about number of times we launched balls with our catapult in the year of “Pitching in” which was WAY tougher on the motor. And this is how we add the stop:

Once again follow the comments above for the changes I have added.

Then we ran this test for the motors while setting the velocity to 50% and then to 75% and then to 100%. We tried different torque values too but the impact it had on the results didn’t point to any significant point in the motor performance. So we went back to playing around with speed only. After canceling the off numbers (the first one which is a half turn and the ones with the stops), here are the numbers I got from our first test.

Velocity: 50
0.80, 0.82, 0.78. 0.78, 0.82, 0.82, 0.80, 0.80

Velocity: 75
0.56, 0.56, 0.54, 0.54, 0.56, 0.54, 0.54, 0.54   		

Velocity: 100
0.32, 0.36, 0.32, 0.34, 0.32 	

Less numbers on the 100% velocity because sensor isn’t sensitive enough for the speed and it would often measure 2 revolutions instead of 1. But you can change the “howmany” for the number of turns that will give you enough results.

Now we should get an average from these numbers ideally? But I’m a programmer, lazy when it comes to repetitive tasks and I will always prefer to write a formula to do a job even if it takes 5 minutes to write the formula but 2 minutes to do it all manually! But with the formula, you start winning once you use it enough number of times. We found out our different motors return numbers in a certain range. So we wrote the formula to pick out the numbers that we are looking for, count how many of those numbers we get and find the average and print it at the end. This is what we added:

What we are doing above is, if the speed is set to 50, get me timer numbers that are between 0.6 and 1.2, if it is 75 get me the ones between 0.3 and 0.9 and for 100 get me the ones that are between 0.2 and 0.6 and count how many of those numbers we got so that we can calculate the average. We had to define 2 variables for this “getAvg” and “avgCount”

So this formula when the speed was set to 50% would return these numbers and add them:

getAvg would be 7.44 and avgCount would be 9. So at the very end when need to print getAvg/avgCount which will return 0.83 and we use this code to display it:

We clear the first line and print the average there. Then we ran a bunch of motors through this test at speeds 50, 75 and 100.

And here are the results (sorted from fastest to slowest):

WLS07 and most likely a few of its friends above are definitely going to the museum. And I’m thinking we’ll keep a log of the motors performances for the classroom going forward. Got lots more motors to put through the test! Here is the final code all together.

And here are a few photos of our setup.

Let us know if you have any thoughts, any questions, any comments or improvements. Here or on our facebook page.

Yas Programmer