import numpy as np import logging from rblidar import RBLidar # Assuming rblidar.py is in the same directory class DataLogger: def __init__(self): self.data_frames = [] # List to store the frames of data logging.basicConfig(level=logging.INFO, format='%(asctime)s %(levelname)s: %(message)s') def frame_callback(self, point_data_array): # Append the received frame (NumPy array) to the list self.data_frames.append(point_data_array) logging.info(f"Logged frame with {len(point_data_array)} points.") def save_data(self, filename='logged_data.npy'): # Concatenate all frames into a single NumPy array and save it if self.data_frames: all_data = np.concatenate(self.data_frames) np.save(filename, all_data) logging.info(f"Data saved to {filename}.") else: logging.info("No data to save.") if __name__ == "__main__": data_logger = DataLogger() lidar = RBLidar("192.168.8.1", 2368, frame_callback=data_logger.frame_callback) try: while True: pass # Keep the program running to receive data except KeyboardInterrupt: logging.info("Stopping and saving data...") data_logger.save_data() # Save data on exit