To perform smaller steps you want to change the sequence to produce small changes per step instead of full ones.
If we start with the pbrStepper.py example provided we can build a microstepping sequence using sine and cosine.
Firstly we need to add the math library to the imports:
# Import library functions we need
import PicoBorgRev
import time
import math
# Tell the system how to drive the stepper
Next we remove the old stepping sequence (line 10):
# Tell the system how to drive the stepper
sequence = [[1.0, 1.0], [1.0, -1.0], [-1.0, -1.0], [-1.0, 1.0]] # Order for stepping
stepDelay = 0.002 # Delay between steps
We should add the voltages for driving the stepper in its place, and a microstep count.
The voltages need to be the voltage actually connected to the PicoBorg Reverse, and the voltage the stepper is meant to work at:
# Tell the system how to drive the stepper
voltageIn = 12.0 # Battery voltage input to the PicoBorgReverse
voltageOut = 5.0 # Stepper motor voltage (see the stepper datasheet)
microsteps = 10 # Number of microsteps per full step
stepDelay = 0.002 # Delay between microsteps
Next we calculate the maximum power output using the voltages:
stepDelay = 0.002 # Delay between microsteps
# Calculate the microstepping sequence
if voltageOut < voltageIn:
powerMax = voltageOut / voltageIn
else:
powerMax = 1.0
# Name the global variables
Now we work out how the sine and cosine values for each position:
else:
powerMax = 1.0
sequence = []
steps = 4 * microsteps
for i in range(steps):
sinOut = math.sin((2.0 * math.pi * i) / steps)
cosOut = math.cos((2.0 * math.pi * i) / steps)
# Name the global variables
Finally we work out the final power and add the step to the sequence:
for i in range(steps):
sinOut = math.sin((2.0 * math.pi * i) / steps)
cosOut = math.cos((2.0 * math.pi * i) / steps)
drive1 = sinOut * powerMax
drive2 = cosOut * powerMax
sequence.append([drive1, drive2])
# Name the global variables
piborg
Mon, 11/17/2014 - 16:01
Permalink
Microstepping with PicoBorg Reverse
To perform smaller steps you want to change the sequence to produce small changes per step instead of full ones.
If we start with the
pbrStepper.pyexample provided we can build a microstepping sequence using sine and cosine.Firstly we need to add the
mathlibrary to the imports:Next we remove the old stepping sequence (line 10):
We should add the voltages for driving the stepper in its place, and a microstep count.
The voltages need to be the voltage actually connected to the PicoBorg Reverse, and the voltage the stepper is meant to work at:
Next we calculate the maximum power output using the voltages:
stepDelay = 0.002 # Delay between microsteps # Calculate the microstepping sequence if voltageOut < voltageIn: powerMax = voltageOut / voltageIn else: powerMax = 1.0 # Name the global variablesNow we work out how the sine and cosine values for each position:
else: powerMax = 1.0 sequence = [] steps = 4 * microsteps for i in range(steps): sinOut = math.sin((2.0 * math.pi * i) / steps) cosOut = math.cos((2.0 * math.pi * i) / steps) # Name the global variablesFinally we work out the final power and add the step to the sequence:
for i in range(steps): sinOut = math.sin((2.0 * math.pi * i) / steps) cosOut = math.cos((2.0 * math.pi * i) / steps) drive1 = sinOut * powerMax drive2 = cosOut * powerMax sequence.append([drive1, drive2]) # Name the global variablesThe rest of the code should then work normally.