def main(self): self.UDP_start() self.FLmotor = motor(PWM1A) while (1): try: self.UDP_get() self.FLmotor.drive(self.throttle) except KeyboardInterrupt: break
def __init__(self, wheelBase, maxAngle, halfLength, increment, servo_mid, servo_dif): self.wheelBase = wheelBase self.increment = increment self.maxAngle = maxAngle self.halfLength = halfLength self.currentDifferential = 0 #start rover in straight line self.angle = 0 #start rover in straight line logger.debug('Timers configured for PWM') self.motor1 = motor(1, servo_mid, servo_dif) # Front Left self.motor2 = motor(2, servo_mid, servo_dif) # Front Right self.motor3 = motor(3, servo_mid, servo_dif) # Back Left self.motor4 = motor(4, servo_mid, servo_dif) # Back Right logger.debug('Motors created') driver.setup_pwm() logger.debug('PWM Setup') logger.debug('Motor Settings:' + '\n\t Wheelbase \t' + str(self.wheelBase) + '\n\t Increment \t' + str(self.increment) + '\n\t Current Diff \t' + str(self.currentDifferential) + '\n\t Current Angle \t' + str(self.angle))
def main(): mass = 1#kg gForce = mass*9.98 initaialForce = gForce motor1 = motor() motor2 = motor() motor3 = motor() motor4 = motor() def start(): torquePerMoyor = initialForce/4; motor1.setTorque(torquePerMotor); motor2.setTorque(torquePerMotor) motor3.setTorque(torquePerMotor) motor4.setTorque(torquePerMotor) def land(): return def howerAt(meter): return
def _init_(self): """Read Submarine Configuration""" self.config = []; if os.path.exists("../sub.config"): with open("../sub.config", 'r') as file: """Will Need to add validation later""" for line in file: pair = line.split('=') config[count(config)] = pair """Begin Motor Configuration""" self.motors = []; i = 1 while i < 7: new_motor = motor(i) self.motors[i] = (new_motor)
def main(): arguments = sys.argv #pull in arguments counter = 0 numExpected = False for item in arguments: if (numExpected): data = item.split('/') times.append(float(data[1])) myDe.debugPrint(times) mtrNum = int(data[0]) motors.append(motor(motorPins[mtrNum - 1], myDe, mtrNum)) print(times) print(mtrNum) numExpected = False #print(item) if (item == "-D" or item == "-d"): myDe.activate() myDe.debugPrint(item, "input " + str(counter)) counter = counter + 1 if (item.startswith("-t")): myDe.debugPrint("found timer input in minutes") numExpected = True count = 0 for tm in times: newTimer = timer(tm, myDe, motors[count]) timers.append(newTimer) count += 1 #myDe.debugPrint("Debugger Activated") for i in range(0, len(timers)): t = threading.Thread(target=beginTimer, args=(i, )) t.daemon = True t.start() activeTimers = True time.sleep(3) while (activeTimers): activeTimers = False for tmr in timers: print(tmr.isRunning()) if (tmr.isRunning()): activeTimers = True time.sleep(1)
def __init__(self, M11, M12, M21, M22): self.rightMotor = motor(M11, M12, False) self.leftMotor = motor(M21, M22, False)
def execute_menu(self, screen, conf): pygame.font.init() engine = motor() running = True keys = [False, False, False] if self.gameMode > 0: timer = timerObject() USEREVENT = 31 pygame.time.set_timer(USEREVENT, 10) if self.gameMode == 1: timer.setTime(241) self.createBar(11) elif self.gameMode == 2: timer.setTime(211) self.createBar(9) elif self.gameMode == 3: timer.setTime(181) self.createBar(5) elif self.gameMode == 4: timer.setTime(161) self.createBar(5) elif self.gameMode == 5: timer.setTime(131) self.createBar(5) elif self.gameMode == 6: timer.setTime(101) self.createBar(5) elif self.gameMode == 7: timer.setTime(71) self.createBar(5) elif self.gameMode == 8: timer.setTime(41) self.createBar(5) elif self.gameMode == 9: timer.setTime(21) self.createBar(5) else: self.createBar(30) self.createGround([[0, screen.get_height()], \ [screen.get_width(), screen.get_height()]]) self.grounds[0].genSupport(70, 1) self.grounds[1].genSupport(10, 0) self.generateBonds() try: timer.start() except: pass while True: screen.fill(0) self.print_stage(screen, conf) self.print_ground(screen) self.print_bars(screen) engine.printResult(screen) command = self.detect_button() if running: objectList = self.detectBar() for event in pygame.event.get(): try: if event.type == USEREVENT: timer.updateTime() except: pass if event.type == pygame.MOUSEBUTTONDOWN: if not command == None: if not command == 2: try: timer.finish() except: pass if command == 5: running = False objectList = [] elements = [] else: return command if event.button == 1: keys[0] = True if event.button == 2: keys[1] = True if event.button == 3: keys[2] = True if event.type == pygame.QUIT: game.ex() if event.type == pygame.MOUSEBUTTONUP: if event.button == 1: keys[0] = False if event.button == 2: keys[1] = False if event.button == 3: keys[2] = False try: if timer.checkEnd(): timer.finish() running = False objectList = [] except: pass if not running: engine.genMatriz(self.bonds, self.numberBonds) engine.solution() cursor = pygame.mouse.get_pos() if len(objectList) > 0: if keys[0]: objectList[0].move(cursor) if keys[1]: if objectList[1].change_bond_status(self.bonds): self.numberBonds -= 1 else: self.numberBonds += 1 keys[1] = False if keys[2]: objectList[0].rotate(cursor) try: timer.printTime(screen, [screen.get_width() - 10, 50]) except: pass pygame.display.flip()
def __init__(self, pi, enable, cw, ccw): wheeler = motor(pi, enable, cw, ccw) polarity = -1
enc_A_chan_B = pyb.Pin('X2', pyb.Pin.AF_PP, pull=pyb.Pin.PULL_UP, af=pyb.Pin.AF1_TIM2) enc_B_chan_A = pyb.Pin('X9', pyb.Pin.AF_PP, pull=pyb.Pin.PULL_UP, af=pyb.Pin.AF2_TIM4) enc_B_chan_B = pyb.Pin('X10', pyb.Pin.AF_PP, pull=pyb.Pin.PULL_UP, af=pyb.Pin.AF2_TIM4) #Motors: DIRA = 'Y5' PWMA = 'Y4' TIMA = 14 CHANA = 1 DIRB = 'Y8' PWMB = 'Y6' TIMB = 12 CHANB = 1 motorA = motor(PWMA, DIRA, TIMA, CHANA) motorB = motor(PWMB, DIRB, TIMB, CHANB) #Stopping Point 08/20/2017 -Joseph Fuentes # Define variables for landing check backup_timer = 5400000 altitude_concurrent_timer = 3600000 acceptable_dist_from_launch = 1000 acceptable_altitude_change = 25 # Global Flag to start GPS data Processing new_data = False start = pyb.millis() # Callback Function
import os import RPi.GPIO as GPIO # GPIO 모듈 import import threading from setDir import * from sonic import * from time import sleep # time 모듈의 sleep() 함수 사용 from motor import * # car 모듈의 모든 함수 사용 STOP = 0 FORWARD = 1 BACKWARD = 2 LEFT = 3 RIGHT = 4 presonic() print('HI') # 소켓 리스닝 시 출력문 while True: # 무한 루프 # th=threading.Thread(target=setDir, args=()) # th.start() drct = setDirTest() motor(drct) # 변환된 데이터에 따라 모터 동작 print("pi :", drct) # 어떤 동작을 하는지 출력 GPIO.cleanup() # GPIO 모듈의 점유 리소스 해제
import network import motor SWITCH = 10 GPIO.setmode(GPIO.BCM) GPIO.setup(SWITCH, GPIO.IN) def hear(phrase): print "heard:" + phrase for a in phrase: if a == "\r" or a == "\n": pass # strip it else: if GPIO.input(SWITCH): network.say("1") else: network.say("0") while True: print "waiting for connection" network.wait(whenHearCall=heard) print "connected" while network.isconnected(): print "server is running" time.sleep(1) print "connection closed" frontRight = motor(1, 2)
def __init__(self): self.mov = motor()
def __init__(self, m1_pin, m2_pin, m3_pin, m4_pin, calibrating): ''' Angles of the quadcopter [ROLL,PITCH,YAW] ''' self.angles = [0, 0, 0] ''' Constants for the quadcopter MIN : is the minimum speed for each of the quadcopter motors PITCH_DES_ANGLE : is the upper limit for the speed ROLL_DES_ANGLE : the angle of pitch desired, is is 0 degrees in idle HOSTNAME : the broker to witch connect ''' self.MIN = 1100 self.MAX = 1300 self.PITCH_DES_ANGLE = 0 self.ROLL_DES_ANGLE = 0 self.HOSTNAME = "localhost" ''' Creating the pi object for interactions with motors ''' self.pi = pigpio.pi() #object rpi ''' The quadcopter is composed by 4 motors ''' self.motors = [ motor(m1_pin, self.MIN, self.MAX, self.pi), motor(m2_pin, self.MIN, self.MAX, self.pi), motor(m3_pin, self.MIN, self.MAX, self.pi), motor(m4_pin, self.MIN, self.MAX, self.pi) ] self.time = 0 ''' The quadcopter balancing is done via a PID controller The values of the PID, might be different for the ROLL and PITCH angles ''' #ROLL self.KR = [0.04, 0, 0] self.pidR = PID(Kp=self.KR[0], Ki=self.KR[1], Kd=self.KR[2], setpoint=self.ROLL_DES_ANGLE) #PITCH self.KP = [0.04, 0, 0] self.pidP = PID(Kp=self.KP[0], Ki=self.KP[1], Kd=self.KP[2], setpoint=self.PITCH_DES_ANGLE) ''' MQTT is used as standar communication protocol between the android app and the quadcopter. It is not a big deal, but the simplest protocol i know, and for this reason the one i will use for the moment. ''' self.mqttc = mqtt.Client() self.mqttc.on_connect = on_connect self.mqttc.on_message = self.on_message self.mqttc.connect(self.HOSTNAME) self.mqttc.loop_start() ''' Variables for generic informations. ''' self.power = False ''' If one wants to calibrate it, during the creation the calibrate method is called, hence calibrating the motors ''' if calibrating == True: self.calibrate()
""" Table jacks of optical table in 14ID-B end station Friedrich Schotte, 10 Nov 2007 """ from motor import * TDSY = motor("14IDB:m17") # downstream vertical TOUTY = motor("14IDB:m18") # outward vertical TINY = motor("14IDB:m19") # inward vertical TUSX = motor("14IDB:m20") # upstream horizontal TDSX = motor("14IDB:m21") # downstream horizontal TDSZ = motor("14IDB:m22") # downstream along X-ray beam (not used yet) table_motors = [TUSX, TDSX, TOUTY, TINY, TDSY] def reset_table(): """ This is to bring the table in a well defined state after it was moved applying al the backlsh corrections""" step = 0.1 for m in table_motors: m -= step m.wait() for m in table_motors: m += step m.wait()
def __init__(self, M11, M12, M21, M22): self.rightMotor = motor(M11, M12, trigeractive=True) self.leftMotor = motor(M21, M22, trigeractive=True)
def main(): arguments = sys.argv #pull in arguments counter = 0 numExpected = False tempExpected = False for item in arguments: if (numExpected): data = item.split('/') times.append(float(data[1])) myDe.debugPrint(times) mtrNum = int(data[0]) motors.append(motor(motorPins[mtrNum - 1], myDe, mtrNum)) print(times) print(mtrNum) numExpected = False if (tempExpected): data = item.split('/') temperatureHold = float(data[1]) times.append(0) myDe.debugPrint(times) mtrNum = int(data[0]) motors.append( motor(motorPins[mtrNum - 1], myDe, mtrNum, True, temperatureHold)) print(times) print(mtrNum) tempExpected = False #print(item) if (item == "-D" or item == "-d"): myDe.activate() myDe.debugPrint(item, "input " + str(counter)) counter = counter + 1 if (item.startswith("-t")): myDe.debugPrint("found timer input in minutes") numExpected = True if (item.startswith("-a")): myDe.debugPrint("temp Input") tempExpected = True count = 0 for tm in times: if (tm == 0): count += 1 continue newTimer = timer(tm, myDe, motors[count]) timers.append(newTimer) count += 1 #myDe.debugPrint("Debugger Activated") for i in range(0, len(timers)): t = threading.Thread(target=beginTimer, args=(i, )) t.daemon = True t.start() activeTimers = True time.sleep(3) while (activeTimers): activeTimers = False message = "Current Temp = " + str(read_temp()) myDe.debugPrint(message) for tmr in timers: print(tmr.isRunning()) if (tmr.isRunning()): activeTimers = True time.sleep(1) afterBrewHopping = True while (afterBrewHopping): afterBrewHopping = False for mtr in motors: message = "Current Temp = " + str(read_temp()) myDe.debugPrint(message) if (mtr.testTemp() != False): tempToFind = mtr.testTemp() curTemp = read_temp() if (tempToFind >= curTemp): message = "curtemp: " + str( read_temp()) + " <g activate temp: " + str( mtr.testTemp()) myDe.debugPrint(message) mtr.activate() mtr.deactivate() else: afterBrewHopping = True message = "curtemp: " + str( read_temp()) + " > activate temp: " + str( mtr.testTemp()) myDe.debugPrint(message) time.sleep(1)