Thanks for the reply, I had thought that this project had gone away, though currently there is rumblings about getting funding for the items, I do not have much control over the parts which are going to be used, though I do know that it will be Arduino Mega, stepper motor and pololu a4988 drivers. Currently I have been able to get five motors (as these are what I had to hand) to do a soft stop/start as requested to reduce wobble.
#define DIR_PIN1 2
#define STEP_PIN1 3
#define ENABLE_PIN1 4
#define DIR_PIN2 5
#define STEP_PIN2 6
#define ENABLE_PIN2 7
#define DIR_PIN3 8
#define STEP_PIN3 9
#define ENABLE_PIN3 10
#define DIR_PIN4 11
#define STEP_PIN4 12
#define ENABLE_PIN4 13
#define DIR_PIN5 14
#define STEP_PIN5 15
#define ENABLE_PIN5 16
void setup() {
pinMode(STEP_PIN1, OUTPUT);
pinMode(DIR_PIN1, OUTPUT);
pinMode(ENABLE_PIN1, OUTPUT);
pinMode(STEP_PIN2, OUTPUT);
pinMode(DIR_PIN2, OUTPUT);
pinMode(ENABLE_PIN2, OUTPUT);
pinMode(STEP_PIN3, OUTPUT);
pinMode(DIR_PIN3, OUTPUT);
pinMode(ENABLE_PIN3, OUTPUT);
pinMode(STEP_PIN4, OUTPUT);
pinMode(DIR_PIN4, OUTPUT);
pinMode(ENABLE_PIN4, OUTPUT);
pinMode(STEP_PIN5, OUTPUT);
pinMode(DIR_PIN5, OUTPUT);
pinMode(ENABLE_PIN5, OUTPUT);
}
#define STEPS 3000
void constantAccel() {
int delays[STEPS];
float angle = 6;
float accel = 0.05;
float c0 = 5000 * sqrt( 2 * angle / accel ) * 0.9000;
float lastDelay = 0;
int highSpeed = 100000;
for (int i = 0; i < STEPS; i++) {
float d = c0;
if ( i > 0 )
d = lastDelay - (2 * lastDelay) / (4 * i + 1);
if ( d < highSpeed )
d = highSpeed;
delays[i] = d;
lastDelay = d;
}
// use delays from the array, forward
for (int i = 0; i < STEPS; i++) {
digitalWrite(STEP_PIN1, HIGH);
delayMicroseconds( delays[i] );
digitalWrite(STEP_PIN1, LOW);
}
// use delays from the array, backward
for (int i = 0; i < STEPS; i++) {
digitalWrite(STEP_PIN1, HIGH);
delayMicroseconds( delays[STEPS-i-1] );
digitalWrite(STEP_PIN1, LOW);
}
// use delays from the array, forward
for (int i = 0; i < STEPS; i++) {
digitalWrite(STEP_PIN2, HIGH);
delayMicroseconds( delays[i] );
digitalWrite(STEP_PIN2, LOW);
}
// use delays from the array, backward
for (int i = 0; i < STEPS; i++) {
digitalWrite(STEP_PIN2, HIGH);
delayMicroseconds( delays[STEPS-i-1] );
digitalWrite(STEP_PIN2, LOW);
}
// use delays from the array, forward
for (int i = 0; i < STEPS; i++) {
digitalWrite(STEP_PIN3, HIGH);
delayMicroseconds( delays[i] );
digitalWrite(STEP_PIN3, LOW);
}
// use delays from the array, backward
for (int i = 0; i < STEPS; i++) {
digitalWrite(STEP_PIN3, HIGH);
delayMicroseconds( delays[STEPS-i-1] );
digitalWrite(STEP_PIN3, LOW);
}
// use delays from the array, forward
for (int i = 0; i < STEPS; i++) {
digitalWrite(STEP_PIN4, HIGH);
delayMicroseconds( delays[i] );
digitalWrite(STEP_PIN4, LOW);
}
// use delays from the array, backward
for (int i = 0; i < STEPS; i++) {
digitalWrite(STEP_PIN4, HIGH);
delayMicroseconds( delays[STEPS-i-1] );
digitalWrite(STEP_PIN4, LOW);
}
// use delays from the array, forward
for (int i = 0; i < STEPS; i++) {
digitalWrite(STEP_PIN5, HIGH);
delayMicroseconds( delays[i] );
digitalWrite(STEP_PIN5, LOW);
}
// use delays from the array, backward
for (int i = 0; i < STEPS; i++) {
digitalWrite(STEP_PIN5, HIGH);
delayMicroseconds( delays[STEPS-i-1] );
digitalWrite(STEP_PIN5, LOW);
}
}
void loop() {
digitalWrite(DIR_PIN1, LOW);
constantAccel();
digitalWrite(DIR_PIN1, HIGH);
constantAccel();
digitalWrite(DIR_PIN2, LOW);
constantAccel();
digitalWrite(DIR_PIN2, HIGH);
constantAccel();
digitalWrite(DIR_PIN3, LOW);
constantAccel();
digitalWrite(DIR_PIN3, HIGH);
constantAccel();
digitalWrite(DIR_PIN4, LOW);
constantAccel();
digitalWrite(DIR_PIN4, HIGH);
constantAccel();
digitalWrite(DIR_PIN5, LOW);
constantAccel();
digitalWrite(DIR_PIN5, HIGH);
constantAccel();
digitalWrite(DIR_PIN4, LOW);
constantAccel();
digitalWrite(DIR_PIN4, HIGH);
constantAccel();
digitalWrite(DIR_PIN3, LOW);
constantAccel();
digitalWrite(DIR_PIN3, HIGH);
constantAccel();
digitalWrite(DIR_PIN2, LOW);
constantAccel();
digitalWrite(DIR_PIN2, HIGH);
constantAccel();
digitalWrite(DIR_PIN1, LOW);
constantAccel();
digitalWrite(DIR_PIN1, HIGH);
constantAccel();
while (true);
}
Though I’m quite new to Arduino coding, so please let me know if I can tidy up this code? Also trying to work out how to add further control to the motors so I can set it that if motor 1 does x steps then motor 3 does x+y steps.