def __init__(self): BrickPiSetup() # setup the serial port for communication self._particles = [Particle(1.0/NUMBER_OF_PARTICLES) for i in range(NUMBER_OF_PARTICLES)] self._motorA = Motor("PORT_A") self._motorB = Motor("PORT_B") BrickPiSetupSensors() #Send the properties of sensors to BrickPi globals.init()
def run(self): try: self.adc = Adc() self.PWM = Motor() self.PWM.setMotorModel(0, 0, 0, 0) while True: L = self.adc.recvADC(0) R = self.adc.recvADC(1) print("The photoresistor voltage on the right is " + str(R) + "V") print("The photoresistor voltage on the left is " + str(L) + "V") if L < 2.99 and R < 2.99: self.PWM.setMotorModel(600, 600, 600, 600) elif abs(L - R) < 0.15: self.PWM.setMotorModel(0, 0, 0, 0) elif L > 3 or R > 3: if L > R: self.PWM.setMotorModel(-1200, -1200, 1400, 1400) elif R > L: self.PWM.setMotorModel(1400, 1400, -1200, -1200) except KeyboardInterrupt: led_Car.PWM.setMotorModel(0, 0, 0, 0)
def __init__(self, game, x, y,id,genes=None): self.groups = game.all_sprites pg.sprite.Sprite.__init__(self, self.groups) self.game = game self.image = pg.Surface((TILESIZE, TILESIZE)) self.image.fill(WHITE) self.rect = self.image.get_rect() self.vx, self.vy = 0, 0 self.x = x * TILESIZE self.y = y * TILESIZE self.logicX = x self.logicY = y if (genes == None): self.behavior = DNA() else: self.behavior = DNA(genes) self.camera = None self.motor = Motor(self,self.behavior.array[4][0],self.behavior.array[4][1]) self.possibleMoves = [] self.currentTile = None self.cameraLvl = self.behavior.array[4][2] self.nxtMove = "top" self.pastMove = "" self.moveThread = threading.Thread(target = self.movement) self.batteryThread = threading.Thread(target = self.consume) self.id = id self.fitness = 0 self.won = False self.Parents = [['None'],['None']]
def __init__(self): # Callibrate the Servo self.pwm_S = Servo() self.pwm_S.setServoPwm('0', SERVO_ORIZON) self.pwm_S.setServoPwm('1', SERVO_VERTIC) self.PWM = Motor()
def BMXstuckDetection(mP, bmxThd, measureCount, countThd, mode=0): global aveinit, stuckCount returnVal = 0 if mode == 0: for i in range(5): bmxinit = BMX055.bmx055_read() print(i, "init:", bmxinit[0:6]) aveinit = aveinit + bmxinit[5] aveinit = aveinit / 5 #print('aveinit', aveinit) Motor.motor(-mP, mP, 0.5) for i in range(measureCount): bmxnow = BMX055.bmx055_read() print(i, "now:", bmxnow[5]) if math.fabs(bmxnow[5] - aveinit) < bmxThd: stuckCount = stuckCount + 1 #print('stuckCount', stuckCount) if stuckCount > countThd: print("stuck DA YO NE ?") #Motor.motor(0, 0, 2) returnVal = 1 break else: stuckCount = 0 if mode == 0: Motor.motor(0, 0, 2) return returnVal
def ParaAvoidance(): n = 0 #GPS.openGPS() #GPS_init = GPS.readGPS() #GPS.closeGPS() #GPS_now = GPS_init dist = 0 try: while dist <= 0.020: Capture.Capture(n) img = cv2.imread('photo/photo' + n + '.jpg') flug = ParaDetection.ParaDetection(img) if flug == 0: Motor.motor(50, 50, 2) #GPS_now = GPS.readGPS() #dist = Cal_rho(GPS_now[2], GPS_now[1], GPS_init[2], GPS_init[1]) Motor.motor_stop() dist += 0.02 else: Motor.motor(-30, 30, 1) Motor.motor_stop() except KeyboardInterrupt: Motor.motor_stop()
def setup_motors(): left_wheel = Motor(0) right_wheel = None#Motor(1) dome = None#Motor(2) left_wheel.init() return (left_wheel,right_wheel,dome)
def __init__(self): self.initialize_brick_pi() self.__motors = [] self.__sensors = [] self.__standard_motor_power = SettingsParser.get_value( "robot", "standard_motor_power") right_motor = Motor.Motor(PORT_B, "right") left_motor = Motor.Motor(PORT_C, "left") self.set_motors([left_motor, right_motor])
def cmps_correct(curr_heading, trim = 15): #print("cmps crct now") if 90 < curr_heading < curr180: #print("spinning left") motors.spinLeft(0.1) elif curr180 < curr_heading < 225: #print("spinning right") motors.spinRight(0.1) else: #print("in range") pass
def cmps_correct(trim=15): print("cmps crct now") if 90 < curr_heading < curr180: print("spinning left----c") motors.spinRight() elif curr180 < curr_heading < 225: print("spinning right---c") motors.spinLeft() else: print("in range") pass
def readCalData(filepath): count = 0 while count <= 100: bmx055data = BMX055.bmx055_read() with open(filepath, 'a') as f: for i in range(6, 8): #print(str(bmx055data[i]) + "\t", end="") f.write(str(bmx055data[i]) + "\t") #print() f.write("\n") count = count + 1 time.sleep(0.1) Motor.motor(0, 0, 1)
def test(): motorA = Motor.Motor(22, 24, 23) motorB = Motor.Motor(27, 20, 21) motorA.stop = False motorB.stop = False motorA.speed = 40 motorB.speed = 40 time.sleep(2) motorA.direction = "backward" motorB.direction = "backward" time.sleep(2) motorA.stop = True motorB.stop = True
def setup(): global rightMotor, leftMotor rightMotor = Motor(7, 11, True) leftMotor = Motor(13, 15, True) rightMotor.gpioSetup() leftMotor.gpioSetup()
def setup(): global rightMotor, leftMotor rightMotor = Motor(11, 12, 13, True) leftMotor = Motor(15, 16, 18, True) rightMotor.gpioSetup() leftMotor.gpioSetup()
def time_boundaries_backward(): # TODO: Seek to top first? Motor.sleep(False) Motor.backward() Motor.speed(100) start = time.time() next = len(interp_values) - 1 safety = collections.deque([0] * 10, 15) try: while True: cur = chan0.value // 64 if cur <= interp_values[next]: print("%3d: %4d --> %.3f\x1b[K" % (next * 10, cur, time.time() - start)) next -= 1 if next < 0: break else: print("%3d: %4d ... %.3f\x1b[K" % (next * 10, cur, time.time() - start)) safety.append(cur) if max(safety) - min(safety) < 2: break # Guard against getting stuck time.sleep(1 / 1000) finally: Motor.sleep(True)
def dealdata(): set_temp_hum={} set_temp_hum['min_temp']=input("please input min start temp:\n") set_temp_hum['min_hum']=input("please input min start hum:\n") #设置温度值更新 con=mc.mysqlconnect() cursor=con.cursor() cursor.execute('update sensorinfo set set_temp=%s,set_hum=%s where id=0',(set_temp_hum['min_temp'],set_temp_hum['min_hum'])) con.commit() cursor.close() con.close() flag=True sleep_flag=False ser=ci.CoorConnectPc() while 1 : data=ci.ReadPort(ser) if data[8:10]!='aa': #温湿度模块 if data[6:8]=='03': now_temp_hum=th.temp_hum_store(data) print 'now temp hum:',now_temp_hum['temp'],now_temp_hum['hum'] print 'set temp hum:',set_temp_hum['min_temp'],set_temp_hum['min_hum'] if flag==True: th.judge_temp_hum(ser,now_temp_hum,set_temp_hum) #光敏模块 if data[6:8]=='02': light=pr.photores_store(data) #智能开关打开且不是睡眠模式 if flag==True and sleep_flag==False: pr.dimming(ser,light) #触摸模块 #有触摸时 if flag==True and data[6:8]=='0e' and data[10:12]=='01': tc.touch(ser,data[8:10],flag,sleep_flag) if sleep_flag==True: #关闭全部灯 pwm.led_light(ser,'00') #关棚帘 mt.time_motor(ser,'03',3) #电机模块 if flag==True and data[6:8]=='09': if data[8:9]=='dd': mt.status_motor(ser,data)
def __init__(self): self.PWM = Motor() self.servo = Servo() self.led = Led() self.ultrasonic = Ultrasonic() self.buzzer = Buzzer() self.adc = Adc() self.light = Light() self.infrared = Line_Tracking() self.tcp_Flag = True self.sonic = False self.Light = False self.Mode = 'one' self.endChar = '\n' self.intervalChar = '#'
def take_command_actions(audio_answer, motor_answer): if 'none' not in audio_answer: reproduce_audio.play_audio(motor_answer) if 'none' not in motor_answer: Motor.Commands(motor_answer, 2)
def main(): maxX = -10000 maxY = -10000 minX = 10000 minY = 10000 t_end = time.time() + 30 setspeed = 100 motor = Motor.Motor(18, 25, 24,13, 27, 17) #time.sleep(5) while time.time() < t_end: magnet = mpu92_test.get_magnet() print(magnet) if(maxX < magnet[0]): maxX = magnet[0] if(minX > magnet[0]): minX = magnet[0] if(maxY < magnet[1]): maxY = magnet[1] if(minY > magnet[1]): minY = magnet[1] # print("maxx",maxX) # print("minx",minX) # print() # print("maxy",maxY) # print("miny",minY) # print() motor.set_speed(setspeed,setspeed) time.sleep(1)
def run(self): self.PWM = Motor() self.pwm_S = Servo() self.pwm_S.setServoPwm('1', 70) deg = 30 for i in range(deg, deg * 5 + 1, deg * 2): self.pwm_S.setServoPwm('0', i) time.sleep(0.2) if i == deg: L = self.get_distance() elif i == deg * 3: M = self.get_distance() else: R = self.get_distance() while True: for i in range(deg * 3, deg, -deg * 2): self.pwm_S.setServoPwm('0', i) time.sleep(0.2) if i == deg: L = self.get_distance() elif i == deg * 3: M = self.get_distance() else: R = self.get_distance() self.run_motor(L, M, R) for i in range(deg, (deg * 5) + 1, deg * 2): self.pwm_S.setServoPwm('0', i) time.sleep(0.2) if i == deg: L = self.get_distance() elif i == deg * 3: M = self.get_distance() else: R = self.get_distance() self.run_motor(L, M, R)
def run(self): self.PWM = Motor() self.pwm_S = Servo() for i in range(30, 151, 60): self.pwm_S.setServoPwm('0', i) time.sleep(0.2) if i == 30: L = self.get_distance() elif i == 90: M = self.get_distance() else: R = self.get_distance() while True: for i in range(90, 30, -60): self.pwm_S.setServoPwm('0', i) time.sleep(0.2) if i == 30: L = self.get_distance() elif i == 90: M = self.get_distance() else: R = self.get_distance() self.run_motor(L, M, R) for i in range(30, 151, 60): self.pwm_S.setServoPwm('0', i) time.sleep(0.2) if i == 30: L = self.get_distance() elif i == 90: M = self.get_distance() else: R = self.get_distance() self.run_motor(L, M, R)
def __init__(self, leftMotorOutA, leftMotorOutB, leftPwm, rightMotorOutA, rightMotorOutB, rightPwm, liftServoPin, pinchServoPin): print 'create robot' self.leftMotor = Motor.motor(leftMotorOutA, leftMotorOutB, leftPwm) self.rightMotor = Motor.motor(rightMotorOutA, rightMotorOutB, rightPwm) self.claw = Claw.claw(liftServoPin, pinchServoPin) self.irSensors = IrSensor.irSensor() self.encoders = Encoders.easy_encoders() self.leftPid = pid_control.easy_PID(P_GAIN, I_GAIN, D_GAIN) self.rightPid = pid_control.easy_PID(P_GAIN, I_GAIN, D_GAIN) self.pixyObj = easy_pixy_test.easy_pixy()
def Start_Bot(): M = Motor.Stepper() while True: #Getting the command from Adafruit IO command = cloud.getCommand() command = command.lower() if command == "forward": M.Move_Forward() elif command == "backward": M.Move_Backward() elif command == "left": M.Turn_Left() elif command == "right": M.Turn_Right() elif command == "stop": M.STOP() else: print('No Match')
def calc(): maxX = -100 maxY = -100 minX = 100 minY = 100 t_end = time.time() + 10 setspeed = 100 motor = Motor.Motor(18, 25, 24, 13, 27, 17) time.sleep(5) while time.time() < t_end: magnet = mpu92_test.get_magnet() if (maxX < magnet[0]): maxX = magnet[0] if (minX > magnet[0]): minX = magnet[0] if (maxY < magnet[1]): maxY = magnet[1] if (minY > magnet[1]): minY = magnet[1] #print("magnet[%+4.2f, %+4.2f, %+4.2f]" % (magnet[0], magnet[1], magnet[2]), end="\t") print("maxx", maxX) print("minx", minX) print() print("maxy", maxY) print("miny", minY) print() motor.set_speed(-100, 100) time.sleep(1)
def run(self): global freq_botao inicio = time.time() while True: fim = time.time() if fim - inicio > 6: Motor.Parar() message, address = serverSocketMotor.recvfrom(1024) message = str(message).replace("b'", '') message = message.replace("'", '') if message == "1": inicio = time.time() if message == "STOP": print('parar') serverSocketMotor.sendto(B'1', address) Motor.Parar() elif message == "ping": print('p') serverSocketMotor.sendto(B'ping', address) elif message[0:2] == 'fb': print('fb') string, freqfb = message.split(':') Motor.freq_botao = float(freqfb) elif message[0:3] == 'SeD': print('SeD') serverSocketMotor.sendto(B'1', address) string, vel, freq, controle, deslocamento = message.split(':') Motor.Subir_descer(float(vel), float(freq), int(controle), float(deslocamento)) elif message[0:3] == 'Cal': print('cal') serverSocketMotor.sendto(B'1', address) cmd, valor, freq = message.split(':') Motor.calcular(float(valor), float(freq)) elif message == "SUBIR": print('Subir') serverSocketMotor.sendto(B'1', address) Motor.subir() elif message == "BAIXAR": print('Baixar') ####print(message) serverSocketMotor.sendto(B'1', address) Motor.baixar()
def main(): setspeed = 100 motor = Motor.Motor(18, 25, 24, 13, 27, 17) motor.set_speed(-setspeed, setspeed) time.sleep(10) #10秒動かす GPIO.cleanup()
def initialization(): print("Auto-Cat initializing") email = Email(465,'*****@*****.**','AutoCatProject') motor = Motor(21,50,5) #schedule.every(1).minutes.do(email.sendEmail,'*****@*****.**','This is a test') #schedule.every().day.at("22:19").do(email.sendEmail,'*****@*****.**','hey :)') schedule.every(1).minutes.do(motor.feed,10,5) #Add any other initializing components here print("Auto-Cat initializing complete")
def judge_temp_hum(ser,now_temp_hum,set_temp_hum): #开空调 if now_temp_hum['temp'] > set_temp_hum['min_temp']: mt.opp_motor(ser,'open','02') else: mt.opp_motor(ser,'close','02') #开加湿器 if now_temp_hum['hum'] < set_temp_hum['min_hum']: mt.opp_motor(ser,'open','01') else: mt.opp_motor(ser,'close','01')
def test_slider(): Motor.sleep(False) Motor.forward() Motor.speed(10) start = chan0.value while chan0.value < 36800: print(chan0.value, chan0.value - start) start = chan0.value time.sleep(1 / 32) print(chan0.value, chan0.value - start) Motor.sleep(True)
def __init__(self, leftMotorOutA, leftMotorOutB, leftPwm, rightMotorOutA, rightMotorOutB, rightPwm, liftServoPin, pinchServoPin): #Set up colorized logger self.logger = logging.getLogger('maze_run') coloredlogs.install(level='DEBUG') #Create objects related to robot self.logger.info('create robot') self.leftMotor = Motor.motor(leftMotorOutA, leftMotorOutB, leftPwm) self.rightMotor = Motor.motor(rightMotorOutA, rightMotorOutB, rightPwm) self.claw = Claw.claw(liftServoPin, pinchServoPin) self.irSensors = IrSensor.irSensor() self.encoders = Encoders.easy_encoders() self.leftPid = pid_control.easy_PID(P_GAIN, I_GAIN, D_GAIN) self.rightPid = pid_control.easy_PID(P_GAIN, I_GAIN, D_GAIN) self.pixyObj = easy_pixy_test.easy_pixy() self.PREVIOUS_CORRECTION_VALUE = 0 self.pickedup = False
def __init__(self, hostname, port=1883): client = mqtt.Client() client.on_connect = self.on_connect client.on_message = self.on_message client.connect(hostname, port, 60) self.motor = Motor.Motor(client) self.motor.start() self.motor.setup() self.manual = True client.loop_forever()
def InicializaAscensor(): global Estado global PlantaActual global PlantaDestino iEstado.Inicializa() Motor.Inicializa() Display.Inicializa() Entradas.Inicializa() Estado = 'Ocupado' iEstado.ActivaLeds('Bajando') Display.Enciende(10) while not LeerEntrada('FCBajo'): Motor.step(1, 100, 1, 0.001) Estado = 'Libre' iEstado.ActivaLeds(Estado) PlantaActual = 0 PlantaDestino = 0 Display.Enciende(PlantaActual)
def __init__(self, parent): Frame.__init__(self, parent) self.parent = parent # size self.width = 250 self.height = 120 # screen size self.sw = self.parent.winfo_screenwidth() self.sh = self.parent.winfo_screenheight() # create a Motor object self.motor = Motor() # init UI and centering in the screen self.initUI() self.centering()