Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interruping blocking-mode functions (e.g., limit switch) #38

Open
luriomer opened this issue May 14, 2024 · 1 comment
Open

Interruping blocking-mode functions (e.g., limit switch) #38

luriomer opened this issue May 14, 2024 · 1 comment

Comments

@luriomer
Copy link

Hello,

In my application I'd like to incorporate limit switches that would stop the motor immediately when engaged (e.g., when reaching a hardstop).
For non-blocking mode functions (i.e., constantly calling run() or runSpeed() inside a loop) it is pretty straight-forward by either interrupts or polling. No problem there.

I wonder if there is a way to do the same for blocking functions, such as runToPosition(). Even if I interrupt to set a flag or whatever, as soon as the ISR function returns (which will be very shortly, if it's just setting a flag) the motor will continue the movement (and if a hard stop was reached it will just slip and won't move).
So basically what I am looking for is a way to use interrupts to conditionally break out runToPosition.

I would say this is a pretty basic feature that many other might need.

Thanks!

@orlin369
Copy link

Hey I had the same problem and I thought it has some blocking mechanism. And yes there is. In file: AccelStepper.cpp at line 418 there is :

// Caution 200ns setup time 
// Delay the minimum allowed pulse width
delayMicroseconds(_minPulseWidth);

This part here is blocking the system to run smoothly. The best solution that I was able to do is the flowing:
Add: YIELD; // Let system housekeeping occur
After the 418 line. This will allow you to run the system smoothly and still it is not thew best solution.

Regards
Orlin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants