def getTrueWindAngle(awa, sog): sVars.AWA_THRESHOLD = 0.9 while(1): sVars.SOG_THRESHOLD = 0.9 while(1): AWAList = parsing.parse(path.join(path.dirname(__file__), 'AWA.txt')) SOGList = parsing.parse(path.join(path.dirname(__file__), 'SOGarray')) AWAentries = searchAWAIndex(awa, AWAList) SOGentries = searchSOGIndex(sog, SOGList) for i in range(len(AWAentries)): index = AWAentries[i][0] column = AWAentries[i][1] for x in range(len(SOGentries)): if (SOGentries[x][0] == index) and (SOGentries[x][1] == column): gVars.currentColumn = column if(awa < 0): gVars.trueWindAngle = -index else: gVars.trueWindAngle = index sVars.SOG_THRESHOLD = 0.9 return index sVars.SOG_THRESHOLD += 10 if(sVars.SOG_THRESHOLD >= 500): print ("Hit Threshold") break sVars.AWA_THRESHOLD += 1 if(sVars.AWA_THRESHOLD >= 100): return None
def __init__(self): self.upwindWaypoint = 0 self.sheetList = parsing.parse(path.join(path.dirname(__file__), 'apparentSheetSetting')) self.oldTackingAngle = 0 self.oldSheet_percent = 0 self.oldAwa = 0 self.meanSpd = 0.75 #from old arduino code self.secLeft = self.CHALLENGE_TIME self.SKLogger = SKLogger() self.sheet_percent = 0 self.STEER_METHOD = self.AWA_METHOD self.exitSpeed = gVars.instructions.SK_exit_speed
def updateWeatherSetting(awa, sog): minIndex = 0 minNum = 500 SOGList = parsing.parse(path.join(path.dirname(__file__), 'SOGarray')) index = boundTo180(awa) SOGrow = SOGList[abs(int(index))] for i in range(len(SOGrow)): if (abs(SOGrow[i] - sog) < minNum): minIndex = i minNum = abs(SOGrow[i] - sog) gVars.currentColumn = minIndex
def updateWeatherSetting(awa, sog): minIndex = 0 minNum = 500 SOGList = parsing.parse(path.join(path.dirname(__file__), "SOGarray")) index = boundTo180(awa) SOGrow = SOGList[abs(int(index))] for i in range(len(SOGrow)): if abs(SOGrow[i] - sog) < minNum: minIndex = i minNum = abs(SOGrow[i] - sog) gVars.currentColumn = minIndex
def getTrueWindAngle(awa, sog): sVars.AWA_THRESHOLD = 0.9 while (1): sVars.SOG_THRESHOLD = 0.9 while (1): AWAList = parsing.parse( path.join(path.dirname(__file__), 'AWA.txt')) SOGList = parsing.parse( path.join(path.dirname(__file__), 'SOGarray')) AWAentries = searchAWAIndex(awa, AWAList) SOGentries = searchSOGIndex(sog, SOGList) for i in range(len(AWAentries)): index = AWAentries[i][0] column = AWAentries[i][1] for x in range(len(SOGentries)): if (SOGentries[x][0] == index) and (SOGentries[x][1] == column): gVars.currentColumn = column if (awa < 0): gVars.trueWindAngle = -index else: gVars.trueWindAngle = index sVars.SOG_THRESHOLD = 0.9 return index sVars.SOG_THRESHOLD += 10 if (sVars.SOG_THRESHOLD >= 500): print("Hit Threshold") break sVars.AWA_THRESHOLD += 1 if (sVars.AWA_THRESHOLD >= 100): return None
def test_noFile(self): self.assertEqual(parsing.parse(""), None) self.assertEqual(parsing.parse("fakeFile"), None)
def test_yesFile(self): self.assertEqual(parsing.parse(path.join(path.dirname(__file__), self.fname))[1][1], 7)
def pointToPointTWA(Dest, initialTack, ACCEPTANCE_DISTANCE): sheetList = parsing.parse(path.join(path.dirname(__file__), 'apparentSheetSetting')) gVars.kill_flagPTP = 0 end_flag = 0 arduino = gVars.arduino TWA = 0 oldColumn = 0 tackDirection = 0 print "Started point to point" gVars.logger.info("Started point to pointTWA") while(end_flag == 0 and gVars.kill_flagPTP == 0): while(gVars.currentData[aut_index] == False): time.sleep(0.1) currentData = gVars.currentData GPSCoord = currentData[gps_index] appWindAng = currentData[awa_index] cog = currentData[cog_index] hog = currentData[hog_index] sog = currentData[sog_index] * 100 if(standardcalc.distBetweenTwoCoords(GPSCoord, Dest) > ACCEPTANCE_DISTANCE): #This if statement determines the sailing method we are going to use based on apparent wind angle if(sog < sVars.SPEED_AFFECTION_THRESHOLD): newTWA = appWindAng newTWA = abs(int(newTWA)) if(appWindAng < 0): gVars.TrueWindAngle = -newTWA else: gVars.TrueWindAngle = newTWA gVars.currentColumn = 0 #print ("TWA is: " + str(gVars.TrueWindAngle)) else: newTWA = standardcalc.getTrueWindAngle(abs(int(appWindAng)),sog) newTWA = abs(int(newTWA)) if(appWindAng < 0): gVars.TrueWindAngle = -newTWA else: gVars.TrueWindAngle = newTWA #print ("Hit else statement") #print ("TWA is: " + str(gVars.TrueWindAngle)) if(standardcalc.isWPNoGo(appWindAng,hog,Dest,sog,GPSCoord)): gVars.logger.info("Cannot reach point directly") #Trying to determine whether 45 degrees clockwise or counter clockwise of TWA wrt North is closer to current heading #This means we are trying to determine whether hog-TWA-45 or hog-TWA+45 (both using TWA wrt North) is closer to our current heading. #Since those values give us TWA wrt to north, we need to subtract hog from them to get TWA wrt to our heading and figure out which one has a smaller value. #To get it wrt to current heading, we use hog-TWA-45-hog and hog-TWA+45-hog. Both terms have hogs cancelling out. #We are left with -TWA-45 and -TWA+45, which makes sense since the original TWA was always with respect to the boat. #Since we are trying to figure out which one is closest to turn to, we use absolute values. if((abs(-newTWA-45)<abs(-newTWA+45) and initialTack is None) or initialTack == 1): initialTack = None while(abs(hog-standardcalc.angleBetweenTwoCoords(GPSCoord, Dest))<80 and gVars.kill_flagPTP ==0): gVars.logger.info("On starboard tack") while(gVars.currentData[aut_index] == False): time.sleep(0.1) gVars.tacked_flag = 0 GPSCoord = currentData[gps_index] appWindAng = currentData[awa_index] cog = currentData[cog_index] hog = currentData[hog_index] sog = currentData[sog_index] * 100 if(sog > sVars.SOG_THRESHOLD): newTWA = standardcalc.getTrueWindAngle(appWindAng, sog) else: newTWA = appWindAng newTWA = abs(int(newTWA)) if( TWA != newTWA or oldColumn != gVars.currentColumn): gVars.logger.info("Changing sheets and rudder") arduino.adjust_sheets(sheetList[newTWA][gVars.currentColumn]) arduino.steer(AWA_METHOD,hog-newTWA-45) TWA = newTWA oldColumn = gVars.currentColumn if(appWindAng > 0): tackDirection = 1 else: tackDirection = 0 if( len(gVars.boundaries) > 0 ): for boundary in gVars.boundaries: if(standardcalc.distBetweenTwoCoords(boundary, GPSCoord) <= boundary.radius): arduino.tack(gVars.currentColumn,tackDirection) gVars.logger.info("Tacking from boundary") gVars.tacked_flag = 1 break if(gVars.tacked_flag): break arduino.tack(gVars.currentColumn,tackDirection) gVars.logger.info("Tacking from 80 degrees") elif((abs(-newTWA-45)>=abs(-newTWA+45) and initialTack is None) or initialTack == 0): initialTack = None while(abs(hog-standardcalc.angleBetweenTwoCoords(GPSCoord, Dest))<80 and gVars.kill_flagPTP == 0): gVars.logger.info("On port tack") while(gVars.currentData[aut_index] == False): time.sleep(0.1) gVars.tacked_flag = 0 GPSCoord = currentData[gps_index] appWindAng = currentData[awa_index] cog = currentData[cog_index] hog = currentData[hog_index] sog = currentData[sog_index]*100 if(sog > sVars.SOG_THRESHOLD): newTWA = standardcalc.getTrueWindAngle(appWindAng, sog) else: newTWA = appWindAng newTWA = abs(int(newTWA)) #TWA = abs(int(TWA)) #print ("TWA is: " + str(newTWA)) if(TWA != newTWA or oldColumn != gVars.currentColumn): gVars.logger.info("Changing sheets and rudder") arduino.adjust_sheets(sheetList[int(abs(newTWA))][gVars.currentColumn]) arduino.steer(AWA_METHOD,hog-newTWA+45) TWA = newTWA oldColumn = gVars.currentColumn if(appWindAng > 0): tackDirection = 1 else: tackDirection = 0 if( len(gVars.boundaries) > 0 ): for boundary in gVars.boundaries: if(standardcalc.distBetweenTwoCoords(boundary, GPSCoord) <= boundary.radius): gVars.logger.info("Tacking from boundary") arduino.tack(gVars.currentColumn,tackDirection) gVars.tacked_flag = 1 break if(gVars.tacked_flag): break arduino.tack(gVars.currentColumn,tackDirection) gVars.logger.info("Tacking from 80 degrees") elif(abs(hog-newTWA-standardcalc.angleBetweenTwoCoords(GPSCoord, Dest))>90): gVars.logger.info("Sailing straight to point") if(TWA != newTWA or oldColumn != gVars.currentColumn): gVars.logger.info("Adjusting sheets and rudder") arduino.adjust_sheets(sheetList[abs(int(newTWA))][gVars.currentColumn]) arduino.steer(COMPASS_METHOD,standardcalc.angleBetweenTwoCoords(GPSCoord,Dest)) TWA = newTWA gVars.currentColumn else: end_flag = 1 print ("Finished Point to Point") gVars.logger.info("Finished Point to Point") return 0
def __init__(self): self.sheetList = parsing.parse( path.join(path.dirname(__file__), 'apparentSheetSetting'))
def __init__(self): self.sheetList = parsing.parse(path.join(path.dirname(__file__), 'apparentSheetSetting'))