def loadSnapshot(self, name): self.StopDDU = True path = self.dir + '/data/snapshots/' + name self.StartDDU = True data = importExport.loadJson(path + '.json') carPath = path + '_car.json' self.car = Car.Car('default', 'default') self.car.load(carPath) trackPath = path + '_track.json' self.track = Track.Track('default') self.track.load(trackPath) self.map = self.track.map data['DDUrunning'] = False data['StopDDU'] = True data['StartDDU'] = False self.initialise(data, False, True) print( time.strftime("%H:%M:%S", time.localtime()) + ': Loaded RTDB snapshot: ' + name + '.json')
def initialise(self, data, BQueryData, BSnapshot): temp = list(data.items()) for i in range(0, len(data)): self.__setattr__(temp[i][0], temp[i][1]) self.initData.extend(temp) if BQueryData: self.queryData.extend(list(data.keys())) if not BSnapshot: self.BSnapshotMode = False self.car = Car.Car(name='default', carPath='default') self.car.load(self.dir + '/data/car/default.json') self.track = Track.Track('default') self.track.load(self.dir + '/data/track/default.json') else: self.BSnapshotMode = True
import threading # Import custom libraries from libs import Car # Server Address IP = "192.168.15.15" # socket.gethostbyname(socket.getfqdn()) PORT = 5420 ADDR = (IP, PORT) # Communication settings HEADER = 10 # Camera setup cam = cv2.VideoCapture(0, cv2.CAP_V4L) # Car setup CAR = Car.Car((32), (11, 13, 33, True), (31, 29, 33, True)) server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) server_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) server_socket.bind(ADDR) print(f"[STATUS] Server successfully boud to IP: {ADDR[0]}:{ADDR[1]}") server_socket.listen() print(f"[STATUS] Server is listening to incoming connections!") def send_camera_feed(cam, HEADER, client_socket): print("Send camera data") while True: ret, frame = cam.read() if type(frame) == type(None):
def setReferenceLap(dirPath: str, TelemPath: str, ibtPath: str = None, ibtFile: dict = None): myLogger = MyLogger() try: root = tk.Tk() root.withdraw() print( time.strftime("%H:%M:%S", time.localtime()) + ':\tImporting reference lap') if not ibtPath and not ibtFile: ibtPath = filedialog.askopenfilename( initialdir=TelemPath, title="Select IBT file", filetypes=(("IBT files", "*.ibt"), ("all files", "*.*"))) if ibtPath == ('', '') and not ibtFile: print( time.strftime("%H:%M:%S", time.localtime()) + ':\t\tNo valid path to ibt file provided...aborting!') return if not ibtFile: d, _ = importIBT.importIBT( ibtPath, lap='f', channels=[ 'zTrack', 'LapDistPct', 'rThrottle', 'rBrake', 'QFuel', 'SessionTime', 'VelocityX', 'VelocityY', 'Yaw', 'Gear', 'YawNorth' ], channelMapPath=dirPath + '/functionalities/libs/iRacingChannelMap.csv') else: d = copy.deepcopy(ibtFile) if not d: print( time.strftime("%H:%M:%S", time.localtime()) + ':\t\tNo valid lap found...aborting!') return d['x'], d['y'] = maths.createTrack(d) # check for monotonic behaviour idxRmv = [] if not maths.strictly_increasing(d['tLap']): idxRmv = np.argwhere(np.diff(d['tLap']) <= 0) if not maths.strictly_increasing(d['LapDistPct']): idxRmv = np.append(idxRmv, np.argwhere(np.diff(d['LapDistPct']) <= 0)) if any(idxRmv): idxRmv = np.unique(idxRmv) d['tLap'] = np.delete(d['tLap'], idxRmv) d['LapDistPct'] = np.delete(d['LapDistPct'], idxRmv) d['x'] = np.delete(d['x'], idxRmv) d['y'] = np.delete(d['y'], idxRmv) # check if car available carList = importExport.getFiles(dirPath + '/data/car', 'json') carName = d['DriverInfo']['Drivers'][ d['DriverInfo']['DriverCarIdx']]['CarScreenNameShort'] carPath = d['DriverInfo']['Drivers'][d['DriverInfo'] ['DriverCarIdx']]['CarPath'] # load or create car car = Car.Car(name=carName, carPath=carPath) if carName + '.json' in carList: car.load(dirPath + '/data/car/' + carName + '.json') else: car.createCar(d) car.save(dirPath) print( time.strftime("%H:%M:%S", time.localtime()) + ':\tCar has been successfully created') # create track TrackName = d['WeekendInfo']['TrackName'] track = Track.Track(TrackName) aNorth = d['YawNorth'][0] track.createTrack( d['x'], d['y'], d['LapDistPct'] * 100, aNorth, float(d['WeekendInfo']['TrackLength'].split(' ')[0]) * 1000) track.save(dirPath) print( time.strftime("%H:%M:%S", time.localtime()) + ':\t\tTrack {} has been successfully created.'.format(TrackName)) print( time.strftime("%H:%M:%S", time.localtime()) + ':\t\tAdding reference lap time to car {}'.format(carName)) # add lap time to car car.addLapTime(TrackName, d['tLap'], d['LapDistPct'] * 100, track.LapDistPct, d['VFuelLap']) car.save(dirPath) print( time.strftime("%H:%M:%S", time.localtime()) + ':\t\tReference lap time set successfully!') myLogger.info('Set reference lap for {} at {}: {} s'.format( carName, d['WeekendInfo']['TrackDisplayName'], convertString.convertTimeMMSSsss(d['tLap'][-1]))) except Exception as e: exc_type, exc_obj, exc_tb = sys.exc_info() fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1] ErrorString = '{} in Line {} of {}:\n\t\t\t\t\t\t> {}'.format( exc_type, exc_tb.tb_lineno, fname, e.args[0]) myLogger.error(ErrorString)
} iDDUControlsNameInit = {} iDDUControlsName = list(iDDUControls.keys()) for i in range(0, len(iDDUControlsName)): if type(iDDUControls[iDDUControlsName[i]]) is bool: iDDUControlsNameInit[iDDUControlsName[i]] = iDDUControls[iDDUControlsName[i]] else: iDDUControlsNameInit[iDDUControlsName[i]] = iDDUControls[iDDUControlsName[i]][0] myRTDB = RTDB.RTDB() myRTDB.initialise(calcData, False, False) myRTDB.initialise(iDDUControlsNameInit, False, False) myRTDB.car = Car.Car('name', 'path') # myRTDB.car.load('C:/Users/Marc/Documents/Projekte/iDDU/data/car/Porsche 718 Cayman GT4.json') myRTDB.car.load('C:/Users/Marc/Documents/Projekte/iDDU/data/car/Ferrari 488 GTE.json') dcList = list(myRTDB.car.dcList.keys()) myRTDB.queryData.extend(dcList) ms = MultiSwitch.MultiSwitch(myRTDB, 0.01) for i in range(0, len(iDDUControlsName)): if type(iDDUControls[iDDUControlsName[i]]) is bool: ms.addMapping(iDDUControlsName[i]) else: ms.addMapping(iDDUControlsName[i], minValue=iDDUControls[iDDUControlsName[i]][1], maxValue=iDDUControls[iDDUControlsName[i]][2], step=iDDUControls[iDDUControlsName[i]][3])