pkerspe / ESP-FlexyStepper

This library is used to control one or more stepper motors from an ESP32 device. It is based on the FlexyStepper library by S.Reifel but provides some additional functionality
MIT License
149 stars 32 forks source link

New feature: calibrating between two points (home and max position) #6

Open xander-m2k opened 3 years ago

xander-m2k commented 3 years ago

I am trying to calibrate between two points, so limit switches on both sides. This means I will first be calibrating on the home position (which you do have a function for), and then move to the other side, until the limit switch hits, and setting that as MAX_STEPS, so it cannot move any further than that point. That means if you try to do an absolute or relative-move, and that comes above MAX_STEPS, it will just stop at MAX_STEPS.

You can now use the limit switch feature to get around this nonexistent feature, but the following functions could be implemented: void startHomeAndLimitCalibration(int beginLimitSwitch, int EndLimitSwitch) (maybe an extra callback function for when this is finished) int getMaxSteps() void setMaxSteps(int maxSteps) void moveToMaxSteps() bool isHomeAndLimitCalibrated()

There could be something I am forgetting, but I think this gets you a good idea of what I mean

FrankNz commented 5 months ago

Hi Firstly thank you for the work you are doin got this software. We are using it at an Aviation museum to drive a model of a Link Trainer. Added to the above.. It would be useful to know when the limit switch (Min || Max) is activated. If I do not know which switch is activated (eg at power on) I could try drive the stepper in the wrong direction which would result in some very bent metal! Is some work on this problem being contemplated? possible timing?

pkerspe commented 5 months ago

Hi Frank,

You could call Arduinos digitalRead(...) function to check which limit switch is triggered after booting. Then you need to set the direction of the initial move accordingly to move in the opposite direction.

You might also have a look at the example https://github.com/examples/Example4_Limit_and_latching_EmergencySwitch/Example4_Limit_and_latching_EmergencySwitch.ino But instead of using two limit switches wired in series for start and end, you use two switches connected to individual pins of your esp. than you update the code to read both input pin values at startup (and also attach an interrupt for the second input pin to update the rest of the logic) and by that you know on which side of the linear movement path you are and can set direction to the opposite end on the first move.

FrankNz commented 5 months ago

Hi Paul, Thanks for the quick response and excellent solution. Frank

On 7 Apr 2024, at 6:08 PM, Paul @.***> wrote:

Hi Frank,

You could call Arduinos digitalRead(...) function to check which limit switch is triggered after booting. Then you need to set the direction of the initial move accordingly to move in the opposite direction.

— Reply to this email directly, view it on GitHub https://github.com/pkerspe/ESP-FlexyStepper/issues/6#issuecomment-2041328624, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACTMFCKZC74IJ5WTBEB6TO3Y4DPHJAVCNFSM4VUVOLEKU5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TEMBUGEZTEOBWGI2A. You are receiving this because you commented.