What do I need to do to assign a second movement operation to the steppers after an operation like this?

In its current state, each stepper provides movement by stopping at a certain distance at the same time. It does this with an accelerated movement. After this process, I want them to wait 3 seconds and move on to the next movement sequence. For example, in a symmetrical way. After these two steps, the steppers will stop.

This is important: I am using accelstepper library. So i want keep using acceleration/decleration on steppers' start-stop.

#include <AccelStepper.h>

// Joint 1
#define E1_STEP_PIN        36
#define E1_DIR_PIN         34
#define E1_ENABLE_PIN      30

// Joint 2
#define Z_STEP_PIN         46
#define Z_DIR_PIN          48
#define Z_ENABLE_PIN       62
#define Z_MIN_PIN          18
#define Z_MAX_PIN          19

// Joint 3
#define Y_STEP_PIN         60
#define Y_DIR_PIN          61
#define Y_ENABLE_PIN       56
#define Y_MIN_PIN          14
#define Y_MAX_PIN          15

// Joint 4
#define X_STEP_PIN         54
#define X_DIR_PIN          55
#define X_ENABLE_PIN       38

// Joint 5 
#define E0_STEP_PIN        26
#define E0_DIR_PIN         28
#define E0_ENABLE_PIN      24


// EG X-Y position bed driven by 2 steppers
AccelStepper joint1(1, E1_STEP_PIN, E1_DIR_PIN);
AccelStepper joint2(1, Z_STEP_PIN, Z_DIR_PIN);
AccelStepper joint3(1, Y_STEP_PIN, Y_DIR_PIN);
AccelStepper joint4(1, X_STEP_PIN, X_DIR_PIN);
AccelStepper joint5(1, E0_STEP_PIN, E0_DIR_PIN);

//test with uint8 converted to long
unsigned int x = 1000;

void setup() {
  Serial.begin(250000);

  // Configure each stepper
  joint1.setMaxSpeed(500.0);       //Safe Value: 500
  joint1.setAcceleration(400.0);   //Safe Value: 400
  joint1.moveTo(400);              //Safe Value: 400

  joint2.setMaxSpeed(500.0);       //Safe Value: 500
  joint2.setAcceleration(400.0);   //Safe Value: 400
  joint2.moveTo(400);              //Safe Value: 400

  joint3.setMaxSpeed(3500.0);       //Safe Value: 3500
  joint3.setAcceleration(3500.0);   //Safe Value: 3500
  joint3.moveTo(4000);              //Safe Value: 4000
  
  joint4.setMaxSpeed(500.0);       //Safe Value: 500
  joint4.setAcceleration(400.0);   //Safe Value: 400
  joint4.moveTo(400);              //Safe Value: 400

  joint5.setMaxSpeed(500.0);       //Safe Value: 500
  joint5.setAcceleration(400.0);   //Safe Value: 400
  joint5.moveTo(400);              //Safe Value: 400
}
void loop() {
  joint1.run();
  joint2.run();
  joint3.run();
  joint4.run();
  joint5.run();
}

Welcome to the Arduino forum.
I guess I don't understand. Why not just write the code to delay and do what you want? What have you tried and what are the results? Since your current code must be working properly, carry on with what you are doing.

You could wrap the *.run()s in a check that all axes have reached their limits:

while{ joint1.distanceToGo() || joint2.distanceToGo() || joint3.distanceToGo() || joint4.distanceToGo() || joint5.distanceToGo() ){ 
  joint1.run();
  joint2.run();
  joint3.run();
  joint4.run();
  joint5.run();
}

and put that loop between targets in setup().

or set a flag that all the steppers are in place before retargeting

if(joint1.distanceToGo() || joint2.distanceToGo() || joint3.distanceToGo() || joint4.distanceToGo() || joint5.distanceToGo() ) {
  ; // still moving
} else {
  finishedMotion = true;
}

if(finishedMotion ){
 //set new target
 // Configure each stepper
  joint1.setMaxSpeed(500.0);       //Safe Value: 500
  joint1.setAcceleration(400.0);   //Safe Value: 400
  joint1.moveTo(0);              //Safe Value: 400
  ...

  finished Motion = false;
}
...

curious what this is driving?

would you want all the joints to move simultaneously and arriving at their final positions simultaneously. And then moving to the "next" position

Did you look into the MultiStepper coordination feature of AccelStepper, and its example?

https://www.airspayce.com/mikem/arduino/AccelStepper/MultiStepper_8pde-example.html

// MultiStepper.pde
// -*- mode: C++ -*-
// Use MultiStepper class to manage multiple steppers and make them all move to 
// the same position at the same time for linear 2d (or 3d) motion.
 
#include <AccelStepper.h>
#include <MultiStepper.h>
 
// EG X-Y position bed driven by 2 steppers
// Alas its not possible to build an array of these with different pins for each :-(
AccelStepper stepper1(AccelStepper::FULL4WIRE, 2, 3, 4, 5);
AccelStepper stepper2(AccelStepper::FULL4WIRE, 8, 9, 10, 11);
 
// Up to 10 steppers can be handled as a group by MultiStepper
MultiStepper steppers;
 
void setup() {
  Serial.begin(9600);
 
  // Configure each stepper
  stepper1.setMaxSpeed(100);
  stepper2.setMaxSpeed(100);
 
  // Then give them to MultiStepper to manage
  steppers.addStepper(stepper1);
  steppers.addStepper(stepper2);
}
 
void loop() {
  long positions[2]; // Array of desired stepper positions
  
  positions[0] = 1000;
  positions[1] = 50;
  steppers.moveTo(positions);
  steppers.runSpeedToPosition(); // Blocks until all are in position
  delay(1000);
  
  // Move to a different coordinate
  positions[0] = -100;
  positions[1] = 100;
  steppers.moveTo(positions);
  steppers.runSpeedToPosition(); // Blocks until all are in position
  delay(1000);
}

Then you wouldn't have to carefully compute each axis's accelerations and the maximum speeds so they end their motions and start/stop their accelerations at the same times.

Oops. That's wrong. Multistepper doesn't do acceleration:

https://www.airspayce.com/mikem/arduino/AccelStepper/classMultiStepper.html

Thanks.
As i said on title, i dont know how to code next step to do second process. I just want to move the position of the steppers to a different position after the first process in a run. There is no problem with the current process. If i code them on void loop section like this, all steppers moving simultaneously as i want. If i code them on void setup section they are moving in order. Probably have to code what I want to do in the void loop section. But I dont know what to write, I'm newbie.

Let me try

Yes. This is exactly what I want. I have a robot arm project. I want to move them to several positions with 3 or 4 steps in a single run command. These steps will run in a order. The code I showed you is the first step.

Yea i tried it. Multistepper doesnt support acceleration and deceleration. Its very annoying.

not sure that this is what i said

if you're trying to build some animated robot (e.g. dog) several steppers need to move in unison between each movement of the appendages. 1+ motors needs to be moved for each "movement".

there would be a sequence of movements and then a sequence might repeat

but for a single movement, all the motors would be stepped at various times so that they all start and stop at the same time. once motor may require 20 steps and another 12 steps

so at the very least, if all motor need to complete the movement in time T and the motor requiring the most steps requires N steps, then that motor needs to be stepped every T/N seconds.

other motors wouldn't be stepped every T/N seconds. you'd need to keep track of which T/N events to step the other motor. if N is 20 and another motor requires 12 steps then it would stepped every 20/12 = 5/3 T/N events

the following shows how 4 motors might be stepped using the T/N approach. the 4 motors require 20, 7, 12 and 13 steps / movement. the columns show an accumulated step amount. a step is made when the accumulated value is >= 1. a "*" when a step occurs and the accumulated value subtracted by 1

         20        7       12       13
   0   1.00 *   0.35     0.60     0.65
   1   1.00 *   0.70     1.20 *   1.30 *
   2   1.00 *   1.05 *   0.80     0.95
   3   1.00 *   0.40     1.40 *   1.60 *
   4   1.00 *   0.75     1.00     1.25 *
   5   1.00 *   1.10 *   1.60 *   0.90
   6   1.00 *   0.45     1.20 *   1.55 *
   7   1.00 *   0.80     0.80     1.20 *
   8   1.00 *   1.15 *   1.40 *   0.85
   9   1.00 *   0.50     1.00     1.50 *
  10   1.00 *   0.85     1.60 *   1.15 *
  11   1.00 *   1.20 *   1.20 *   0.80
  12   1.00 *   0.55     0.80     1.45 *
  13   1.00 *   0.90     1.40 *   1.10 *
  14   1.00 *   1.25 *   1.00     0.75
  15   1.00 *   0.60     1.60 *   1.40 *
  16   1.00 *   0.95     1.20 *   1.05 *
  17   1.00 *   1.30 *   0.80     0.70
  18   1.00 *   0.65     1.40 *   1.35 *
  19   1.00 *   1.00     1.00     1.00 *

Yes, I am aware of this situation. This is how it should be. I just want to move the position of the steppers to a different position after the first process in a run. After all i'll calculate what you explained. Denavit Hartenberg calculation is also a separate issue :slight_smile:

then i don't understand what your question is

Thanks for this explanation too. I took note of this

The way CNC/3dPrinter machines solve synchronized, straight-line motion is by figuring out the axis with the longest motion, planning the speed/acceleration curve for it, and synchronizing all the slower axes with the motion of the controlling axis. The synchronization uses the Bresenham Algorithm trick that all the slower axes will step at most once per fast-axis-step.

If you identify the fastest axis and let AccelStepper determine its acceleration, you could step the other, slower axes as needed when that fast axis steps.

AccelStepper doesn't directly expose when a step happens but you could use something like this to determine if a step happened:

stepperFastAxis.run()
distanceToGo = stepperFastAxis.distanceToGo();
if (distanceToGo != lastDistanceToGo){
  stepOtherAxesAsNeeded();
  lastDistanceToGo = distanceToGo;   
}

Here's an example of coordinated motion of several axes in proportion with each other using Bresenham's algorithm (but it doesn't plan acceleration):

I got the answer to my question. This is what I wanted to do. thanks a lot !

Wow, an essential post. Thanks again

Now I can move 2 steppers as I said. However, when I install more than two steppers, it runs smoothly until the last step I process, and then enters the loop at the last step. I think I'm having a problem with the following part;

if(joint1.distanceToGo() || joint2.distanceToGo() || joint3.distanceToGo() || joint4.distanceToGo() || joint5.distanceToGo() )

I couldn't fully adapt it here. There is no problem while using 2 steppers but +2 steppers not compatible for this i think. How can i my first question with +2 steppers

What is your full new code? How does it use this "if" And what does it do wrong?

In:

That logic to set 'finishedMotion = true' if any stepper is still moving is written a little bit backwards, but I thought it seemed clear.

You could turn it around and DeMorgan it like:

if(joint1.distanceToGo() ==0 && joint2.distanceToGo() ==0 && joint3.distanceToGo() ==0 && joint4.distanceToGo() ==0 && joint5.distanceToGo() ==0) {
   finishedMotion = true;
}

... but it is equivalent.

The 7 column is missing a step.

The floating point arithmetic, roundoffs, and comparisons might make it hard to tell if a number is 1.00 or not, which could be the cause.

This T/N approach almost like the integer based Bresenham algorithm. If you were to multiply the table, increments, and decision rule by 40, the operations and storage would all be in perfect integers. Bresenham also shifts the accumulator initialization a bit to center the slower series of steps within the run and to make the decision-rule comparison into a comparison with zero.