Much analyzing of the profile information generated by the sketch is output in CSV format, for easy importing into a spreadsheet. Some work has been done to use curve fitting on the data, to generate a simple algorithm the setting to use for a desired rotation speed. The data, even most (interesting) segments of it, are not linear enough for the solver built into LibreOffice Calc. At least not with any of the transpositions that I tried. For reading, the solver available in Excel is better. There also supposed to be an addon for OpenOffice that handles non-linear solving. My initial test could not get OpenOffice to run on my computer. It crashed on startup. Before I got (too) seriously annoyed, I happened to get an email from plot.ly. There version 2 software supports curve fitting, including non-linear curves. A quick test and exploration with initial data showed good results. More work is going to be needed, but it appears that breaking the data into 3 CW and 3 CCW segments should give usable linear or quadratic fits. We'll see how that goes when I have enough sample data to produce reasonable error bounds.
- Plotly Alpha Workspace
- quadratic
- Advanced options
- fit only to a specified range
- display fit over a specified range
- Plotly python offline
- servo C
- quadratic fit over 1400:1450; display over 1350:1480
- -0.00617±0.00062 x^2 + 16.3±1.8 x - 10607.2519±1.3e3
- quadratic fit over 1400:1450; display over 1350:1480
- «b»spline ¦ curve segments (3 each «C»CW?)
- search: "python curve fitting regression"
Finding curve to fit the data, or a transformation of the data, is not working well. The basic shape of the curve looks very simple, but I have not found an equation to get a clean match to either the full curve, or half the curve. Transcendental trig comes closest, but have not figured out how to 'pull' the corner in to match the data. Do not really want transcendental trig in the line follower robot code anyway.
Graph of profile data: x = ay^3 + by^2 + ct + d ?? http://academics.utep.edu/Portals/1788/CALCULUS%20MATERIAL/1_2%20GRAPHS%20OF%20EQNS.pdf broken link page 23 : y = 2x^3 curve looks rotated 90°, and offset from profile data x = ay^3 + d
The final result might come down to an embedded lookup table. By making sure to store that using PROGMEM, we can avoid using up the limited Arduino ram. Personal preference is to use an equation. Or 6. Though the lookup is likely to be faster.
The data shows that the portion (time fraction) of a rotation that is HIGH (light blocked by the bar) is consistently different when rotating clockwise and counterclockwise. The only way I can see for that to occur, is that, even with no external load, the rotation speed changes in different parts of a single rotation. IE, there is an internal load (friction) that varies depending on the current rotation angle, AND the high load points are different depending on whether the rotation is clockwise or counter clockwise.
A minor variation of that also explains the symptoms seen while testing at very close to zero rotation speed. For this servo, there are 4 setting values that seem to be 'full stop'. Given the surrounding pattern, 3 of those should be 'very slow clockwise'. That can be accounted for by assuming a generally greater turning resistance in the clockwise direction. The low applied power can not overcome the internal resistance.
The 'full power' speed clockwise is higher than the full power speed counterclockwise. That probably means that the 'very slow' ccw settings are actually the ones being affected (more) by the internal resistance. Those 'almost stopped' settings should really be some value of 'slow'.
The above should not matter for initial profiling of the servo speed versus target setting. At least as long as resistance is fairly consistent as the actual rotation speed changes. That is, the resistance is either continuously increasing, or continuously decreasing, as the setting distance varies from the true 'full stop' value. What is important, is the shape of the curve for speed versus setting value. Once that is determined, sample points can reprofiled at higher resolution / repetitions, to get better numbers to use for the speed and direction calculations. Even the calculated fraction is not really needed. Just need to use the relative intervals to model the complete profile.