Skip to content

Commit

Permalink
Moved or deleted deprecated code, added support for signal recognitio…
Browse files Browse the repository at this point in the history
…n, integrated the code for thermistors and motor control in the sound card driver and updated the communications controller to the newest configurations that do not require Uplink
  • Loading branch information
dyka3773 committed Dec 13, 2023
1 parent 50baf8c commit 80eef5f
Show file tree
Hide file tree
Showing 23 changed files with 382 additions and 812 deletions.
3 changes: 2 additions & 1 deletion Rocket/app/Camera/CameraController.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ async def run_camera_cycle(starting_time: float):
try:
threading.Thread(
target=start_recording,
args=(record_for,)
args=(record_for,),
daemon=True
).start()
except Exception:
logging.error("An Error has occured in the Camera Driver")
Expand Down
10 changes: 4 additions & 6 deletions Rocket/app/Camera/camera_driver.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import eBUS as eb
import lib.PvSampleUtils as psu
import logging
import numpy as np
import time
import os
from datetime import datetime

import Camera.lib.PvSampleUtils as psu

logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(levelname)s - %(module)s:%(lineno)d - %(message)s',
Expand Down Expand Up @@ -142,9 +143,6 @@ def acquire_images_for(device: eb.PvDevice, stream: eb.PvStream, record_for: int
device.StreamEnable()
start.Execute() # type: ignore

# Acquire images until the user instructs us to stop.
logging.info("\n<press a key to stop streaming>")

time_when_started = time.perf_counter()

while (time.perf_counter() - time_when_started < record_for):
Expand All @@ -161,15 +159,15 @@ def acquire_images_for(device: eb.PvDevice, stream: eb.PvStream, record_for: int
_, frame_rate_val = frame_rate.GetValue() # type: ignore
_, bandwidth_val = bandwidth.GetValue() # type: ignore

logging.info(f"BlockID: {pvbuffer.GetBlockID()}")
logging.debug(f"BlockID: {pvbuffer.GetBlockID()}")

payload_type: eb.PvPayloadType = pvbuffer.GetPayloadType()

# Only process data if the payload type is image
if payload_type == eb.PvPayloadTypeImage:
image: eb.PvImage = pvbuffer.GetImage()
image_data: np.ndarray = image.GetDataPointer()
logging.info(
logging.debug(
f" W: {image.GetWidth()} H: {image.GetHeight()}")

if opencv_is_available:
Expand Down
181 changes: 17 additions & 164 deletions Rocket/app/DataStorage.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ def _create_db(self):
with sqlite.connect(self.db_filename, timeout=10) as db:
db.executescript('''
DROP TABLE IF EXISTS ROCKET_DATA;
DROP TABLE IF EXISTS MODE;
-- TODO: Add contraints in the values of the columns where needed
Expand All @@ -50,27 +49,16 @@ def _create_db(self):
motor_speed INTEGER, -- The speed of the motor in (rpm?)
sound_card_status INTEGER, -- The status of the sound card. Possible values: 0 = OFF, 1 = ON, 2 = RECORDING, 3 = ERROR
camera_status INTEGER, -- The status of the camera. Possible values: 0 = OFF, 1 = ON, 2 = RECORDING, 3 = ERROR
cell_heater_status BOOLEAN, -- The status of the cell heater. Possible values: 0 = OFF, 1 = ON
electronics_heater_status BOOLEAN, -- The status of the electronics heater. Possible values: 0 = OFF, 1 = ON
temp_1 REAL, -- The temperature of the first sensor in (Celsius?)
temp_2 REAL, -- The temperature of the second sensor in (Celsius?)
-- Add sensors here if needed
pressure_1 REAL, -- The pressure of the first sensor in (atm?)
pressure_2 REAL, -- The pressure of the second sensor in (atm?)
temp_3 REAL, -- The temperature of the sound card sensor in (Kelvin)
-- Add sensors here if needed
LO_signal BOOLEAN, -- The status of the LO signal. Possible values: 0 = OFF, 1 = ON
SOE_signal BOOLEAN, -- The status of the SOE signal. Possible values: 0 = OFF, 1 = ON
SODS_signal BOOLEAN, -- The status of the SODS signal. Possible values: 0 = OFF, 1 = ON
PO_signal BOOLEAN, -- The status of the PO signal. Possible values: 0 = OFF, 1 = ON. (It should always be 1)
error_code INTEGER, -- The error code of the system in case of an error. Possible values: TBD
PRIMARY KEY (time)
);
CREATE TABLE MODE (
time DATETIME DEFAULT(STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')),
mode TEXT, -- The mode of the experiment. Possible values: TEST, FLIGHT
PRIMARY KEY (mode, time)
);
);
''')

db.commit()
Expand Down Expand Up @@ -110,29 +98,7 @@ async def save_camera_status(self, camera_status: int):
await sqlu.add_camera_status(cursor, camera_status)
await db.commit()

async def add_cell_heater_status(self, heater_status: bool):
"""Adds the status of the heater to the database.
Args:
heater_status (bool): The status of the heater. Possible values: 0 = OFF, 1 = ON
"""
async with sql.connect(self.db_filename, timeout=10) as db:
cursor = await db.cursor()
await sqlu.add_cell_heater_status(cursor, heater_status)
await db.commit()

async def add_electronics_heater_status(self, heater_status: bool):
"""Adds the status of the heater to the database.
Args:
heater_status (bool): The status of the heater. Possible values: 0 = OFF, 1 = ON
"""
async with sql.connect(self.db_filename, timeout=10) as db:
cursor = await db.cursor()
await sqlu.add_electronics_heater_status(cursor, heater_status)
await db.commit()

async def _save_temperature_of_sensor(self, temp: float, sensor_num: int):
async def save_temperature_of_sensor(self, temp: float, sensor_num: int):
"""Adds the temperature of a specified sensor to the database.
Args:
Expand All @@ -144,18 +110,6 @@ async def _save_temperature_of_sensor(self, temp: float, sensor_num: int):
await sqlu.add_temp_to_sensor(cursor, temp, sensor_num)
await db.commit()

async def _save_pressure_of_sensor(self, pressure: float, sensor_num: int):
"""Adds the pressure of a specified sensor to the database.
Args:
pressure (float): The pressure of the sensor to be added to the database.
sensor_num (int): The number of the sensor to be added to the database.
"""
async with sql.connect(self.db_filename, timeout=10) as db:
cursor = await db.cursor()
await sqlu.add_pressure_to_sensor(cursor, pressure, sensor_num)
await db.commit()

async def save_status_of_signal(self, status: bool, signal_name: str):
"""Adds the status of a specified signal to the database.
Expand All @@ -168,6 +122,20 @@ async def save_status_of_signal(self, status: bool, signal_name: str):
await sqlu.add_signal_status(cursor, status, signal_name)
await db.commit()

async def save_signals(self, LO: bool, SOE: bool, SODS: bool):
"""Adds the status of the signals to the database.
Args:
LO (bool): The status of the LO signal. Possible values: True = ON, False = OFF
SOE (bool): The status of the SOE signal. Possible values: True = ON, False = OFF
SODS (bool): The status of the SODS signal. Possible values: True = ON, False = OFF
"""
await asyncio.gather(
self.save_status_of_signal(LO, 'LO'),
self.save_status_of_signal(SOE, 'SOE'),
self.save_status_of_signal(SODS, 'SODS')
)

async def save_error_code(self, error_code: int):
"""Adds the error code of the system to the database.
Expand All @@ -179,22 +147,6 @@ async def save_error_code(self, error_code: int):
await sqlu.add_error_code(cursor, error_code)
await db.commit()

async def save_sensor_data(self, temp_1: float, temp_2: float, press_1: float, press_2: float):
"""Adds the data of the sensors to the database.
Args:
temp_1 (float): The temperature of the first sensor in (Celsius?)
temp_2 (float): The temperature of the second sensor in (Celsius?)
press_1 (float): The pressure of the first sensor in (atm?)
press_2 (float): The pressure of the second sensor in (atm?)
"""
await asyncio.gather(
self._save_temperature_of_sensor(temp_1, 1),
self._save_temperature_of_sensor(temp_2, 2),
self._save_pressure_of_sensor(press_1, 1),
self._save_pressure_of_sensor(press_2, 2),
)

async def get_motor_speed(self) -> int | None:
"""Gets the speed of the motor from the database.
Expand All @@ -221,45 +173,6 @@ async def get_sound_card_status(self) -> int | None:

return status

async def get_camera_status(self) -> int | None:
"""Gets the status of the camera from the database.
Returns:
int: The status of the camera. Possible values: 0 = OFF, 1 = ON, 2 = RECORDING, 3 = ERROR
"""
async with sql.connect(self.db_filename, timeout=10) as db:
cursor = await db.cursor()
status = await sqlu.get_camera_status(cursor)
await db.commit()

return status

async def get_cell_heater_status(self) -> bool | None:
"""Gets the status of the heater from the database.
Returns:
bool: The status of the heater. Possible values: 0 = OFF, 1 = ON
"""
async with sql.connect(self.db_filename, timeout=10) as db:
cursor = await db.cursor()
status = await sqlu.get_cell_heater_status(cursor)
await db.commit()

return status

async def get_electronics_heater_status(self) -> bool | None:
"""Gets the status of the heater from the database.
Returns:
bool: The status of the heater. Possible values: 0 = OFF, 1 = ON
"""
async with sql.connect(self.db_filename, timeout=10) as db:
cursor = await db.cursor()
status = await sqlu.get_electronics_heater_status(cursor)
await db.commit()

return status

async def get_temp_of_sensor_for_the_last_x_secs(self, sensor_num: int, secs_ago: int = 1) -> Iterable[Row] | None:
"""Gets the temperature of a specified sensor from the database.
Expand All @@ -277,38 +190,6 @@ async def get_temp_of_sensor_for_the_last_x_secs(self, sensor_num: int, secs_ago

return temp

async def get_pressure_of_sensor(self, sensor_num: int) -> float | None:
"""Gets the pressure of a specified sensor from the database.
Args:
sensor_num (int): The number of the sensor to get the pressure from.
Returns:
float: The pressure of the specified sensor.
"""
async with sql.connect(self.db_filename, timeout=10) as db:
cursor = await db.cursor()
pressure = await sqlu.get_pressure_of_sensor(cursor, sensor_num)
await db.commit()

return pressure

async def get_status_of_signal(self, signal_name: str) -> bool | None:
"""Gets the status of a specified signal from the database.
Args:
signal_name (str): The name of the signal to get the status from.
Returns:
bool: The status of the specified signal.
"""
async with sql.connect(self.db_filename, timeout=10) as db:
cursor = await db.cursor()
status = await sqlu.get_status_of_signal(cursor, signal_name)
await db.commit()

return status

async def get_error_code(self) -> int | None:
"""Gets the error code of the system from the database.
Expand All @@ -334,31 +215,3 @@ async def get_last_row_of_all_data(self) -> sql.Row | None:
await db.commit()

return data

async def save_mode(self, mode: str):
"""Adds the mode of the experiment to the database.
Args:
mode (str): The mode of the experiment to be added to the database.
"""
async with sql.connect(self.db_filename, timeout=10) as db:
cursor = await db.cursor()
await sqlu.add_mode(cursor, mode)
await db.commit()

async def get_mode(self) -> str:
"""Gets the mode of the experiment from the database.
Returns:
str: The mode of the experiment.
"""
async with sql.connect(self.db_filename, timeout=10) as db:
cursor = await db.cursor()
mode = await sqlu.get_mode(cursor)
await db.commit()

if mode:
return mode
else:
await asyncio.sleep(0.1)
return await self.get_mode()
4 changes: 0 additions & 4 deletions Rocket/app/Enums/ErrorCodesEnum.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,10 @@ class ErrorCodesEnum(Enum):
MOTOR_SPEED_ERROR = 1
SOUND_CARD_ERROR = 2
CAMERA_ERROR = 3
HEATER_ERROR = 4
TEMP_1_ERROR = 5
PRESSURE_1_ERROR = 6
TEMP_2_ERROR = 7
PRESSURE_2_ERROR = 8
UNKNOWN_ERROR = 9
OVERHEAT_ERROR = 10
OVERPRESSURE_ERROR = 11
TEMP_SENSOR_NULL_ERROR = 12
CONNECTION_ERROR = 13

Expand Down
8 changes: 8 additions & 0 deletions Rocket/app/Enums/MotorSpeedsEnum.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,11 @@ class MotorSpeedsEnum(Enum):

STOP = 0
FULL_SPEED = 255


class MotorPWMSpeeds(Enum):
"""An enum to store the motor_util speeds."""

STOP = 65535
HALF_SPEED = 32768
FULL_SPEED = 0
4 changes: 2 additions & 2 deletions Rocket/app/Enums/PinsEnum.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class PinsEnum(Enum):
"""An enum to store the pins used in the Jetson Nano."""

LO = 11 # FIXME: Change this later
SOE = 12 # FIXME: Change this later
SODS = 13 # FIXME: Change this later
SOE = 13 # FIXME: Change this later
SODS = 15 # FIXME: Change this later
UART_TX = 8 # These will not be used by the code but it's nice to have them for reference
UART_RX = 10 # These will not be used by the code but it's nice to have them for reference
Loading

0 comments on commit 80eef5f

Please sign in to comment.