New updates for testing

This commit is contained in:
shrkey
2016-02-21 18:19:18 +00:00
parent 0abbcfd415
commit c2b05aeb22

View File

@@ -168,83 +168,62 @@ import time
class dw_DCMotor: class dw_DCMotor:
def __init__(self, controller, num): def __init__(self, controller, num):
self.speed = 0
self.MC = controller self.MC = controller
self.motornum = num self.motornum = num
modepin = in1 = in2 = 0 modepin = in1 = in2 = 0
if (num == 0): if (num == 0):
modepin = 11 in2 = 8 #phase
in2 = 8 in1 = 9 #enable
in1 = 9
elif (num == 1): elif (num == 1):
modepin = 11 in2 = 10 #phase
in2 = 10 in1 = 11 #enable
in1 = 11
elif (num == 2): elif (num == 2):
modepin = 13 in2 = 7 #phase
in2 = 7 in1 = 6 #enable
in1 = 6
elif (num == 3): elif (num == 3):
modepin = 13 in2 = 5 #phase
in2 = 5 in1 = 4 #enable
in1 = 4
elif (num == 4): elif (num == 4):
modepin = 15 in2 = 0 #phase
in2 = 0 in1 = 1 #enable
in1 = 1
elif (num == 5): elif (num == 5):
modepin = 15 in2 = 2 #phase
in2 = 2 in1 = 3 #enable
in1 = 3
else: else:
raise NameError('MotorHAT Motor must be between 1 and 6 inclusive') raise NameError('MotorHAT Motor must be between 1 and 6 inclusive')
self.MODEpin = modepin self.PHpin = in1
self.IN1pin = in1 self.ENpin = in2
self.IN2pin = in2
def setMotorSpeed(self, value):
if(value > 0) and (value <= 255):
self.run(self, dw_MotorCONTROL.FORWARD, value)
if(value == 0):
self.run(self, dw_MotorCONTROL.RELEASE, value)
if(value < 0) and (value >= -255):
self.run(self, dw_MotorCONTROL.BACKWARD, abs(value))
def run(self, command, speed = 0):
def setMode(self, level):
if not self.MC: if not self.MC:
return return
if (level == dw_MotorCONTROL.ININ):
GPIO.output(self.MODEpin, GPIO.LOW)
if (level == dw_MotorCONTROL.PHASE):
GPIO.output(self.MODEpin, GPIO.HIGH)
def run(self, command):
if not self.MC:
return
if( GPIO.input( self.MODEpin ) == GPIO.LOW ):
if (command == dw_MotorCONTROL.FORWARD): if (command == dw_MotorCONTROL.FORWARD):
self.MC.setPin(self.IN2pin, 0) self.MC.setPin(self.PHpin, 0)
self.MC.setPin(self.IN1pin, 1) self.MC._pwm.setPWM(self.ENpin, 0, speed*16)
if (command == dw_MotorCONTROL.BACKWARD): if (command == dw_MotorCONTROL.BACKWARD):
self.MC.setPin(self.IN1pin, 0) self.MC.setPin(self.PHpin, 1)
self.MC.setPin(self.IN2pin, 1) self.MC._pwm.setPWM(self.ENpin, 0, speed*16)
if (command == dw_MotorCONTROL.RELEASE): if (command == dw_MotorCONTROL.RELEASE):
self.MC.setPin(self.IN1pin, 0) self.MC.setPin(self.PHpin, 0)
self.MC.setPin(self.IN2pin, 0) self.MC.setPin(self.ENpin, 0)
else:
if (command == dw_MotorCONTROL.FORWARD):
self.MC.setPin(self.IN2pin, 0)
self.MC.setPin(self.IN1pin, 1)
if (command == dw_MotorCONTROL.BACKWARD):
self.MC.setPin(self.IN1pin, 0)
self.MC.setPin(self.IN2pin, 1)
if (command == dw_MotorCONTROL.RELEASE):
self.MC.setPin(self.IN1pin, 0)
self.MC.setPin(self.IN2pin, 0)
def setSpeed(self, speed): def setSpeed(self, speed):
if (speed < 0): if (speed < 0):
speed = 0 speed = 0
if (speed > 255): if (speed > 255):
speed = 255 speed = 255
self.MC._pwm.setPWM(self.PWMpin, 0, speed*16) self.MC._pwm.setPWM(self.ENpin, 0, speed*16)
class dw_MotorCONTROL: class dw_MotorCONTROL:
FORWARD = 1 FORWARD = 1
@@ -267,15 +246,15 @@ class dw_MotorCONTROL:
# self.steppers = [ Adafruit_StepperMotor(self, 1), Adafruit_StepperMotor(self, 2) ] # self.steppers = [ Adafruit_StepperMotor(self, 1), Adafruit_StepperMotor(self, 2) ]
self._pwm = PWM(addr, debug=False) self._pwm = PWM(addr, debug=False)
self._pwm.setPWMFreq(self._frequency) self._pwm.setPWMFreq(self._frequency)
# Just gonna default to high for now
GPIO.setmode(GPIO.BCM) GPIO.setmode(GPIO.BCM)
GPIO.setup(11, GPIO.OUT) GPIO.setup(17, GPIO.OUT)
GPIO.setup(13, GPIO.OUT) GPIO.setup(27, GPIO.OUT)
GPIO.setup(15, GPIO.OUT) GPIO.setup(22, GPIO.OUT)
GPIO.output(11, GPIO.LOW) GPIO.output(17, GPIO.HIGH)
GPIO.output(13, GPIO.LOW) GPIO.output(27, GPIO.HIGH)
GPIO.output(15, GPIO.LOW) GPIO.output(22, GPIO.HIGH)
def setPin(self, pin, value): def setPin(self, pin, value):
if (pin < 0) or (pin > 15): if (pin < 0) or (pin > 15):