MultiStepper Library

Hi All,
A basics question as I am still in the planning stage of the program. If you have linked steppers with the <MultiStepper.h>, can I still use the accelStepper functions on each motor? EG:
void setup(){
//configure each stepper
stepper1.setMaxSpeed(300.0);
stepper2.setMaxSpeed(300.0);
//hand steppers to MultiStepper to manage
steppers.addStepper(stepper1);
steppers.addStepper(stepper2);
}
then later in loop somewhere:
stepper1.distanceToGo().......

is this possible?

Forgive the possibly silly question as I am only learning and have a long way to go yet.....

type or paste code here

I remember reading somewhere that MultiStepper doesn't do acceleration. I can't find it in the documentation right now. I might have been looking in the sources.

Yes, that is true. I am not concerned with acceleration. I am more looking at having two motors connected or "Linked" like the MultiStepper class enables however I would like to control the speed of one motor and have the other calculate the required speed from the first. I also would like to poll the current position of the motors but the multistepper class does not have functions for this.

Can I call accelStepper functions without upsetting the MultiStepper function?

I’ve done what you want with an array of Accelstepper .
It works flawlessly, but is hobbled by Accelsteper’s limit of ~4000 steps/sec on AVRs… a faster processor, or a ‘trimmed’ library might do what you want.

A few years ago, I had a similar project with my own software driving step+dir drivers… easily pushing 10K steps per second and other things on a 16MHz AVR.

That sounds awesome, Speed does not present an issue as I am using an ESP32 (mainly for onboard bluetooth) and the motor speed output pulse is fairly slow, even with microstepping. Any chance that you might have a snippet of code as an example? I am still getting my head around arrays. The char array for bluetooth is cooking my noodle :).

For reference, I am quite proficient in CNC programing of industrial machines but C++ coding is all very new. You have to start somewhere I suppose....

Free gift…
Doesn’t do everything you wanted, but it works, and has all the bits and maybe some more.
It provides a simple serial command line.

AccelStepper Module.pdf (208.0 KB)
files

Create a new folder ‘stepper_test’, copy the files
Just compile, upload & run then you’ll get some ideas…
You’ll need to set the pins declared at the top of the ink

stepper_test.ino (4.0 KB)

Serial.ino (12.4 KB)

Awesome, Thanks man!

if you want to have two stepper-motors or even three in sync even with different speeds but keeping a contant ratio of dx / dy you can use the bresenham algorythm.

With steppermotors you can have high precision at least with using microstepping. Still the movement is granular. This means for
x-distance 1000 steps
y-distance 100 steps
each ten x-steps do one y-step ratio 100 / 1000 = 0,1
the bresenham-algorythm does one x-step and adds 0,1 to a y-float
everytime the y-float changes left of the decimal-point do a y-step

if the ratio is above 1
x-distance 100 steps
y-distance 1000 steps
dy/dx = 1000 / 100 = 10

the y-axle becomes the "leading" axle
do one y-step and add 0,1 to the x-float
if x-float changes left from decimal-point do a x-step
y 1 dx 0.1
y 2 dx 0.2
y 3 dx 0.3
y 4 dx 0.4
y 5 dx 0.5
y 6 dx 0.6
y 7 dx 0.7
y 8 dx 0.8
y 9 dx 0.9
y 10 dx 1.0 = x-float has changed left from decimal-point create an x-step-pulse
y 11 dx 1.1
....

This is the basic principle
additionally you have to take care of directions
but this applies to any dx/dy-ratios
x-distance 3000
y-distance 1000
dy/dx = 0.33
dx = 1 dy = 0.33
dx = 2 dy = 0.66
dx = 3 dy = 0.99
dx = 4 dy = 1.32 y-float changed left from decimal-point create a y-pulse
dx = 5 dy = 1.65
dx = 6 dy = 1.98
dx = 7 dy = 2.31 y-float changed left from decimal-point create a y-pulse
dx = 8 dy = 2.64
dx = 9 dy = 2.97
dx = 10 dy = 3.30 y-float changed left from decimal-point create a y-pulse

As you can see every three x-steps one y-step resulting in
x-distance 3000 y-distance 1000

There is a loop that creates the steps with this loop running "n" times where "n" is the number of steps of the leading axle

With the dy/dx-ratio you have to check which axle is "leading" and you have to check directions
x-distance plus-minus y-distance plus-minus

With this method you can do even acceleration / decceleration. The leading axle determines the acceleration and the following axle has a smaller but fitting acceleration.

From time to time I have searched for simple demo-codes using the bresenham-algorithm but I haven't found a real simple demo-code yet

Be the change you want to see in the world
best regards Stefan

I think How to build an 2-axis Arduino CNC Gcode Interpreter – Marginally Clever Robots is good -- Here it is, ported to Wokwi with a couple corrections: GcodeCNCDemo2Axis.ino - Wokwi ESP32, STM32, Arduino Simulator

The problem with a simple demo of the Bresenham's line algorithm - Wikipedia is that it breaks down into special cases. In the case of two stepper motors, you need to iterate on the stepper that's going faster, and sum up the fraction (or commonly fixed-point integer fraction) that the line advances along the slower axis. If you do an arc, the changeover from one axis being faster/dominant to the other axis being dominant really complicates things.

The simplest demonstration case of the bresenham algorithm would be a phase-locked loop, generating a pulse train at higher (or lower) frequencies from a source signal. At its root, bresenham is a lot simpler than the implementations make it look.