siteswapjuggler / RAMP

Arduino Interpolation Library
GNU General Public License v3.0
139 stars 23 forks source link

Some strange behaviour with short ramps #3

Closed davideo71 closed 5 years ago

davideo71 commented 5 years ago

Hi!

Getting some great use out of this lib but am encountering some erratic behaviors when the ramp time is set to very short (for me it happens below 135 millis when ramping to 900). The ramp starts to return a very large number from the update() function rather than expected values and doesn't finished().

siteswapjuggler commented 5 years ago

Can you tell me your version of the library and send me the code which cause this trouble. I'll investigate on this as soon as possible.

davideo71 commented 5 years ago

Sure! I'm using the 0.4.1 version of the lib. The code below generates the issue for me. (sorry, not so capable with the code inserts here)

` //isolated ramp issue //This runs on my teensy3.2 ( Arduino compatible) with a little OLED display attached. //I've left the OLED code here just in case you have a similar setup

/* //_OLED__

include

include

//#ifdef U8X8_HAVE_HW_SPI //#include //#endif

ifdef U8X8_HAVE_HW_I2C

include

endif

U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0, A5, A4, U8X8_PIN_NONE); */

include

rampInt myRamp; rampInt newRamp;

//int minimalRPM; int stageOfMove=0; int rampValue;

int ramptime = 50;// 50 SEEMS TOO FAST? CHANGE THIS TO A VALUE > 200 TO MAKE THE RAMP WORK AS EXPECTED!!

void setup() { //SETUP OLED // u8g2.begin(); // u8g2.setPowerSave(0); // welcome();

}

void loop() {

makeDaMove(); //debugDisplay(); }

bool makeDaMove(){// set the _thisMove.stageOfMove to 1 to start the whole thing

bool _moveDone = false;

if(stageOfMove== 0){ 
  myRamp= newRamp;                  //set up a fresh ramp 
  stageOfMove=1;       
}

if(stageOfMove== 1){
myRamp.go(500,ramptime,LINEAR); //start the timer
stageOfMove++; //move to the next stage }

if(stageOfMove== 2){      
  if(myRamp.isFinished()){          //if it ends 
    stageOfMove = 0;                //start again
  }
}

rampValue = myRamp.update(); //the rampValue is the one that's problematic :-) return _moveDone; } /* void debugDisplay(){ //u8g2.setFont(u8g2_font_8x13_t_symbols); u8g2.firstPage(); do { u8g2.setCursor(0, 12); u8g2.print("ramp val "); u8g2.setCursor(70, 12); u8g2.print(rampValue);

  } while ( u8g2.nextPage() );

}

void welcome(){ u8g2.setFont(u8g2_font_8x13_t_symbols); u8g2.firstPage(); do { u8g2.setCursor(0, 10); u8g2.print(F("Screen On!")); u8g2.setCursor(0, 25); u8g2.print(F("All Clear!")); } while ( u8g2.nextPage() ); delay(1000); } */


`
siteswapjuggler commented 5 years ago

Hmmm I didn't test it yet but I can say that your declaration seems strange :

rampInt myRamp; rampInt newRamp;

and then myRamp = newRamp; in the setup... this shouldn't mean to work like that.

I'm actually not sure what cpp does in this case, probably something like a pointer association which could cause a mess. In your case you just need to reset "myRamp" in stageOfMove == 0 with something like this myRamp.go(yourInitialValue);

davideo71 commented 5 years ago

The myRamp = newRamp construction doesn't seem to create issues but your way seems cleaner so I am using that (I didn't realize I could just reset the ramp like that with a single value).

This doesn't change to the issue I described before (which is still there), but my code has improved a bit.

siteswapjuggler commented 5 years ago

Hello there,

thanks for your patience on this issue, I just pushed a commit that should correct this.

Have a nice day.