def __init__(self, USs=[ US(trig=US1_TRIG, echo=US1_ECHO), US(trig=US2_TRIG, echo=US2_ECHO) ], labels=['back', 'front']): self.USs = USs self.USs_labels = labels self.US_pools = [] self.USs_out = Manager().dict({l: 0.0 for l in self.USs_labels}) self.toSleep = 0.2
def __init__(self, car, mb, USs = [US(trig = US1_TRIG, echo = US1_ECHO), US(trig = US2_TRIG, echo = US2_ECHO)], labels = ['back', 'front']): self.USs = USs self.USs_labels = labels self.US_pools = [] self.USs_out = Manager().dict({l:0.0 for l in self.USs_labels}) self.voltage_threshold = 7.0 self.US_threshold = 20 self.toSleep = 0.2 self.car = car self.mb = mb self.uv_counter = 0
def US_pooling(self, US, label): while(1): try: d = US.get_distance() print(self.USs_out) self.USs_out[label] = d except Exception: pass
def US_pooling(US, label, ret_value): while (1): try: d = US.get_distance() ret_value[label] = d # if d != None: # print("{}: {:.1f} cm\n".format(label, d)) except Exception: pass
Created on Fri Mar 19 10:40:35 2021 @author: root """ from multiprocessing import Process, Manager from LIBRARY.rpi_US import US import numpy as np from time import sleep US1_TRIG = 22 US1_ECHO = 17 US2_TRIG = 24 US2_ECHO = 23 back = US(trig = US1_TRIG, echo = US1_ECHO) front = US(trig = US2_TRIG, echo = US2_ECHO) #print(back,front) class random_mvmnt(): def __init__(self, car, mb, USs = [US(trig = US1_TRIG, echo = US1_ECHO), US(trig = US2_TRIG, echo = US2_ECHO)], labels = ['back', 'front']): self.USs = USs self.USs_labels = labels self.US_pools = [] self.USs_out = Manager().dict({l:0.0 for l in self.USs_labels}) self.voltage_threshold = 7.0 self.US_threshold = 20 self.toSleep = 0.2 self.car = car self.mb = mb
""" from LIBRARY.rpi_US import US import numpy as np import matplotlib.pyplot as plt from time import time, sleep from multiprocessing import Pool, cpu_count, Process, Value, Manager US1_TRIG = 22 US1_ECHO = 17 US2_TRIG = 24 US2_ECHO = 23 back = US(trig=US1_TRIG, echo=US1_ECHO) front = US(trig=US2_TRIG, echo=US2_ECHO) n = cpu_count() pool_size = 2 #pool = Pool(processes = 2) pool = [] def US_pooling(US, label, ret_value): while (1): try: d = US.get_distance() ret_value[label] = d # if d != None:
# -*- coding: utf-8 -*- """ Created on Fri Mar 19 10:40:35 2021 @author: root """ from multiprocessing import Process, Manager from LIBRARY.rpi_US import US US1_TRIG = 22 US1_ECHO = 17 US2_TRIG = 24 US2_ECHO = 23 bl = US(trig = US1_TRIG, echo = US1_ECHO) br = US(trig = US2_TRIG, echo = US2_ECHO) bl.setup_US_ports() br.setup_US_ports() #print(back,front) class US_multi(): def __init__(self, USs = [US(trig = US1_TRIG, echo = US1_ECHO), US(trig = US2_TRIG, echo = US2_ECHO)], labels = ['back', 'front']): self.USs = USs self.USs_labels = labels self.US_pools = [] self.USs_out = Manager().dict({l:0.0 for l in self.USs_labels}) self.toSleep = 0.2
# -*- coding: utf-8 -*- """ Created on Fri Mar 19 10:40:35 2021 @author: root """ from multiprocessing import Process, Manager from LIBRARY.rpi_US import US US1_TRIG = 22 US1_ECHO = 17 US2_TRIG = 24 US2_ECHO = 23 back = US(trig=US1_TRIG, echo=US1_ECHO) front = US(trig=US2_TRIG, echo=US2_ECHO) back.setup_US_ports() front.setup_US_ports() #print(back,front) class US_multi(): def __init__(self, USs=[ US(trig=US1_TRIG, echo=US1_ECHO), US(trig=US2_TRIG, echo=US2_ECHO) ], labels=['back', 'front']): self.USs = USs