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

stepper.startasync() and stepper.stopasync() #378

Closed
ar055 opened this issue Nov 3, 2020 · 7 comments
Closed

stepper.startasync() and stepper.stopasync() #378

ar055 opened this issue Nov 3, 2020 · 7 comments

Comments

@ar055
Copy link

ar055 commented Nov 3, 2020

commit e4d5059

could you please post some lua code demonstrating how these functions work?

  1. I was unable to start stepper motors with the stepper.startasync () command.
  2. the stepper.stopasync () command stops all motors.

my code:

m1.stepper =  stepper.attach(m1.dir_pin, m1.step_pin, 200, 60, 6000, 100, 100)
m2.stepper =  stepper.attach(m2.dir_pin, m2.step_pin, 200, 60, 6000, 100, 100)

function run(motor)
  function _run()
    pio.pin.setlow(motor.en_pin)
    stepper.start(motor.stepper)
--    stepper.startasync(motor.stepper)  -- does not work
  end
  if motor.stepper:getdistance() ~= 0 then
    th = thread.start(_run)
  end
end

m1.stepper:move(1000)
m2.stepper:move(1000)

run(m1)
run(m2)
tmr.sleepms(1000)

stepper.stopasync(m1.stepper)  -- all steppers stopped
@chowette
Copy link
Contributor

chowette commented Nov 3, 2020

I do not reproduce your bug with only one motor. ( I have only one wired yet)

Your code look similar to mine, except that I have added the startasync() exactly to avoid an additional thread.

What I see is another bug :

m1.stepper =  stepper.attach(m1.dir_pin, m1.step_pin, 200, 60, 6000, 100, 100)
m1.stepper:move(1000)
pio.pin.setlow(m1.en_pin)
stepper.startasync(m1.stepper)
tmr.sleepms(1000)
stepper.stop(m1.stepper)  -- or stepper.stopasync(m1.stepper) 
-- here come the bug
stepper.start(m1.stepper) -- or stepper.startasync(m1.stepper)

Restarting a stepper after a call to stop() or stopasync() leave the stepper in an incoherent state. Note that calling the move() method reset this state.

m1.stepper:move(m1.stepper:getdistance())
stepper.start(m1.stepper) -- or stepper.startasync(m1.stepper)

@chowette
Copy link
Contributor

chowette commented Nov 3, 2020

I see where the bug from your sample code

stepper.stopasync(m1.stepper)  -- all steppers stopped

comes from :

void stepper_stop(int mask, uint8_t async) {

the mask parameter is never used. I will provide a patch soon

@ar055
Copy link
Author

ar055 commented Nov 4, 2020

idn't know that startasync starts the process itself, my mistake was pio.pin.sethigh (motor.en_pin) right after stepper.startasync(motor.stepper).
confirm, stepper.startasiync() - it's work!

@chowette
Copy link
Contributor

chowette commented Nov 4, 2020

Yeah, the documentation is lacking ... But I don't know how to edit the wiki.

I did not see that you disabled the motors right after the startasync() , I am glad it works for you.

@the0ne
Copy link
Collaborator

the0ne commented Nov 4, 2020

Wiki is a separate repo that can be pulled, locally modified and pushed:

Any GitHub wiki can be cloned by appending wiki.git to the repo url, so the clone url for the repo https://myorg/myrepo/ is: [email protected]:myorg/myrepo.wiki.git (for ssh) or https://github.com/my/myrepo.wiki.git (for https).

You make edits, and commit and push your changes, like any normal repo. This wiki repo is distinct from any clone of the project repo (the repo without wiki.get appended).

@chowette
Copy link
Contributor

chowette commented Nov 4, 2020

Thank you @the0ne , I will give it a try.

@chowette
Copy link
Contributor

chowette commented Nov 4, 2020

see 3abf0ea in #377 for a fix to the stop() and stopasync() to stop only the stepper that where asked .

@ar055 ar055 closed this as completed Nov 8, 2020
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

3 participants