stepper motor stepping wrong

Hello

I am working on a project that requires a stepper motor to find it’s home position. I am using a controllino for this in combination with a NEMA 34 stepper motor, driven by a leadshine ES-D808. (NEMA 34 Closed Loop Stepper System 8.0Nm: | DamenCNC B.V.)

For testing purposes I want to drive the stepper incremental clockwise and counterclockwise.
1 step to the left of it’s zero position, 1 step to the right of it’s zero position, 2 steps to the left of it’s zero position, 2 steps to the right of it’s zero position,…

The sketch I use for this doesn’t work. The stepper motor is not pending around a zero reference point. It’s rotating while doing the movement.

// Include the AccelStepper library:
#include <AccelStepper.h>

// Define stepper motor connections and motor interface type. Motor interface type must be set to 1 when using a driver:
#define dirPin A4
#define stepPin A5
#define motorInterfaceType 1

// Create a new instance of the AccelStepper class:
AccelStepper stepper = AccelStepper(motorInterfaceType, stepPin, dirPin);

long homing_L = 0;
long homing_R = 0;

void setup() {
Serial.begin(9600);

stepper.setMaxSpeed(1000); // Set speed fast enough to follow pot rotation
stepper.setAcceleration(500); // High Acceleration to follow pot rotation

}

void loop() {

stepper.runToNewPosition(homing_L);
Serial.print(homing_L);
homing_L --;
Serial.print(" ");
stepper.runToNewPosition(homing_R);
Serial.println(homing_R);
homing_R ++;

}

What is the problem here?

If your positions start at 0 and increment by 1 then, at least to start with, there will be very little movement. Is that what you want?

The stepper motor is not pending around a zero reference point. It's rotating while doing the movement.

I don't understand. How could it move without rotating?

I have not noticed runToNewPosition() before and reading the documentation I can't tell how it differs from runToPosition().

Please post a sample of the output from your program.

...R

Robin2:
If your positions start at 0 and increment by 1 then, at least to start with, there will be very little movement. Is that what you want?
I don't understand. How could it move without rotating?

I have not noticed runToNewPosition() before and reading the documentation I can't tell how it differs from runToPosition().

Read the code itself, not the docs! Its just a call to moveTo() followed by runToPostion().

So it will work.

But all these short moves take a long time due to the speed ramping, this is not how to home.
Move in one direction using run() until you hit the home switch, call stop(), then setCurrentPosition().

IE something like:

  stepper.setMaxSpeed (HOMING_SPEED) ;
  stepper.moveTo (1000000) ; // ie definitely past the homing sw
  while (digitalRead (HOME_SW) == ??)  // loop till hit the switch
    stepper.run() ;
  stepper.stop () ;
  stepper.moveToPosition () ; // let the deceleration phase complete
  stepper.setCurrentPosition (HOME_POS) ;
  stepper.setMaxSpeed (NORMAL_SPEED) ;

MarkT:
Read the code itself, not the docs! Its just a call to moveTo() followed by runToPostion().

So it will work.

I never suggested that it would not work.

The purpose of documentation is so that people don't have to read code. Reading code is a last resort - it is all too readily accepted by users of Open Source software when the correct thing is for the software developer to write proper documentation.

...R

The whole point of Open Source is to read the source, and learn to use appropriate comments in it (useful ones, not noise). Auto-generated docs can be created from this if you find a web-browser easier to use than a good programming editor with language-bindings.

Writing documentation separate from the source will always lead to discrepancies, and most documentation is not kept upto date or complete, unless its auto-generated.

The documentation a user of some turnkey software package needs is a very different animal from the documentation a programmer needs to use a library of code effectively (or even to figure out if its going to
be useful). Perhaps you conflate the two?

MarkT:
The whole point of Open Source is to read the source ...

I disagree with that very fundamentally.

In my view of the world the purpose of Open Source code is so that other programmers can develop the code in other ways for their projects. And, of course, well written code with appropriate comments will make it easier for a programmer to understand.

But that is completely different (IMHO) from a user incorporating the code unchanged in support of another project - which is how most Arduino libraries are used. I expect libraries to be capable of being used by people who do not have the skill or experience to understand the source code, perhaps not even enough knowledge to be able to find the source code. The documentation should provide all of the information that a library user needs.

...R