Comments (3)
Hi,
Interesting application, I'd use the getMpCustomTorqueCharacteristicsDRV8825With
factory method if you managed to benchmark your motors (it's hard to do on a finite linear actuator, because it can't continually rotate) otherwise Exponential is very good.
Stepping jobs act like Future proxies (in fact they contain 3 Futures but the result()
of a Jobs is a proxy of the result()
call to the "job done" future.), Following snippet goes back and forth 1/8th of rotation for ever.
from stepper_motors_juanmf1.Controller import MotorDriver, BipolarStepperMotorDriver
from stepper_motors_juanmf1.ControllerFactory import MultiProcessingControllerFactory
from stepper_motors_juanmf1.StepperMotor import GenericStepper, PG35S_D48_HHC2
def main():
factory = MultiProcessingControllerFactory()
motor = GenericStepper(minPps=50, maxPps=300, maxSleepTime=1/50, minSleepTime=1/300, spr=200)
# motor = PG35S_D48_HHC2(loaded=True)
driver: BipolarStepperMotorDriver = (factory.setUpProcess()
.withDriver(multiprocessObserver=None,
factoryFnReference=factory.getMpExponentialTMC2209With,
# factoryFnReference=factory.getMpCustomTorqueCharacteristicsDRV8825With,
stepperMotor=motor, directionGpioPin=16, stepGpioPin=20, enableGpioPin=21)
.spawn())[0]
while True:
driver.signedSteps(int(motor.spr * 1/8)).result()
driver.signedSteps(-int(motor.spr * 1/8)).result()
You could also use events. If you need not to block on a stepping job, say your app needs to keep vigilant of balls coming, then you could be open to change course on the fly or wait for 2 built in events:
<your optionalEventNamePrefix>steppingCompleteAdvance
fired by default 10 steps prior to completion. Fired fromstepper_motors_juanmf1.Navigation.Navigation.go
<your optionalEventNamePrefix>steppingCompleteFinalStep
fires on last step, technically before the stepping job completes. Fired fromstepper_motors_juanmf1.Controller.BipolarStepperMotorDriver._doOperateStepper
.
So, if you are confident you can wait until a job is done to decide on next move, use the snippet as example.
from steppermotors.
I'm running two motors synchronously and need to know when the move I have given them is complete so I can tell them to move again. Currently we are using the sleep command as a poor substitute to ensure the motors don't get overlapping commands. I am an EE and not a CompSci major so I apologize if I am asking an ignorant question.
from steppermotors.
No worries,
Your (basic) answer is already there.
No Sleep
Above, these lines complete 1/8th turn in one direction, no time.sleep
used, then goes back to original position. then repeat.
# .result() blocks until stepping job is done.
while True:
driver.signedSteps(int(motor.spr * 1/8)).result().
driver.signedSteps(-int(motor.spr * 1/8)).result()
2 motors in sync
Make sure you use the MultiProcessingControllerFactory
factory to minimize pulse timing issues (also start your app with nice -15
or something high to help here) .
Then you have several scenarios.
- your main app can have the luxury of blocking while motors work (your
time.sleep
case is a poor approach to this one).
xJob = driverX.signedSteps(300)
yJob = driverY.signedSteps(200)
# We get here immediately, jobs probably didn't start yet.
xJob.result(). # blocks until done
yJob.result() # blocks until done, continues if already done
print("both drivers just completed their job, but this thread was blocked all along")
- You can't afford to block because your app need to be responsive to other events. I'd assume a PONG game won't work well with blocking. Maybe you are going to an initial position and the opponent already shot, so you need to change course before running stepping job is done.
Simplest approach is same as before but instead of blocking right away you test for some input.
If there are other parts of your system that need to get notified of a stepping job done you could use the EventDispatecher
to register listeners. But that's a more sophisticated topic.
Hope this helps.
BTW BasicSynchronizedNavigation
has a latch feature to start motors after the last expected one sent it's job for stepping. If you want full sync, including starts time. If motors/drivers are of the same kind, this can be more efficient as both motors' initial and subsequent pulses would require one go through the logic, emitting signals perfectly at the same time.
from steppermotors.
Related Issues (17)
- Support for Adafruit Motorkit HOT 6
- OrderedDict not sorted.
- Chained jobs need a way to pass to child process. HOT 1
- Add support for best selling Bipolar Drivers & motors HOT 2
- Multiprocess Jobs in Main Process do not know when counterpart jobs in Child process start or end. HOT 1
- Job Chain does not work with StaticNavigation HOT 1
- StaticNavigation is not increasing motor's PPS when micro-stepping. HOT 1
- Add support for Unipolar stepping in Navigation classes other than synchronized HOT 1
- Add latch to synchronizedNav so that several steppers start together HOT 1
- Builders don't make it through multiprocess spawning, thus only factory methods work for now on MP. HOT 1
- SynchronizedNavigation returns Boolean in job while other strategies return time.monotonic_ns()
- Change pulse based PPS definitions in StepperMotor for Steps based.
- Half stepping on Unipolar seem to move slower.
- multiprocess Manager() creates a new process per invocation. wrap in singleton. HOT 1
- Benchmark broken after cumulative changes since previous releases. HOT 1
- Logging reentrant lock attempt HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from steppermotors.