def __init__(self, size, image_array, position): self._buffer = mp.Queue() self.lidar = Lidar(self._buffer) print(self.lidar.start_lidar()) self.lf = LidarFunktions() self.size = size self.position = position self.shared_line_map_array = image_array
class GenerateMaps: def __init__(self, size, image_array, position): self._buffer = mp.Queue() self.lidar = Lidar(self._buffer) print(self.lidar.start_lidar()) self.lf = LidarFunktions() self.size = size self.position = position self.shared_line_map_array = image_array def get_line_map(self, color=200, thickness=5): lidar_data = mp.Process(target=self.lidar.get_scan) lidar_data.start() while not self._buffer.empty(): i, data = self._buffer.get() pre_data = self.lf.prepare_data(data, position) line_map = self.lf.draw_line_map( np.zeros(self.size, dtype=np.uint8), pre_data, color, thickness) self.shared_line_map_array[:] = line_map.reshape(-1) print(self.shared_line_map_array[:])
px = ox def movement(last_pre_data, pre_data, rotation, size): last_cp = draw_map(last_pre_data, size) cp = draw_map(pre_data, size) cp = rotate(cp, rotation) # Queue lidar_data = Queue() mainMap_img_q = ImageQueue(5, 2) pci_img_q = ImageQueue(3, 2) lidar = Lidar(lidar_data) lf = LidarFunctions() print(lidar.start_lidar()) size = (5000, 5000) position = (size[0] // 2, size[1] // 2) mainMap = np.zeros(size, np.uint8) # mainMapArray = Array() new_scan_event = Event() get_lidar_data = Process(target=lidar.get_scan_v3, args=(new_scan_event, 3)) start_time = time.time() last_line_map = None rotation_counter = 0 last_rotation = 0 new_scan_event.set()
cv2.imwrite("img{i}.jpg".format(i=i), mainMap) else: print("Buffer empty") time.sleep(0.1) buffer_empty_counter += 1 if buffer_empty_counter > 8: exit() if __name__ == '__main__': mainMap = np.zeros((10000, 10000)) position = (5000, 5000) buffer = Queue() lidar = Lidar(buffer) print(lidar.start_lidar()) lidar_scan = Process(target=lidar.get_scan) main_p = Process(target=main_process) try: print("start") main_p.start() lidar_scan.start() while True: if not main_p.is_alive(): lidar_scan.terminate() lidar.stop() exit() time.sleep(1)
# Queue lidar_data_queue = mp.Queue() # Shard Memory position = mp.Array(c.c_uint16, 2) rotation = mp.Value(c.c_float) pre_data_shared = mp.Array(c.c_uint16, 362 * 2) lineMap_shared = mp.Array(c.c_uint8, size[0] * size[1] + 1) mainMap_array = mp.Array(c.c_uint8, size[0] * size[1]) position[:] = [size[0] // 2, size[1] // 2] rotation.value = 0 # Classes and Funktion lidar = Lidar(lidar_data_queue) # Processes get_lidar_data = mp.Process(target=lidar.get_scan) process_data = mp.Process(target=process_lidar_data, args=(lidar_data_queue, pre_data_shared, lineMap_shared, mainMap_array, rotation, size)) print(lidar.start_lidar()) get_lidar_data.start() process_data.start() try: time.sleep(1) last_mainMap = np.zeros(size, dtype=np.uint8) st = time.time()