Re: While Loop Issue.

52 views
Skip to first unread message
Message has been deleted

gjgsm...@gmail.com

unread,
Oct 14, 2021, 6:56:05 PM10/14/21
to accelstepper
I kinda see what your trying to do but confused about your terminology somewhat.

Is the Actuator movement IN/OUT the 'first' axis? (ie. extendActuator(); / retractActuator(); )
And the 'Steps Down' =  RotateRelativeZ() the 'second' axis?

Would probably also need the rest of your code to work it out.

Keep in mind that Non-blocking stepper moves execute a 'step', if required, on each pass of the loop so any other code like Serial.print() will also execute and can potentially slow the stepper movement.

Cheers

Geoff

On Friday, 15 October 2021 at 02:34:32 UTC+11 hector.t...@googlemail.com wrote:
Working on a 2 - axis machine to cut material. Ideally the code runs an Actuator out and then In before incrementing a stepper down by a specified amount, for 3 loops.
I.e. Actuator Extends, Retracts then Steps Down (and Repeats x3), 

 However the Actuator movement runs in and out for 3 loops then once the loop is finished the stepper finally moves.
I.e., Extend, Retract (and Repeats x3), then Steps Down.

void cuttingMovement() 
{
  Serial.println("====== TEST STARTED ========");
  while (layersCounted < 3)  //While Loop keeps running the loop until the condition is false.
  {
    extendActuator();                   //Runs the extension function for the actuator.
    retractActuator();                  //Runs the retraction function for the actuator.
    RotateRelativeZ();
    layersCounted = layersCounted + 1; //Formula to add 1 for every layer counted.
    Serial.print("layersCounted = ");   //Prints statement to show that the While Loop has been updated.
    Serial.println(layersCounted);      //Print the updated statement.
    delay(500);                         //Delay next loop by offTimer which is used to achieved 40% Duty Cycle.
  }
  Serial.println("Cutting Stopped."); //Prints statement to show that the While Loop has been stopped.
  layersCounted = 0;
  Serial.println("layersCounted Reset."); //Prints statement to show that layers counted has been reset.
  Serial.println("====== TEST END ========");
}

void RotateRelativeZ() //Function to move the Y-Stepper absolutely (+/-).
{
  stepperZ.moveTo(stepsRequiredZ);  //Sets absolute distance for the Y-Stepper to move.
  Serial.println("Z-Axis Position Reached Absolutely."); //Prints statement to show that the Z-Stepper has reached its position.
}

Rest of the code available if needed to bring more context to the issue. Thanks in advance.
Reply all
Reply to author
Forward
Message has been deleted
0 new messages