Open XenonFlits opened 10 months ago
I puzzled a bit and came to this:
import board
import stepper
import time
import random
import digitalio
#https://github.com/ktritz/stepper_pio
motordisable = digitalio.DigitalInOut(board.D9) #to disable stepper
motordisable.direction = digitalio.Direction.OUTPUT
motordisable.value = True #no power on stepper
s = stepper.Stepper(
board.D7,
dir_pin=board.D8,
max_velocity=1600,
acceleration=.1 #,
#delays="scurve"
)
s.dir_active = "HIGH"
s._setup_sm()
s.reset() #set encoder position to zero
while True: #create some random position movement, 1 full turn is 5
motordisable.value = False
s.max_velocity=10000
s.acceleration=.1
time.sleep(.1)
randomposition=random.random()*4+1 #add some bias to avoid unimpressive mini-movements
s.max_velocity=300 #go slow to random position
s.acceleration=1.5
s.position=randomposition
time.sleep(1.5) #to avoid overlapping instructions, finish first
s.max_velocity=10000 # go fast to zero
s.acceleration=.1
s.position=0
time.sleep(.4)
motordisable.value = True #disable stepper to reduce energy consumption and temperature
time.sleep(3.5)
Some questions remain:
What does "plot" do? I guess that only works with an encoder?
Does max_velocity have a maximum itself?
Using the scurve parameter seems not only change the acceleration profile, but also increases the distance the stepper moves?
Is there a way to check if the motor is busy, to avoid overlapping instructions?
This should be useful for some people. To see it working
Hi, I found your code. It looks promising, but I have some troubles how to use it. I see stored parameters p, v and l. I see an initialisation with s._setup_sm(). I see a ENC_TICKS_PER_MM parameter. I see that parameters for encoder and end stops are optional. How do I get your code to work? I have a stepper pulse pin on D7 with a stepper that does 200*8 = 1600 steps per revolution or 3 mm per step if that is easier. D8 is a direction pin, D9 is a disable pin. This reduces the current to a hold current. I have no encoder at this moment, but plan to use it later this week.
Kind Regards from Amsterdam