Skip to content

Commit

Permalink
Fixed flat earth bollocks
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander James Wallar committed Jan 27, 2014
1 parent 099454a commit 4aed4ce
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 65 deletions.
18 changes: 9 additions & 9 deletions app/Locabean/res/layout/activity_node.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,6 @@
android:layout_marginBottom="27dp"
android:text="@string/send" />

<Button
android:id="@+id/btnStop"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/btnSend"
android:layout_centerHorizontal="true"
android:layout_marginBottom="26dp"
android:text="@string/stop" />

<Button
android:id="@+id/btnStart"
android:layout_width="match_parent"
Expand Down Expand Up @@ -94,4 +85,13 @@
android:text="@string/averageSPL"
android:textAppearance="?android:attr/textAppearanceLarge" />

<Button
android:id="@+id/btnStop"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/btnSend"
android:layout_centerHorizontal="true"
android:layout_marginBottom="29dp"
android:text="@string/stop" />

</RelativeLayout>
5 changes: 1 addition & 4 deletions locaudio/detectionserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,7 @@ def get_position_viewer(sound_name):
ret_list.append(
{
"confidence": round(location.confidence, 3),
"position": Point(
round(location.position.x, 3),
round(location.position.y, 3)
)
"position": location.position
}
)

Expand Down
53 changes: 27 additions & 26 deletions locaudio/triangulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
MAX_RADIUS_INC = 10
MIN_RADIUS_INC = -10
RADIUS_STEP = 1
EARTH_RADIUS = 1000 * 6371


def distance_from_sound(r_ref, l_ref, l_current):
Expand All @@ -63,10 +64,6 @@ def distance_from_sound(r_ref, l_ref, l_current):
return r_ref * math.pow(10, (l_ref - l_current) / float(20))


def meters_to_lat_lng_dist(meters):
return meters / float(111 * 1000)


def distance_from_detection_event(x, y, node_event):
"""
Expand All @@ -86,20 +83,24 @@ def distance_from_detection_event(x, y, node_event):
"""

earth_radius = 6373 * 1000
degrees_to_radians = math.pi / 180.0
lat1 = math.radians(x)
lon1 = math.radians(y)
lat2 = math.radians(node_event.x)
lon2 = math.radians(node_event.y)

phi1 = (90.0 - x) * degrees_to_radians
phi2 = (90.0 - node_event.x) * degrees_to_radians
dlon = lon2 - lon1
dlat = lat2 - lat1

theta1 = y * degrees_to_radians
theta2 = node_event.y * degrees_to_radians
a = (
(math.sin(dlat / 2)) ** 2 +
math.cos(lat1) * math.cos(lat2) * (math.sin(dlon / 2)) ** 2
)

cos = (math.sin(phi1) * math.sin(phi2) * math.cos(theta1 - theta2) +
math.cos(phi1) * math.cos(phi2))
arc = math.acos(cos)
c = 2 * math.atan2(math.sqrt(a), math.sqrt(1 - a))

return earth_radius * arc
distance = EARTH_RADIUS * c

return distance


def normal_distribution(x):
Expand Down Expand Up @@ -186,12 +187,8 @@ def position_evaluation(x, y, r_ref, l_ref, node_events):
[
normal_distribution(
(
meters_to_lat_lng_dist(
distance_from_detection_event(x, y, n)
) -
meters_to_lat_lng_dist(
distance_from_sound(r_ref, l_ref, n.spl)
)
distance_from_detection_event(x, y, n) -
distance_from_sound(r_ref, l_ref, n.spl)
) / n.get_std()
) / n.get_std() for n in node_events
]
Expand Down Expand Up @@ -450,10 +447,13 @@ def plot_detection_events(res, r_ref, l_ref, d_events, filename):
ax = fig.add_subplot(111)
ax.set_xlabel("X Location")
ax.set_ylabel("Y Location")
v_min = -10
v_max = 10
v_step = 0.1
x = y = np.arange(v_min, v_max, v_step)
x_min = 56.3399
x_max = 56.3400
y_min = -2.80834
y_max = -2.80824
v_step = 0.000001
x = np.arange(x_min, x_max, v_step)
y = np.arange(y_min, y_max, v_step)
X, Y = np.meshgrid(x, y)

zs = np.array(
Expand All @@ -464,8 +464,6 @@ def plot_detection_events(res, r_ref, l_ref, d_events, filename):
)

Z = zs.reshape(X.shape)
ax.set_xlim(v_min, v_max)
ax.set_ylim(v_min, v_max)
ax.pcolormesh(X, Y, Z, cmap=cm.jet)
ax.scatter(
[p.position.x for p in res],
Expand All @@ -483,6 +481,9 @@ def plot_detection_events(res, r_ref, l_ref, d_events, filename):
s=300
)

ax.set_xlim(x_min, x_max)
ax.set_ylim(y_min, y_max)

plt.savefig(filename)
return plt

Expand Down
7 changes: 4 additions & 3 deletions run.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@

import locaudio
import sys

import socket

if __name__ == "__main__":
if len(sys.argv) == 3:
locaudio.config.run(sys.argv[1], sys.argv[2])
elif len(sys.argv) == 0:
locaudio.config.run("localhost", 8000)
elif len(sys.argv) == 1:
ip_addr = socket.gethostbyname(socket.getfqdn())
locaudio.config.run(ip_addr, 8000)
else:
raise Exception("Correct argument form not supplied")

7 changes: 0 additions & 7 deletions tests/config.json

This file was deleted.

36 changes: 20 additions & 16 deletions tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
import json
import locaudio.db as db
import locaudio.api as api
import socket


server_addr = "192.168.1.9"
server_addr = socket.gethostbyname(socket.getfqdn())
server_port = 8000

test_sound_name = "Cock"
Expand All @@ -24,31 +25,31 @@

d_dicts = [
{
"x": -9,
"y": -1,
"spl": 83,
"x": 56.3399723,
"y": -2.8082881,
"spl": 65,
"timestamp": time.time(),
"fingerprint": f_print
},
{
"x": -2,
"y": 1,
"spl": 97,
"timestamp": time.time() - 7,
"x": 56.3399723,
"y": -2.8082881,
"spl": 65,
"timestamp": time.time() - 1,
"fingerprint": f_print
},
{
"x": 1,
"y": 3,
"spl": 86,
"timestamp": time.time() - 10,
"x": 56.3399723,
"y": -2.8082881,
"spl": 65,
"timestamp": time.time(),
"fingerprint": f_print
},
{
"x": 0,
"y": -1,
"spl": 100,
"timestamp": time.time() - 5,
"x": 56.3399723,
"y": -2.8082881,
"spl": 65,
"timestamp": time.time(),
"fingerprint": f_print
}
]
Expand Down Expand Up @@ -77,5 +78,8 @@ def test_names(self):

if __name__ == "__main__":
print "\n=== Server Testing ===\n"
global server_addr
if len(sys.argv) == 2:
server_addr = sys.argv[1]
unittest.main()

0 comments on commit 4aed4ce

Please sign in to comment.