def __init__(self, min_speed=25): # make the motor banks self._LEFT = [ Motor(0, 1, 'cw', 'ccw'), Motor(0, 2, 'cw', 'ccw'), Motor(0, 3, 'cw', 'ccw') ] self._RIGHT = [ Motor(1, 1, 'ccw', 'cw'), Motor(1, 2, 'ccw', 'cw'), Motor(1, 3, 'ccw', 'cw') ] # get the motors ready to run for m in self._LEFT: MOTOR.dcCONFIG(m._address, m._number, m.direction, 0, m._acceleration) print("Starting motors at speed 0.") MOTOR.dcSTART(m._address, m._number) m._stopped = False for m in self._RIGHT: MOTOR.dcCONFIG(m._address, m._number, m.direction, 0, m._acceleration) print("Starting motors at speed 0.") MOTOR.dcSTART(m._address, m._number) m._stopped = False
def stop(self): for m in self._LEFT + self._RIGHT: MOTOR.dcSTOP(m._address, m._number) time.sleep(m._acceleration) m.speed = 0 m._direction = m._forward MOTOR.dcCONFIG(m._address, m._number, m.direction, m.speed, m._acceleration) m._stopped = True print("motor: {0}, {1} speed: {2} direction: {3}".format( m._address, m._number, m.speed, m.direction))
def initMotor(FLdir,FRdir,RLdir,RRdir): #print("Setting: ",rotation) MOTOR.dcCONFIG(ctl,FL,FLdir,0.0,0.0) MOTOR.dcCONFIG(ctl,FR,FRdir,0.0,0.0) MOTOR.dcCONFIG(ctl,RL,RLdir,0.0,0.0) MOTOR.dcCONFIG(ctl,RR,RRdir,0.0,0.0) MOTOR.dcSTART(ctl,FL) MOTOR.dcSTART(ctl,FR) MOTOR.dcSTART(ctl,RL) MOTOR.dcSTART(ctl,RR) if (FLdir == FRdir == RLdir == RRdir == "cw") : status = "forward" return elif (FLdir == FRdir == RLdir == RRdir == "ccw"): status = "reverse" return elif (FLdir == RLdir == "cw" and FRdir == RRdir == "ccw"): status = "left" elif (FLdir == RLdir == "ccw" and FRdir == RRdir == "cw"): status = "right" else: status = 'something not right' return status
def reverse(self, increment): # decrease forward speed of both banks for m in self._LEFT + self._RIGHT: if m._stopped: MOTOR.dcSTART(m._address, m._number) tmp = m.speed - increment if tmp >= 0 and m.direction == m._forward: new_speed = min([100, tmp]) MOTOR.dcSPEED(m._address, m._number, new_speed) time.sleep(m._acceleration) m.speed = new_speed if tmp >= 0 and m.direction == m._reverse: m.direction = m._forward new_speed = min([100, tmp]) MOTOR.dcSTOP(m._address, m._number) time.sleep(m._acceleration) MOTOR.dcCONFIG(m._address, m._number, m.direction, new_speed, m._acceleration) MOTOR.dcSTART(m._address, m._number) time.sleep(m._acceleration) m.speed = new_speed if tmp < 0 and m.direction == m._forward: m.direction = m._reverse new_speed = min([100, abs(tmp)]) MOTOR.dcSTOP(m._address, m._number) time.sleep(m._acceleration) MOTOR.dcCONFIG(m._address, m._number, m.direction, new_speed, m._acceleration) MOTOR.dcSTART(m._address, m._number) time.sleep(m._acceleration) m.speed = -new_speed if tmp < 0 and m.direction == m._reverse: new_speed = min([100, abs(tmp)]) MOTOR.dcSPEED(m._address, m._number, new_speed) time.sleep(m._acceleration) m.speed = -new_speed print(m.speed)
def __init__(self, loginVo, sensorName): self.loginVo = loginVo self.sensorName = sensorName MOTOR.dcCONFIG(0,3,'cw',100, 1)
def start(self, msg): MOTOR.dcCONFIG(config.ADDR, msg['motor'], msg['dir'], msg['speed'], msg['acc']) MOTOR.dcSTART(config.ADDR, msg['motor'])
def SetAcceleration(self,Acceleration): self.Acceleration = Acceleration MOTOR.dcCONFIG(0,self.Motor_Number,self.Direction,self.DutyCycle,self.Acceleration)
def __init__(self,MotorNumber): self.Motor_Number = MotorNumber MOTOR.dcCONFIG(0,self.Motor_Number,self.Direction,self.DutyCycle,self.Acceleration) # dcCONFIG(addr,motor,dir,speed,acceleration) MOTOR.dcSTART(0,self.Motor_Number) # dcSTART(addr,motor)
def right(self, increment): # decrease speed of right bank for m in self._RIGHT: if m._stopped: MOTOR.dcCONFIG(m._address, m._number, m.direction, 0, m._acceleration) MOTOR.dcSTART(m._address, m._number) tmp = m.speed - increment if tmp >= 0 and m.direction == m._forward: new_speed = min([tmp, 100]) MOTOR.dcSPEED(m._address, m._number, new_speed) time.sleep(m._acceleration) m.speed = new_speed elif tmp < 0 and m.direction == m._forward: m.direction = m._reverse new_speed = min([abs(tmp), 100]) MOTOR.dcSTOP(m._address, m._number) time.sleep(m._acceleration) MOTOR.dcCONFIG(m._address, m._number, m.direction, new_speed, m._acceleration) MOTOR.dcSTART(m._address, m._number) time.sleep(m._acceleration) m.speed = -new_speed elif tmp < 0 and m.direction == m._reverse: new_speed = min([abs(tmp), 100]) MOTOR.dcSPEED(m._address, m._number, new_speed) time.sleep(m._acceleration) m.speed = -new_speed elif tmp >= 0 and m.direction == m._reverse: m.direction = m._forward new_speed = min([tmp, 100]) MOTOR.dcSTOP(m._address, m._number) time.sleep(m._acceleration) MOTOR.dcCONFIG(m._address, m._number, m.direction, new_speed, m._acceleration) MOTOR.dcSTART(m._address, m._number) time.sleep(m._acceleration) m.speed = -new_speed print("motor: {0}, {1} speed: {2} direction: {3}".format( m._address, m._number, m.speed, m.direction)) # increase speed of left bank for m in self._LEFT: if m._stopped: MOTOR.dcCONFIG(m._address, m._number, m.direction, 0, m._acceleration) MOTOR.dcSTART(m._address, m._number) tmp = m.speed + increment if tmp >= 0 and m.direction == m._forward: new_speed = min([tmp, 100]) MOTOR.dcSPEED(m._address, m._number, new_speed) time.sleep(m._acceleration) m.speed = new_speed elif tmp >= 0 and m.direction == m._reverse: m.direction = m._forward new_speed = min([tmp, 100]) MOTOR.dcSTOP(m._address, m._number) time.sleep(m._acceleration) MOTOR.dcCONFIG(m._address, m._number, m.direction, new_speed, m._acceleration) MOTOR.dcSTART(m._address, m._number) time.sleep(m._acceleration) m.speed = new_speed elif tmp < 0 and m.direction == m._reverse: new_speed = min([abs(tmp), 100]) MOTOR.dcSPEED(m._address, m._number, new_speed) time.sleep(m._acceleration) m.speed = -new_speed elif tmp < 0 and m.direction == m._forward: m.direction = m._reverse new_speed = min([abs(tmp), 100]) MOTOR.dcSTOP(m._address, m._number) time.sleep(m._acceleration) MOTOR.dcCONFIG(m._address, m._number, m.direction, new_speed, m._acceleration) MOTOR.dcSTART(m._address, m._number) time.sleep(m._acceleration) m.speed = -new_speed print("motor: {0}, {1} speed: {2} direction: {3}".format( m._address, m._number, m.speed, m.direction))
from flask import Flask, render_template import piplates.RELAYplate as RELAY import piplates.MOTORplate as MOTOR import socket RELAY.getID(0) MOTOR.dcCONFIG(2, 1, 'ccw', 0, 2.5) app = Flask(__name__) @app.route("/") def hello(): return render_template('home.html') @app.route("/relay_on/<int:relay_number>") def relay_on(relay_number): RELAY.relayON(0, relay_number) return render_template('home.html') @app.route("/motor/<int:motor_number>/<int:value>") def motor(motor_number, value): print str(value) MOTOR.dcSPEED(2, motor_number, value) if (value > 20): MOTOR.dcSTART(2, motor_number) else: MOTOR.dcSTOP(2, motor_number) return render_template('home.html')
def emergencyStopAll(self): #this one still needs work for x in range(1, 4): MOTOR.dcCONFIG(self.plate, x, 'cw', 0, 0) self.motorStop(self.plate, x) self.running = False
def motorStart(self, plate, motor, dir, speed, accel): MOTOR.dcCONFIG(self.plate, motor, dir, speed, accel) MOTOR.dcSTART(self.plate, motor)
def move_track(self, motor_number, direction, speed): MOTOR.dcSTOP(0, motor_number) MOTOR.dcCONFIG(0, motor_number, direction, speed, 0) MOTOR.dcSTART(0, motor_number)