def _updateAWA(self): if STATIC_AWA == None: # Sets the apparent wind angle boat_bearing = self.arduinoData.hog # Reverse direction for boat vector if (boat_bearing >= 0): boat_bearing -= 180 else: boat_bearing += 180 boat_speed = self.arduinoData.sog # Reverse direction for wind vector wind_bearing = self.trueWindAngle if (wind_bearing >= 0): wind_bearing -= 180 else: wind_bearing += 180 wind_speed = self.trueWindSpeed boat_x = boat_speed * math.cos(boat_bearing) boat_y = boat_speed * math.sin(boat_bearing) wind_x = wind_speed * math.cos(wind_bearing) wind_y = wind_speed * math.sin(wind_bearing) x = boat_x + wind_x y = boat_y + wind_y if self.previousx is None: self.previousx = x awa = math.atan(y/x) if (math.copysign(self.previousx, x) != self.previousx or self.flipflag): if (not self.flipflag): self.flipflag = True elif (math.copysign(self.previousx, x) != self.previousx): self.flipflag = False print(str(self.previousx) + ", " + str(x)) if(awa > 0): awa -= math.pi else: awa += math.pi awa = math.degrees(awa) awa -= self.arduinoData.hog awa = standardcalc.boundTo180(awa) self.previousx = x else: awa = standardcalc.boundTo180(standardcalc.boundTo360(STATIC_AWA)-standardcalc.boundTo180(self.arduinoData.hog)) self.arduinoData.awa = standardcalc.boundTo180(awa)
def testLessThanNegative360More(self): self.assertEqual(standardcalc.boundTo360(self.num7), self.num7bounded)
def testGreaterThan360ToAbove180(self): self.assertEqual(standardcalc.boundTo360(self.num5), self.num5bounded)
def testGreaterThan360(self): self.assertEqual(standardcalc.boundTo360(self.num4), self.num4bounded)
def testLessThan180(self): self.assertEqual(standardcalc.boundTo360(self.num3), self.num3bounded)
def testNoChange(self): self.assertEqual(standardcalc.boundTo360(self.num1), self.num1bounded)