From 89b8f62feb4f7d0dd37f86f5e76380716fda4af2 Mon Sep 17 00:00:00 2001 From: shrkey Date: Tue, 13 Sep 2016 22:38:54 +0100 Subject: [PATCH 01/14] stepper library testing --- darkwater_640/darkwater_640.py | 337 +++++++++++++++++---------------- 1 file changed, 172 insertions(+), 165 deletions(-) diff --git a/darkwater_640/darkwater_640.py b/darkwater_640/darkwater_640.py index 4fae5d6..ffef84c 100644 --- a/darkwater_640/darkwater_640.py +++ b/darkwater_640/darkwater_640.py @@ -5,194 +5,200 @@ from PCA9685 import PCA9685 import time import math -# class dw_Stepper: -# MICROSTEPS = 8 -# MICROSTEP_CURVE = [0, 50, 98, 142, 180, 212, 236, 250, 255] +class dw_Stepper: + MICROSTEPS = 8 + MICROSTEP_CURVE = [0, 50, 98, 142, 180, 212, 236, 250, 255] -# #MICROSTEPS = 16 -# # a sinusoidal curve NOT LINEAR! -# #MICROSTEP_CURVE = [0, 25, 50, 74, 98, 120, 141, 162, 180, 197, 212, 225, 236, 244, 250, 253, 255] + #MICROSTEPS = 16 + # a sinusoidal curve NOT LINEAR! + #MICROSTEP_CURVE = [0, 25, 50, 74, 98, 120, 141, 162, 180, 197, 212, 225, 236, 244, 250, 253, 255] -# def __init__(self, controller, num, steps=200): -# self.speed = 0 -# self.MC = controller -# self.motornum = num -# modepin = in1 = in2 = 0 + def __init__(self, controller, num, steps=200): + self.speed = 0 + self.MC = controller + self.motornum = num + modepin = in1 = in2 = 0 -# self.revsteps = steps -# self.sec_per_step = 0.1 -# self.steppingcounter = 0 -# self.currentstep = 0 + self.revsteps = steps + self.sec_per_step = 0.1 + self.steppingcounter = 0 + self.currentstep = 0 -# if (num == 0): -# ain2 = 2 #phase -# ain1 = 3 #enable -# bin2 = 4 #phase -# bin1 = 5 #enable -# elif (num == 1): -# ain2 = 6 #phase -# ain1 = 7 #enable -# bin2 = 8 #phase -# bin1 = 9 #enable -# elif (num == 2): -# ain2 = 10 #phase -# ain1 = 11 #enable -# bin2 = 12 #phase -# bin1 = 13 #enable -# else: -# raise NameError('MotorHAT Stepper must be between 1 and 3 inclusive') + if (num == 0): + ain2 = 2 #phase + ain1 = 3 #enable + bin2 = 4 #phase + bin1 = 5 #enable + elif (num == 1): + ain2 = 6 #phase + ain1 = 7 #enable + bin2 = 8 #phase + bin1 = 9 #enable + elif (num == 2): + ain2 = 10 #phase + ain1 = 11 #enable + bin2 = 12 #phase + bin1 = 13 #enable + else: + raise NameError('MotorHAT Stepper must be between 1 and 3 inclusive') -# self.PHpinA = ain2 -# self.ENpinA = ain1 -# self.PHpinB = bin2 -# self.ENpinB = bin1 -# # switch off both drivers -# self.run(dw_Controller.RELEASE, 0) + self.PHpinA = ain2 + self.ENpinA = ain1 + self.PHpinB = bin2 + self.ENpinB = bin1 -# def run(self, command, speed = 0): -# if not self.MC: -# return -# if (command == dw_Controller.FORWARD): -# self.MC.setPin(self.PHpin, 0) -# self.MC._pwm.set_pwm(self.ENpin, 0, speed*16) -# if (command == dw_Controller.BACKWARD): -# self.MC.setPin(self.PHpin, 1) -# self.MC._pwm.set_pwm(self.ENpin, 0, speed*16) -# if (command == dw_Controller.RELEASE): -# self.MC.setPin(self.PHpinA, 0) -# self.MC.setPin(self.ENpinA, 0) -# self.MC.setPin(self.PHpinB, 0) -# self.MC.setPin(self.ENpinB, 0) + # switch off both drivers + self.run(dw_Controller.RELEASE, 0) -# def off(self): -# self.run(dw_Controller.RELEASE, 0) + def run(self, command, speed = 0): + if not self.MC: + return + if (command == dw_Controller.FORWARD): + self.MC.setPin(self.PHpin, 0) + self.MC._pwm.set_pwm(self.ENpin, 0, speed*16) + if (command == dw_Controller.BACKWARD): + self.MC.setPin(self.PHpin, 1) + self.MC._pwm.set_pwm(self.ENpin, 0, speed*16) + if (command == dw_Controller.RELEASE): + self.MC.setPin(self.PHpinA, 0) + self.MC.setPin(self.ENpinA, 0) + self.MC.setPin(self.PHpinB, 0) + self.MC.setPin(self.ENpinB, 0) -# def setSpeed(self, rpm): -# self.sec_per_step = 60.0 / (self.revsteps * rpm) -# self.steppingcounter = 0 + def off(self): + self.run(dw_Controller.RELEASE, 0) -# def oneStep(self, dir, style): -# pwm_a = pwm_b = 255 + def setSpeed(self, rpm): + self.sec_per_step = 60.0 / (self.revsteps * rpm) + self.steppingcounter = 0 -# # first determine what sort of stepping procedure we're up to -# if (style == dw_Controller.SINGLE): -# if ((self.currentstep/(self.MICROSTEPS/2)) % 2): -# # we're at an odd step, weird -# if (dir == dw_Controller.FORWARD): -# self.currentstep += self.MICROSTEPS/2 -# else: -# self.currentstep -= self.MICROSTEPS/2 -# else: -# # go to next even step -# if (dir == dw_Controller.FORWARD): -# self.currentstep += self.MICROSTEPS -# else: -# self.currentstep -= self.MICROSTEPS -# if (style == dw_Controller.DOUBLE): -# if not (self.currentstep/(self.MICROSTEPS/2) % 2): -# # we're at an even step, weird -# if (dir == dw_Controller.FORWARD): -# self.currentstep += self.MICROSTEPS/2 -# else: -# self.currentstep -= self.MICROSTEPS/2 -# else: -# # go to next odd step -# if (dir == dw_Controller.FORWARD): -# self.currentstep += self.MICROSTEPS -# else: -# self.currentstep -= self.MICROSTEPS -# if (style == dw_Controller.INTERLEAVE): -# if (dir == dw_Controller.FORWARD): -# self.currentstep += self.MICROSTEPS/2 -# else: -# self.currentstep -= self.MICROSTEPS/2 + def oneStep(self, dir, style): + pwm_a = pwm_b = 255 -# if (style == dw_Controller.MICROSTEP): -# if (dir == dw_Controller.FORWARD): -# self.currentstep += 1 -# else: -# self.currentstep -= 1 + # first determine what sort of stepping procedure we're up to + if (style == dw_Controller.SINGLE): + if ((self.currentstep/(self.MICROSTEPS/2)) % 2): + # we're at an odd step, weird + if (dir == dw_Controller.FORWARD): + self.currentstep += self.MICROSTEPS/2 + else: + self.currentstep -= self.MICROSTEPS/2 + else: + # go to next even step + if (dir == dw_Controller.FORWARD): + self.currentstep += self.MICROSTEPS + else: + self.currentstep -= self.MICROSTEPS + if (style == dw_Controller.DOUBLE): + if not (self.currentstep/(self.MICROSTEPS/2) % 2): + # we're at an even step, weird + if (dir == dw_Controller.FORWARD): + self.currentstep += self.MICROSTEPS/2 + else: + self.currentstep -= self.MICROSTEPS/2 + else: + # go to next odd step + if (dir == dw_Controller.FORWARD): + self.currentstep += self.MICROSTEPS + else: + self.currentstep -= self.MICROSTEPS + if (style == dw_Controller.INTERLEAVE): + if (dir == dw_Controller.FORWARD): + self.currentstep += self.MICROSTEPS/2 + else: + self.currentstep -= self.MICROSTEPS/2 -# # go to next 'step' and wrap around -# self.currentstep += self.MICROSTEPS * 4 -# self.currentstep %= self.MICROSTEPS * 4 + if (style == dw_Controller.MICROSTEP): + if (dir == dw_Controller.FORWARD): + self.currentstep += 1 + else: + self.currentstep -= 1 -# pwm_a = pwm_b = 0 -# if (self.currentstep >= 0) and (self.currentstep < self.MICROSTEPS): -# pwm_a = self.MICROSTEP_CURVE[self.MICROSTEPS - self.currentstep] -# pwm_b = self.MICROSTEP_CURVE[self.currentstep] -# elif (self.currentstep >= self.MICROSTEPS) and (self.currentstep < self.MICROSTEPS*2): -# pwm_a = self.MICROSTEP_CURVE[self.currentstep - self.MICROSTEPS] -# pwm_b = self.MICROSTEP_CURVE[self.MICROSTEPS*2 - self.currentstep] -# elif (self.currentstep >= self.MICROSTEPS*2) and (self.currentstep < self.MICROSTEPS*3): -# pwm_a = self.MICROSTEP_CURVE[self.MICROSTEPS*3 - self.currentstep] -# pwm_b = self.MICROSTEP_CURVE[self.currentstep - self.MICROSTEPS*2] -# elif (self.currentstep >= self.MICROSTEPS*3) and (self.currentstep < self.MICROSTEPS*4): -# pwm_a = self.MICROSTEP_CURVE[self.currentstep - self.MICROSTEPS*3] -# pwm_b = self.MICROSTEP_CURVE[self.MICROSTEPS*4 - self.currentstep] + # go to next 'step' and wrap around + self.currentstep += self.MICROSTEPS * 4 + self.currentstep %= self.MICROSTEPS * 4 + + pwm_a = pwm_b = 0 + if (self.currentstep >= 0) and (self.currentstep < self.MICROSTEPS): + pwm_a = self.MICROSTEP_CURVE[self.MICROSTEPS - self.currentstep] + pwm_b = self.MICROSTEP_CURVE[self.currentstep] + elif (self.currentstep >= self.MICROSTEPS) and (self.currentstep < self.MICROSTEPS*2): + pwm_a = self.MICROSTEP_CURVE[self.currentstep - self.MICROSTEPS] + pwm_b = self.MICROSTEP_CURVE[self.MICROSTEPS*2 - self.currentstep] + elif (self.currentstep >= self.MICROSTEPS*2) and (self.currentstep < self.MICROSTEPS*3): + pwm_a = self.MICROSTEP_CURVE[self.MICROSTEPS*3 - self.currentstep] + pwm_b = self.MICROSTEP_CURVE[self.currentstep - self.MICROSTEPS*2] + elif (self.currentstep >= self.MICROSTEPS*3) and (self.currentstep < self.MICROSTEPS*4): + pwm_a = self.MICROSTEP_CURVE[self.currentstep - self.MICROSTEPS*3] + pwm_b = self.MICROSTEP_CURVE[self.MICROSTEPS*4 - self.currentstep] -# # go to next 'step' and wrap around -# self.currentstep += self.MICROSTEPS * 4 -# self.currentstep %= self.MICROSTEPS * 4 + # go to next 'step' and wrap around + self.currentstep += self.MICROSTEPS * 4 + self.currentstep %= self.MICROSTEPS * 4 -# # only really used for microstepping, otherwise always on! -# self.MC._pwm.setPWM(self.PWMA, 0, pwm_a*16) -# self.MC._pwm.setPWM(self.PWMB, 0, pwm_b*16) + # only really used for microstepping, otherwise always on! + self.MC._pwm.setPWM(self.PWMA, 0, pwm_a*16) + self.MC._pwm.setPWM(self.PWMB, 0, pwm_b*16) -# # set up coil energizing! -# coils = [0, 0, 0, 0] + # set up coil energizing! + coils = [0, 0, 0, 0] -# if (style == dw_Controller.MICROSTEP): -# if (self.currentstep >= 0) and (self.currentstep < self.MICROSTEPS): -# coils = [1, 1, 0, 0] -# elif (self.currentstep >= self.MICROSTEPS) and (self.currentstep < self.MICROSTEPS*2): -# coils = [0, 1, 1, 0] -# elif (self.currentstep >= self.MICROSTEPS*2) and (self.currentstep < self.MICROSTEPS*3): -# coils = [0, 0, 1, 1] -# elif (self.currentstep >= self.MICROSTEPS*3) and (self.currentstep < self.MICROSTEPS*4): -# coils = [1, 0, 0, 1] -# else: -# step2coils = [ [1, 0, 0, 0], -# [1, 1, 0, 0], -# [0, 1, 0, 0], -# [0, 1, 1, 0], -# [0, 0, 1, 0], -# [0, 0, 1, 1], -# [0, 0, 0, 1], -# [1, 0, 0, 1] ] -# coils = step2coils[self.currentstep/(self.MICROSTEPS/2)] + if (style == dw_Controller.MICROSTEP): + if (self.currentstep >= 0) and (self.currentstep < self.MICROSTEPS): + coils = [1, 1, 0, 0] + elif (self.currentstep >= self.MICROSTEPS) and (self.currentstep < self.MICROSTEPS*2): + coils = [0, 1, 1, 0] + elif (self.currentstep >= self.MICROSTEPS*2) and (self.currentstep < self.MICROSTEPS*3): + coils = [0, 0, 1, 1] + elif (self.currentstep >= self.MICROSTEPS*3) and (self.currentstep < self.MICROSTEPS*4): + coils = [1, 0, 0, 1] + else: + step2coils = [ [1, 0, 0, 0], + [1, 1, 0, 0], + [0, 1, 0, 0], + [0, 1, 1, 0], + [0, 0, 1, 0], + [0, 0, 1, 1], + [0, 0, 0, 1], + [1, 0, 0, 1] ] + coils = step2coils[self.currentstep/(self.MICROSTEPS/2)] -# #print "coils state = " + str(coils) -# self.MC.setPin(self.AIN2, coils[0]) -# self.MC.setPin(self.BIN1, coils[1]) -# self.MC.setPin(self.AIN1, coils[2]) -# self.MC.setPin(self.BIN2, coils[3]) + #print "coils state = " + str(coils) + self.MC.setPin(self.PHpinA, coils[0]) #ain2 + self.MC.setPin(self.ENpinB, coils[1]) #bin1 + self.MC.setPin(self.ENpinA, coils[2]) #ain1 + self.MC.setPin(self.PHpinB, coils[3]) #bin2 -# return self.currentstep + #self.PHpinA = ain2 + # self.ENpinA = ain1 + # self.PHpinB = bin2 + # self.ENpinB = bin1 -# def step(self, steps, direction, stepstyle): -# s_per_s = self.sec_per_step -# lateststep = 0 + return self.currentstep -# if (stepstyle == dw_Controller.INTERLEAVE): -# s_per_s = s_per_s / 2.0 -# if (stepstyle == dw_Controller.MICROSTEP): -# s_per_s /= self.MICROSTEPS -# steps *= self.MICROSTEPS + def step(self, steps, direction, stepstyle): + s_per_s = self.sec_per_step + lateststep = 0 -# print s_per_s, " sec per step" + if (stepstyle == dw_Controller.INTERLEAVE): + s_per_s = s_per_s / 2.0 + if (stepstyle == dw_Controller.MICROSTEP): + s_per_s /= self.MICROSTEPS + steps *= self.MICROSTEPS -# for s in range(steps): -# lateststep = self.oneStep(direction, stepstyle) -# time.sleep(s_per_s) + print s_per_s, " sec per step" -# if (stepstyle == dw_Controller.MICROSTEP): -# # this is an edge case, if we are in between full steps, lets just keep going -# # so we end on a full step -# while (lateststep != 0) and (lateststep != self.MICROSTEPS): -# lateststep = self.oneStep(dir, stepstyle) -# time.sleep(s_per_s) + for s in range(steps): + lateststep = self.oneStep(direction, stepstyle) + time.sleep(s_per_s) + + if (stepstyle == dw_Controller.MICROSTEP): + # this is an edge case, if we are in between full steps, lets just keep going + # so we end on a full step + while (lateststep != 0) and (lateststep != self.MICROSTEPS): + lateststep = self.oneStep(dir, stepstyle) + time.sleep(s_per_s) class dw_Motor: def __init__(self, controller, num): @@ -333,12 +339,13 @@ class dw_Controller: GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) GPIO.setup(27, GPIO.OUT) - GPIO.output(27, GPIO.HIGH) # set for en/phase mode - low = in/in mode + #GPIO.output(27, GPIO.HIGH) # set for en/phase mode - low = in/in mode + GPIO.output(27, GPIO.LOW) # set for en/phase mode - low = in/in mode self.motors = [ dw_Motor(self, m) for m in range(6) ] self.servos = [ dw_Servo(self, m, freq) for m in range(2) ] - #self.steppers = [ dw_Stepper(self, m) for m in range(3) ] + self.steppers = [ dw_Stepper(self, m) for m in range(3) ] def setPin(self, pin, value): if (pin < 0) or (pin > 15): From c7db60bf6f72ea523c6bbeb998232ed9ad71d44f Mon Sep 17 00:00:00 2001 From: shrkey Date: Tue, 13 Sep 2016 22:45:21 +0100 Subject: [PATCH 02/14] indentation --- darkwater_640/darkwater_640.py | 176 ++++++++++++++++----------------- 1 file changed, 88 insertions(+), 88 deletions(-) diff --git a/darkwater_640/darkwater_640.py b/darkwater_640/darkwater_640.py index ffef84c..57532a5 100644 --- a/darkwater_640/darkwater_640.py +++ b/darkwater_640/darkwater_640.py @@ -75,107 +75,107 @@ class dw_Stepper: def oneStep(self, dir, style): pwm_a = pwm_b = 255 - # first determine what sort of stepping procedure we're up to - if (style == dw_Controller.SINGLE): - if ((self.currentstep/(self.MICROSTEPS/2)) % 2): - # we're at an odd step, weird - if (dir == dw_Controller.FORWARD): - self.currentstep += self.MICROSTEPS/2 - else: - self.currentstep -= self.MICROSTEPS/2 - else: - # go to next even step - if (dir == dw_Controller.FORWARD): - self.currentstep += self.MICROSTEPS - else: - self.currentstep -= self.MICROSTEPS - if (style == dw_Controller.DOUBLE): - if not (self.currentstep/(self.MICROSTEPS/2) % 2): - # we're at an even step, weird - if (dir == dw_Controller.FORWARD): - self.currentstep += self.MICROSTEPS/2 - else: - self.currentstep -= self.MICROSTEPS/2 - else: - # go to next odd step - if (dir == dw_Controller.FORWARD): - self.currentstep += self.MICROSTEPS - else: - self.currentstep -= self.MICROSTEPS - if (style == dw_Controller.INTERLEAVE): - if (dir == dw_Controller.FORWARD): - self.currentstep += self.MICROSTEPS/2 - else: - self.currentstep -= self.MICROSTEPS/2 + # first determine what sort of stepping procedure we're up to + if (style == dw_Controller.SINGLE): + if ((self.currentstep/(self.MICROSTEPS/2)) % 2): + # we're at an odd step, weird + if (dir == dw_Controller.FORWARD): + self.currentstep += self.MICROSTEPS/2 + else: + self.currentstep -= self.MICROSTEPS/2 + else: + # go to next even step + if (dir == dw_Controller.FORWARD): + self.currentstep += self.MICROSTEPS + else: + self.currentstep -= self.MICROSTEPS + if (style == dw_Controller.DOUBLE): + if not (self.currentstep/(self.MICROSTEPS/2) % 2): + # we're at an even step, weird + if (dir == dw_Controller.FORWARD): + self.currentstep += self.MICROSTEPS/2 + else: + self.currentstep -= self.MICROSTEPS/2 + else: + # go to next odd step + if (dir == dw_Controller.FORWARD): + self.currentstep += self.MICROSTEPS + else: + self.currentstep -= self.MICROSTEPS + if (style == dw_Controller.INTERLEAVE): + if (dir == dw_Controller.FORWARD): + self.currentstep += self.MICROSTEPS/2 + else: + self.currentstep -= self.MICROSTEPS/2 - if (style == dw_Controller.MICROSTEP): - if (dir == dw_Controller.FORWARD): - self.currentstep += 1 - else: - self.currentstep -= 1 + if (style == dw_Controller.MICROSTEP): + if (dir == dw_Controller.FORWARD): + self.currentstep += 1 + else: + self.currentstep -= 1 - # go to next 'step' and wrap around - self.currentstep += self.MICROSTEPS * 4 - self.currentstep %= self.MICROSTEPS * 4 + # go to next 'step' and wrap around + self.currentstep += self.MICROSTEPS * 4 + self.currentstep %= self.MICROSTEPS * 4 - pwm_a = pwm_b = 0 - if (self.currentstep >= 0) and (self.currentstep < self.MICROSTEPS): - pwm_a = self.MICROSTEP_CURVE[self.MICROSTEPS - self.currentstep] - pwm_b = self.MICROSTEP_CURVE[self.currentstep] - elif (self.currentstep >= self.MICROSTEPS) and (self.currentstep < self.MICROSTEPS*2): - pwm_a = self.MICROSTEP_CURVE[self.currentstep - self.MICROSTEPS] - pwm_b = self.MICROSTEP_CURVE[self.MICROSTEPS*2 - self.currentstep] - elif (self.currentstep >= self.MICROSTEPS*2) and (self.currentstep < self.MICROSTEPS*3): - pwm_a = self.MICROSTEP_CURVE[self.MICROSTEPS*3 - self.currentstep] - pwm_b = self.MICROSTEP_CURVE[self.currentstep - self.MICROSTEPS*2] - elif (self.currentstep >= self.MICROSTEPS*3) and (self.currentstep < self.MICROSTEPS*4): + pwm_a = pwm_b = 0 + if (self.currentstep >= 0) and (self.currentstep < self.MICROSTEPS): + pwm_a = self.MICROSTEP_CURVE[self.MICROSTEPS - self.currentstep] + pwm_b = self.MICROSTEP_CURVE[self.currentstep] + elif (self.currentstep >= self.MICROSTEPS) and (self.currentstep < self.MICROSTEPS*2): + pwm_a = self.MICROSTEP_CURVE[self.currentstep - self.MICROSTEPS] + pwm_b = self.MICROSTEP_CURVE[self.MICROSTEPS*2 - self.currentstep] + elif (self.currentstep >= self.MICROSTEPS*2) and (self.currentstep < self.MICROSTEPS*3): + pwm_a = self.MICROSTEP_CURVE[self.MICROSTEPS*3 - self.currentstep] + pwm_b = self.MICROSTEP_CURVE[self.currentstep - self.MICROSTEPS*2] + elif (self.currentstep >= self.MICROSTEPS*3) and (self.currentstep < self.MICROSTEPS*4): pwm_a = self.MICROSTEP_CURVE[self.currentstep - self.MICROSTEPS*3] pwm_b = self.MICROSTEP_CURVE[self.MICROSTEPS*4 - self.currentstep] - # go to next 'step' and wrap around - self.currentstep += self.MICROSTEPS * 4 - self.currentstep %= self.MICROSTEPS * 4 + # go to next 'step' and wrap around + self.currentstep += self.MICROSTEPS * 4 + self.currentstep %= self.MICROSTEPS * 4 - # only really used for microstepping, otherwise always on! - self.MC._pwm.setPWM(self.PWMA, 0, pwm_a*16) - self.MC._pwm.setPWM(self.PWMB, 0, pwm_b*16) + # only really used for microstepping, otherwise always on! + self.MC._pwm.setPWM(self.PWMA, 0, pwm_a*16) + self.MC._pwm.setPWM(self.PWMB, 0, pwm_b*16) - # set up coil energizing! - coils = [0, 0, 0, 0] + # set up coil energizing! + coils = [0, 0, 0, 0] - if (style == dw_Controller.MICROSTEP): - if (self.currentstep >= 0) and (self.currentstep < self.MICROSTEPS): - coils = [1, 1, 0, 0] - elif (self.currentstep >= self.MICROSTEPS) and (self.currentstep < self.MICROSTEPS*2): - coils = [0, 1, 1, 0] - elif (self.currentstep >= self.MICROSTEPS*2) and (self.currentstep < self.MICROSTEPS*3): - coils = [0, 0, 1, 1] - elif (self.currentstep >= self.MICROSTEPS*3) and (self.currentstep < self.MICROSTEPS*4): - coils = [1, 0, 0, 1] - else: - step2coils = [ [1, 0, 0, 0], - [1, 1, 0, 0], - [0, 1, 0, 0], - [0, 1, 1, 0], - [0, 0, 1, 0], - [0, 0, 1, 1], - [0, 0, 0, 1], - [1, 0, 0, 1] ] - coils = step2coils[self.currentstep/(self.MICROSTEPS/2)] + if (style == dw_Controller.MICROSTEP): + if (self.currentstep >= 0) and (self.currentstep < self.MICROSTEPS): + coils = [1, 1, 0, 0] + elif (self.currentstep >= self.MICROSTEPS) and (self.currentstep < self.MICROSTEPS*2): + coils = [0, 1, 1, 0] + elif (self.currentstep >= self.MICROSTEPS*2) and (self.currentstep < self.MICROSTEPS*3): + coils = [0, 0, 1, 1] + elif (self.currentstep >= self.MICROSTEPS*3) and (self.currentstep < self.MICROSTEPS*4): + coils = [1, 0, 0, 1] + else: + step2coils = [ [1, 0, 0, 0], + [1, 1, 0, 0], + [0, 1, 0, 0], + [0, 1, 1, 0], + [0, 0, 1, 0], + [0, 0, 1, 1], + [0, 0, 0, 1], + [1, 0, 0, 1] ] + coils = step2coils[self.currentstep/(self.MICROSTEPS/2)] - #print "coils state = " + str(coils) - self.MC.setPin(self.PHpinA, coils[0]) #ain2 - self.MC.setPin(self.ENpinB, coils[1]) #bin1 - self.MC.setPin(self.ENpinA, coils[2]) #ain1 - self.MC.setPin(self.PHpinB, coils[3]) #bin2 + #print "coils state = " + str(coils) + self.MC.setPin(self.PHpinA, coils[0]) #ain2 + self.MC.setPin(self.ENpinB, coils[1]) #bin1 + self.MC.setPin(self.ENpinA, coils[2]) #ain1 + self.MC.setPin(self.PHpinB, coils[3]) #bin2 - #self.PHpinA = ain2 - # self.ENpinA = ain1 - # self.PHpinB = bin2 - # self.ENpinB = bin1 + #self.PHpinA = ain2 + # self.ENpinA = ain1 + # self.PHpinB = bin2 + # self.ENpinB = bin1 - return self.currentstep + return self.currentstep def step(self, steps, direction, stepstyle): s_per_s = self.sec_per_step From 3d55fefa1a8c741994b85888f6351ad3adcdee0b Mon Sep 17 00:00:00 2001 From: shrkey Date: Tue, 13 Sep 2016 22:47:41 +0100 Subject: [PATCH 03/14] more indents --- darkwater_640/darkwater_640.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/darkwater_640/darkwater_640.py b/darkwater_640/darkwater_640.py index 57532a5..26d1407 100644 --- a/darkwater_640/darkwater_640.py +++ b/darkwater_640/darkwater_640.py @@ -147,11 +147,11 @@ class dw_Stepper: if (style == dw_Controller.MICROSTEP): if (self.currentstep >= 0) and (self.currentstep < self.MICROSTEPS): coils = [1, 1, 0, 0] - elif (self.currentstep >= self.MICROSTEPS) and (self.currentstep < self.MICROSTEPS*2): + elif (self.currentstep >= self.MICROSTEPS) and (self.currentstep < self.MICROSTEPS*2): coils = [0, 1, 1, 0] - elif (self.currentstep >= self.MICROSTEPS*2) and (self.currentstep < self.MICROSTEPS*3): + elif (self.currentstep >= self.MICROSTEPS*2) and (self.currentstep < self.MICROSTEPS*3): coils = [0, 0, 1, 1] - elif (self.currentstep >= self.MICROSTEPS*3) and (self.currentstep < self.MICROSTEPS*4): + elif (self.currentstep >= self.MICROSTEPS*3) and (self.currentstep < self.MICROSTEPS*4): coils = [1, 0, 0, 1] else: step2coils = [ [1, 0, 0, 0], From d382b174ff673ebd827c51f2fc3867dec723532f Mon Sep 17 00:00:00 2001 From: shrkey Date: Tue, 13 Sep 2016 22:53:18 +0100 Subject: [PATCH 04/14] stepper test --- 640steppertest.py | 80 +++------------------------------- darkwater_640/darkwater_640.py | 5 +++ 2 files changed, 11 insertions(+), 74 deletions(-) diff --git a/640steppertest.py b/640steppertest.py index 568d40f..27c5c17 100644 --- a/640steppertest.py +++ b/640steppertest.py @@ -2,83 +2,15 @@ import time from darkwater_640.darkwater_640 import dw_Controller, dw_Servo, dw_Motor dw = dw_Controller( addr=0x60 ) -m1 = dw.getMotor(1) -m2 = dw.getMotor(2) +s1 = dw.getStepper(1) m3 = dw.getMotor(3) -m4 = dw.getMotor(4) -m5 = dw.getMotor(5) -m6 = dw.getMotor(6) -m1.off() -m2.off() +s1.off() m3.off() -m4.off() -m5.off() -m6.off() time.sleep(1) -##time.sleep(10) -print "Set forward - " -print "Motor 1" -m1.setMotorSpeed(255) -time.sleep(1) -print "Motor 2" -m2.setMotorSpeed(255) -time.sleep(1) -print "Motor 3" -m3.setMotorSpeed(255) -time.sleep(1) -print "Motor 4" -m4.setMotorSpeed(255) -time.sleep(1) -print "Motor 5" -m5.setMotorSpeed(255) -time.sleep(1) -print "Motor 6" -m6.setMotorSpeed(255) -time.sleep(1) -print "Stopping - " -print "Motor 1" -m1.setMotorSpeed(0) -time.sleep(1) -print "Motor 2" -m2.setMotorSpeed(0) -time.sleep(1) -print "Motor 3" -m3.setMotorSpeed(0) -time.sleep(1) -print "Motor 4" -m4.setMotorSpeed(0) -time.sleep(1) -print "Motor 5" -m5.setMotorSpeed(0) -time.sleep(1) -print "Motor 6" -m6.setMotorSpeed(0) -time.sleep(1) -print "Set reverse - " -print "Motor 1" -m1.setMotorSpeed(-255) -time.sleep(1) -print "Motor 2" -m2.setMotorSpeed(-255) -time.sleep(1) -print "Motor 3" m3.setMotorSpeed(-255) -time.sleep(1) -print "Motor 4" -m4.setMotorSpeed(-255) -time.sleep(1) -print "Motor 5" -m5.setMotorSpeed(-255) -time.sleep(1) -print "Motor 6" -m6.setMotorSpeed(-255) -time.sleep(1) -print "All off" -m1.off() -m2.off() -m3.off() -m4.off() -m5.off() -m6.off() +s1.oneStep( dw_Controller.FORWARD, dw_Controller.SINGLE); + +s1.off() +m3.off() \ No newline at end of file diff --git a/darkwater_640/darkwater_640.py b/darkwater_640/darkwater_640.py index 26d1407..cfb269e 100644 --- a/darkwater_640/darkwater_640.py +++ b/darkwater_640/darkwater_640.py @@ -377,6 +377,11 @@ class dw_Controller: raise NameError('Servos must be between 1 and 2 inclusive') return self.servos[num-1] + def getStepper(self, num): + if (num < 1) or (num > 3): + raise NameError('Stepper motors must be between 1 and 3 inclusive') + return self.steppers[num-1] + def setAllPWM(self, value): if(value > 0): self._pwm.set_all_pwm(0, value) From afe2d9c0b80ef37f4cb91de022b4983a410910dc Mon Sep 17 00:00:00 2001 From: shrkey Date: Tue, 13 Sep 2016 22:56:03 +0100 Subject: [PATCH 05/14] oops --- darkwater_640/darkwater_640.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/darkwater_640/darkwater_640.py b/darkwater_640/darkwater_640.py index cfb269e..eac20a3 100644 --- a/darkwater_640/darkwater_640.py +++ b/darkwater_640/darkwater_640.py @@ -138,8 +138,8 @@ class dw_Stepper: self.currentstep %= self.MICROSTEPS * 4 # only really used for microstepping, otherwise always on! - self.MC._pwm.setPWM(self.PWMA, 0, pwm_a*16) - self.MC._pwm.setPWM(self.PWMB, 0, pwm_b*16) + self.MC._pwm.set_pwm(self.PWMA, 0, pwm_a*16) + self.MC._pwm.set_pwm(self.PWMB, 0, pwm_b*16) # set up coil energizing! coils = [0, 0, 0, 0] From 78eea1026a659c183365a997dc8cf8b9989acc48 Mon Sep 17 00:00:00 2001 From: shrkey Date: Tue, 13 Sep 2016 23:00:54 +0100 Subject: [PATCH 06/14] remove pwm --- darkwater_640/darkwater_640.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/darkwater_640/darkwater_640.py b/darkwater_640/darkwater_640.py index eac20a3..75486bb 100644 --- a/darkwater_640/darkwater_640.py +++ b/darkwater_640/darkwater_640.py @@ -138,8 +138,8 @@ class dw_Stepper: self.currentstep %= self.MICROSTEPS * 4 # only really used for microstepping, otherwise always on! - self.MC._pwm.set_pwm(self.PWMA, 0, pwm_a*16) - self.MC._pwm.set_pwm(self.PWMB, 0, pwm_b*16) + #self.MC._pwm.set_pwm(self.PWMA, 0, pwm_a*16) + #self.MC._pwm.set_pwm(self.PWMB, 0, pwm_b*16) # set up coil energizing! coils = [0, 0, 0, 0] From ab26bc288561e0b2dd7d46bc7227e7f8a409c669 Mon Sep 17 00:00:00 2001 From: shrkey Date: Tue, 13 Sep 2016 23:16:38 +0100 Subject: [PATCH 07/14] rejig --- darkwater_640/darkwater_640.py | 48 +++++++++++++++++----------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/darkwater_640/darkwater_640.py b/darkwater_640/darkwater_640.py index 75486bb..d2c6bfe 100644 --- a/darkwater_640/darkwater_640.py +++ b/darkwater_640/darkwater_640.py @@ -25,27 +25,27 @@ class dw_Stepper: self.currentstep = 0 if (num == 0): - ain2 = 2 #phase - ain1 = 3 #enable - bin2 = 4 #phase - bin1 = 5 #enable + ain1 = 2 #phase + ain2 = 3 #enable + bin1 = 4 #phase + bin2 = 5 #enable elif (num == 1): - ain2 = 6 #phase - ain1 = 7 #enable - bin2 = 8 #phase - bin1 = 9 #enable + ain1 = 6 #phase + ain2 = 7 #enable + bin1 = 8 #phase + bin2 = 9 #enable elif (num == 2): - ain2 = 10 #phase - ain1 = 11 #enable - bin2 = 12 #phase - bin1 = 13 #enable + ain1 = 10 #phase + ain2 = 11 #enable + bin1 = 12 #phase + bin2 = 13 #enable else: raise NameError('MotorHAT Stepper must be between 1 and 3 inclusive') - self.PHpinA = ain2 - self.ENpinA = ain1 - self.PHpinB = bin2 - self.ENpinB = bin1 + self.ain1 = ain1 + self.ain2 = ain2 + self.bin1 = bin1 + self.bin2 = bin2 # switch off both drivers self.run(dw_Controller.RELEASE, 0) @@ -60,10 +60,10 @@ class dw_Stepper: self.MC.setPin(self.PHpin, 1) self.MC._pwm.set_pwm(self.ENpin, 0, speed*16) if (command == dw_Controller.RELEASE): - self.MC.setPin(self.PHpinA, 0) - self.MC.setPin(self.ENpinA, 0) - self.MC.setPin(self.PHpinB, 0) - self.MC.setPin(self.ENpinB, 0) + self.MC.setPin(self.ain1, 0) + self.MC.setPin(self.ain2, 0) + self.MC.setPin(self.bin1, 0) + self.MC.setPin(self.bin2, 0) def off(self): self.run(dw_Controller.RELEASE, 0) @@ -165,10 +165,10 @@ class dw_Stepper: coils = step2coils[self.currentstep/(self.MICROSTEPS/2)] #print "coils state = " + str(coils) - self.MC.setPin(self.PHpinA, coils[0]) #ain2 - self.MC.setPin(self.ENpinB, coils[1]) #bin1 - self.MC.setPin(self.ENpinA, coils[2]) #ain1 - self.MC.setPin(self.PHpinB, coils[3]) #bin2 + self.MC.setPin(self.ain1, coils[0]) #ain2 + self.MC.setPin(self.bin1, coils[1]) #bin1 + self.MC.setPin(self.ain2, coils[2]) #ain1 + self.MC.setPin(self.bin2, coils[3]) #bin2 #self.PHpinA = ain2 # self.ENpinA = ain1 From bf07ee72766fd34912bd0855b42dd3a204bf99bb Mon Sep 17 00:00:00 2001 From: shrkey Date: Sat, 17 Sep 2016 20:52:00 +0100 Subject: [PATCH 08/14] New motor code to handle IN/IN mode --- darkwater_640/darkwater_640.py | 128 +++++++++++++++++++-------------- 1 file changed, 74 insertions(+), 54 deletions(-) diff --git a/darkwater_640/darkwater_640.py b/darkwater_640/darkwater_640.py index d2c6bfe..5b3b0f8 100644 --- a/darkwater_640/darkwater_640.py +++ b/darkwater_640/darkwater_640.py @@ -13,7 +13,7 @@ class dw_Stepper: # a sinusoidal curve NOT LINEAR! #MICROSTEP_CURVE = [0, 25, 50, 74, 98, 120, 141, 162, 180, 197, 212, 225, 236, 244, 250, 253, 255] - def __init__(self, controller, num, steps=200): + def __init__(self, controller, num, steps=200, forcemode=False): self.speed = 0 self.MC = controller self.motornum = num @@ -24,23 +24,28 @@ class dw_Stepper: self.steppingcounter = 0 self.currentstep = 0 - if (num == 0): - ain1 = 2 #phase - ain2 = 3 #enable - bin1 = 4 #phase - bin2 = 5 #enable - elif (num == 1): - ain1 = 6 #phase - ain2 = 7 #enable - bin1 = 8 #phase - bin2 = 9 #enable - elif (num == 2): - ain1 = 10 #phase - ain2 = 11 #enable - bin1 = 12 #phase - bin2 = 13 #enable + if(self.MC.getMode() != dw_Controller.ININ && forcemode != True ): + raise NameError('Mode needs to be set to ININ for stepper mode operation') else: - raise NameError('MotorHAT Stepper must be between 1 and 3 inclusive') + self.MC.setmode(dw_Controller.ININ) + + if (num == 0): + ain1 = 2 + ain2 = 3 + bin1 = 4 + bin2 = 5 + elif (num == 1): + ain1 = 6 + ain2 = 7 + bin1 = 8 + bin2 = 9 + elif (num == 2): + ain1 = 10 + ain2 = 11 + bin1 = 12 + bin2 = 13 + else: + raise NameError('Stepper must be between 1 and 3 inclusive') self.ain1 = ain1 self.ain2 = ain2 @@ -102,11 +107,6 @@ class dw_Stepper: self.currentstep += self.MICROSTEPS else: self.currentstep -= self.MICROSTEPS - if (style == dw_Controller.INTERLEAVE): - if (dir == dw_Controller.FORWARD): - self.currentstep += self.MICROSTEPS/2 - else: - self.currentstep -= self.MICROSTEPS/2 if (style == dw_Controller.MICROSTEP): if (dir == dw_Controller.FORWARD): @@ -137,10 +137,6 @@ class dw_Stepper: self.currentstep += self.MICROSTEPS * 4 self.currentstep %= self.MICROSTEPS * 4 - # only really used for microstepping, otherwise always on! - #self.MC._pwm.set_pwm(self.PWMA, 0, pwm_a*16) - #self.MC._pwm.set_pwm(self.PWMB, 0, pwm_b*16) - # set up coil energizing! coils = [0, 0, 0, 0] @@ -164,25 +160,17 @@ class dw_Stepper: [1, 0, 0, 1] ] coils = step2coils[self.currentstep/(self.MICROSTEPS/2)] - #print "coils state = " + str(coils) self.MC.setPin(self.ain1, coils[0]) #ain2 self.MC.setPin(self.bin1, coils[1]) #bin1 self.MC.setPin(self.ain2, coils[2]) #ain1 self.MC.setPin(self.bin2, coils[3]) #bin2 - #self.PHpinA = ain2 - # self.ENpinA = ain1 - # self.PHpinB = bin2 - # self.ENpinB = bin1 - return self.currentstep def step(self, steps, direction, stepstyle): s_per_s = self.sec_per_step lateststep = 0 - if (stepstyle == dw_Controller.INTERLEAVE): - s_per_s = s_per_s / 2.0 if (stepstyle == dw_Controller.MICROSTEP): s_per_s /= self.MICROSTEPS steps *= self.MICROSTEPS @@ -228,40 +216,59 @@ class dw_Motor: else: raise NameError('Motors must be between 1 and 6 inclusive') + # for phase enable self.PHpin = in2 self.ENpin = in1 + # for in/in + self.IN2pin = in2 + self.IN1pin = in1 # switch off - self.run(dw_Controller.RELEASE, 0) + self.run(dw_Controller.STOP, 0) def setMotorSpeed(self, value): # Check for PWM values if(value > 1000) and (value < 1500): - self.run(dw_Controller.BACKWARD, round(translate(value,1500,1000, 0, 255))) + self.run(dw_Controller.REVERSE, round(translate(value,1500,1000, 0, 255))) if(value > 1500) and (value <= 2000): self.run(dw_Controller.FORWARD, round(translate(value, 1500, 2000, 0, 255))) if(value == 1500): - self.run(dw_Controller.RELEASE, 0) + self.run(dw_Controller.STOP, 0) if(value > 0) and (value <= 255): self.run(dw_Controller.FORWARD, value) if(value == 0): - self.run(dw_Controller.RELEASE, value) + self.run(dw_Controller.STOP, value) if(value < 0) and (value >= -255): - self.run(dw_Controller.BACKWARD, abs(value)) + self.run(dw_Controller.REVERSE, abs(value)) def run(self, command, speed = 0): if not self.MC: return - if (command == dw_Controller.FORWARD): - self.MC.setPin(self.PHpin, 0) - self.MC._pwm.set_pwm(self.ENpin, 0, speed*16) - if (command == dw_Controller.BACKWARD): - self.MC.setPin(self.PHpin, 1) - self.MC._pwm.set_pwm(self.ENpin, 0, speed*16) - if (command == dw_Controller.RELEASE): - self.MC.setPin(self.PHpin, 0) - self.MC.setPin(self.ENpin, 0) + if (self.MC.getMode() == dw_Controller.PHASE): + if (command == dw_Controller.FORWARD): + self.MC.setPin(self.PHpin, 0) + self.MC._pwm.set_pwm(self.ENpin, 0, speed*16) + if (command == dw_Controller.REVERSE): + self.MC.setPin(self.PHpin, 1) + self.MC._pwm.set_pwm(self.ENpin, 0, speed*16) + if (command == dw_Controller.STOP): + self.MC.setPin(self.PHpin, 0) + self.MC.setPin(self.ENpin, 0) + else: ## IN/IN mode + if (command == dw_Controller.FORWARD): + self.MC.setPin(self.IN2pin, 0) + self.MC._pwm.set_pwm(self.IN1pin, 0, speed*16) + if (command == dw_Controller.REVERSE): + self.MC.setPin(self.IN1pin, 0) + self.MC._pwm.set_pwm(self.IN2pin, 0, speed*16) + if (command == dw_Controller.STOP): + self.MC.setPin(self.IN1pin, 1) + self.MC.setPin(self.IN2pin, 1) + if (command == dw_Controller.COAST): + self.MC.setPin(self.IN1pin, 0) + self.MC.setPin(self.IN2pin, 0) + def off(self): - self.run(dw_Controller.RELEASE, 0) + self.run(dw_Controller.STOP, 0) class dw_Servo: @@ -317,9 +324,11 @@ class dw_Servo: class dw_Controller: FORWARD = 1 - BACKWARD = 2 - BRAKE = 3 - RELEASE = 4 + REVERSE = 2 + BRAKEFORWARD = 3 + BRAKEREVERSE = 4 + STOP = 5 #brake + COAST = 6 # in/in only SINGLE = 1 DOUBLE = 2 @@ -339,14 +348,25 @@ class dw_Controller: GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) GPIO.setup(27, GPIO.OUT) - #GPIO.output(27, GPIO.HIGH) # set for en/phase mode - low = in/in mode - GPIO.output(27, GPIO.LOW) # set for en/phase mode - low = in/in mode + + self.setMode(self.ININ) # set high for en/phase mode - low = in/in mode self.motors = [ dw_Motor(self, m) for m in range(6) ] self.servos = [ dw_Servo(self, m, freq) for m in range(2) ] self.steppers = [ dw_Stepper(self, m) for m in range(3) ] + def setMode(self, mode = 1): + if (mode == self.ININ): + self._mode = self.ININ + GPIO.output(27, GPIO.HIGH) + else: + self._mode = self.PHASE + GPIO.output(27, GPIO.LOW) + + def getMode(self): + return self._mode + def setPin(self, pin, value): if (pin < 0) or (pin > 15): raise NameError('PWM pin must be between 0 and 15 inclusive') From d5fbd166b8a8ce95e112474d53e90f379b4edefa Mon Sep 17 00:00:00 2001 From: shrkey Date: Sat, 17 Sep 2016 21:04:32 +0100 Subject: [PATCH 09/14] updated stepper --- darkwater_640/darkwater_640.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/darkwater_640/darkwater_640.py b/darkwater_640/darkwater_640.py index 5b3b0f8..ec38593 100644 --- a/darkwater_640/darkwater_640.py +++ b/darkwater_640/darkwater_640.py @@ -5,6 +5,9 @@ from PCA9685 import PCA9685 import time import math +# Stepper motor code based on Adafruit Python Library for DC + Stepper Motor HAT +# Written by Limor Fried for Adafruit Industries. MIT license. + class dw_Stepper: MICROSTEPS = 8 MICROSTEP_CURVE = [0, 50, 98, 142, 180, 212, 236, 250, 255] @@ -61,17 +64,17 @@ class dw_Stepper: if (command == dw_Controller.FORWARD): self.MC.setPin(self.PHpin, 0) self.MC._pwm.set_pwm(self.ENpin, 0, speed*16) - if (command == dw_Controller.BACKWARD): + if (command == dw_Controller.REVERSE): self.MC.setPin(self.PHpin, 1) self.MC._pwm.set_pwm(self.ENpin, 0, speed*16) - if (command == dw_Controller.RELEASE): + if (command == dw_Controller.STOP): self.MC.setPin(self.ain1, 0) self.MC.setPin(self.ain2, 0) self.MC.setPin(self.bin1, 0) self.MC.setPin(self.bin2, 0) def off(self): - self.run(dw_Controller.RELEASE, 0) + self.run(dw_Controller.STOP, 0) def setSpeed(self, rpm): self.sec_per_step = 60.0 / (self.revsteps * rpm) From 47bdab0e5a9419803c0f222bb0bcdb96d2ef354b Mon Sep 17 00:00:00 2001 From: shrkey Date: Sat, 17 Sep 2016 21:09:42 +0100 Subject: [PATCH 10/14] dodgy c synatx in there :) --- darkwater_640/darkwater_640.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/darkwater_640/darkwater_640.py b/darkwater_640/darkwater_640.py index ec38593..2dfdd2d 100644 --- a/darkwater_640/darkwater_640.py +++ b/darkwater_640/darkwater_640.py @@ -27,7 +27,7 @@ class dw_Stepper: self.steppingcounter = 0 self.currentstep = 0 - if(self.MC.getMode() != dw_Controller.ININ && forcemode != True ): + if(self.MC.getMode() != dw_Controller.ININ and forcemode != True ): raise NameError('Mode needs to be set to ININ for stepper mode operation') else: self.MC.setmode(dw_Controller.ININ) From 171cdd37d18c40cd0a90298bbae456c2f26b0e42 Mon Sep 17 00:00:00 2001 From: shrkey Date: Sat, 17 Sep 2016 21:11:33 +0100 Subject: [PATCH 11/14] setmode bug --- darkwater_640/darkwater_640.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/darkwater_640/darkwater_640.py b/darkwater_640/darkwater_640.py index 2dfdd2d..f47c1f9 100644 --- a/darkwater_640/darkwater_640.py +++ b/darkwater_640/darkwater_640.py @@ -30,7 +30,7 @@ class dw_Stepper: if(self.MC.getMode() != dw_Controller.ININ and forcemode != True ): raise NameError('Mode needs to be set to ININ for stepper mode operation') else: - self.MC.setmode(dw_Controller.ININ) + self.MC.setMode(dw_Controller.ININ) if (num == 0): ain1 = 2 From ab0b820d3b39687f7125f4f4648bd9faa11762a9 Mon Sep 17 00:00:00 2001 From: shrkey Date: Sat, 17 Sep 2016 21:12:57 +0100 Subject: [PATCH 12/14] release bug --- darkwater_640/darkwater_640.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/darkwater_640/darkwater_640.py b/darkwater_640/darkwater_640.py index f47c1f9..8bea3a7 100644 --- a/darkwater_640/darkwater_640.py +++ b/darkwater_640/darkwater_640.py @@ -56,7 +56,7 @@ class dw_Stepper: self.bin2 = bin2 # switch off both drivers - self.run(dw_Controller.RELEASE, 0) + self.run(dw_Controller.STOP, 0) def run(self, command, speed = 0): if not self.MC: From 8ca4d47d0c87688423b94b1366db513f4b2de666 Mon Sep 17 00:00:00 2001 From: shrkey Date: Sat, 17 Sep 2016 21:19:53 +0100 Subject: [PATCH 13/14] mode fix --- darkwater_640/darkwater_640.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/darkwater_640/darkwater_640.py b/darkwater_640/darkwater_640.py index 8bea3a7..5c64ab5 100644 --- a/darkwater_640/darkwater_640.py +++ b/darkwater_640/darkwater_640.py @@ -362,10 +362,10 @@ class dw_Controller: def setMode(self, mode = 1): if (mode == self.ININ): self._mode = self.ININ - GPIO.output(27, GPIO.HIGH) + GPIO.output(27, GPIO.LOW) else: self._mode = self.PHASE - GPIO.output(27, GPIO.LOW) + GPIO.output(27, GPIO.HIGH) def getMode(self): return self._mode From 3cfca22056db6f9a32bc52b02a35af594f7a2069 Mon Sep 17 00:00:00 2001 From: shrkey Date: Sat, 17 Sep 2016 21:25:45 +0100 Subject: [PATCH 14/14] another test --- darkwater_640/darkwater_640.py | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/darkwater_640/darkwater_640.py b/darkwater_640/darkwater_640.py index 5c64ab5..f63892e 100644 --- a/darkwater_640/darkwater_640.py +++ b/darkwater_640/darkwater_640.py @@ -61,17 +61,12 @@ class dw_Stepper: def run(self, command, speed = 0): if not self.MC: return - if (command == dw_Controller.FORWARD): - self.MC.setPin(self.PHpin, 0) - self.MC._pwm.set_pwm(self.ENpin, 0, speed*16) - if (command == dw_Controller.REVERSE): - self.MC.setPin(self.PHpin, 1) - self.MC._pwm.set_pwm(self.ENpin, 0, speed*16) + if (command == dw_Controller.STOP): - self.MC.setPin(self.ain1, 0) - self.MC.setPin(self.ain2, 0) - self.MC.setPin(self.bin1, 0) - self.MC.setPin(self.bin2, 0) + self.MC.setPin(self.ain1, 1) + self.MC.setPin(self.ain2, 1) + self.MC.setPin(self.bin1, 1) + self.MC.setPin(self.bin2, 1) def off(self): self.run(dw_Controller.STOP, 0)