Fastest way to use 2 stepper motors simultaneously

I am trying to create a project of a small turret which incorporates object detection(this part is irrelevant I only wanted to give some clarity)
I searched for several forums but couldn't find a definitive answer:
My main objective is to use the turret in x and y axises with each having a nema17 step motor individually. I need to be able to find the fastest way possible for the turret the aim which means:

x for x axis length , y for y axis length, c(x,y) for the final point.
x(t) for the time to finish the distance of x from current point . (same for y(t) c(t))

Now what I am trying to accomplish is to reach the point c in the fastest way possible, which happens to be the longest duration between x(t) and y(t) (because the slower one would already be at its final point by the time the longer one gets there)

So if x > y --> x(t) > y(t) thus:
c(t) = x(t)

  • To be able to do that, i need to use both stepper motors simultaneously in different steps and I don't know if I'm able to to dat with an arduino uno.
  • I do not want to make it "seem" like the stepper motors are working simultaneously via moving each motor in small increments beacuse that would still actually be smaller than my goal.

I do have an option to use two arduinos (1 for each stepper motor) but I am asking if there is a more efficient option, if not, please give me some advice on my journey

I am sorry for not depicting a code but the code is not really written yet. I want to specify this detail first and then start coding.
I apologise if my description is too explanatory and long but I saw too many forums with the same question that lead to nowhere so that's why.

Note: Arduino's only objective is to move the turret and shoot, so other calculations and commands are done by a raspberry pi 4

You can absolutely control the motors in small steps one after the other. This is roughly the way most "Multitasking" in Industrial Controllers work. The Arduino should work fast enough, so it is not noticable to humans.
A 3D Printer has at least 4 Axis and a single core controller is perfectly fine.

You can move multiple steppers with synchronized motion:

The trick for coordinated motion is the Bresenham line drawing algorithm, where you step the fast axis at speed, and step the slow axis or not as needed by keeping track of the ratio between the slower stepping and the faster stepping.

AccelStepper has a multi-stepper option, but speed is limited.

1 Like

Hi at @theo_1080

welcome to the arduino-forum.
You did not exactly define what fastest way means.

  • fastest way to finish the project
    or
  • fastest way to finish x-movement and y-movement

If it doesn't matter that it might happend that one axle finishes its way sooner than the other axle

set target X set target Y
repeat

  • create a single steppulse for X until target X is reached
  • create a single steppulse for Y until target Y is reached

until both targets are reached

1 Like

Can you please elaborate more on this subject, or guide me to a link?

I am new to this subject so please bear with me:

Wouldn't using this method mean that the total time for turret to get to his location would equal to total time spent on getting to the x axis + total time spent on getting to the y axis?

I will be looking into this, thank you

I believe he means that x&y will be stepping as fast as possible, but the shorter axis motion will reach its setting first. It doesn't go directly, but goes diagonally at maxX & maxY travel speed until it reaches Y(X) and then continues stepping at maxX (maxY) speed along X (Y) until it reaches the destination.

Turret-wise, it starts turning both as fast as possible, and if it reaches azimuth or elevation first, it stops stepping along that axis, but continues at full speed along the other adjustment.

@DaveX

I am completely and utterly thrilled. :slightly_smiling_face: :upside_down_face: :yum: :smile: :stuck_out_tongue: :grin: :green_heart: :yellow_heart: :orange_heart: :heart: :100: :+1: :ok_hand: :clap: :smile: :grin:
This is the most compact G-code interpreter I've ever seen.

Of course, I don't earn my money from internet research doing this hundreds of hours
but I spent dozens of hours researching to find a good implementation of the Bresenham algorithm
You won't find much and then it's either highly complicated and/or incomplete in the sense of entering G-code as a character string
==> code generates the step pulses coordinated for two axes

@DaveX I can't thank you enough for posting this.

best regards Stefan

1 Like

Thanks but it’s the MarginallyCleverRobots guy who wrote the code. I just implemented it on wokwi

It’s missing a few things as compared to more practical implementations: non-blocking, acceleration, and motion planning, but it is amazing with the parsing, axis sorting, and bresenham coordinated motion.

I had made a couple other implementations of MarginallyClever's other programs:

GCodeUnoCncShieldV3.ino Copy - Wokwi ESP32, STM32, Arduino Simulator 4 axis configured for CNC shield on Uno

GcodeCNCDemo2Axis_CNCV3.ino - Wokwi ESP32, STM32, Arduino Simulator 2 axis on Uno CNC shield

GcodeDemo6AxRumbaESP32.ino - Wokwi ESP32, STM32, Arduino Simulator 6 axis gcode on a esp32

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