0

Steppers sometimes not running smoothly
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Re: Steppers sometimes not running smoothly

by adafruit_support_carter on Thu Jul 25, 2019 4:15 pm

Maybe it's stepping too fast? Try adding a small delay in the loop:
Code: Select all | TOGGLE FULL SIZE
import time
from adafruit_motorkit import MotorKit

kit = MotorKit()

for i in range(100):
    kit.stepper1.onestep()
    time.sleep(0.01)

adafruit_support_carter
 
Posts: 12991
Joined: Tue Nov 29, 2016 2:45 pm

Re: Steppers sometimes not running smoothly

by AnnBel on Thu Jul 25, 2019 4:26 pm

The result is better now :) but not fully 100%

(rotations are not fully completed)

Kind regards, Ann

AnnBel
 
Posts: 48
Joined: Sat Apr 20, 2019 5:59 pm

Re: Steppers sometimes not running smoothly

by adafruit_support_carter on Thu Jul 25, 2019 4:32 pm

That may just be the number of steps (100) in the example. Just bump that up.

If it's still not stepping smoothly, then try increasing the amount of delay.

adafruit_support_carter
 
Posts: 12991
Joined: Tue Nov 29, 2016 2:45 pm

Re: Steppers sometimes not running smoothly

by AnnBel on Thu Jul 25, 2019 4:41 pm

Indeed, I tested a bit with both the range and delays.
I hope it's good to go in this way.

To return to my original question, I would like to combine the stepper runs with a monitoring function .

I'm using multiprocessing mechanism

But I noticed that the steppers are not reacting optimally.
Is there anything additional that I have to do to end/terminate stepper runs ?

Thanks a lot

Kind regards, Ann

AnnBel
 
Posts: 48
Joined: Sat Apr 20, 2019 5:59 pm

Re: Steppers sometimes not running smoothly

by adafruit_support_carter on Thu Jul 25, 2019 7:34 pm

The threaded example gets tricky. Smooth motor motion requires a nice consistent change of the coils, which is what onestep() does. The value you've found works best for time.sleep() gives you a sense of how often onestep() needs to be called. You'll need to switch from time.sleep() to something that tracks delta time and calls onestep(). And you'll also need some mechanism to make sure only one thread is calling onestep() at a time, since it's not really written to be thread safe.

Multithreading is difficult.

adafruit_support_carter
 
Posts: 12991
Joined: Tue Nov 29, 2016 2:45 pm

Re: Steppers sometimes not running smoothly

by AnnBel on Sat Jul 27, 2019 9:24 am

Hi

Could you please send an example code ?

Thx

Kind regards, Ann

AnnBel
 
Posts: 48
Joined: Sat Apr 20, 2019 5:59 pm

Re: Steppers sometimes not running smoothly

by AnnBel on Sun Jul 28, 2019 4:10 am

Hi

Or is it an option to use another type of motor ( DC motor ) ?

Kind regards, Ann

AnnBel
 
Posts: 48
Joined: Sat Apr 20, 2019 5:59 pm

Re: Steppers sometimes not running smoothly

by AnnBel on Mon Jul 29, 2019 12:23 pm

Hi

(Reminder )

Thx

AnnBel
 
Posts: 48
Joined: Sat Apr 20, 2019 5:59 pm

Re: Steppers sometimes not running smoothly

by adafruit_support_carter on Mon Jul 29, 2019 12:40 pm

Forgot, there is a simple multi-thread example here:
https://github.com/adafruit/Adafruit_Ci ... er_test.py

And you can probably use time.sleep() in the thread stepping looping (the example currently has none). It should only block the thread, not the entire process.

adafruit_support_carter
 
Posts: 12991
Joined: Tue Nov 29, 2016 2:45 pm

Re: Steppers sometimes not running smoothly

by AnnBel on Thu Aug 01, 2019 5:52 pm

Hi,

Thanks a lot

The code works, but is not really a basis for a start/stop mechanism (as far as I can see).
After a lot of testing, I don't see this solution for a start/stop mechanism as follows:

t1 = thread 1 > monitoring
t2 = thread 2 > stepper 1
t3 = thread 3 > stepper 2

t2 and t3 should react and start/stop based on monitoring from t1.
(working with e.g. threading events (wait/set) does not "stop" the steppers from running. The steppers should be forced somehow, but I don't find this mechanism).

Do you have suggestions ?


Thank you in advance

Kind regards, Ann

AnnBel
 
Posts: 48
Joined: Sat Apr 20, 2019 5:59 pm

Re: Steppers sometimes not running smoothly

by adafruit_support_carter on Thu Aug 01, 2019 7:17 pm

The code works, but is not really a basis for a start/stop mechanism (as far as I can see).

Correct. The example is fairly basic and just shows how two threads can run with each driving a stepper. To expand this further with additional threads and thread coordination will require some effort. This is a general threading issue, not a library issue.

adafruit_support_carter
 
Posts: 12991
Joined: Tue Nov 29, 2016 2:45 pm

Re: Steppers sometimes not running smoothly

by AnnBel on Fri Aug 02, 2019 2:29 am

Hi,

Ok thanks
Do you have an example code? Guidelines to setup this mechanism?

Thanksin advance,
Kind regards, Ann

AnnBel
 
Posts: 48
Joined: Sat Apr 20, 2019 5:59 pm

Re: Steppers sometimes not running smoothly

by adafruit_support_carter on Fri Aug 02, 2019 10:36 am

Sorry, don't have any specific example code to show other than that one simple example. Inter-thread communication, like threads in general, is a broad topic. There's no one way to go about it.

adafruit_support_carter
 
Posts: 12991
Joined: Tue Nov 29, 2016 2:45 pm

Re: Steppers sometimes not running smoothly

by AnnBel on Fri Aug 02, 2019 11:07 am

Hi

If i make inter -threading test cases , they work fine.

But if i include steppers in the test cases they do not react accordingly, it seems that they should be forced somehow.

What is the correct mechanism for a start /stop process?

Thank you,

Kind regards, Ann

AnnBel
 
Posts: 48
Joined: Sat Apr 20, 2019 5:59 pm

Re: Steppers sometimes not running smoothly

by AnnBel on Fri Aug 02, 2019 12:50 pm

Hi

Would you please provide an alternative?

Thank you in advance,
Kind regards, Ann

AnnBel
 
Posts: 48
Joined: Sat Apr 20, 2019 5:59 pm

Please be positive and constructive with your questions and comments.