RAMP
RAMP copied to clipboard
Interpolation on the fly - best practice?
Hello!
I want to use RAMP to smooth the acceleration of a motor. But the ramp should be updated "on the fly" that means the input value for the speed can change any time and RAMPS should smoothen the change.
Should I use go() whenever a new value is provided or update() ?
The lib is great but it lacks of a more comprehensive documentation.
Thanks!
Hi, I'm not about what exactly you want to do. Update() is the method used to calculate the value taking care of the elapsed time since last call. Go() is the method to assign a new goal. If your want to assign a new destination value with a constant speed you have to calculate it before passing it as a duration argument in the go function.
Hope it helps.
Hi! Yes but how can I make the interpolation go to a new value while it is running? E.g When counting to 100 just stop and go down to 0 but of course with continious grading.
Still don't understand your request so I'll have to guess. Let's say you start at 0, when button 1 pressed it goes to 100 in 10 seconds, when button 2 pressed it stop where it is and go to 20 in 2 secondes. This will result in the pseudo code below :
setup() { myRamp.go(0) }
loop() { if (button1Pressed) { myRamp.go(100, 10000); } if (button2Pressed) { myRamp.go(20, 2000); }
Serial.println(myRamp.update()); }
The ramp is an object that interpolate beetween two values A and B. Each time you call the go method the actual interpolated value is calculated and become the new A, then it takes the argument of the method for B, duration and other parameters.
I'm really not sure to understand your problem because what you seems to want is basically what the library does... can you share a simple example of your code, the exepected behaviour and how the actual result differs from it ?
Hi! Sorry for being not precise enough. Maybe what I want is not possible. I am working with this code:
#include <Ramp.h>
elapsedMillis FastTimer;
elapsedMillis SlowTimer;
rampInt myRamp;
void setup() { Serial.begin(115200); myRamp.go(3200,3000, CUBIC_INOUT); myRamp.setAutomation(false); } void loop() { if(!(FastTimer%5)) myRamp.update(); if(FastTimer >= 50){ Serial.println(myRamp.getValue()); FastTimer = 0; } if(SlowTimer >= 500){ myRamp.go(random(0,3200), 4000, CUBIC_INOUT); SlowTimer = 0; } }
So every 500ms the interpolation should go to a random new target. Of course this works, but I want the curve be smooth and continious "breaking" and not discontinous as I marked in the screenshot. But As mentioned above maybe that is not possible with using the lib "as it is".
Thanks anyway!
Ooooooook now I see what you mean :) the problem here is that you use the CUBIC_INOUT interpolation so you basically tell him to slow down each time you trigger a new go.
What you want will need a new approach closest to what we see in 3D printing and based on distance, speed, acceleration, which is not the current approach of this library.
It could be a nice and appreciated improvement for motor driving but I sadly don't have much time to work on this right now. I would suggest you to look if other library does exist for this specific task, try something from scratch, or try to hack with smaller and custom linear ramps.
I opened a new issue based on your suggestion and closing this one.