def adjust_hog(self): # Update HOG from rudder change hogChange = (self.boatData.sow * math.sin(self.boatData.rudder * math.pi / 180.0) * self.CLOCK_INTERVAL) * self.HOG_CHANGE_FACTOR self.boatData.hog += hogChange self.boatData.hog = standardcalc.bound_to_180(self.boatData.hog)
def adjust_current(self): # self.currentFlowAngle += standardcalc.generate_bell_curve(self.CURRENT_ANGLE_FLUCTUATIONS * self.CLOCK_INTERVAL) # self.currentFlowSpeed += standardcalc.generate_bell_curve(self.CURRENT_SPEED_FLUCTUATIONS * self.CLOCK_INTERVAL) self.currentFlowAngle += random.gauss(0,1) * self.CLOCK_INTERVAL self.currentFlowSpeed += random.gauss(0,1) * self.CLOCK_INTERVAL self.currentFlowAngle = standardcalc.bound_to_180(self.currentFlowAngle) self.currentFlowSpeed = abs(self.currentFlowSpeed) self.currentFlowVector = standardcalc.Vector2D.create_from_angle(self.currentFlowAngle, self.currentFlowSpeed)
def adjust_current(self): self.currentFlowAngle += random.gauss(0, 1) * self.CLOCK_INTERVAL self.currentFlowSpeed += random.gauss(0, 0.3) * self.CLOCK_INTERVAL self.currentFlowAngle = standardcalc.bound_to_180( self.currentFlowAngle) if self.currentFlowSpeed > self.MAX_CURRENT_SPEED: self.currentFlowSpeed = self.MAX_CURRENT_SPEED self.currentFlowSpeed = abs(self.currentFlowSpeed) self.currentFlowVector = standardcalc.Vector2D.create_from_angle( self.currentFlowAngle, self.currentFlowSpeed)
def adjust_true_wind(self): # True wind angle is allowed to fluctuate # self.trueWindAngle += standardcalc.generate_bell_curve(self.WIND_ANGLE_FLUCTUATIONS * self.CLOCK_INTERVAL) # self.trueWindSpeed += standardcalc.generate_bell_curve(self.WIND_SPEED_FLUCTUATIONS * self.CLOCK_INTERVAL) self.trueWindAngle += random.gauss(0,1) * self.CLOCK_INTERVAL self.trueWindSpeed += random.gauss(0,1) * self.CLOCK_INTERVAL self.trueWindAngle = standardcalc.bound_to_180(self.trueWindAngle) self.trueWindSpeed = abs(self.trueWindSpeed) self.windVector = -standardcalc.Vector2D.create_from_angle(self.trueWindAngle, self.trueWindSpeed)
def adjust_true_wind(self): # True wind angle is allowed to fluctuate self.trueWindAngle += random.gauss(0, 1) * self.CLOCK_INTERVAL self.trueWindSpeed += random.gauss(0, 0.3) * self.CLOCK_INTERVAL if self.trueWindSpeed > self.MAX_WIND_SPEED: self.trueWindSpeed = self.MAX_WIND_SPEED if self.trueWindSpeed < self.MIN_WIND_SPEED: self.trueWindSpeed = self.MIN_WIND_SPEED self.trueWindAngle = standardcalc.bound_to_180(self.trueWindAngle) self.trueWindSpeed = abs(self.trueWindSpeed) self.windVector = -standardcalc.Vector2D.create_from_angle( self.trueWindAngle, self.trueWindSpeed)
def update_vectors(self): self.boatVector = standardcalc.Vector2D.create_from_angle(self.boatData.hog, self.boatData.sow) \ + self.currentFlowVector # Update COG and SOG self.boatData.cog = self.boatVector.angle() self.boatData.sog = self.boatVector.length() self.apparentWindVector = self.windVector - self.boatVector # 4 Feb 2016 self.boatData.awa = standardcalc.bound_to_180( standardcalc.Vector2D.angle_between(self.boatVector, -self.apparentWindVector)) self.boatData.windspeed = self.apparentWindVector.length()
def adjust_hog(self): # Make functional, i.e. go to desired rudder angle immediately # hogChange = self.currentData['sog'] * math.sin(self.currentData['rudderAngle']* math.pi / 180.0) \ # / self.L_CENTERBOARD_TO_RUDDER * self.TIME_SCALE # self.currentData['hog'] += hogChange # self.currentData['hog'] = standardcalc.bound_to_180(self.currentData['hog']) #Update HOG from rudder change hogChange = self.boatData.sow * math.sin(self.boatData.rudder * math.pi / 180.0) \ / self.L_CENTERBOARD_TO_RUDDER * self.TIME_SCALE self.boatData.hog += hogChange self.boatData.hog = standardcalc.bound_to_180(self.boatData.hog)
def adjust_aw(self): self.boatVector = standardcalc.Vector2D.create_from_angle(self.boatData.hog, self.boatData.sow) \ - self.currentFlowVector # Update COG and SOG self.boatData.cog = self.boatVector.angle() self.boatData.sog = self.boatVector.length() self.apparentWindVector = self.windVector - self.boatVector # print str(self.apparentWindVector.angle()) + " " + str(self.apparentWindVector.length()) self.boatData.awa = standardcalc.bound_to_180( standardcalc.Vector2D.angle_between(self.boatVector, -self.apparentWindVector)) self.boatData.windspeed = self.apparentWindVector.length()
def gust_manager(self): if self.gustTimer <= 0: if random.randint(1, self.GUST_PROBABILITY / self.TIME_SCALE) == 2: self.preGustTrueWindAngle = self.trueWindAngle self.preGustTrueWindSpeed = self.trueWindSpeed self.trueWindSpeed = random.randint(20, 30) self.trueWindAngle += random.randint(-5, 5) self.gustTimer = random.randint(5, 80) / self.TIME_SCALE else: self.gustTimer -= 1 if self.verbose: print "Gust is active. Timer: " + str(self.gustTimer) if self.gustTimer <= 0: self.trueWindSpeed = abs(self.preGustTrueWindSpeed + random.randint(-2, 2)) self.trueWindAngle = standardcalc.bound_to_180(self.preGustTrueWindAngle + random.randint(-1, 1))
def gust_manager(self): if self.gustTimer <= 0: if random.randint(1, self.GUST_PROBABILITY / self.CLOCK_INTERVAL) == 2: self.preGustTrueWindAngle = self.trueWindAngle self.preGustTrueWindSpeed = self.trueWindSpeed self.trueWindSpeed = random.randint(20, 30) self.trueWindAngle += random.randint(-5, 5) self.gustTimer = random.randint(5, 80) / self.CLOCK_INTERVAL else: self.gustTimer -= 1 if self.verbose: print "Gust is active. Timer: " + str(self.gustTimer) if self.gustTimer <= 0: self.trueWindSpeed = abs(self.preGustTrueWindSpeed + random.randint(-2, 2)) self.trueWindAngle = standardcalc.bound_to_180( self.preGustTrueWindAngle + random.randint(-1, 1))
def data(): lat = boatDataStruct.gps_coord.lat lng = boatDataStruct.gps_coord.long aws = boatDataStruct.windspeed awa = boatDataStruct.awa hog = boatDataStruct.hog sow = boatDataStruct.sow tws = TWS twa = TWA awa_abs = standardcalc.bound_to_180(boatDataStruct.hog + boatDataStruct.awa) # Data to be sent in one array. coords = [ lat, lng, awa_abs, sow, hog, dest.lat, dest.long, currentVector.length(), currentVector.angle(), awa, aws, twa, tws ] # Converts data to JSON. return json.dumps(coords)
def testNoChange(self): self.assertEqual(standardcalc.bound_to_180(self.num1), self.num1bounded)
def testGreaterThan180(self): self.assertEqual(standardcalc.bound_to_180(self.num2), self.num2bounded)
def testLessThan180(self): self.assertEqual(standardcalc.bound_to_180(self.num3), self.num3bounded)
def testLessThan360ToPositive(self): self.assertEqual(standardcalc.bound_to_180(self.num7), self.num7bounded)
def testGreaterThan360ToNegative(self): self.assertEqual(standardcalc.bound_to_180(self.num5), self.num5bounded)
def testLessThan360ToNegative(self): self.assertEqual(standardcalc.bound_to_180(self.num6), self.num6bounded)
def testGreaterThan360ToPositive(self): self.assertEqual(standardcalc.bound_to_180(self.num4), self.num4bounded)