Telling the stepper to move again before it gets to the last position is wrong.
It will go a lot faster if you let it actually get up to speed (and to a position) before changing the target.
I think I´ve fixed now the issue with the change of the target, have I done it right?
All 3 steppers are moving now as desired. But if I set the resolution(n) higher, they are moving slowly. I think the MEGA with 16MHz is to slow for realtime-calculation of the values.
Is there a possibility to calculate the values in advance, save them somehow and later just read them and run the accelstepper-code?
#include <AccelStepper.h>
#include <spline.h>
Spline tempCurveX;
Spline tempCurveY;
Spline tempCurveZ;
AccelStepper stepperX(1, 33, 35);
AccelStepper stepperY(1, 51, 53);
AccelStepper stepperZ(1, 24, 22);
const int panM0 = 23;
const int panM1 = 25;
const int panM2 = 27;
const int tiltM0 = 41;
const int tiltM1 = 43;
const int tiltM2 = 45;
const int sliderMS1 = 34;
const int sliderMS2 = 32;
const int sliderMS3 = 30;
const int stepper4M0 = 52;
const int stepper4M1 = 50;
const int stepper4M2 = 48;
long nPosition = 0;
float n[7] = {
-800,0,1000,2000,3000,4000,4800 };
float x[7] = {
0,0,9000,11000,9000,0,0 };
float y[7] = {
0,0,5000,0,5000,0,0 };
float z[7] = {
0,0,90000,100000,90000,0,0 };
void setup()
{
// Serial.begin(9600);
digitalWrite (tiltM0, LOW);
digitalWrite (tiltM1, LOW);
digitalWrite (tiltM2, HIGH);
digitalWrite (panM0, LOW);
digitalWrite (panM1, LOW);
digitalWrite (panM2, HIGH);
digitalWrite (sliderMS1, HIGH);
digitalWrite (sliderMS2, HIGH);
digitalWrite (sliderMS3, LOW);
stepperX.setMaxSpeed(4000);
stepperY.setMaxSpeed(4000);
stepperZ.setMaxSpeed(4000);
}
void loop()
{
tempCurveX.setPoints(n,x,7);
tempCurveX.setDegree(Catmull);
tempCurveY.setPoints(n,y,7);
tempCurveY.setDegree(Catmull);
tempCurveZ.setPoints(n,z,7);
tempCurveZ.setDegree(Catmull);
if(nPosition <=4000){
if (stepperX.distanceToGo() == 0 && stepperY.distanceToGo() == 0 && stepperZ.distanceToGo() == 0){
float tempY = tempCurveY.value(nPosition);
float tempX = tempCurveX.value(nPosition);
float tempZ = tempCurveZ.value(nPosition);
long tempGerundetX = long(tempX+0.5);
long tempGerundetY = long(tempY+0.5);
long tempGerundetZ = long(tempZ+0.5);
stepperX.moveTo(tempGerundetX);
stepperY.moveTo(tempGerundetY);
stepperZ.moveTo(tempGerundetZ);
// Serial.println(tempGerundetX);
nPosition++;
}
stepperX.setSpeed(4000);
stepperX.runSpeedToPosition();
stepperY.setSpeed(4000);
stepperY.runSpeedToPosition();
stepperZ.setSpeed(3000);
stepperZ.runSpeedToPosition();
}
}