Mobatools programming question

Hi,

my first post here.

This is about using mobatools to control two step motors.

I have two questions and need some help.

  1. if I need drive two motors , start and end at same time (say total 30 seconds) with different speed, but each motor also change speed at time 0-10, 10-20, 20-30, how to do this? will mobatools give smooth change from one speed to another?

  2. if i also need to define acceleration/deceleration for each time region, can mobatools do that? if not, which library is best to go with?

Thanks a lot!

Question 1. Yes. Of course small changes in requested speed yield correspondingy small changes in motor speed. The best thing is to try it.

You can assign a speed and/or accel, independently for each axis at any time.

I find MobaTools easier to learn and use.

A 'quick and dirty' demo:

#include <MobaTools.h>

constexpr int stepsPerRev = 800;
constexpr byte stepPin1 = 6;
constexpr byte dirPin1 = 5;
constexpr byte stepPin2 = 9;
constexpr byte dirPin2 = 8; 
MoToStepper stepper1( stepsPerRev, STEPDIR );
MoToStepper stepper2( stepsPerRev, STEPDIR );
const int speed1[] = { 5000, 15000, 10000 };
const int speed2[] = { 3000, 5000, 4000 };

void setup() {
  // put your setup code here, to run once:
  stepper1.attach( stepPin1, dirPin1 );
  stepper2.attach( stepPin2, dirPin2 );
  // set initial speeds and ramp
  // ramplen is set dependign on speed, so that it need nearly the same time for both steppers.
  stepper1.setSpeedSteps( speed1[0], speed1[0]/20 ); // set speed and ramplen
  stepper2.setSpeedSteps( speed2[0], speed2[0]/20 );
  // start moving
  stepper1.rotate(1);
  stepper2.rotate(1);
  for ( byte i=1; i<3; i++ ) { 
  delay( 10000 );
  stepper1.setSpeedSteps( speed1[i], speed1[i]/20 );
  stepper2.setSpeedSteps( speed2[i], speed2[i]/20 );
  }
  delay(10000);
  // stop moving
  stepper1.rotate(0);
  stepper2.rotate(0);
 }

void loop() {
  // put your main code here, to run repeatedly:

}
1 Like

hi, MicroBahner

Thank you very much for your code!

To end the rotations at the same time the two speeds have to be calculated precisely and the speed of the second motor depends on the speed of the first motor.

Anyway: You should describe your project. What is the final puprose of two stepper-motors start and stop at the same time but using different speeds.

It might well be that is not really important to stop the two motors at the exact same millisecond. But this highly depends on the details of your project.

A different approach to achieve perfect synchronisiation is to use the bresenham-algorithm.

Here is a WOKWI-Simulation using real Arduino C++-Code to demonstrate the bresenham-algorithm in combination with a G-Code-Parser

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.