Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
PYSQUARED_VERSION ?= v2.0.0-alpha-25w29
PYSQUARED_VERSION ?= v2.0.0-alpha-25w31
PYSQUARED ?= git+https://github.com/proveskit/pysquared@$(PYSQUARED_VERSION)
BOARD_MOUNT_POINT ?= ""
BOARD_TTY_PORT ?= ""
Expand Down
2 changes: 1 addition & 1 deletion config.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"battery_voltage": 5.2,
"critical_battery_voltage": 6.6,
"cubesat_name": "Orpheus",
"cubesat_name": "PROVES-",
"current_draw": 240.5,
"debug": true,
"degraded_battery_voltage": 6.6,
Expand Down
2 changes: 1 addition & 1 deletion src/flight-software/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

logger.info(
"Booting",
hardware_version=os.uname().version,
hardware_version=os.uname().version, # type: ignore[attr-defined]
software_version=__version__,
)

Expand Down
206 changes: 38 additions & 168 deletions src/flight-software/repl.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,12 @@
import os
import time

import board
import digitalio

try:
# from board_definitions import proveskit_rp2040_v4 as board
raise ImportError
except ImportError:
import board

try:
from typing import Union
except Exception:
pass

import os

from lib.adafruit_drv2605 import DRV2605 # This is Hacky V5a Devel Stuff###
from lib.adafruit_mcp230xx.mcp23017 import (
MCP23017, # This is Hacky V5a Devel Stuff###
)
from lib.adafruit_mcp9808 import MCP9808 # This is Hacky V5a Devel Stuff###
from lib.adafruit_tca9548a import TCA9548A # This is Hacky V5a Devel Stuff###
from lib.adafruit_veml7700 import VEML7700 # This is Hacky V5a Devel Stuff###

# from lib.pysquared.Big_Data import AllFaces ### This is Hacky V5a Devel Stuff###
from lib.pysquared.beacon import Beacon
Expand All @@ -31,11 +16,13 @@
from lib.pysquared.hardware.busio import _spi_init, initialize_i2c_bus
from lib.pysquared.hardware.digitalio import initialize_pin
from lib.pysquared.hardware.imu.manager.lsm6dsox import LSM6DSOXManager
from lib.pysquared.hardware.light_sensor.manager.veml7700 import VEML7700Manager
from lib.pysquared.hardware.magnetometer.manager.lis2mdl import LIS2MDLManager
from lib.pysquared.hardware.power_monitor.manager.ina219 import INA219Manager
from lib.pysquared.hardware.radio.manager.rfm9x import RFM9xManager
from lib.pysquared.hardware.radio.manager.sx1280 import SX1280Manager
from lib.pysquared.hardware.radio.packetizer.packet_manager import PacketManager
from lib.pysquared.hardware.temperature_sensor.manager.mcp9808 import MCP9808Manager
from lib.pysquared.logger import Logger
from lib.pysquared.nvm.counter import Counter
from lib.pysquared.protos.power_monitor import PowerMonitorProto
Expand All @@ -53,10 +40,17 @@

logger.info(
"Booting",
hardware_version=os.uname().version,
hardware_version=os.uname().version, # type: ignore[attr-defined]
software_version=__version__,
)


def get_temp(sensor):
for i in range(1000):
print(sensor.get_temperature().value)
time.sleep(0.1)


watchdog = Watchdog(logger, board.WDT_WDI)
watchdog.pet()

Expand Down Expand Up @@ -99,6 +93,13 @@
100000,
)

i2c0 = initialize_i2c_bus(
logger,
board.SCL0,
board.SDA0,
100000,
)

sleep_helper = SleepHelper(logger, config, watchdog)

uhf_radio = RFM9xManager(
Expand Down Expand Up @@ -134,53 +135,6 @@
sband_radio,
)


## Initializing the Burn Wire ##
ENABLE_BURN_A = initialize_pin(
logger, board.FIRE_DEPLOY1_A, digitalio.Direction.OUTPUT, True
)
ENABLE_BURN_B = initialize_pin(
logger, board.FIRE_DEPLOY1_B, digitalio.Direction.OUTPUT, True
)


def dumb_burn(duration=5) -> None:
"""
This function is used to test the burn wire.
It will turn on the burn wire for 5 seconds and then turn it off.

Args:
duration (int): The duration to burn for in seconds. Default is 5 seconds.
Returns:
None
"""
ENABLE_BURN_A.value = False
ENABLE_BURN_B.value = False
logger.info("Burn Wire Enabled")
time.sleep(duration)
logger.info("Burn Wire Disabled")
ENABLE_BURN_A.value = True
ENABLE_BURN_B.value = True


## Initializing the Heater ##
def heater_pulse() -> None:
"""
This function is used to turn on the heater.
It will turn on the heater for 5 seconds and then turn it off.

Args:
None
Returns:
None
"""
ENABLE_HEATER.value = False
logger.info("Heater Enabled")
time.sleep(5)
logger.info("Heater Disabled")
ENABLE_HEATER.value = True


## Initialize the MCP23017 GPIO Expander and its pins ##
GPIO_RESET = initialize_pin(
logger, board.GPIO_EXPANDER_RESET, digitalio.Direction.OUTPUT, True
Expand Down Expand Up @@ -218,7 +172,7 @@ def heater_pulse() -> None:
# Face Control Helper Functions
def all_faces_off():
"""
This function turns off all of the faces. Note the load switches are disabled high.
This function turns off all of the faces. Note the load switches are disabled low.
"""
FACE0_ENABLE.value = False
FACE1_ENABLE.value = False
Expand All @@ -229,7 +183,7 @@ def all_faces_off():

def all_faces_on():
"""
This function turns on all of the faces. Note the load switches are enabled low.
This function turns on all of the faces. Note the load switches are enabled high.
"""
FACE0_ENABLE.value = True
FACE1_ENABLE.value = True
Expand All @@ -246,103 +200,26 @@ def all_faces_on():
tca = TCA9548A(i2c1, address=int(0x77))


### This is Hacky V5a Devel Stuff###
class Face:
def __init__(self, add: int, pos: str, tca: TCA9548A, logger: Logger) -> None:
self.tca: TCA9548A = tca
self.address: int = add
self.position: str = pos
self.logger: Logger = logger

# Define sensors based on position using a dictionary lookup instead of if-elif chain
sensor_map: dict[str, tuple[str, ...]] = {
"x+": ("MCP", "VEML", "DRV"),
"x-": ("MCP", "VEML"),
"y+": ("MCP", "VEML", "DRV"),
"y-": ("MCP", "VEML"),
"z-": ("MCP", "VEML", "DRV"),
}

# Use tuple instead of list for immutable data
self.senlist: tuple[str, ...] = sensor_map.get(pos, ())

# Initialize sensor states dict only with needed sensors
self.sensors: dict[str, bool] = {sensor: False for sensor in self.senlist}

# Initialize sensor objects as None
self.mcp: MCP9808 | None = None
self.veml: VEML7700 | None = None
self.drv: DRV2605 | None = None

def sensor_init(self, senlist, address) -> None:
if "MCP" in senlist:
try:
self.mcp = MCP9808(self.tca[address], address=27)
self.sensors["MCP"] = True
except Exception as e:
self.logger.error("Error Initializing Temperature Sensor", e)

if "VEML" in senlist:
try:
self.veml = VEML7700(self.tca[address])
self.sensors["VEML"] = True
except Exception as e:
self.logger.error("Error Initializing Light Sensor", e)

if "DRV" in senlist:
try:
self.drv = DRV2605(self.tca[address])
self.sensors["DRV"] = True
except Exception as e:
self.logger.error("Error Initializing Motor Driver", e)


class AllFaces:
def __init__(self, tca: TCA9548A, logger: Logger) -> None:
self.tca: TCA9548A = tca
self.faces: list[Face] = []
self.logger: Logger = logger

# Create faces using a loop instead of individual variables
positions: list[tuple[str, int]] = [
("y+", 0),
("y-", 1),
("x+", 2),
("x-", 3),
("z-", 4),
]
for pos, addr in positions:
face: Face = Face(addr, pos, tca, self.logger)
face.sensor_init(face.senlist, face.address)
self.faces.append(face)

def face_test_all(self) -> list[list[float]]:
results: list[list[float]] = []
for face in self.faces:
if face:
try:
temp: Union[float, None] = (
face.mcp.temperature if face.sensors.get("MCP") else None # type: ignore
)
light: Union[float, None] = (
face.veml.lux if face.sensors.get("VEML") else None # type: ignore
)
results.append([temp, light]) # type: ignore
except Exception:
results.append([None, None]) # type: ignore
return results


all_faces = AllFaces(tca, logger)
light_sensor0 = VEML7700Manager(logger, tca[0])
light_sensor1 = VEML7700Manager(logger, tca[1])
light_sensor2 = VEML7700Manager(logger, tca[2])
light_sensor3 = VEML7700Manager(logger, tca[3])
light_sensor4 = VEML7700Manager(logger, tca[4])


## Onboard Temp Sensor ##
mcp1 = MCP9808(i2c1, address=30) # Not working for some reason
temp_sensor5 = MCP9808Manager(logger, i2c0, addr=25) # Antenna Board
temp_sensor6 = MCP9808Manager(logger, i2c1, addr=27) # Flight Controller Board
temp_sensor0 = MCP9808Manager(logger, tca[0], addr=27)
temp_sensor1 = MCP9808Manager(logger, tca[1], addr=27)
temp_sensor2 = MCP9808Manager(logger, tca[2], addr=27)
temp_sensor3 = MCP9808Manager(logger, tca[3], addr=27)
temp_sensor4 = MCP9808Manager(logger, tca[4], addr=27)


battery_power_monitor: PowerMonitorProto = INA219Manager(logger, i2c1, 0x40)
solar_power_monitor: PowerMonitorProto = INA219Manager(logger, i2c1, 0x44)

try:
battery_power_monitor: PowerMonitorProto = INA219Manager(logger, i2c1, 0x40)
solar_power_monitor: PowerMonitorProto = INA219Manager(logger, i2c1, 0x44)
except Exception as e:
logger.error("Error Initializing Power Monitors", e)

## Init Misc Pins ##
burnwire_heater_enable = initialize_pin(
Expand All @@ -356,10 +233,3 @@ def face_test_all(self) -> list[list[float]]:
antenna_deployment = BurnwireManager(
logger, burnwire_heater_enable, burnwire1_fire, enable_logic=True
)


## Initialize the MCP23017 GPIO Expander and its pins ##
GPIO_RESET = initialize_pin(
logger, board.GPIO_EXPANDER_RESET, digitalio.Direction.OUTPUT, True
)
mcp2 = MCP23017(i2c1)
Loading