I am planing a few projects and want to do some events based on curves. Input curves, output curves and correlative curves.
A quick "for instance" would be if I want to start a stepper motor slow, graduate to full speed, then gradually slow again to a stop. Being able to set the curve for acceleration and deceleration.
A second for instance would be if I want to have two input points and, based on the speed of the trigger between those two points, the output would be timed differently. Let's say there was a 10ms difference between two inputs, then I'd want the output to be 8ms after the second input. But if the difference between the two inputs is 50ms, the output might be 15ms after the second input. But there would be a curve.
I suppose on case two, the output could be built into a ladder but there has to be a more efficient way of doing it.
For the first case, you should look at the AccelStepper library. For the second case, simple arithmetic seems to be all you need but if you want to use more complicated algorithms there is nothing stopping you from implementing them.
MarkT:
By curve do you mean an arbitrary mathematical function or just table-lookup style mapping?
Is time always one of the variables?
And "events based on curves" means what exactly?
TIme should be the only variable for now.
To explain what I mean by "curves" is that there would be a correlative connection between the events but rather than a straight linear line timing connection there would be connection somewhere along the lines of a sin wave.
I work in the printing industry and the term "curve" is almost self explanatory.
It turns out it's harder to describe to the general public. Having said that, anyone who understands a bell curve should understand what I am talking about.
The general public's view of a curve is a bent line; mathematically, a straight line is a curve, it's just that the curvature is zero. A straight line is a special case of a curve. If you have no powers higher than 1 in a polynomial, you have a straight line.
y=5 is a straight horizontal line curve (highest x power =0)
y= 2x + 5 is a sloping straight line curve(highest x power =1)
y=3x^2 + 2x + 5 is a parabolic curve, and now it's what the general public probably call a "curve" (highest x power =2)
I think what MarkT was getting at, was not that he doesn't know what a curve is, but rather can the relationship be defined by an equation (like y=4x+9 or y=2x^2 + 6x +3) or is it only known at certain points where a short straight line joins the known points and intrapolation might be required.
Taking your example of the two points given (delta=10, output =8 and delta=50, output =15), and requiring a curve between them, and taking a straight line as a legitimate example of a curve, it's arithmetically totally trivial to find the output for a delta between 10 and 50)
Bittsen:
I work in the printing industry and the term "curve" is almost self explanatory.
It turns out it's harder to describe to the general public.
Clearly you have a layman's understanding of what a curve is, but you need to understand what you're dealing with in mathematical terms. There is a big difference between seeing pigment on paper, and understanding the mathematical relationship that describes it.
The example I'm showing would be representative of the type of curve I'm referring to.
Specifically, this one would relate tot he feeder speed on a printing press (but that's not the final application I'm working on.
As the speed of the press increases, the feeder timing needs to advance to overcome the inertia and friction of the sheet of paper going from standing still to full speed (acceleration). As the press increases in speed the timing issue becomes stable again, flattening the curve. If the timing continued to advance at a steady rate then the sheet of paper ends up going too fast when it encounters the "stop" on the registration table. So, oddly, there's actually a point where the advance of the timing needs to reverse a little. But that's moot for what I am working on.
So, for the press analogy, I would add a pair of sensors tot he main 1:1 point of the press.
I would then add a mechanism to advance or retard the timing of the feeder.
The arduino would control that advance or retard based on the speed of the machine.
Using the term LED to define the output was for convenience. It would probably be a servo or some other mechanism.
I was just wondering if there was going to be a relatively easy way to configure the math for this. Otherwise it would be cumbersome to build a set of variables and code them.
There are several simple functions that could be adjusted to accurately fit a curve like that. If you were to post the actual data points, people could help decide which approach is best.
jremington:
There are several simple functions that could be adjusted to accurately fit a curve like that. If you were to post the actual data points, people could help decide which approach is best.
I don't have data points yet.
This will have to be a build first. It's going to have to be trial and error of a completed project to find the data points. And the data points could change depending on conditions. An example would be that heavier (thicker) paper has more mass so it's acceleration would tend to be slower than a lighter weight paper. But I will approach the variables later.
For development purposes, to simplify things, you could approximate that S-curve with three straight bits. It starts at about 30 degrees. then the long middle part is about 45, then 30-ish at the top.
That would let you get built and then calibrate later.
So accelerate smoothly up to a speed, then decelerate. Possibly insert a section in there where it runs at a constant speed.
An array storing the data, perhaps, or as has been pointed out, merely use math to calculate it. The 2nd and 3rd 90 degree sections of a sine wave would give you a very smooth accel/decel. If the Arduino has so much to do that calculating sines would slow it down, you only need to store a 90 degree chunk of a sine wave in an array.