Skip to content

Commit a85cf47

Browse files
ineskhouSystem AdministratorMikefly123jmpollak
authored
Light sensor manager (#6)
* updated versoin of light sensor to include autolux * flipped faces so cube will init + changed faces so they work with current * added degraded battery voltage in config so we can enter the repl * linting solves * Appease the Linter * changed so typecheck passes * Remove file * point to new relese * linter * right release version * Appease the Linter * Fixing the Linter Again * dumbburn * added temp to rpl * trying to appease linter * trying to appease linker p2 * FIX DA LINT * Cleaned Up Burnwire Stuff --------- Co-authored-by: System Administrator <root@macbookpro.lan> Co-authored-by: Michael Pham <61564344+Mikefly123@users.noreply.github.com> Co-authored-by: jmpollak <jmpollak@cpp.edu>
1 parent 657db75 commit a85cf47

File tree

5 files changed

+84
-214
lines changed

5 files changed

+84
-214
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
PYSQUARED_VERSION ?= v2.0.0-alpha-25w29
1+
PYSQUARED_VERSION ?= v2.0.0-alpha-25w31
22
PYSQUARED ?= git+https://github.com/proveskit/pysquared@$(PYSQUARED_VERSION)
33
BOARD_MOUNT_POINT ?= ""
44
BOARD_TTY_PORT ?= ""

config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"battery_voltage": 5.2,
33
"critical_battery_voltage": 6.6,
4-
"cubesat_name": "Orpheus",
4+
"cubesat_name": "PROVES-",
55
"current_draw": 240.5,
66
"debug": true,
77
"degraded_battery_voltage": 6.6,

src/flight-software/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737

3838
logger.info(
3939
"Booting",
40-
hardware_version=os.uname().version,
40+
hardware_version=os.uname().version, # type: ignore[attr-defined]
4141
software_version=__version__,
4242
)
4343

src/flight-software/repl.py

Lines changed: 38 additions & 168 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,12 @@
1+
import os
12
import time
23

4+
import board
35
import digitalio
4-
5-
try:
6-
# from board_definitions import proveskit_rp2040_v4 as board
7-
raise ImportError
8-
except ImportError:
9-
import board
10-
11-
try:
12-
from typing import Union
13-
except Exception:
14-
pass
15-
16-
import os
17-
18-
from lib.adafruit_drv2605 import DRV2605 # This is Hacky V5a Devel Stuff###
196
from lib.adafruit_mcp230xx.mcp23017 import (
207
MCP23017, # This is Hacky V5a Devel Stuff###
218
)
22-
from lib.adafruit_mcp9808 import MCP9808 # This is Hacky V5a Devel Stuff###
239
from lib.adafruit_tca9548a import TCA9548A # This is Hacky V5a Devel Stuff###
24-
from lib.adafruit_veml7700 import VEML7700 # This is Hacky V5a Devel Stuff###
2510

2611
# from lib.pysquared.Big_Data import AllFaces ### This is Hacky V5a Devel Stuff###
2712
from lib.pysquared.beacon import Beacon
@@ -31,11 +16,13 @@
3116
from lib.pysquared.hardware.busio import _spi_init, initialize_i2c_bus
3217
from lib.pysquared.hardware.digitalio import initialize_pin
3318
from lib.pysquared.hardware.imu.manager.lsm6dsox import LSM6DSOXManager
19+
from lib.pysquared.hardware.light_sensor.manager.veml7700 import VEML7700Manager
3420
from lib.pysquared.hardware.magnetometer.manager.lis2mdl import LIS2MDLManager
3521
from lib.pysquared.hardware.power_monitor.manager.ina219 import INA219Manager
3622
from lib.pysquared.hardware.radio.manager.rfm9x import RFM9xManager
3723
from lib.pysquared.hardware.radio.manager.sx1280 import SX1280Manager
3824
from lib.pysquared.hardware.radio.packetizer.packet_manager import PacketManager
25+
from lib.pysquared.hardware.temperature_sensor.manager.mcp9808 import MCP9808Manager
3926
from lib.pysquared.logger import Logger
4027
from lib.pysquared.nvm.counter import Counter
4128
from lib.pysquared.protos.power_monitor import PowerMonitorProto
@@ -53,10 +40,17 @@
5340

5441
logger.info(
5542
"Booting",
56-
hardware_version=os.uname().version,
43+
hardware_version=os.uname().version, # type: ignore[attr-defined]
5744
software_version=__version__,
5845
)
5946

47+
48+
def get_temp(sensor):
49+
for i in range(1000):
50+
print(sensor.get_temperature().value)
51+
time.sleep(0.1)
52+
53+
6054
watchdog = Watchdog(logger, board.WDT_WDI)
6155
watchdog.pet()
6256

@@ -99,6 +93,13 @@
9993
100000,
10094
)
10195

96+
i2c0 = initialize_i2c_bus(
97+
logger,
98+
board.SCL0,
99+
board.SDA0,
100+
100000,
101+
)
102+
102103
sleep_helper = SleepHelper(logger, config, watchdog)
103104

104105
uhf_radio = RFM9xManager(
@@ -134,53 +135,6 @@
134135
sband_radio,
135136
)
136137

137-
138-
## Initializing the Burn Wire ##
139-
ENABLE_BURN_A = initialize_pin(
140-
logger, board.FIRE_DEPLOY1_A, digitalio.Direction.OUTPUT, True
141-
)
142-
ENABLE_BURN_B = initialize_pin(
143-
logger, board.FIRE_DEPLOY1_B, digitalio.Direction.OUTPUT, True
144-
)
145-
146-
147-
def dumb_burn(duration=5) -> None:
148-
"""
149-
This function is used to test the burn wire.
150-
It will turn on the burn wire for 5 seconds and then turn it off.
151-
152-
Args:
153-
duration (int): The duration to burn for in seconds. Default is 5 seconds.
154-
Returns:
155-
None
156-
"""
157-
ENABLE_BURN_A.value = False
158-
ENABLE_BURN_B.value = False
159-
logger.info("Burn Wire Enabled")
160-
time.sleep(duration)
161-
logger.info("Burn Wire Disabled")
162-
ENABLE_BURN_A.value = True
163-
ENABLE_BURN_B.value = True
164-
165-
166-
## Initializing the Heater ##
167-
def heater_pulse() -> None:
168-
"""
169-
This function is used to turn on the heater.
170-
It will turn on the heater for 5 seconds and then turn it off.
171-
172-
Args:
173-
None
174-
Returns:
175-
None
176-
"""
177-
ENABLE_HEATER.value = False
178-
logger.info("Heater Enabled")
179-
time.sleep(5)
180-
logger.info("Heater Disabled")
181-
ENABLE_HEATER.value = True
182-
183-
184138
## Initialize the MCP23017 GPIO Expander and its pins ##
185139
GPIO_RESET = initialize_pin(
186140
logger, board.GPIO_EXPANDER_RESET, digitalio.Direction.OUTPUT, True
@@ -218,7 +172,7 @@ def heater_pulse() -> None:
218172
# Face Control Helper Functions
219173
def all_faces_off():
220174
"""
221-
This function turns off all of the faces. Note the load switches are disabled high.
175+
This function turns off all of the faces. Note the load switches are disabled low.
222176
"""
223177
FACE0_ENABLE.value = False
224178
FACE1_ENABLE.value = False
@@ -229,7 +183,7 @@ def all_faces_off():
229183

230184
def all_faces_on():
231185
"""
232-
This function turns on all of the faces. Note the load switches are enabled low.
186+
This function turns on all of the faces. Note the load switches are enabled high.
233187
"""
234188
FACE0_ENABLE.value = True
235189
FACE1_ENABLE.value = True
@@ -246,103 +200,26 @@ def all_faces_on():
246200
tca = TCA9548A(i2c1, address=int(0x77))
247201

248202

249-
### This is Hacky V5a Devel Stuff###
250-
class Face:
251-
def __init__(self, add: int, pos: str, tca: TCA9548A, logger: Logger) -> None:
252-
self.tca: TCA9548A = tca
253-
self.address: int = add
254-
self.position: str = pos
255-
self.logger: Logger = logger
256-
257-
# Define sensors based on position using a dictionary lookup instead of if-elif chain
258-
sensor_map: dict[str, tuple[str, ...]] = {
259-
"x+": ("MCP", "VEML", "DRV"),
260-
"x-": ("MCP", "VEML"),
261-
"y+": ("MCP", "VEML", "DRV"),
262-
"y-": ("MCP", "VEML"),
263-
"z-": ("MCP", "VEML", "DRV"),
264-
}
265-
266-
# Use tuple instead of list for immutable data
267-
self.senlist: tuple[str, ...] = sensor_map.get(pos, ())
268-
269-
# Initialize sensor states dict only with needed sensors
270-
self.sensors: dict[str, bool] = {sensor: False for sensor in self.senlist}
271-
272-
# Initialize sensor objects as None
273-
self.mcp: MCP9808 | None = None
274-
self.veml: VEML7700 | None = None
275-
self.drv: DRV2605 | None = None
276-
277-
def sensor_init(self, senlist, address) -> None:
278-
if "MCP" in senlist:
279-
try:
280-
self.mcp = MCP9808(self.tca[address], address=27)
281-
self.sensors["MCP"] = True
282-
except Exception as e:
283-
self.logger.error("Error Initializing Temperature Sensor", e)
284-
285-
if "VEML" in senlist:
286-
try:
287-
self.veml = VEML7700(self.tca[address])
288-
self.sensors["VEML"] = True
289-
except Exception as e:
290-
self.logger.error("Error Initializing Light Sensor", e)
291-
292-
if "DRV" in senlist:
293-
try:
294-
self.drv = DRV2605(self.tca[address])
295-
self.sensors["DRV"] = True
296-
except Exception as e:
297-
self.logger.error("Error Initializing Motor Driver", e)
298-
299-
300-
class AllFaces:
301-
def __init__(self, tca: TCA9548A, logger: Logger) -> None:
302-
self.tca: TCA9548A = tca
303-
self.faces: list[Face] = []
304-
self.logger: Logger = logger
305-
306-
# Create faces using a loop instead of individual variables
307-
positions: list[tuple[str, int]] = [
308-
("y+", 0),
309-
("y-", 1),
310-
("x+", 2),
311-
("x-", 3),
312-
("z-", 4),
313-
]
314-
for pos, addr in positions:
315-
face: Face = Face(addr, pos, tca, self.logger)
316-
face.sensor_init(face.senlist, face.address)
317-
self.faces.append(face)
318-
319-
def face_test_all(self) -> list[list[float]]:
320-
results: list[list[float]] = []
321-
for face in self.faces:
322-
if face:
323-
try:
324-
temp: Union[float, None] = (
325-
face.mcp.temperature if face.sensors.get("MCP") else None # type: ignore
326-
)
327-
light: Union[float, None] = (
328-
face.veml.lux if face.sensors.get("VEML") else None # type: ignore
329-
)
330-
results.append([temp, light]) # type: ignore
331-
except Exception:
332-
results.append([None, None]) # type: ignore
333-
return results
334-
335-
336-
all_faces = AllFaces(tca, logger)
203+
light_sensor0 = VEML7700Manager(logger, tca[0])
204+
light_sensor1 = VEML7700Manager(logger, tca[1])
205+
light_sensor2 = VEML7700Manager(logger, tca[2])
206+
light_sensor3 = VEML7700Manager(logger, tca[3])
207+
light_sensor4 = VEML7700Manager(logger, tca[4])
208+
337209

338210
## Onboard Temp Sensor ##
339-
mcp1 = MCP9808(i2c1, address=30) # Not working for some reason
211+
temp_sensor5 = MCP9808Manager(logger, i2c0, addr=25) # Antenna Board
212+
temp_sensor6 = MCP9808Manager(logger, i2c1, addr=27) # Flight Controller Board
213+
temp_sensor0 = MCP9808Manager(logger, tca[0], addr=27)
214+
temp_sensor1 = MCP9808Manager(logger, tca[1], addr=27)
215+
temp_sensor2 = MCP9808Manager(logger, tca[2], addr=27)
216+
temp_sensor3 = MCP9808Manager(logger, tca[3], addr=27)
217+
temp_sensor4 = MCP9808Manager(logger, tca[4], addr=27)
218+
219+
220+
battery_power_monitor: PowerMonitorProto = INA219Manager(logger, i2c1, 0x40)
221+
solar_power_monitor: PowerMonitorProto = INA219Manager(logger, i2c1, 0x44)
340222

341-
try:
342-
battery_power_monitor: PowerMonitorProto = INA219Manager(logger, i2c1, 0x40)
343-
solar_power_monitor: PowerMonitorProto = INA219Manager(logger, i2c1, 0x44)
344-
except Exception as e:
345-
logger.error("Error Initializing Power Monitors", e)
346223

347224
## Init Misc Pins ##
348225
burnwire_heater_enable = initialize_pin(
@@ -356,10 +233,3 @@ def face_test_all(self) -> list[list[float]]:
356233
antenna_deployment = BurnwireManager(
357234
logger, burnwire_heater_enable, burnwire1_fire, enable_logic=True
358235
)
359-
360-
361-
## Initialize the MCP23017 GPIO Expander and its pins ##
362-
GPIO_RESET = initialize_pin(
363-
logger, board.GPIO_EXPANDER_RESET, digitalio.Direction.OUTPUT, True
364-
)
365-
mcp2 = MCP23017(i2c1)

0 commit comments

Comments
 (0)