Skip to content

Commit

Permalink
Merge branch 'bench-test'
Browse files Browse the repository at this point in the history
# Conflicts:
#	Rocket/app/SoundCard/SoundCardController.py
#	Rocket/app/SoundCard/motor_driver.py
#	Rocket/app/utils/data_handling_utils.py
  • Loading branch information
dyka3773 committed Jan 24, 2024
2 parents 2edbbaf + 2d28f22 commit 377e0c3
Show file tree
Hide file tree
Showing 21 changed files with 637 additions and 567 deletions.
8 changes: 5 additions & 3 deletions Ground Station/dropstar_gui/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,15 @@ async def status() -> Tuple[Mapping[str, str | int | None], int]:
Returns a tuple containing the status and the HTTP status code.
"""

motor_speed, sound_card_status, camera_status, LO, SOE, SODS, error_code = await asyncio.gather(
motor_speed, sound_card_status, camera_status, LO, SOE, SODS, error_code, led_status = await asyncio.gather(
experiment_status.get_motor_speed(),
experiment_status.get_sound_card_status(),
experiment_status.get_camera_status(),
experiment_status.get_LO_signal(),
experiment_status.get_SOE_signal(),
experiment_status.get_SODS_signal(),
experiment_status.get_errors()
experiment_status.get_errors(),
experiment_status.get_led_status()
)

status = {
Expand All @@ -66,7 +67,8 @@ async def status() -> Tuple[Mapping[str, str | int | None], int]:
'LO_status': LO,
'SOE_status': SOE,
'SODS_status': SODS,
'errors': error_code
'errors': error_code,
'led_status': led_status
}
return status, 200

Expand Down
23 changes: 12 additions & 11 deletions Ground Station/dropstar_gui/controllers/figures.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from cProfile import label
import io
import numpy as np
import matplotlib
import asyncio
import logging

from matplotlib import pyplot as plt

Expand All @@ -11,6 +10,8 @@

matplotlib.use('agg')

logging.basicConfig(level=logging.INFO,
format='%(asctime)s - %(levelname)s - %(message)s')

FIGURES = ["temperature", "pressure"]

Expand All @@ -23,25 +24,25 @@ async def get_temp_plot(img: io.BytesIO) -> None:
"""
time_range_of_plot = 60 # This value determines the time range of the plot

sensor1, sensor2, sensor3 = await asyncio.gather(
sensor1_data, sensor2_data, sensor3_data = await asyncio.gather(
get_temperature("sensor1", time_range_of_plot),
get_temperature("sensor2", time_range_of_plot),
get_temperature("sensor3", time_range_of_plot)
)

# FIXME: This can probably be done in one line for every sensor so that we don't have to repeat the code
x_1 = [i/3 for i in range(len(sensor1))]
x_2 = [i/3 for i in range(len(sensor2))]
x_3 = [i/3 for i in range(len(sensor3))]

figure, ax = plt.subplots()

ax.plot(x_1, sensor1, label="Sensor 1")
ax.plot(x_2, sensor2, label="Sensor 2")
ax.plot(x_3, sensor3, label="Sensor 3")
logging.debug(f"Sensor 1 data: {sensor1_data}")
logging.debug(f"Sensor 2 data: {sensor2_data}")
logging.debug(f"Sensor 3 data: {sensor3_data}")

ax.plot(*sensor1_data, label="Right Sensor")
ax.plot(*sensor2_data, label="Left Sensor")
ax.plot(*sensor3_data, label="Sound Card")
ax.set_title("Temperature Plot")
ax.set_xlabel("Time (s)")
ax.set_ylabel("Temperature (C)")
ax.legend()
ax.grid()
figure.savefig(img, format='png')
plt.close(figure)
Expand Down
61 changes: 50 additions & 11 deletions Ground Station/dropstar_gui/controllers/status.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import aiosqlite as sql
import logging
import datetime

logging.basicConfig(level=logging.INFO,
format='%(asctime)s - %(levelname)s - %(message)s')
Expand Down Expand Up @@ -57,15 +58,15 @@ async def get_camera_status() -> bool:
return status


async def get_temperature(sensor: str, time: int) -> list[int]:
async def get_temperature(sensor: str, time: int) -> tuple[list[int], list[float]]:
"""Gets the temperature from the db.
Args:
sensor (str): The sensor from which the temperature will be read.
time (int): The time for which the temperature will be read.
Returns:
list: The temperature values for the given time.
tuple[list[float], list[float]]: A list of tuples containing the time and temperature.
"""
async with sql.connect('file:GS_data.db?mode=ro', timeout=10, isolation_level=None, uri=True) as db:
if sensor == 'sensor1':
Expand All @@ -77,22 +78,41 @@ async def get_temperature(sensor: str, time: int) -> list[int]:
else:
raise ValueError('Invalid sensor name')

results = await db.execute(f'''SELECT {col}
# This query gets the last 180 temperature readings which we assume is about 1 minute of data because we have 3.3 Hz sampling rate
results = await db.execute(f'''SELECT time, {col}
FROM GS_data
WHERE time >= DATETIME('now', '-{time} seconds')
WHERE {col} IS NOT NULL
ORDER BY time DESC
LIMIT 180
''')
temperature = await results.fetchall()
time_to_temperature = await results.fetchall() # This is a list of tuples

temp_list = [x for (x,) in temperature]
temp_list.reverse()
# I need to convert the list of tuples into a tuple of lists
# I think this is returning a tuple of tuples instead of a tuple of lists but I'm not sure
temp_tuple = tuple(zip(*time_to_temperature))
if len(temp_tuple) == 0:
return ([], [])

logging.debug(f'Got temperature: {temp_list}')
temp_tuple = (list(temp_tuple[0]), list(temp_tuple[1]))

if len(temp_list) == 0:
temp_list = [-1]
# I need to reverse the lists so that the time is in ascending order
temp_tuple[0].reverse()
temp_tuple[1].reverse()

return temp_list
returned_times = []
returned_temps = []

for time_before_format, temp in zip(temp_tuple[0], temp_tuple[1]):
formated_time = datetime.datetime.strptime(
time_before_format, '%Y-%m-%d %H:%M:%S.%f')
returned_times.append(formated_time)
returned_temps.append(temp)

temp_tuple = (returned_times, returned_temps)

logging.debug(f'Got times: {temp_tuple[0]}')
logging.debug(f'Got temperatures: {temp_tuple[1]}')
return temp_tuple # type: ignore


async def get_LO_signal() -> bool:
Expand Down Expand Up @@ -169,3 +189,22 @@ async def get_errors() -> int | None:
error_code = None

return error_code


async def get_led_status() -> int | None:
"""Gets the led status from the db.
Returns:
int: The led status.
"""
async with sql.connect('file:GS_data.db?mode=ro', timeout=10, isolation_level=None, uri=True) as db:
result = db.execute(
'SELECT led_status FROM GS_data ORDER BY time DESC LIMIT 1')
status = await result
status = await status.fetchone()
try:
status = status[0] # type: ignore
except TypeError:
status = None

return status
110 changes: 48 additions & 62 deletions Ground Station/dropstar_gui/static/js/utilities.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
function setMotorStatus(motor, speed){
if (speed == 0){
$(motor).html(`Stopped \t\t (${speed})`)
function setMotorStatus(motor, status){
if (status == 0){
$(motor).html("OFF")
$(motor).removeClass()
$(motor).addClass("text-danger")
}
else if (speed == 255){
$(motor).html(`Max Speed \t\t (${speed})`)
else if (status == 1){
$(motor).html("ON")
$(motor).removeClass()
$(motor).addClass("text-success")
}
else if (speed > 0){
$(motor).html(`Speed Up \t\t (${speed})`)
$(motor).removeClass()
// $(motor).addClass("text-primary") // This is the default color which is blue
}
else {
$(motor).html(`Error \t\t (${speed})`)
$(motor).html(`Error \t\t (${status})`)
$(motor).removeClass()
$(motor).addClass("text-warning")
$(motor).addClass("text-dark")
}
}

function setSoundCardStatus(soundCard, status){
if (status == false){
$(soundCard).html("OFF")
if (status == 0){
$(soundCard).html("FINISHED")
$(soundCard).removeClass()
$(soundCard).addClass("text-danger")
}
else if (status == true){
$(soundCard).html("ON")
else if (status == 1){
$(soundCard).html("ON / IVED OFF")
$(soundCard).removeClass()
$(soundCard).addClass("text-primary") // This is the default color which is blue
}
else if (status == 2){
$(soundCard).html("ON / IVED RECORDING")
$(soundCard).removeClass()
$(soundCard).addClass("text-success")
}
Expand All @@ -42,13 +42,18 @@ function setSoundCardStatus(soundCard, status){
}

function setCameraStatus(camera, status){
if (status == false){
$(camera).html("OFF")
if (status == 0){
$(camera).html("FINISHED")
$(camera).removeClass()
$(camera).addClass("text-danger")
}
else if (status == true){
$(camera).html("ON")
else if (status == 1){
$(camera).html("ON / STANDBY")
$(camera).removeClass()
$(camera).addClass("text-primary")
}
else if (status == 2){
$(camera).html("RECORDING")
$(camera).removeClass()
$(camera).addClass("text-success")
}
Expand All @@ -60,60 +65,41 @@ function setCameraStatus(camera, status){
}
}

function setLOStatus(lo, status){
if (status == false){
$(lo).html("OFF")
$(lo).removeClass()
$(lo).addClass("text-danger")
}
else if (status == true){
$(lo).html("ON")
$(lo).removeClass()
$(lo).addClass("text-success")
}
else {
$(lo).html(`Error \t\t (${status})`)
$(lo).removeClass()
$(lo).addClass("text-warning")
$(lo).addClass("text-dark")
function setLEDStatus(led, status){
if (status == 0){
$(led).html("OFF")
$(led).removeClass()
$(led).addClass("text-danger")
}
}

function setSOEStatus(soe, status){
if (status == false){
$(soe).html("OFF")
$(soe).removeClass()
$(soe).addClass("text-danger")
}
else if (status == true){
$(soe).html("ON")
$(soe).removeClass()
$(soe).addClass("text-success")
else if (status == 1){
$(led).html("ON")
$(led).removeClass()
$(led).addClass("text-success")
}
else {
$(soe).html(`Error \t\t (${status})`)
$(soe).removeClass()
$(soe).addClass("text-warning")
$(soe).addClass("text-dark")
$(led).html(`Error \t\t (${status})`)
$(led).removeClass()
$(led).addClass("text-warning")
$(led).addClass("text-dark")
}
}

function setSODSStatus(sods, status){
function setSignalStatus(element, status){
if (status == false){
$(sods).html("OFF")
$(sods).removeClass()
$(sods).addClass("text-danger")
$(element).html("OFF")
$(element).removeClass()
$(element).addClass("text-danger")
}
else if (status == true){
$(sods).html("ON")
$(sods).removeClass()
$(sods).addClass("text-success")
$(element).html("ON")
$(element).removeClass()
$(element).addClass("text-success")
}
else {
$(sods).html(`Error \t\t (${status})`)
$(sods).removeClass()
$(sods).addClass("text-warning")
$(sods).addClass("text-dark")
$(element).html(`Error \t\t (${status})`)
$(element).removeClass()
$(element).addClass("text-warning")
$(element).addClass("text-dark")
}
}

Expand Down
Loading

0 comments on commit 377e0c3

Please sign in to comment.