query the flock-server
This commit is contained in:
parent
262393f58c
commit
0a2ddf3a10
BIN
assets/needle_to_flock.png
Normal file
BIN
assets/needle_to_flock.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 852 B |
@ -108,6 +108,18 @@
|
|||||||
id: to_dest
|
id: to_dest
|
||||||
source: 'assets/needle_to_dest.png'
|
source: 'assets/needle_to_dest.png'
|
||||||
pos_hint: {"center_x": 0.5, "center_y": 0.7}
|
pos_hint: {"center_x": 0.5, "center_y": 0.7}
|
||||||
|
canvas.before:
|
||||||
|
PushMatrix
|
||||||
|
Rotate:
|
||||||
|
angle: app.dbearing
|
||||||
|
axis: 0, 0, 1
|
||||||
|
origin: self.center
|
||||||
|
canvas.after:
|
||||||
|
PopMatrix
|
||||||
|
Image:
|
||||||
|
id: to_flock
|
||||||
|
source: 'assets/needle_to_flock.png'
|
||||||
|
pos_hint: {"center_x": 0.5, "center_y": 0.7}
|
||||||
canvas.before:
|
canvas.before:
|
||||||
PushMatrix
|
PushMatrix
|
||||||
Rotate:
|
Rotate:
|
||||||
|
|||||||
51
main.py
51
main.py
@ -12,12 +12,16 @@ from kivy.uix.image import Image
|
|||||||
from kivy.vector import Vector
|
from kivy.vector import Vector
|
||||||
from kivy.animation import Animation
|
from kivy.animation import Animation
|
||||||
from math import atan2, sin, cos, degrees, floor
|
from math import atan2, sin, cos, degrees, floor
|
||||||
|
import requests
|
||||||
|
|
||||||
from geopy.distance import geodesic
|
from geopy.distance import geodesic
|
||||||
|
|
||||||
from os import path
|
from os import path
|
||||||
import pickle
|
import pickle
|
||||||
|
|
||||||
|
FLOCK_SERVER="http://192.168.0.8:5000"
|
||||||
|
|
||||||
|
|
||||||
class IconButton(ButtonBehavior, Image):
|
class IconButton(ButtonBehavior, Image):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -57,6 +61,7 @@ class FlockompassApp(App):
|
|||||||
session_data = DictProperty()
|
session_data = DictProperty()
|
||||||
needle_angle = NumericProperty(0)
|
needle_angle = NumericProperty(0)
|
||||||
fbearing = NumericProperty(0)
|
fbearing = NumericProperty(0)
|
||||||
|
dbearing = NumericProperty(0)
|
||||||
|
|
||||||
dest_distance = StringProperty("")
|
dest_distance = StringProperty("")
|
||||||
dashboard_dest = StringProperty("")
|
dashboard_dest = StringProperty("")
|
||||||
@ -185,7 +190,12 @@ class FlockompassApp(App):
|
|||||||
self.dest_distance = "Destino: %s\nVel: %0.1f km/h" % (dest_distance,
|
self.dest_distance = "Destino: %s\nVel: %0.1f km/h" % (dest_distance,
|
||||||
self.gps_data['speed'] * 1.609344)
|
self.gps_data['speed'] * 1.609344)
|
||||||
|
|
||||||
|
self.session_data.update({'speed': self.gps_data['speed'] * 1.609344,
|
||||||
|
'bearing': self.gps_data['bearing'],
|
||||||
|
'lat': self.gps_data['lat'],
|
||||||
|
'lon': self.gps_data['lon']})
|
||||||
|
|
||||||
|
|
||||||
def center_map_on_gps(self):
|
def center_map_on_gps(self):
|
||||||
self.ms.ids.mapview.center_on(self.gps_data['lat'],
|
self.ms.ids.mapview.center_on(self.gps_data['lat'],
|
||||||
self.gps_data['lon'])
|
self.gps_data['lon'])
|
||||||
@ -227,14 +237,12 @@ class FlockompassApp(App):
|
|||||||
lat2 = self.session_data['dest_lat']
|
lat2 = self.session_data['dest_lat']
|
||||||
lon2 = self.session_data['dest_lon']
|
lon2 = self.session_data['dest_lon']
|
||||||
|
|
||||||
fbearing = atan2(sin(lon2 - lon1) * cos(lat2),
|
dbearing = atan2(sin(lon2 - lon1) * cos(lat2),
|
||||||
cos(lat1) * sin(lat2)
|
cos(lat1) * sin(lat2)
|
||||||
- sin(lat1) * cos(lat2) * cos(lon2-lon1))
|
- sin(lat1) * cos(lat2) * cos(lon2-lon1))
|
||||||
fbearing = self.needle_angle - degrees(fbearing)
|
dbearing = self.needle_angle - degrees(dbearing)
|
||||||
|
|
||||||
#fbearing = (fbearing + 360) % 360
|
self.cs._anim &= Animation(dbearing=dbearing,
|
||||||
|
|
||||||
self.cs._anim &= Animation(fbearing=fbearing,
|
|
||||||
d=0.1,
|
d=0.1,
|
||||||
t='out_quad')
|
t='out_quad')
|
||||||
|
|
||||||
@ -258,6 +266,37 @@ class FlockompassApp(App):
|
|||||||
self.compass_enable()
|
self.compass_enable()
|
||||||
self.gps_start(1000, 0)
|
self.gps_start(1000, 0)
|
||||||
|
|
||||||
|
def flock_server_register(self):
|
||||||
|
|
||||||
|
register_url = "{server}/register/?dest_lon={dest_lon}&dest_lat={dest_lat}"
|
||||||
|
r = requests.get(register_url.format(server=FLOCK_SERVER,
|
||||||
|
dest_lon=self.session_data['dest_lon'],
|
||||||
|
dest_lat=self.session_data['dest_lat']))
|
||||||
|
out = r.json()
|
||||||
|
|
||||||
|
self.session_data['bike_id'] = out['bike_id']
|
||||||
|
|
||||||
|
|
||||||
|
def flock_server_update(self):
|
||||||
|
update_url = "{server}/update/{bike_id}/?lat={lat}&lon={lon}&speed={speed}&bearing={bearing}"
|
||||||
|
req = requests.get(update_url.format(server=FLOCK_SERVER,
|
||||||
|
bike_id=self.session_data['bike_id'],
|
||||||
|
speed=self.session_data['speed'],
|
||||||
|
bearing=self.session_data['bearing'],
|
||||||
|
lat=self.session_data['lat'],
|
||||||
|
lon=self.session_data['lon']))
|
||||||
|
resp = req.json()
|
||||||
|
self.session_data.update(resp)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def flock(self, dt):
|
||||||
|
if 'bike_id' in self.session_data:
|
||||||
|
self.flock_server_update()
|
||||||
|
else:
|
||||||
|
self.flock_server_register()
|
||||||
|
|
||||||
|
|
||||||
def build(self):
|
def build(self):
|
||||||
|
|
||||||
# start GPS
|
# start GPS
|
||||||
@ -296,7 +335,7 @@ class FlockompassApp(App):
|
|||||||
self.cs._anim1 = None
|
self.cs._anim1 = None
|
||||||
screen_manager.add_widget(self.cs)
|
screen_manager.add_widget(self.cs)
|
||||||
|
|
||||||
#Clock.schedule_interval(self.dump, 2.0)
|
Clock.schedule_interval(self.flock, 20.0)
|
||||||
|
|
||||||
return screen_manager
|
return screen_manager
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user