Hallo,
Ich versuch seit Tagen die Geschwindigkeit der Stepper im Loop zu ändern und komme nicht drauf warum das nicht geht.
Eine Änderung von homeSpeed
, homeAccel
, Speed
oder Accel
bewirkt keine Änderung.
Nur wenn ich diese Werte ändere:
// Set Max Speed and Acceleration of each Steppers at startup for homing
stepperE0.setMaxSpeed(6000.0); // Set Max Speed of Stepper (Slower to get better accuracy)
stepperE0.setAcceleration(1000.0); // Set Acceleration of Stepper
stepperX.setMaxSpeed(6000.0); // Set Max Speed of Stepper (Slower to get better accuracy)
stepperX.setAcceleration(1000.0); // Set Acceleration of Stepper
stepperY.setMaxSpeed(6000.0); // Set Max Speed of Stepper (Slower to get better accuracy)
stepperY.setAcceleration(1000.0); // Set Acceleration of Stepper
stepperZ.setMaxSpeed(6000.0); // Set Max Speed of Stepper (Slower to get better accuracy)
stepperZ.setAcceleration(1000.0); // Set Acceleration of Stepper
fahren die Stepper wesentlich schneller wenn ich auf die Endschalter fahre.
Danach ist die Geschwindigkeit und die Beschleunigung immer gleich.
Der komplette Code:
/* Motor Homing code using AccelStepper and the Serial Monitor
Created by Yvan / https://Brainy-Bits.com
This code is in the public domain...
You can: copy it, use it, modify it, share it or just plain ignore it!
Thx!
*/
#include "AccelStepper.h"
// Library created by Mike McCauley at http://www.airspayce.com/mikem/arduino/AccelStepper/
// AccelStepper Setup
AccelStepper stepperE0(1, 26, 28); // 1 = Easy Driver interface
// Ramps-Board E0 Pin 26 connected to STEP pin
// Ramps-Board E0 Pin 28 connected to DIR pin
// AccelStepper Setup
AccelStepper stepperX(1, 54, 55); // 1 = Easy Driver interface
// CNC-Board Pin 54 connected to STEP pin
// CNC-Board Pin 55 connected to DIR pin
// AccelStepper Setup
AccelStepper stepperY(1, 60, 61); // 1 = Easy Driver interface
// CNC-Board Pin 60 connected to STEP pin
// CNC-Board Pin 61 connected to DIR pin
// AccelStepper Setup
AccelStepper stepperZ(1, 46, 48); // 1 = Easy Driver interface
// NANO Pin 46 connected to STEP pin
// NANO Pin 48 connected to DIR pin
// Define the Pins used
#define home_switch_E0 11 // Pin 11 connected to Home Switch (MicroSwitch)
#define home_switch_X 6 // Pin 11 connected to Home Switch (MicroSwitch)
#define home_switch_Y 5 // Pin 11 connected to Home Switch (MicroSwitch)
#define home_switch_Z 4 // Pin 11 connected to Home Switch (MicroSwitch)
#define E0_ENABLE_PIN 24
#define X_ENABLE_PIN 38
#define Y_ENABLE_PIN 56
#define Z_ENABLE_PIN 62
// Stepper Travel Variables
long TravelE0; // Used to store the X value entered in the Serial Monitor
//int move_finished=1; // Used to check if move is completed
long initial_homing_E0=-1; // Used to Home Stepper at startup
long initial_homing_X=-1; // Used to Home Stepper at startup
long initial_homing_Y=-1; // Used to Home Stepper at startup
long initial_homing_Z=-1; // Used to Home Stepper at startup
// Set Home Position
long home_E0=0; // Home Position E0
long home_X=0; // Home Position E0
long home_Y=0; // Home Position E0
long home_Z=0; // Home Position E0
// Set Home Speed
float homeSpeed=6000.0;
float homeAccel=1000.0;
// Set Speed
float Speed=6000.0;
float Accel=1000.0;
// Set Mode
int Mode=1; // 1 = Normal Mode, 2 = Upper Position, 3 = Lower Position
void setup() {
Serial.begin(9600); // Start the Serial monitor with speed of 9600 Bauds
pinMode(home_switch_E0, INPUT_PULLUP);
pinMode(home_switch_X, INPUT_PULLUP);
pinMode(home_switch_Y, INPUT_PULLUP);
pinMode(home_switch_Z, INPUT_PULLUP);
pinMode(E0_ENABLE_PIN , OUTPUT);
pinMode(X_ENABLE_PIN , OUTPUT);
pinMode(Y_ENABLE_PIN , OUTPUT);
pinMode(Z_ENABLE_PIN , OUTPUT);
delay(5000); // Wait for EasyDriver wake up
// Set Max Speed and Acceleration of each Steppers at startup for homing
stepperE0.setMaxSpeed(6000.0); // Set Max Speed of Stepper (Slower to get better accuracy)
stepperE0.setAcceleration(1000.0); // Set Acceleration of Stepper
stepperX.setMaxSpeed(6000.0); // Set Max Speed of Stepper (Slower to get better accuracy)
stepperX.setAcceleration(1000.0); // Set Acceleration of Stepper
stepperY.setMaxSpeed(6000.0); // Set Max Speed of Stepper (Slower to get better accuracy)
stepperY.setAcceleration(1000.0); // Set Acceleration of Stepper
stepperZ.setMaxSpeed(6000.0); // Set Max Speed of Stepper (Slower to get better accuracy)
stepperZ.setAcceleration(1000.0); // Set Acceleration of Stepper
// Start Homing procedure of Stepper Motor at startup
Serial.print("Stepper E0 is Homing . . . . . . . . . . . ");
while (digitalRead(home_switch_E0)) { // Make the Stepper move CCW until the switch is activated
stepperE0.moveTo(initial_homing_E0); // Set the position to move to
initial_homing_E0--; // Decrease by 1 for next move if needed
stepperE0.run(); // Start moving the stepper
}
stepperE0.setCurrentPosition(home_E0); // Set the current position as zero for now
stepperE0.setSpeed(homeSpeed); // Set Max Speed of Stepper (Slower to get better accuracy)
stepperE0.setAcceleration(homeAccel); // Set Acceleration of Stepper
initial_homing_E0=1;
while (!digitalRead(home_switch_E0)) { // Make the Stepper move CW until the switch is deactivated
stepperE0.moveTo(initial_homing_E0);
stepperE0.run();
initial_homing_E0++;
}
stepperE0.setCurrentPosition(home_E0);
Serial.println("Homing Completed");
Serial.println("");
stepperE0.setSpeed(Speed); // Set Max Speed of Stepper (Faster for regular movements)
stepperE0.setAcceleration(Accel); // Set Acceleration of Stepper
Serial.print("Stepper is Homing X . . . . . . . . . . . ");
while (digitalRead(home_switch_X)) { // Make the Stepper move CCW until the switch is activated
stepperX.moveTo(initial_homing_X); // Set the position to move to
initial_homing_X--; // Decrease by 1 for next move if needed
stepperX.run(); // Start moving the stepper
}
stepperX.setCurrentPosition(home_X); // Set the current position as zero for now
stepperX.setSpeed(homeSpeed); // Set Max Speed of Stepper (Slower to get better accuracy)
stepperX.setAcceleration(homeAccel); // Set Acceleration of Stepper
initial_homing_X=1;
while (!digitalRead(home_switch_X)) { // Make the Stepper move CW until the switch is deactivated
stepperX.moveTo(initial_homing_X);
stepperX.run();
initial_homing_X++;
}
stepperX.setCurrentPosition(home_X);
Serial.println("Homing Completed");
Serial.println("");
stepperX.setSpeed(Speed); // Set Max Speed of Stepper (Faster for regular movements)
stepperX.setAcceleration(Accel); // Set Acceleration of Stepper
Serial.print("Stepper Y is Homing . . . . . . . . . . . ");
while (digitalRead(home_switch_Y)) { // Make the Stepper move CCW until the switch is activated
stepperY.moveTo(initial_homing_Y); // Set the position to move to
initial_homing_Y--; // Decrease by 1 for next move if needed
stepperY.run(); // Start moving the stepper
}
stepperY.setCurrentPosition(home_Y); // Set the current position as zero for now
stepperY.setSpeed(homeSpeed); // Set Max Speed of Stepper (Slower to get better accuracy)
stepperY.setAcceleration(homeAccel); // Set Acceleration of Stepper
initial_homing_Y=1;
while (!digitalRead(home_switch_Y)) { // Make the Stepper move CW until the switch is deactivated
stepperY.moveTo(initial_homing_Y);
stepperY.run();
initial_homing_Y++;
}
stepperY.setCurrentPosition(home_Y);
Serial.println("Homing Completed");
Serial.println("");
stepperY.setSpeed(Speed); // Set Max Speed of Stepper (Faster for regular movements)
stepperY.setAcceleration(Accel); // Set Acceleration of Stepper
Serial.print("Stepper Z is Homing . . . . . . . . . . . ");
while (digitalRead(home_switch_Z)) { // Make the Stepper move CCW until the switch is activated
stepperZ.moveTo(initial_homing_Z); // Set the position to move to
initial_homing_Z--; // Decrease by 1 for next move if needed
stepperZ.run(); // Start moving the stepper
}
stepperZ.setCurrentPosition(home_Z); // Set the current position as zero for now
stepperZ.setSpeed(homeSpeed); // Set Max Speed of Stepper (Slower to get better accuracy)
stepperZ.setAcceleration(homeAccel); // Set Acceleration of Stepper
initial_homing_Z=1;
while (!digitalRead(home_switch_Z)) { // Make the Stepper move CW until the switch is deactivated
stepperZ.moveTo(initial_homing_Z);
stepperZ.run();
initial_homing_Z++;
}
stepperZ.setCurrentPosition(home_Z);
Serial.println("Homing Completed");
Serial.println("");
stepperZ.setSpeed(Speed); // Set Max Speed of Stepper (Faster for regular movements)
stepperZ.setAcceleration(Accel); // Set Acceleration of Stepper
}
void loop() {
if (Mode = 1){
stepperE0.moveTo(12300);
stepperX.moveTo(12300);
stepperY.moveTo(12300);
stepperZ.moveTo(12300);
while (stepperE0.currentPosition() !=12300 || stepperX.currentPosition() !=12300 || stepperY.currentPosition() !=12300 || stepperZ.currentPosition() !=12300 ) {
stepperE0.run();
stepperX.run();
stepperY.run();
stepperZ.run();
}
stepperE0.moveTo(0);
stepperX.moveTo(0);
stepperY.moveTo(0);
stepperZ.moveTo(0);
while (stepperE0.currentPosition() !=0 || stepperX.currentPosition() !=0 || stepperY.currentPosition() !=0 || stepperZ.currentPosition() !=0 ) {
stepperE0.run();
stepperX.run();
stepperY.run();
stepperZ.run();
}
}
if (Mode = 2){
stepperE0.moveTo(12300);
stepperX.moveTo(12300);
stepperY.moveTo(12300);
stepperZ.moveTo(12300);
while (stepperE0.currentPosition() !=12300 || stepperX.currentPosition() !=12300 || stepperY.currentPosition() !=12300 || stepperZ.currentPosition() !=12300 ) {
stepperE0.run();
stepperX.run();
stepperY.run();
stepperZ.run();
}
Mode = 0;
}
}
Ich verwende dazu einen Mega mit RAMPS 1.6 und TMC2208
Wäre sehr froh wenn mir jemand bei dem Thema einen Tipp geben kann warum das nicht funktioniert. Ich habe zwar schon viele Projekte mit dem Arduino gemacht aber die Stepper sind Neuland für mich.
Danke für jede Hilfe!
MfG fec-tech