Skip to content

Commit

Permalink
Merge pull request #413 from ltindall/add_parameters
Browse files Browse the repository at this point in the history
Add parameters to GUI and config ini. Improve GUI readability.
  • Loading branch information
ltindall authored Feb 15, 2024
2 parents 3fe1335 + 52dd87d commit 95b850f
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 56 deletions.
11 changes: 9 additions & 2 deletions birdseye/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,13 @@ def pffilter_copy(pf, n_downsample=None):

class RFMultiSeparableEnv:
def __init__(
self, sensor=None, actions=None, state=None, simulated=True, num_particles=2000
self,
sensor=None,
actions=None,
state=None,
simulated=True,
num_particles=2000,
resample_proportion=0.1,
):
# Sensor definitions
self.sensor = sensor
Expand All @@ -77,6 +83,7 @@ def __init__(
# Flag for simulation vs real data
self.simulated = simulated
self.n_particles = num_particles
self.resample_proportion = resample_proportion

# self.pfrnn = pfrnn()

Expand Down Expand Up @@ -185,7 +192,7 @@ def reset(
),
n_particles=self.n_particles,
dynamics_fn=self.dynamics,
resample_proportion=0.1, # 0.005,
resample_proportion=self.resample_proportion, # 0.1, # 0.005,
noise_fn=lambda x, **kwargs: self.particle_noise(x, sigmas=[1, 2, 2]),
weight_fn=lambda hyp, o, xp=None, **kwargs: self.sensor.weight(hyp, o),
resample_fn=systematic_resample,
Expand Down
5 changes: 2 additions & 3 deletions birdseye/mqtt_fake.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def message_handler(data):
"predictions": {
"mini2_telem": [
{
"rssi": "-40",
"rssi_max": "-60",
"conf": "0.33034399151802063",
"xywh": [
609.8685302734375,
Expand All @@ -47,7 +47,7 @@ def message_handler(data):
],
"mini2_video": [
{
"rssi": "-80",
"rssi_max": "-90",
"conf": "0.33034399151802063",
"xywh": [
609.8685302734375,
Expand All @@ -60,7 +60,6 @@ def message_handler(data):
},
"position": [32.922651, -117.120815],
"heading": 0,
"rssi": [-40, -60],
"gps": "fix",
}
target_data = {
Expand Down
32 changes: 24 additions & 8 deletions birdseye/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,12 +278,28 @@ def plot_map(self, axis1=None, output=None, save_as="resultMap.png"):
# Set axis dimensions, labels and tick marks
axis1.set_xlim(0, int(self.width_meters))
axis1.set_ylim(0, int(self.height_meters))
axis1.set_xlabel("Longitude")
axis1.set_ylabel("Latitude")
axis1.set_xticks(np.linspace(0, int(self.width_meters), num=8))
axis1.set_xticklabels(self.x_ticks, rotation=30, ha="center")
axis1.set_yticks(np.linspace(0, int(self.height_meters), num=8))
axis1.set_yticklabels(self.y_ticks)
axis1.set_xticks(np.linspace(0, int(self.width_meters), num=11))
axis1.set_xticklabels(
np.linspace(
-int(self.width_meters / 2), int(self.width_meters / 2), num=11
),
rotation=0,
ha="center",
)
axis1.set_yticks(np.linspace(0, int(self.height_meters), num=11))
axis1.set_yticklabels(
np.linspace(
-int(self.height_meters / 2), int(self.height_meters / 2), num=11
)
)
axis1.set_xlabel("meters")
axis1.set_ylabel("meters")
# axis1.set_xlabel("Longitude")
# axis1.set_ylabel("Latitude")
# axis1.set_xticks(np.linspace(0, int(self.width_meters), num=8))
# axis1.set_xticklabels(self.x_ticks, rotation=30, ha="center")
# axis1.set_yticks(np.linspace(0, int(self.height_meters), num=8))
# axis1.set_yticklabels(self.y_ticks)
axis1.grid()

# Save or display
Expand Down Expand Up @@ -798,12 +814,12 @@ def live_plot(
data=None,
sidebar=False,
separable=False,
map_distance=200,
map_distance=500,
):
"""
Create a live plot
"""

map_distance /= 2
lines = (
[]
) # https://matplotlib.org/3.5.0/api/_as_gen/matplotlib.pyplot.legend.html
Expand Down
4 changes: 3 additions & 1 deletion geolocate.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ directivity_tx = 1
freq = 5.7e9
fading_sigma = 8
threshold = -120
particle_distance = 250
map_width = 400
n_particles = 3000
resample_proportion = 0.1
#1000
# if defined, use static antenna position and heading.
# static_position = -41.276825,174.777969
Expand Down
61 changes: 26 additions & 35 deletions geolocate.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ def __init__(self, config_path="geolocate.ini"):
"flask_host": "0.0.0.0", # nosec
"flask_port": "4999",
"use_flask": "false",
"map_width": "500",
"n_particles": "3000",
"resample_proportion": "0.1",
}
default_config.update(self.config)
self.config = default_config
Expand Down Expand Up @@ -245,7 +248,7 @@ def data_handler(self, message_data):
# self.data["rssi"] = float(metadata["rssi_mean"])
# self.data["rssi"] = float(metadata["rssi_min"])
# self.data["rssi"] = float(metadata.get["rssi_max"])
pass
self.data["rssi"] = None
else:
self.data["rssi"] = message_data.get("rssi", None)

Expand Down Expand Up @@ -290,7 +293,7 @@ def run_flask(self, flask_host, flask_port, fig, results):
"""
Flask
"""
app = Flask(__name__)
app = Flask(__name__, template_folder="templates", static_folder="static")

@app.route("/gui/<path:filename>")
def gui_file(filename):
Expand All @@ -316,16 +319,24 @@ def refresh():
def gui_form():
if request.method == "POST":
user = request.form.get("name", None)
self.config["n_targets"] = request.form.get(
"n_targets", self.config["n_targets"]
)
form_inputs = [
"n_targets",
"n_particles",
"resample_proportion",
"map_width",
]
for input_name in form_inputs:
self.config[input_name] = request.form.get(
input_name, self.config[input_name]
)
reset = request.form.get("reset", None)
if reset == "reset":
self.stop()
self.image_buf = BytesIO()
self.start()
return redirect(request.referrer)

@app.route("/")
@app.route("/guiFile")
def gui_from_file():
if not self.image_buf.getbuffer().nbytes:
Expand All @@ -338,30 +349,6 @@ def gui_from_buffer():
return render_template("loading.html")
return render_template("gui_from_buffer.html", config=self.config)

@app.route("/")
def index():
flask_start_time = timer()

if not self.image_buf.getbuffer().nbytes:
return render_template("loading.html")

data = base64.b64encode(self.image_buf.getvalue()).decode("ascii")

flask_end_time = timer()

logging.debug("=======================================")
logging.debug("Flask Timing")
logging.debug("time step = %s", str(results.time_step))
logging.debug(
"buffer size = {:.2f} MB".format(len(self.image_buf.getbuffer()) / 1e6)
)
logging.debug(
"Duration = {:.4f} s".format(flask_end_time - flask_start_time)
)
logging.debug("=======================================")

return render_template("birdseye_live.html", data=data)

host_name = flask_host
port = flask_port
self.flask_thread = threading.Thread(
Expand Down Expand Up @@ -447,7 +434,9 @@ def main(self, stopped):
fading_sigma = float(self.config["fading_sigma"])
threshold = float(self.config["threshold"])

particle_distance = float(self.config["particle_distance"])
n_particles = int(self.config["n_particles"])
map_width = float(self.config["map_width"])
resample_proportion = float(self.config["resample_proportion"])

local_plot = self.config["local_plot"].lower()
make_gif = self.config["make_gif"].lower()
Expand All @@ -460,16 +449,17 @@ def main(self, stopped):

# BirdsEye
global_start_time = datetime.utcnow().timestamp()
n_simulations = 100
max_iterations = 400

reward_func = (
lambda pf, **kwargs: pf.weight_entropy
) # lambda *args, **kwargs: None

# REPP/Lavapilot parameters
r_min = 10
horizon = 1 # 8
min_bound = 0.82
min_std_dev = 35
num_particles = 3000 # 3000

step_duration = 1

# Sensor
Expand Down Expand Up @@ -513,7 +503,8 @@ def main(self, stopped):
actions=actions,
state=state,
simulated=False,
num_particles=num_particles,
num_particles=n_particles,
resample_proportion=resample_proportion,
)

belief = env.reset()
Expand Down Expand Up @@ -647,7 +638,7 @@ def main(self, stopped):
data=self.data,
sidebar=False,
separable=True,
map_distance=particle_distance,
map_distance=map_width,
)
# safe image buf
tmp_buf = BytesIO()
Expand Down
6 changes: 6 additions & 0 deletions static/styles/birdseye.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.container {
display: flex; /*sets form and image next to each other*/
/*border-radius: 2%;
padding: 5%;*/
}
23 changes: 16 additions & 7 deletions templates/gui_from_file.html
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
<html>
<head>
<title>BirdsEye</title>
<link rel="stylesheet" type="text/css" href="{{ url_for('static',filename='styles/birdseye.css') }}">
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
</head>
<body>
<img id="map" src="" />
<form action = "{{ url_for('gui_form') }}" method = "post">
<p>Number of targets:</p>
<p><input type = "text" name="n_targets" value="{{ config.n_targets }}"/></p>

<p><button name="reset" type="submit" value="reset">Reset</button></p>
</form>
<div class="container">
<img id="map" src="" />
<form action = "{{ url_for('gui_form') }}" method = "post">
<p>Number of targets:</p>
<p><input type = "text" name="n_targets" value="{{ config.n_targets }}"/></p>
<p>Number of particles:</p>
<p><input type = "text" name="n_particles" value="{{ config.n_particles }}"/></p>
<p>Particle resample proportion:</p>
<p><input type = "text" name="resample_proportion" value="{{ config.resample_proportion }}"/></p>
<p>Map width (meters):</p>
<p><input type = "text" name="map_width" value="{{ config.map_width }}"/></p>

<p><button name="reset" type="submit" value="reset">Reset</button></p>
</form>
</div>
<script>
$(document).ready(function(){
setInterval(refreshFunction, 1000);
Expand Down

0 comments on commit 95b850f

Please sign in to comment.