def Reception(mybaudrate=19200): global com ''' 受信 アスキーコードから文字列に変換したものを返す mybaudrate:ボーレート ''' try: com.flushInput() #print("a") text = com.readline().decode('utf-8').strip() #受信と空白の削除 #print(text) com.flushOutput() text = text.replace("\r\n", "") #power=text.split(":")[0] #print(text) text = text.split(":")[1] #print(text) text = text.split(",") #print("d") cngtext = "" #print(text) for x in text: cngtext += chr(int(x, 16)) Other.saveLog(receptionLog, cngtext, datetime.datetime.now()) #f.write(text) #f.write("\n") #print(text) except Exception: cngtext = "" print("NO DATA") #com.close() return cngtext
def takePhoto(): global photoName global gpsData photo = "" photo = Capture.Capture(photopath) gpsData = GPS.readGPS() if not(photo == "Null"): photoName = photo Other.saveLog(captureLog, time.time() - t_start, gpsData, BME280.bme280_read(), photoName)
def to_list(self): elements_list = list() elements_list.append(self.trip_id) elements_list.append(Other.to_real_time(self.arrival_time)) elements_list.append(Other.to_real_time(self.departure_time)) elements_list.append(self.stop_id) elements_list.append(self.stop_sequence) elements_list.append(self.pickup_type) elements_list.append(self.drop_off_type) return elements_list
def rotate_control(θ, azimuth, t_start): try: timeout_count = time.time() while azimuth - 30 > θ or θ > azimuth + 30: if 0 <= azimuth < 30: if azimuth - 30 + 360 <= θ <= 360: break if 330 <= azimuth <= 360: if 0 <= θ <= azimuth + 30 - 360: break if azimuth < 180: if azimuth < θ < azimuth + 180: run = pwm_control.Run() run.turn_right_l() time.sleep(1) else: #-- 0 < θ < azimuth or azimuth + 180 < θ < 360 --# run = pwm_control.Run() run.turn_left_l() time.sleep(1) else: #-- 180 < azimuth --# if azimuth - 180 < θ < azimuth: run = pwm_control.Run() run.turn_left_l() time.sleep(1) else: #-- 0 < θ < azimuth - 180 or azimuth < θ < 360 --# run = pwm_control.Run() run.turn_right_l() time.sleep(1) #run = pwm_control.Run() #run.stop() #time.sleep(0.5) #get_magdata_average() get_data() θ = calculate_angle_2D(magx, magy, magx_off, magy_off) Other.saveLog(Calibration_rotate_controlLog, 'Calibration_rotate_control', time.time() - t_start, θ, azimuth) if time.time() - timeout_count >= 60: print('rotate control timeout') break print("rotate control finished") #print(θ) except KeyboardInterrupt: run = pwm_control.Run() run.stop() print("faulted to rotate control to goal direction") finally: #run = pwm_control.Run() #run.stop() pass
def transmitPhoto(): global t_start photoName = Capture.Capture(photopath) Other.saveLog(captureLog, time.time() - t_start, GPS.readGPS(), BME280.bme280_read(), photoName) print("Send Photo") sendPhoto.sendPhoto(photoName) print("Send Photo Finished") Other.saveLog(sendPhotoLog, time.time() - t_start, GPS.readGPS(), photoName)
class Child(object): def __init__(self): self.other = Other() def implicit(self): self.other.implicit() def override(self): print "CHILD ovrried()" def altered(self): print "CHILD before Other altered()" self.other.altered() print "CHILD after other altered()"
def read_coordinates(): try: with open("sgtfs/coordinates.txt", 'r', encoding="utf-8") as file: lines = file.readlines() stop_counter = 0 coordinates_counter = 0 list_of_coordinates = list() for i, line in enumerate(lines): if i == 0: if ord(line[0]) > 1000: line = line[1:] stop_counter += 1 # Here we parse the line parsed_line = Other.split_by(line, "\t") # We add it to the list if it contains coordinates if len(parsed_line) > 1: # Parsing the coordinates coordinates = re.split(", ", parsed_line[1]) list_of_coordinates.append([parsed_line[0], coordinates[0], coordinates[1]]) coordinates_counter += 1 print(str(stop_counter) + " stops were in the file") print(str(coordinates_counter) + " coordinates were in the file") return list_of_coordinates except FileNotFoundError: print("There is no sgtfs/coordinates.txt file")
def update_stops(self, li, comparator): # First add the stops for i, stop in enumerate(li): li[i].name = comparator.look_for_stop(li[i].name) char = stop.name[0] # Here we check if it's not a false stop or "*" or "/" or "//" if char != "*" and char != "/" and char != "$": stop_id = Other.to_id(stop.name) # Then we go into the list of stops in the agency to see if it was already there found = False for stop_in_memory in self.stops: if normalize(stop_in_memory.id) == normalize(stop_id): found = True break if not found: for stop_in_memory in self.stops: if comparator.compare(stop_in_memory.name, stop.name): li[i].name = stop_in_memory.name found = True break if not found: self.stops.append(Stop.Stop(stop.name))
def payserverresults(self): #self.paymomey=self.driver.find_element_by_css_selector("#pay_count_detail .price_change").text #支付金额 #self.driver.find_element_by_class_name("show").click() #peoplecount=self.driver.find_element_by_css_selector(".order_sub_name_details td:nth-child(1)").text #出行人数 #self.peoplecounts=other.splittext(peoplecount,1,":") messagepeople=self.driver.find_element_by_css_selector(".order_sub_name_details td:nth-child(2)").text #联系人 self.messagepeoples=Other.splittext(messagepeople,1,":")
def init_routes_from_file(self, path="gtfs"): path += "/routes.txt" issue = Other.read_csv(path, self.add_route) if issue: print("The file routes.txt was not found") print(str(self.count) + " routes were imported") self.count = 0
def makeDepthPressureTemperatureData(self): if self.finalData is None: return s1 = self.finalData.iloc[:, 4] s1.dropna(inplace=True, how='all') s2, s3 = pd.Series(), pd.Series() PresDF = self.finalData.iloc[:, [0, 1]] TemperDF = self.finalData.iloc[:, [0, 2]] for i in range(s1.size): s2 = s2.append(pd.Series([ Other.searchAndInterpolate(PresDF, self.finalData.iloc[i, 3]) ]), ignore_index=True) s3 = s3.append(pd.Series([ Other.searchAndInterpolate(TemperDF, self.finalData.iloc[i, 3]) ]), ignore_index=True) self.depthPressureTemperatureData = pd.concat([s1, s2, s3], axis=1)
def sqlBed(bedID): with Other.sqlQuery() as connection: cursor = connection.cursor() cursor.execute( '''SELECT ots_bn.sosbed.bedname from ots_bn.sosbed WHERE ots_bn.sosbed.bedid = :bedid''', bedid=bedID) row = cursor.fetchone() return row[0]
def init_stops_from_file(self, path="gtfs"): path += "/stops.txt" issue = Other.read_csv(path, self.add_stop) if issue: print("No stop.txt file") print(str(self.count) + " stops have been imported from the file") self.count = 0
def Mission(photo_path1,photo_path2): photo_path1 = '' photo_path2 = '' try: # --- Save photos in two resolution --- # camera = picamera.PiCamera() camera.resolution = (320,240) camera.capture(photo_path1) camera.resolution = (640,480) camera.capture(photo_path2) # --- Read two images --- # img1 = cv2.imread(photo_path1) img2 = cv2.imread(photo_path2) # --- hight resolution --- # dst1 = cv2.resize(img1, (img1.shape[1]*4, img1.shape[0]*4), interpolation=cv2.INTER_NEAREST) dst2 = cv2.resize(img1, (img1.shape[1]*4, img1.shape[0]*4), interpolation=cv2.INTER_LINEAR) dst3 = cv2.resize(img1, (img1.shape[1]*4, img1.shape[0]*4), interpolation=cv2.INTER_CUBIC) # --- Save high resolution images --- # filepath = '' filepath = Other.fileName('/home/pi/photo/nearest','jpg') # nearest cv2.imwrite(filepath, dst1) filepath = Other.fileName('/home/pi/photo/linear','jpg') # linear cv2.imwrite(filepath, dst2) filepath = Other.fileName('/home/pi/photo/cubic','jpg') # cubic cv2.imwrite(filepath, dst3) # --- Convert to grayscale --- # gray0 = cv2.cvtColor(img2, cv2.COLOR_BGR2GRAY) gray1 = cv2.cvtColor(dst1, cv2.COLOR_BGR2GRAY) gray2 = cv2.cvtColor(dst2, cv2.COLOR_BGR2GRAY) gray3 = cv2.cvtColor(dst3, cv2.COLOR_BGR2GRAY) # --- Calculate ssim --- # print("ssim_n: " + str(measurement_nearest(compare_ssim, gray0 = gray0, gray1 = gray1))) print("ssim_l: " + str(measurement_linear(compare_ssim, gray0 = gray0, gray2 = gray2))) print("ssim_c: " + str(measurement_cubic(compare_ssim, gray0 = gray0, gray3 = gray3))) except picamera.exc.PiCameraMMALError: photo_path = 'Null' time.sleep(1) except: print(traceback.format_exc()) time.sleep(0.1) return photo_path
def preciseCalcStaticLevel(self, referencePoint): lowBound = int(max(1, referencePoint - 50)) highBound = int(min(self.maxDepth, referencePoint + 50)) if self.tableInd == 0: tempDF11 = self.finalData.iloc[:self.centralDots[1], [4, 3]] tempDF22 = self.finalData.iloc[:self.centralDots[0], [0, 1]] else: tempDF11 = self.finalData.iloc[self.centralDots[1]:, [4, 3]] tempDF22 = self.finalData.iloc[self.centralDots[0]:, [0, 1]] tempDF1 = tempDF11.dropna(how='all') tempDF2 = tempDF22.dropna(how='all') prevPres = 9000 for i in range(lowBound, highBound): timeDepth = Other.searchAndInterpolate(tempDF1, i) newPres = Other.searchAndInterpolate(tempDF2, timeDepth) if (newPres - prevPres) * 10 > 0.7: return i else: prevPres = newPres return referencePoint
def __init__(self, name, id=None, description="", latitude="", longitude="", url="", location_type="", parent_station=""): self.name = name if id is None: self.id = Other.to_id(name) else: self.id = id self.description = description self.latitude = latitude self.longitude = longitude self.url = url self.locationType = location_type self.parent_station = parent_station
def fuse_two_stops(real_name, alias): real_id = Other.to_id(real_name) alias_id = Other.to_id(alias) # We first take care of stops.txt Other.replace_in_file("gtfs/stops.txt", alias, delete_line=True, escape=True) # Now we take care of stop_times.txt Other.replace_in_file("gtfs/stop_times.txt", alias_id, real_id, escape=True)
def __init__(self): self.list_differentiation = list() self.list_of_list_of_identical_stops = list() self.threshold = None try: with io.open("sgtfs/same_stops.txt", "r", encoding="utf-8") as f: equalities = f.readlines() except FileNotFoundError: print("same_stops.txt not found") equalities = list() try: with io.open("sgtfs/different_stops.txt", "r", encoding="utf-8") as f: differences = f.readlines() except FileNotFoundError: print("different_stops.txt not found") differences = list() for line in equalities: list_of_same_names = Other.split_by(line, "=") self.list_of_list_of_identical_stops.append(list_of_same_names) for line in differences: different_stops = Other.split_by(line, "!") self.list_differentiation.append(different_stops) try: with io.open("threshold.txt", encoding="utf-8") as f: line = f.readline() threshold = re.sub("\\n", "", line) threshold = threshold[1:] except FileNotFoundError: print("threshold.txt not found") threshold = "0.6" self.threshold = float(threshold)
def LongtransmitPhoto(sendimgName = ""): global t_start photo = "" IM920.Send("G" + str(nLat) + " " + str(nLon)) IM920.Send("G" + str(nLat) + " " + str(nLon)) IM920.Send("G" + str(nLat) + " " + str(nLon)) if sendimgName == "": IM920.Strt("2") #distancemode! time.sleep(1) Motor.motor(15, 15, 0.9) Motor.motor(0, 0, 1) takePhoto() print("Send Photo") sendPhoto.sendPhoto(photoName) print("Send Photo Finished") Other.saveLog(sendPhotoLog, time.time() - t_start, GPS.readGPS(), photoName) IM920.Strt("2") #distancemode time.sleep(1) else: # 1st time transmit print("airphoto") IM920.Strt("2") #distancemode! time.sleep(1) Motor.motor(15, 15, 0.9) Motor.motor(0, 0, 1) print("Send Photo") sendPhoto.sendPhoto(sendimgName) print("Send Photo Finished") Other.saveLog(sendPhotoLog, time.time() - t_start, GPS.readGPS(), sendimgName) IM920.Strt("2") #distancemode time.sleep(1) IM920.Send("G" + str(nLat) + " " + str(nLon)) IM920.Send("G" + str(nLat) + " " + str(nLon)) IM920.Send("G" + str(nLat) + " " + str(nLon))
def calibration(): global ellipseScale mPL, mPR, mPS = 0, 0, 0 dt = 0.05 roll = 0 time.sleep(1) fileCal = Other.fileName(calibrationLog, "txt") print("Calibration Start") IM920.Send("P7C") Motor.motor(30, 0, 1) t_cal_start = time.time() while(math.fabs(roll) <= 600): if(time.time() - t_cal_start >= 10): calData = ellipseScale Motor.motor(0, 0, 1) Motor.motor(-60, -60, 2) print("Calibration Failed") Other.saveLog(stuckLog, time.time() - t_start, GPS.readGPS(), 3, 0) Other.saveLog(fileCal, time.time() - t_start, "Calibration Failed") break mPL, mPR, mPS, bmx055data = pidControl.pidSpin(-300, 1.0, 1.1, 0.2, dt) with open(fileCal, '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") roll = roll + bmx055data[5] * dt Motor.motor(mPL, mPR, dt, 1) else: Motor.motor(0, 0, 1) calData = Calibration.Calibration(fileCal) Other.saveLog(fileCal, calData) Other.saveLog(fileCal, time.time() - t_start) Motor.motor(0, 0, 1) setup() print("Calibration Finished") return calData
def setup(): global phaseChk pi.set_mode(17, pigpio.OUTPUT) pi.set_mode(22, pigpio.OUTPUT) pi.write(22, 1) pi.write(17, 0) time.sleep(1) BME280.bme280_setup() BME280.bme280_calib_param() BMX055.bmx055_setup() GPS.openGPS() with open(phaseLog, 'a') as f: pass phaseChk = int(Other.phaseCheck(phaseLog))
def Capture(path, width = 320, height = 240): filepath = "" try: with picamera.PiCamera() as camera: #camera.rotation = 270 camera.resolution = (width,height) filepath = Other.fileName(path,"jpg") camera.capture(filepath) except picamera.exc.PiCameraMMALError: filepath = "Null" time.sleep(0.8) except: print(traceback.format_exc()) time.sleep(0.1) filepath = "Null" return filepath
def init_from_line(self, line): # Initialise values from the line splited_line = Other.split_by(line, "\t") # We get the name self.name = splited_line[0] # Here we get the directions the bus can go # No number means both directions are possible try: if splited_line[1] == '1': self.link_up = False elif splited_line[1] == '2': self.link_down = False except IndexError: pass
def setup(): global phaseChk pi.set_mode(17, pigpio.OUTPUT) pi.set_mode(22, pigpio.OUTPUT) pi.write(22, 1) #IM920 Turn On pi.write(17, 0) #Outcasing Turn Off time.sleep(1) BME280.bme280_setup() BME280.bme280_calib_param() BMX055.bmx055_setup() GPS.openGPS() with open(phaseLog, 'a') as f: pass #if it is End to End Test, then phaseChk = int(Other.phaseCheck(phaseLog)) #if it is debug phaseChk = 8
def __init__(self, field, wname, data): self.field = field self.wellName = wname self.data = data self.resID = Other.makeID() self.tableModels = None self.checks = None self.tableInd = None self.ro = None self.ppl = None self.pvnk = None self.finalData = None self.finalFig = None self.supTimes = None self.dataFromSupTimes = None self.vdp = None self.layer = None self.otsFieldID = None self.otsWellID = None self.otsMesID = None self.otsNewMesID = None self.tpID = None self.region = None self.tzehID = None self.avgTempGradient = None self.GOB = None self.OWB = None self.GWB = None self.staticLevel = None self.maxDepth = None self.depthPressureTemperatureData = None self.layersIDs = None self.otsResearchWellID = None self.otsResearchLayerInputIds = [] self.otsResearchMarkerLayer = {} self.centralDots = [] self.warning = False self.interpreted = False self.discretMan = None self.discretSPS = None
def setup(): global phaseChk global startPosStatus pi.set_mode(17,pigpio.OUTPUT) pi.set_mode(22,pigpio.OUTPUT) pi.write(22,1) #IM920 Turn On IM920.Strt("2") #distance mode pi.write(17,0) #Outcasing Turn Off time.sleep(1) BME280.bme280_setup() BME280.bme280_calib_param() BMX055.bmx055_setup() TSL2561.tsl2561_setup() GPS.openGPS() with open(phaseLog, 'a') as f: pass #if it is End to End Test, then try: phaseChk = int(Other.phaseCheck(phaseLog)) except: phaseChk = 0 #if it is debug #phaseChk = 8 if phaseChk == 0: Other.saveLog(positionLog, "Goal", gLat, gLon, "\t") startPosStatus = 1 else: Other.saveLog(positionLog, "\t") if(Other.positionCheck(positionLog) == [0.0, 0.0]): print("Not Logged Start Position") startPosStatus = 1 else: rsLat, rsLon = Other.positionCheck(positionLog) print(rsLat, rsLon) startPosStatus = 0
run.turn_right_l() time.sleep(0.1) run = pwm_control.Run() run.straight_n() if __name__ == '__main__': try: print('Program Start {0}'.format(time.time())) t_start = time.time() # --- Setup Phase --- # setup() print('Start {0}'.format(phaseChk)) if phaseChk == 1: IM920.Send('P1S') Other.saveLog(phaseLog, '1', 'Program Started', time.time() - t_start) IM920.Send('P1F') phaseChk += 1 print('phaseChk = '+str(phaseChk)) # --- Sleep Phase --- # if phaseChk == 2: IM920.Send('P2S') t_sleep_start = time.time() Other.saveLog(phaseLog, '2', 'Sleep Phase Started', time.time() - t_start) IM920.Send('P2F') phaseChk += 1 print('phaseChk = '+str(phaseChk)) # --- Release Phase --- #
def init_from_file(self, path="gtfs"): path += "/agency.txt" issue = Other.read_csv(path, self.init_from_line) if issue: print("No file found, please answer the following questions: ") self.init_from_line(["", "", "", "", "", "", "", "", "", ""])
def print(self): # Print everything into files to the gtfs folder print("write in gtfs folder") Other.export_in_csv([self, ], "agency.txt") Other.export_in_csv(self.calendar.services, "calendar.txt") list_of_stops = sorted(self.stops) Other.export_in_csv(list_of_stops, "stops.txt") list_of_routes = sorted(self.routes) Other.export_in_csv(list_of_routes, "routes.txt") list_of_trips = list() for route in list_of_routes: sorted_list_of_trips = sorted(route.trips) list_of_trips += sorted_list_of_trips Other.export_in_csv(list_of_trips, "trips.txt") list_of_stops_times = list() for trip in list_of_trips: list_of_stops_times += trip.stop_times Other.export_in_csv(list_of_stops_times, "stop_times.txt") self.print_coordinates_file() print("finished exporting coordinates.txt")
def add_timetable(self, file_path="sgtfs/timetable.txt"): # This function takes a timetable and convert it to a list of trips try: with io.open(file_path, encoding="utf-8") as f: lines = f.readlines() except FileNotFoundError: print("No timetable file") return None for line in lines: line.strip() # Here we get the name of the line and the service metadata = Other.split_by(lines[0], "\t") route_name = metadata[0] trips_service = metadata[1] try: empty_time = metadata[2] except IndexError: empty_time = "-" try: separator = metadata[3] except IndexError: separator = ":" lines.pop(0) list_stops_names = list() list_times = list() for line in lines: name, times_list = Agency.get_list_of_times_and_stop_name(line, separator, empty_time) list_stops_names.append(name) list_times.append(times_list) # Here we perform a check to ensure that # Right now, we have a table of horizontal lines. # We have to get vertical lines instead. count = 0 # The if is here in case there is actually no times in the timetable.txt if len(list_times) > 0: # It's time for a little check. # It would be inconvenient that a bug allows to write anything in the files lenght = len(list_times[0]) i = 0 for times in list_times: i += 1 lenght2 = len(times) if lenght != lenght2: print("issue of lenght at the list " + list_stops_names[i]) print("The lenght is " + str(lenght2) + " instead of " + str(lenght)) assert lenght == lenght2 # Transposed is the transposition of the table list_times transposed = list(map(list, zip(*list_times))) # Now we find the bus line in memory route1 = None for route in self.routes: if route.id == route_name: route1 = route break if route1 is None: # Then we have to create the bus line (add a route to the agency) route1 = Route.Route.from_stops_list(route_name, list_stops_names) self.routes.append(route1) # Here we initialise the graph (just getting the stops names in the file) route1.graph = LinkedStops.LinkedStops(route1.id) # We make comparison with the list of stops in memory to avoid to have sames # stops with different names with Comparator.Comparator() as comparator: self.update_stops(route1.graph.list_stops_of_graph, comparator) # Now that we made sure that the list of stops has nothing unusual, we can actually draw the graph route1.graph.create_from_file() # Here we check that the stops of the timetable correspond to the stops of the graph list_stops_names = route1.graph.check_stops(list_stops_names, comparator) for times in transposed: route1.add_trip_from_times(list_stops_names, times, trips_service) count += 1 print(str(count) + " trips have been added to the line " + route_name)
break else: returnVal = 0 print(data, power) return returnVal if __name__ == "__main__": try: mode = 0 logPath = "photoRecieveLog.txt" photoPath = "receivePhoto" photoSize = (120, 160) convertedPhotoSize = (320, 240) Other.saveLog(receptionLog, "0", "receiveprogram start", datetime.datetime.now()) print("Ready") while 1: im920data = read(baudrate) mode = receiveData(im920data) if (mode == 1): t_start = time.time() print("Photo Receive") receivePhoto(logPath, photoPath, photoSize, convertedPhotoSize) print(time.time() - t_start) print("MissionFinish") else: print("mode : " + str(mode) + " " + str(datetime.datetime.now()))
def init_trips_from_file(self, path="gtfs"): path += "/trips.txt" Other.read_csv(path, self.add_trip)
def altered(self): print "CHILD, BEFORE altered()" return Other.altered() print "CHILD,AFTER altered9)"
def timer(t): global cond time.sleep(t) cond = False if __name__ == '__main__' try: print('Program Start {0}'.format(time.time())) t_start = time.time() # --- Setup Phase --- # setup() print('Start {0}'.format(phaseChk)) if phaseChk <= 1: IM920.Send('P1S') Other.SaveLog(phaseLog, '1', 'Program Started', time.time() - t_atart) IM920.Send('P1F') # --- Sleep Phase --- # if phaseChk <= 2: Im920.Send('P2S') t_sleep_start = time.time() Other.SaveLog(phaseLog, '2', 'Sleep Phase Started', time.time - t_start) Im920.Send('P2F') # --- Release Phase --- # if phaseChk <= 3: IM920.Send('P3S') Other.SaveLog(phaseLog, '3', 'Release Phase Started', time.time - t_start) t_relase_start = tim.time() print('Release Phase Started {}'.format(time.time - t_start))
def write_to_disk(self): # Here we write the data from the object in files so that it can be destroyed Other.write_list_of_list_in_file("sgtfs/same_stops.txt", self.list_of_list_of_identical_stops, "=") Other.write_list_of_list_in_file("sgtfs/different_stops.txt", self.list_differentiation, "!") Other.write_list_of_list_in_file("threshold.txt", [str(self.threshold)], "")
def receiveData(data): returnVal = 0 #print(data) comdata, power = getCommand(data) if (comdata == ['50,51,53']): Other.saveLog(receptionLog, "1-1", "Program Started", power, datetime.datetime.now()) returnVal = 2 powerread(power) print("Program Started") elif (comdata == ['50,31,46']): Other.saveLog(receptionLog, "1-2", "Program Started", power, datetime.datetime.now()) returnVal = 2 powerread(power) print("Program Started2") elif (comdata == ['50,32,53']): Other.saveLog(receptionLog, "2", "Sleep Started", power, datetime.datetime.now()) returnVal = 2 powerread(power) print("Sleep Started") elif (comdata == ['50,32,44']): Other.saveLog(receptionLog, "2", "Sleep now", power, datetime.datetime.now()) returnVal = 2 powerread(power) print("Sleep Now") elif (comdata == ['50,32,46']): Other.saveLog(receptionLog, "2", "Sleep Finished", power, datetime.datetime.now()) returnVal = 2 powerread(power) print("Sleep Finished") elif (comdata == ['50,33,53']): Other.saveLog(receptionLog, "3", "Release started", power, datetime.datetime.now()) returnVal = 2 powerread(power) print("Release Started") elif (comdata == ['50,33,44']): Other.saveLog(receptionLog, "3", "Release judge now", power, datetime.datetime.now()) returnVal = 2 powerread(power) print("Release judge now") elif (comdata == ['50,33,46']): Other.saveLog(receptionLog, "3", "Release judge finished", power, datetime.datetime.now()) returnVal = 2 powerread(power) print("Release judge finished") elif (comdata == ['50,34,53']): Other.saveLog(receptionLog, "4", "Land started", power, datetime.datetime.now()) returnVal = 2 powerread(power) print("Land judge started") elif (comdata == ['50,34,44']): Other.saveLog(receptionLog, "4", "Land judge now", power, datetime.datetime.now()) returnVal = 2 powerread(power) print("Land judge now") elif (comdata == ['50,34,46']): Other.saveLog(receptionLog, "4", "Land FInished", power, datetime.datetime.now()) returnVal = 2 powerread(power) print("Land judge finished") elif (comdata == ['50,35,53']): Other.saveLog(receptionLog, "5", "Melt started", power, datetime.datetime.now()) returnVal = 2 powerread(power) print("Melt Started") elif (comdata == ['50,35,46']): Other.saveLog(receptionLog, "5", "Melt Finished", power, datetime.datetime.now()) returnVal = 2 powerread(power) print("Melt finished") elif (comdata == ['50,36,53']): Other.saveLog(receptionLog, "6", "ParaAvoidance started", power, datetime.datetime.now()) returnVal = 2 powerread(power) print("ParaAvoidance started") elif (comdata == ['50,36,46']): Other.saveLog(receptionLog, "6", "ParaAvoidance finished", power, datetime.datetime.now()) returnVal = 2 powerread(power) print("ParaAvoidance finished") elif (comdata == ['50,37,53']): Other.saveLog(receptionLog, "7", "Running Phase Started", power, datetime.datetime.now()) returnVal = 2 powerread(power) print("Running Phase Started") elif (comdata == ['50,37,46']): Other.saveLog(receptionLog, "7", "Running Phase Finished", power, datetime.datetime.now()) returnVal = 2 powerread(power) print("Running Phase Finished") elif (comdata == ['50,38,53']): Other.saveLog(receptionLog, "8", "GoalDetection Phase Started", power, datetime.datetime.now()) returnVal = 2 powerread(power) print("GoalDeetection Phase Started") elif (comdata == ['50,38,46']): Other.saveLog(receptionLog, "8", "GoalDetection Phase Finished", power, datetime.datetime.now()) returnVal = 2 powerread(power) print("GoalDeetection Phase Finished") elif (comdata == ['50,40,46']): Other.saveLog(receptionLog, "10", "all Finished", power, datetime.datetime.now()) returnVal = 2 powerread(power) print("Running Phase Finished") elif (comdata == ['45,4F']): Other.saveLog(receptionLog, "11", "Error Occured", power, datetime.datetime.now()) returnVal = 2 powerread(power) print("EO") elif str('47') in str(comdata): #GPS gps = int(comdata, 16) print(gps) Other.saveLog(receptionLog, "0", "GPS", gps, power, datetime.datetime.now()) elif (comdata == ['4D']): for i in range(3): if (comdata == ['4D']): Send("M", baudrate) Send("M", baudrate) #print(data) time.sleep(0.1) data = read(baudrate) data = getCommand(data) time.sleep(0.2) returnVal = 1 else: returnVal = 0 break else: returnVal = 0 print(data, power) return returnVal
import os import Other a = os.listdir("sgtfs") for filename in a: Other.delete_BOM("sgtfs/" + filename)
def init_stop_times(self, path="gtfs"): path += "/stop_times.txt" Other.read_csv(path, self.add_stop_time)
#mPLeft = mPLeft + mPS #mPRight = mPRight - mPS #Limited motor at motorPowerMax mPLeft = int(motorPowerMax if mPLeft > motorPowerMax else mPLeft) mPLeft = int(motorPowerMax / 2 if mPLeft < motorPowerMax / 2 else mPLeft) mPRight = int(motorPowerMax if mPRight > motorPowerMax else mPRight) mPRight = int(motorPowerMax / 2 if mPRight < motorPowerMax / 2 else mPRight) return [mPLeft, mPRight, mPS] if __name__ == "__main__": try: setup() time.sleep(1) fileCal = Other.fileName(calibrationLog, "txt") Motor.motor(40, 0, 1) Calibration.readCalData(fileCal) Motor.motor(0, 0, 1) ellipseScale = Calibration.Calibration(fileCal) Other.saveLog(fileCal, ellipseScale) gpsInterval = 0 #Get GPS data #print("Getting GPS Data") while(not checkGPSstatus(gpsData)): gpsData = GPS.readGPS() time.sleep(1)
run.turn_right_l() time.sleep(0.1) run = pwm_control.Run() run.straight_n() if __name__ == '__main__': try: print('Program Start {0}'.format(time.time())) t_start = time.time() # --- Setup Phase --- # setup() print('Start {0}'.format(phaseChk)) if phaseChk == 1: IM920.Send('P1S') Other.saveLog(phaseLog, '1', 'Program Started', time.time() - t_start) IM920.Send('P1F') phaseChk += 7 print('phaseChk = '+str(phaseChk)) ''' # --- Sleep Phase --- # if phaseChk == 2: IM920.Send('P2S') t_sleep_start = time.time() Other.saveLog(phaseLog, '2', 'Sleep Phase Started', time.time() - t_start) IM920.Send('P2F') phaseChk += 1 print('phaseChk = '+str(phaseChk)) # --- Release Phase --- #
GPS.closeGPS() Motor.motor(0, 0, 2) Motor.motor_stop() pi.write(17, 0) if __name__ == "__main__": try: t_start = time.time() # ------------------- Setup Fhase ------------------- # setup() print("Program Start {0}".format(time.time())) print(phaseChk) if (phaseChk <= 1): IM920.Send("P1S") Other.saveLog(phaseLog, "1", "Program Started", time.time() - t_start) IM920.Send("P1F") # ------------------- Sleep Phase --------------------- # Other.saveLog(phaseLog, "2", "Sleep Phase Started", time.time() - t_start) if (phaseChk <= 2): print("Sleep Phase Started {0}".format(time.time())) IM920.Send("P2S") pi.write(22, 0) #IM920 Turn Off t_wait_start = time.time() while (time.time() - t_wait_start <= t_sleep): bme280Data = BME280.bme280_read() #Read BME280 data bmx055Data = BMX055.bmx055_read() #Read BMX055 data luxData = TSL2561.readLux() #Read TSL2561 data gpsData = GPS.readGPS() #Read GPS data
def implicit(self): return Other.implicit()
pi.write(17, 0) Motor.motor(0, 0, 1) Motor.motor_stop() if __name__ == "__main__": try: print("Program Start {0}".format(time.time())) t_start = time.time() #-----setup phase ---------# setup() print("Start Phase is {0}".format(phaseChk)) if (phaseChk <= 1): IM920.Send("P1S") Other.saveLog(phaseLog, "1", "Program Started", time.time() - t_start) IM920.Send("P1F") # ------------------- Sleep Phase --------------------- # if (phaseChk <= 2): Other.saveLog(phaseLog, "2", "Sleep Phase Started", time.time() - t_start) print("Sleep Phase Started {0}".format(time.time() - t_start)) IM920.Send("P2S") #pi.write(22, 0) #IM920 Turn Off t_sleep_start = time.time() # --- Sleep --- # while (time.time() - t_sleep_start <= t_sleep): Other.saveLog(sleepLog, time.time() - t_start, GPS.readGPS(),
pi.write(17, 0) Motor.motor(0, 0, 1) Motor.motor_stop() if __name__ == "__main__": try: print("Program Start {0}".format(time.time())) t_start = time.time() #-----setup phase ---------# setup() print("Start Phase is {0}".format(phaseChk)) if (phaseChk <= 1): IM920.Send("P1S") Other.saveLog(phaseLog, "1", "Program Started", time.time() - t_start) IM920.Send("P1F") # ------------------- Sleep Phase --------------------- # if (phaseChk <= 2): Other.saveLog(phaseLog, "2", "Sleep Phase Started", time.time() - t_start) print("Sleep Phase Started {0}".format(time.time() - t_start)) IM920.Send("P2S") pi.write(22, 1) #IM920 Turn Off t_sleep_start = time.time() # --- Sleep --- # while (time.time() - t_sleep_start <= t_sleep): photoName = Capture.Capture(photopath)
def __init__(self): self.other = Other()
def rotate_control(θ, lon2, lat2, t_start): direction = calculate_direction(lon2, lat2) azimuth = direction["azimuth1"] #--- 0 <= azimuth <= 360 ---# print('goal azimuth = ' + str(azimuth)) #print('θ = '+str(θ)) try: t1 = time.time() while azimuth - 30 > θ or θ > azimuth + 30: if 0 <= azimuth < 30: if azimuth - 30 + 360 <= θ <= 360: break if 330 <= azimuth <= 360: if 0 <= θ <= azimuth + 30 - 360: break #--- use Timer ---# global cond cond = True thread = Thread(target=timer, args=([1])) thread.start() while cond: run = pwm_control.Run() run.turn_right() get_data() θ = math.degrees(math.atan((magy - magy_off) / (magx - magx_off))) #--- -90 <= θ <= 90 ---# if θ >= 0: if magx - magx_off < 0 and magy - magy_off < 0: #Third quadrant θ = θ + 180 #180 <= θ <= 270 if magx - magx_off > 0 and magy - magy_off > 0: #First quadrant pass #0 <= θ <= 90 else: if magx - magx_off < 0 and magy - magy_off > 0: #Second quadrant θ = 180 + θ #90 <= θ <= 180 if magx - magx_off > 0 and magy - magy_off < 0: #Fourth quadrant θ = 360 + θ #270 <= θ <= 360 #--- Half turn ---# θ += 180 if θ >= 360: θ -= 360 #--- 0 <= θ <= 360 ---# print('θ = ' + str(θ)) Other.saveLog(Calibration_rotate_controlLog, 'Calibration_rotate_control', time.time() - t_start, θ, azimuth) run = pwm_control.Run() run.stop() time.sleep(0.5) if time.time() - t1 >= 60: #judge = False print('rotate control timeout') break #judge = True print("rotate control finished") #print(θ) except KeyboardInterrupt: run = pwm_control.Run() run.stop() print("faulted to rotate control to goal direction") finally: run = pwm_control.Run() run.stop() return judge
pi.write(17, 0) Motor.motor(0, 0, 1) Motor.motor_stop() if __name__ == "__main__": try: t_start = time.time() # ------------------- Setup Phase --------------------- # print("Program Start {0}".format(time.time())) setup() print(phaseChk) IM920.Send("Start") # ------------------- Waiting Phase --------------------- # Other.saveLog(phaseLog, "2", "Waiting Phase Started", time.time() - t_start) if (phaseChk <= 2): t_wait_start = time.time() while (time.time() - t_wait_start <= t_setup): Other.saveLog(waitingLog, time.time() - t_start, GPS.readGPS(), BME280.bme280_read(), TSL2561.readLux(), BMX055.bmx055_read()) print("Waiting") IM920.Send("Sleep") time.sleep(1) IM920.Send("Waiting Finished") pi.write(22, 0) #IM920 Turn Off # ------------------- Release Phase ------------------- # Other.saveLog(phaseLog, "3", "Release Phase Started",