Menu

StpDuoBuff

Perrotti

Class StpDuoBuff

Adds a circular buffer to automatically execute motion sequences. Introduces the use of the TMoveParam structure to store movements.

Public declaration:

#define STP_MAX_BUFF_MOVES  10

typedef struct{
  byte mvType;
  union{
    long  steps; 
    float param;
  }
}
TMoveParam;

class StpDuoBuff: public StepperDuo{
public:
  // Construction
  StpDuoBuff();

  // Initialization
  void begin(uint startSpeed, uint cruiseSpeed);
  void beginLf(int mPin_1, int mPin_2, int mPin_3, int mPin_4);
  void beginRg(int mPin_1, int mPin_2, int mPin_3, int mPin_4);
  void turboOn();
  void turboOff();
  void halfStepOn();
  void halfStepOff();
  void setBrakeCutPercent(byte brakeCutPercent);
  void setReportSteps(long steps);

  // Operation
  void run();
  void moveSteps(byte mvType, long steps);
  void moveSteps(TMoveParam* mov);
  boolean addMoveSteps(byte mvType, long steps);
  boolean addMoveSteps(TMoveParam* mov);
  void moveOn(byte mvType);
  void goNow();
  void clearMoves();
  void stopNow();
  void decelStop();
  void motorOff();

  // Monitoring
  boolean halfStep();
  boolean isMoving();
  byte getMoveType();
  byte movesCount();

protected:
  virtual void onStepsDone(long steps, long totalSteps){}
  virtual void onStartMoveSteps(byte mvType, long steps){}
  virtual void onMoveStepsDone(byte mvType, long steps){}
  virtual void onAllMovesDone(){}

private:
  boolean executeOn= false;

  TMoveParam* getNextMove(TMoveParam* mov);
  TMoveParam* checkLastMove();
};

How to use

Read first the topics discussed on the Stepper Motors page.

Initialization

Call begin() before any method to inform startSpeed and cruiseSpeed. Next, call beginLf() and beginRg() methods to inform control pins of stepper motors.
Then select the operation mode of motors (half step, turbo or none).
If needed, configure the brake cut percent calling setBrakeCutPercent().
If you want to receive events when certain number of steps are performed, call setReportSteps() informing the number of steps to trigger the event onStepsDone(). The value zero on steps parameter disable onStepsDone() event.

Operation

Dont forget to call run() method at least once per loop.
To start a move not buffered, call moveSteps() or moveOn(). moveSteps() execute the number of steps informed and stop (after decelerate). moveOn() causes the movement to continue until some method is called to stop.
To stop the movement immediately call stopNow(). To stop with deceleration call decelStop().

To add movements on buffer, call addMoveSteps(). To execute the movements stored call goNow(), the movements will be executed in sequence. To clear the buffer call clearMoves(). This not interrupt current move. movesCount() return the number of moves on buffer, current move is not included.


Related

Wiki: StepperCouple
Wiki: StepperDuo
Wiki: StepperMotors
Wiki: StepperSingle
Wiki: StpDuoTimer2

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.