flock bearing on compass

This commit is contained in:
rgarcia-herrera 2020-08-11 00:27:57 -05:00
parent 82be1ba9e0
commit ab5a918f2c
3 changed files with 28 additions and 2 deletions

View File

@ -73,3 +73,14 @@
origin: self.center origin: self.center
canvas.after: canvas.after:
PopMatrix PopMatrix
Image:
id: to_flock
source: 'needle_to_flock.png'
canvas.before:
PushMatrix
Rotate:
angle: app.fbearing
axis: 0, 0, 1
origin: self.center
canvas.after:
PopMatrix

19
main.py
View File

@ -10,7 +10,7 @@ from kivy.uix.screenmanager import ScreenManager, Screen, RiseInTransition
from kivy.vector import Vector from kivy.vector import Vector
from kivy.animation import Animation from kivy.animation import Animation
from math import floor from math import atan2, sin, cos, degrees, floor
class MapScreen(Screen): class MapScreen(Screen):
@ -26,6 +26,7 @@ class FlockompassApp(App):
gps_data = DictProperty() gps_data = DictProperty()
session_data = DictProperty() session_data = DictProperty()
needle_angle = NumericProperty(0) needle_angle = NumericProperty(0)
fbearing = NumericProperty(0)
def dump(self, dt): def dump(self, dt):
print(dt, self.gps_data, self.session_data) print(dt, self.gps_data, self.session_data)
@ -68,6 +69,18 @@ class FlockompassApp(App):
self.ms.ids.mapview.center_on(self.session_data['dest_lat'], self.ms.ids.mapview.center_on(self.session_data['dest_lat'],
self.session_data['dest_lon']) self.session_data['dest_lon'])
else:
lat1 = self.gps_data['lat']
lon1 = self.gps_data['lon']
lat2 = self.session_data['dest_lat']
lon2 = self.session_data['dest_lon']
self.fbearing = atan2(sin(lon2 - lon1) * cos(lat2),
cos(lat1) * sin(lat2)
- sin(lat1) * cos(lat2) * cos(lon2-lon1))
self.fbearing = self.needle_angle + degrees(self.fbearing)
self.fbearing = (self.fbearing + 360) % 360
def get_field(self, dt): def get_field(self, dt):
needle_angle = 7 needle_angle = 7
@ -88,7 +101,9 @@ class FlockompassApp(App):
# animate the needle # animate the needle
if self.cs._anim: if self.cs._anim:
self.cs._anim.stop(self) self.cs._anim.stop(self)
self.cs._anim = Animation(needle_angle=needle_angle, d=.2, t='out_quad') self.cs._anim = Animation(needle_angle=needle_angle,
d=0.2,
t='out_quad')
self.cs._anim.start(self) self.cs._anim.start(self)
def compass_enable(self): def compass_enable(self):

BIN
needle_to_flock.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB