I added some sliders to my plotting program to allow me to make adjustments to the acceleration profile on the Arduino in real time. Last time I had added one "split point" to straighten out the top part of the graph. I added another split point so I have 4 points total, the minimum, upper split, lower split and maximum. Each point has a "delta" associated with it. When the period is at the lower split, the amount we change the period per step is the "lower split delta". So the per-step change is a mapping of period to delta, a blend of the 4 points. Here is a screenshot of the app showing a graph with slight easing at the start and end:
As I said before this is a very simple solution. Only 8 data points with 2 integer comparisons to make and one "map" function, also integer-based. Here's the code for the acceleration:
// perform constant acceleration
long change;
if (period < LSPLIT) change = map(period, MIN, LSPLIT, MIND, LSPLITD);
else if (period < USPLIT) change = map(period, LSPLIT, USPLIT, LSPLITD, USPLITD);
else change = map(period, USPLIT, MAX, USPLITD, MAXD);
if (period < targetPeriod) { // accelerating
period += change;
if (period > targetPeriod) period = targetPeriod;
if (period > MAX) period = MAX;
} else if (period > targetPeriod) { // decelerating
period -= change;
if (period < targetPeriod) period = targetPeriod;
if (period < MIN) period = MIN;
}
Timer1.setPeriod(period);
I've run it on the motors and it seems to work great. The acceleration factor is pretty low right now, I want time to be able to see it happen, but I'm sure there will be plenty of tweaking done to the values once the motors are installed on the mill.