This has been done a couple times before, however, I decided to do it myself for fun.
As many already know, the motor input from 0 to 127 is not linear to velocity but to torque instead. A couple attempts have been made to linearize this trend and called it TrueSpeed, as seen here.
Upon seeing this I set up a test bench with three brand new highspeed motors and three brand new quadratic encoders and ran the code attached in the zip file below called RPM Test. After running this test, I received the following data.
Columns A and B are the recorded data from the program. After I recorded this data, I went to the website “Polynomial Regression Data Fit” and pasted this data into the “Data Entry Area”, I ran the regression and increased the degree of the polynomial until I got to the 32nd degree polynomial, at this point I was happy with how the polynomial fit to the data as well as the 0.9668 correlation coefficient (r^2). I took the polynomial it gave me and reformatted it to Desmos language. After putting it into this Desmos, I restricted the domain to 127.
Now, to calculate the real linear values that should be used, I took the lowest point and the highest point of the graph, added them together, and then divided that by 127 to get a stepping resolution of 127 to create 127 equidistant points along the curve. I took the lowest point (1.593) and added the resolution times the variable z and recorded each value from 0 to 127. I put these values into column I of the google spreadsheet and then rounded them in column j. I then created an array of size 128 (0 to 127) and wrote out the values and got my final result:
const ubyte trueSpeed[128] = {
0, 3, 5, 7, 8, 9, 10, 10, 11, 11,
11, 12, 12, 12, 12, 12, 12, 13, 13, 13,
13, 14, 14, 14, 14, 14, 15, 15, 15, 15,
16, 16, 16, 16, 16, 16, 17, 17, 17, 17,
18, 18, 18, 18, 18, 19, 19, 19, 20, 20,
20, 20, 21, 21, 21, 22, 22, 22, 22, 23,
23, 23, 24, 24, 24, 24, 25, 25, 25, 26,
26, 26, 27, 27, 27, 28, 28, 28, 29, 29,
30, 30, 31, 31, 32, 32, 33, 33, 34, 35,
35, 36, 37, 37, 38, 39, 39, 40, 41, 41,
42, 43, 44, 45, 46, 46, 47, 48, 49, 50,
51, 53, 54, 55, 57, 60, 62, 65, 69, 72,
76, 80, 82, 85, 87, 91, 101, 127
};
Notice how the numbers steadily increase more and more, this is because of the close to logarithmic relation between the motor speed (0 - 127) and the RPM. I believe this is the most mathematically/statistically accurate way to linearize this relationship.
Let me know what you think and feel free to use my work,
Aidan