Hi,
I am using TeensyStep4 with a Teensy 4.1 on PlatformIO. I have 10 stepper motors that I control and so I set up an array of stepper motor objects as shown below:
Moving the motors together in a group works beautifully. I have an array of target positions and I pass them to the the stepper objects as shown below:
I'm having a problem though when I want to move only one of the motors. I have written the following subroutine to start testing a homing sequence:
I would expect only the 5th stepper motor in the array to move, but all the stepper motors from the 5th to the tenth one move! This is the output that I get from the serial monitor:
Homing initiated...
Spreader 1 array initial position: 15915
Spreader 2 array initial position: 15915
Spreader 3 array initial position: 15915
Spreader 4 array initial position: 15915
Spreader 5 array initial position: 15915
Spreader 6 array initial position: 15915
Spreader 7 array initial position: 15915
Spreader 8 array initial position: 15915
Spreader 9 array initial position: 15915
Spreader 10 array initial position: 15915
Spreader 1 array final position: 15915
Spreader 2 array final position: 15915
Spreader 3 array final position: 15915
Spreader 4 array final position: 15915
Spreader 5 array final position: 15415
Spreader 6 array final position: 16415
Spreader 7 array final position: 16415
Spreader 8 array final position: 16415
Spreader 9 array final position: 16415
Spreader 10 array final position: 16415
As can be seen, the 5th stepper motor in the array does change its position correctly, but I don't know why the other stepper motors (greater than the 5th one) also change their positions (and in the opposite direction). If anyone could shed any light on this, I would appreciate it.
Thanks very much.
I am using TeensyStep4 with a Teensy 4.1 on PlatformIO. I have 10 stepper motors that I control and so I set up an array of stepper motor objects as shown below:
Code:
// Stepper objects
// Arguments are x & y where
// x is the pulse output pin
// y is the direction output pin
Stepper stepper1(STEPPER1_PULSE_PIN, STEPPER1_DIR_PIN);
Stepper stepper2(STEPPER2_PULSE_PIN, STEPPER2_DIR_PIN);
Stepper stepper3(STEPPER3_PULSE_PIN, STEPPER3_DIR_PIN);
Stepper stepper4(STEPPER4_PULSE_PIN, STEPPER4_DIR_PIN);
Stepper stepper5(STEPPER5_PULSE_PIN, STEPPER5_DIR_PIN);
Stepper stepper6(STEPPER6_PULSE_PIN, STEPPER6_DIR_PIN);
Stepper stepper7(STEPPER7_PULSE_PIN, STEPPER7_DIR_PIN);
Stepper stepper8(STEPPER8_PULSE_PIN, STEPPER8_DIR_PIN);
Stepper stepper9(STEPPER9_PULSE_PIN, STEPPER9_DIR_PIN);
Stepper stepper10(STEPPER10_PULSE_PIN, STEPPER10_DIR_PIN);
Stepper steppers[10] = {stepper1, stepper2, stepper3, stepper4, stepper5, stepper6, stepper7, stepper8, stepper9, stepper10};
StepperGroup g1{steppers[0], steppers[1], steppers[2], steppers[3], steppers[4], steppers[5], steppers[6], steppers[7], steppers[8], steppers[9]};
Moving the motors together in a group works beautifully. I have an array of target positions and I pass them to the the stepper objects as shown below:
Code:
// Set the new stepper targets
for (int i = 0; i <= 9; i++) {
steppers[i].setTargetAbs(stepperTargets[i]);
}
// Move the stepper group
g1.move();
I'm having a problem though when I want to move only one of the motors. I have written the following subroutine to start testing a homing sequence:
Code:
// Home all the spreaders
void spreaderHoming() {
Serial.println();
Serial.println("Homing initiated...");
Serial.println();
// Set the speed for the stepper motors for the homing routine
for (int i = 0; i <= 9; i++) {
steppers[i].setMaxSpeed(HOME_SPEED);
Serial.print("Spreader ");
Serial.print(i + 1);
Serial.print(" array initial position: ");
Serial.println(steppers[i].getPosition());
}
steppers[4].moveAbsAsync(steppers[4].getPosition() - 500);
do {
inputsUpdate();
if (inputArray[ADDR_PROXY_6]) {
Serial.println("Proxy detected...");
}
} while (steppers[4].isMoving);
delay(1000);
Serial.println();
for (int i = 0; i <= 9; i++) {
Serial.print("Spreader ");
Serial.print(i + 1);
Serial.print(" array final position: ");
Serial.println(steppers[i].getPosition());
}
}
I would expect only the 5th stepper motor in the array to move, but all the stepper motors from the 5th to the tenth one move! This is the output that I get from the serial monitor:
Homing initiated...
Spreader 1 array initial position: 15915
Spreader 2 array initial position: 15915
Spreader 3 array initial position: 15915
Spreader 4 array initial position: 15915
Spreader 5 array initial position: 15915
Spreader 6 array initial position: 15915
Spreader 7 array initial position: 15915
Spreader 8 array initial position: 15915
Spreader 9 array initial position: 15915
Spreader 10 array initial position: 15915
Spreader 1 array final position: 15915
Spreader 2 array final position: 15915
Spreader 3 array final position: 15915
Spreader 4 array final position: 15915
Spreader 5 array final position: 15415
Spreader 6 array final position: 16415
Spreader 7 array final position: 16415
Spreader 8 array final position: 16415
Spreader 9 array final position: 16415
Spreader 10 array final position: 16415
As can be seen, the 5th stepper motor in the array does change its position correctly, but I don't know why the other stepper motors (greater than the 5th one) also change their positions (and in the opposite direction). If anyone could shed any light on this, I would appreciate it.
Thanks very much.