void StepperControlAxis::checkMovement() { checkAxisDirection(); // Handle movement if destination is not already reached or surpassed if ( ( (coordDestinationPoint > coordSourcePoint && coordCurrentPoint < coordDestinationPoint) || (coordDestinationPoint < coordSourcePoint && coordCurrentPoint > coordDestinationPoint) || coordHomeAxis) && axisActive) { // home or destination not reached, keep moving // If end stop reached or the encoder doesn't move anymore, stop moving motor, otherwise set the timing for the next step if ((coordHomeAxis && !endStopAxisReached(false)) || (!coordHomeAxis && !endStopAxisReached(!movementToHome))) { // Get the axis speed, in steps per second axisSpeed = calculateSpeed(coordSourcePoint, coordCurrentPoint, coordDestinationPoint, motorSpeedMin, motorSpeedMax, motorStepsAcc); // // Set the moments when the step is set to true and false // if (axisSpeed > 0) // { // Take the requested speed (steps / second) and divide by the interrupt speed (interrupts per seconde) // This gives the number of interrupts (called ticks here) before the pulse needs to be set for the next step // stepOnTick = moveTicks + (1000.0 * 1000.0 / motorInterruptSpeed / axisSpeed / 2); // stepOffTick = moveTicks + (1000.0 * 1000.0 / motorInterruptSpeed / axisSpeed); // } } else { axisActive = false; } } else { // Destination or home reached. Deactivate the axis. axisActive = false; } // If end stop for home is active, set the position to zero if (endStopAxisReached(false)) { coordCurrentPoint = 0; } }
void StepperControlAxis::setStepAxis() { if (coordHomeAxis && coordCurrentPoint == 0) { // Keep moving toward end stop even when position is zero // but end stop is not yet active if (motorHomeIsUp) { coordCurrentPoint = -1; } else { coordCurrentPoint = 1; } } if (coordCurrentPoint < coordDestinationPoint) { coordCurrentPoint++; } else if (coordCurrentPoint > coordDestinationPoint) { coordCurrentPoint--; } // set a step on the motors setMotorStep(); // if the home end stop is reached, set the current position if (endStopAxisReached(false)) { coordCurrentPoint = 0; } }