Mobatools different ramp for accel and decel

Not sure if this is possible or not. I'm using a closed loop stepper driven ballscrew and need to change directions as quickly as possible. Currently the motor driver is happy with a 400 ramp length (1 revolution), anything shorter than that and it trips out (too many lost steps I believe) but it's always on the acceleration side that it happens so I believe I could shorten the deceleration ramp but reading through the documentation I can't see where that's an option.

I know I could reset it in the code where it resets the moveto to the other direction but there's already a dwell for some reason that I'm working on getting rid of so I don't want to add more code at that spot and make it worse.

#include <MobaTools.h>

/* eps32 test code */



const int SEL_SW = 13;      // Manual / auto select switch
const int MAN_UP = 16;      // Stepper Manual Up button
const int MAN_DN = 17;      // Stepper Manual Down Button
const int AUT_START = 18;   // Auto Start Button
const int AUT_STOP = 19;    // Auto Stop Button
const int HOME_SW = 33;     // Manual / auto select switch

const int DIR = 2;          // Stepper DIR Pin 2
const int STEP = 4;         // Stepper STEP Pin 4

const int SPEED_IN = 32;    // Analog Input
//const int CYCLES_IN = xx;  // Analog Input
//const int DWELL_IN = xx;  // Analog Input

bool isStepping = false;
bool home_state = 0;
bool MAN_UP_STATE = LOW;
bool MAN_UP_PREV = LOW;
bool MAN_DN_STATE = LOW;
bool MAN_DN_PREV = LOW;
bool AUT_START_STATE = LOW;
//int DWELL_DATA = 0;
//int DWELL = 0;
//int Start_Time = 0;
//int Stop_Time = 0;
int Cycle_To_Do = 0;
int cycle_cnt=0;

long maxSpeed = 20000;
int ramp_len=400;

bool HOMED = false;

                              // ballscrew is 5mm pitch
const long EndPoint = 36576;  //52832 = 26"     36576 = 18"     24384 = 12"
long nextPos = 0;

MoToStepper myStepper (400,STEPDIR); // setps per rev and what type of control
//MoToTimer stepperPause;              // leftover from example 


void setup()
{  
  Serial.begin(115200);
  pinMode(AUT_START,INPUT_PULLUP);
  pinMode(AUT_STOP,INPUT_PULLUP);
  pinMode(MAN_UP,INPUT_PULLUP);
  pinMode(MAN_DN,INPUT_PULLUP);
  
  pinMode(HOME_SW,INPUT_PULLUP);
  
  myStepper.attach( STEP, DIR );      //4, 2
  
  myStepper.setRampLen( ramp_len );   //400
  
  delay(2000);        // need to prevent partial run when loading 

  Cycle_To_Do=2;          // this will come from selector switch CYCLES_IN

  // ***** HOMING THE CARRIGE *****
  myStepper.setZero(0);               //
  myStepper.setSpeed( 5000 );         // slow speed for homing
  
  myStepper.moveTo(3000);             // move the carrige down some
  while ( myStepper.distanceToGo()!=0 )
  {
    //Serial.println("Staging");
    myStepper.moveTo(3000);   
  }

  while (HOMED == false )           // move up to home switch
   {
    //Serial.println("Homing");
    home_state = digitalRead(HOME_SW);  // Check the switch
                                        // It was not working
                                        // correctly when I used
                                        // if (digitalRead(HOME_SW) == 0)
                                        // but the switch was buggy
                                        // so maybe ok now that its fixed

    myStepper.moveTo(myStepper.currentPosition()-400);    // keep moving up
        if (home_state==0)
        {
          myStepper.stop();
          myStepper.setZero(1200);          // come down off the switch
          myStepper.moveTo(0);
          HOMED=true;
        }
        if (myStepper.distanceToGo()==0 && HOMED == true)
        {
          myStepper.setSpeed(maxSpeed);     // Set full speed
          Serial.println("HOMED");
        }
   }
}


void loop()
{
if(digitalRead(SEL_SW)==false)    //****************** manual mode *********** 
                                  // none of this is tested yet
{
  if(digitalRead(MAN_UP)==false && HOMED == false)
  {
    Serial.println("UP button pressed");
    if (myStepper.currentPosition()-100 >0)
    {
      myStepper.moveTo(myStepper.currentPosition()-100);
      if(digitalRead(HOME_SW)==false)
      {
        myStepper.stop();
        Serial.println("LIMIT");
      }
    }
  }
  else if(digitalRead(MAN_DN)==false && HOMED == false)
{
      myStepper.moveTo(myStepper.currentPosition()+100);
} 

}
else    //************************ automnatic mode ************************** 
{       //  This is where I'm working now

  if( !isStepping )     // not currently cycling
  {
    if(digitalRead(AUT_START)==false) // check for start button press
      {
        Serial.println("START button pressed");
        isStepping = true;
        myStepper.moveTo(EndPoint); 
      }
  }

  else   // is running cycles
  {
    if ( myStepper.distanceToGo()==0 )              // reached target
      {
        if(myStepper.currentPosition() == EndPoint) // if it's at the bottom
        {
          myStepper.moveTo(0);                      // new target at the top
        }
        else                                        // it's at the top
        {
          myStepper.moveTo(EndPoint);               // new targer at the bottom
          cycle_cnt++;                              // count the # of cycles
        }
                                                    // if it's at the top
                                                    // and had done the # of 
                                                    // cycles needed
      if( cycle_cnt>=Cycle_To_Do && myStepper.currentPosition() == 0)
      {
        myStepper.stop();
        isStepping = false;
        cycle_cnt=0;
        Serial.println("done");
      }

    }
    else            // moving between end points
    {
      if(digitalRead(AUT_STOP)==false)        // check the stop button
        {
          Serial.println("STOP button pressed");
          myStepper.setSpeed(0);              // stop with ramp
          stepperPause.setTime( 1000 );       // not sure if needed
          myStepper.setSpeed(maxSpeed);       // reset speed
          myStepper.moveTo(0);                // go back to the up position
          cycle_cnt=Cycle_To_Do;              // cancel any outstanding cycles
          isStepping = false;
        }
    }
  }
  }
}

Any help would be appreciated
Thanks.

Hi @mooser66 ,

welcome to the arduino-forum

If it is really a closed loop stepper. Not a single step will be lost.

Closed loop means: There is an encoder that gives feedback about the real position in steps.
And with this information the closed-loop drive will go on creating step-pulses until target-position is reached even in the case of lost steps.

So either your stepper-driver is not a closed loop driver or something else and something very strange is happening.

You should post the exact type of your "closed loop stepper"-system including the datasheet / manual

You should post your complete sketch as a code-section. Without seeing and analysing your code it is almost impossible to give any kind of advice.

It isn't, in deed. You cannot set ramp length differently for acceleration and deceleration.
But as you already suggested, you can change it on the fly. This should not create a noticeable dwell time. That must be a different problem.

Hi Stephan. I didn't go into details about the stepper as I was really after if it was possible to have different decel and accel ramps (which MicroBahner confirms it isn't)
The controller is a Rattm Motor 2HSS86 and a NEMA34 1200Nm stepper moving a 16lb weight waaaay faster than it should be and then trying to reverse it as fast as possible... The driver error is signalled with the flashing error light and according to the manual mean "Error occurs when the actual position
following error exceeds the limit which
is set by the position error limit

(Sorry, hit enter and can't see how to edit the post) Anyway, that's where the closed loop is giving up and shuts down.... If I ramp at 400 (one full turn) it will go for countless cycles but if I drop down to say 350 it will trip when trying to accelerate after the direction change.. if I drop to 300 it will trip on any acceleration.

I will post the code with hopes that someone can improve the way I'm working it. The code was originally done on an arduino, then added accelstepper moved to a esp8266 and then Mobatools then moved to the current esp32 so it's been twisted and butchered and no doubt now the best way to be written and could use a fresh set of eyes with way more experience than mine. Thanks for the verification about the ramp options

So you either should set a different error-limit or use a stepper-motor with more torque.

By the way a nema 34 with 1200 Nm would be 12 full meters loooooong.

1200 Nm must be a typo

I'd like to go servo or even pneumatic as I believe we're maxed out here with this setup but right now they want to use the existing so I'm stuck with what I got.

And yeah, I mixed up, it's a 12N.m (wish it was 1200, maybe then it could sling this weight faster :slight_smile:

I've managed to get it down to running 7 seconds for a 18" cycle, the target is 5 and I've run out of ideas.
Any faster on the speed and it errors, and shorter on the ramp and it errors (on acceleration)

There's a bunch of weirdness in the code but I don't think it's a problem with the processor speed, I think physics is kicking my butt at this point. object at rest and in motion and all that.

Edited the original post with the code marked up as best I can. It's pretty rough but semi functional.

There's still some analog reads that need to be done, 3 in all but I think I can limit the checks to when the carriage is at the top position as there will be a dwell there between each cycle.

Thanks again