Skip to content

Commit

Permalink
FC v4c Updates V1.1.1 (#41)
Browse files Browse the repository at this point in the history
* Updated to pet the watchdog

* Create rv3028.py

* Update pysquared_eps.py

* Changed the Boot Count Iter

The boot count now iterates in the pysquared.py rather than in the main.py

* Update pysquared.py

Fixed bug with setting the boot count in NVM before the microcontroller is correctly setup

* Update main.py

Added c.hardware["WDT"] toggle to main

* Update pysquared.py

Added RTC Get/Set Time & Date

* Update code.py

* Ran Linter

---------

Co-authored-by: DeathStar <[email protected]>
Co-authored-by: DeathStar <[email protected]>
  • Loading branch information
3 people authored Oct 16, 2024
1 parent 8ee23f9 commit d3d44d8
Show file tree
Hide file tree
Showing 5 changed files with 465 additions and 111 deletions.
123 changes: 67 additions & 56 deletions Batt_Board/lib/pysquared_eps.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import adafruit_tca9548a # I2C Multiplexer
import adafruit_pct2075 # Temperature Sensor
import adafruit_max31856 # Thermocouple
import adafruit_vl6180x # LiDAR Distance Sensor for Antenna
import adafruit_vl6180x # LiDAR Distance Sensor for Antenna
import adafruit_ina219 # Power Monitor

# CAN Bus Import
Expand Down Expand Up @@ -183,7 +183,6 @@ def __init__(self):
"ERROR INITIALIZING FACES: " + "".join(traceback.format_exception(e))
)


if self.c_boot > 200:
self.c_boot = 0

Expand Down Expand Up @@ -230,13 +229,13 @@ def __init__(self):
self.debug_print(
"[ERROR][SOLAR Power Monitor]" + "".join(traceback.format_exception(e))
)

# Initialize LiDAR
try:
self.LiDAR = adafruit_vl6180x.VL6180X(self.i2c1,offset=0)
self.LiDAR = adafruit_vl6180x.VL6180X(self.i2c1, offset=0)
self.hardware["LiDAR"] = True
except Exception as e:
self.debug_print('[ERROR][LiDAR]' + ''.join(traceback.format_exception(e)))
self.debug_print("[ERROR][LiDAR]" + "".join(traceback.format_exception(e)))

# Define Charge Indicate Pin
self.charge_indicate = digitalio.DigitalInOut(board.CHRG)
Expand Down Expand Up @@ -281,7 +280,7 @@ def __init__(self):
try:
self.spi0cs0 = digitalio.DigitalInOut(board.SPI0_CS0)
self.spi0cs0.switch_to_output()
self.can_bus = CAN(self.spi0, self.spi0cs2, loopback=True, silent=True)
self.can_bus = CAN(self.spi0, self.spi0cs0, loopback=True, silent=True)
self.hardware["CAN"] = True

except Exception as e:
Expand Down Expand Up @@ -633,12 +632,10 @@ def heater_on(self):
self.heater.duty_cycle = 0x7FFF
except Exception as e:
self.debug_print(
"[ERROR] Cant turn on heater: "
+ "".join(traceback.format_exception(e))
"[ERROR] Cant turn on heater: " + "".join(traceback.format_exception(e))
)
self.heater.duty_cycle = 0x0000


def heater_off(self):
if self.hardware["FLD"]:
try:
Expand All @@ -664,18 +661,20 @@ def heater_off(self):
# =======================================================#

def distance(self):
if self.hardware['LiDAR']:
if self.hardware["LiDAR"]:
try:
distance_mm = 0
for _ in range(10):
distance_mm += self.LiDAR.range
time.sleep(0.01)
self.debug_print('distance measured = {0}mm'.format(distance_mm/10))
return distance_mm/10
self.debug_print("distance measured = {0}mm".format(distance_mm / 10))
return distance_mm / 10
except Exception as e:
self.debug_print('LiDAR error: ' + ''.join(traceback.format_exception(e)))
self.debug_print(
"LiDAR error: " + "".join(traceback.format_exception(e))
)
else:
self.debug_print('[WARNING] LiDAR not initialized')
self.debug_print("[WARNING] LiDAR not initialized")
return 0

def burn(self, burn_num, dutycycle=0, freq=1000, duration=1):
Expand Down Expand Up @@ -735,7 +734,7 @@ def burn(self, burn_num, dutycycle=0, freq=1000, duration=1):
burnwire.deinit()
self._relayA.drive_mode = digitalio.DriveMode.OPEN_DRAIN

def smart_burn(self,burn_num,dutycycle=0.1):
def smart_burn(self, burn_num, dutycycle=0.1):
"""
Operate burn wire circuits. Wont do anything unless the a nichrome burn wire
has been installed.
Expand All @@ -751,107 +750,119 @@ def smart_burn(self,burn_num,dutycycle=0.1):

freq = 1000

distance1=0
distance2=0
#self.dist=self.distance()
distance1 = 0
distance2 = 0
# self.dist=self.distance()

try:
# convert duty cycle % into 16-bit fractional up time
dtycycl=int((dutycycle/100)*(0xFFFF))
self.debug_print('----- SMART BURN WIRE CONFIGURATION -----')
self.debug_print('\tFrequency of: {}Hz\n\tDuty cycle of: {}% (int:{})'.format(freq,(100*dtycycl/0xFFFF),dtycycl))
dtycycl = int((dutycycle / 100) * (0xFFFF))
self.debug_print("----- SMART BURN WIRE CONFIGURATION -----")
self.debug_print(
"\tFrequency of: {}Hz\n\tDuty cycle of: {}% (int:{})".format(
freq, (100 * dtycycl / 0xFFFF), dtycycl
)
)
# create our PWM object for the respective pin
# not active since duty_cycle is set to 0 (for now)
if '1' in burn_num:
if "1" in burn_num:
burnwire = pwmio.PWMOut(board.ENABLE_BURN, frequency=freq, duty_cycle=0)
else:
return False


try:
distance1=self.distance()
distance1 = self.distance()
self.debug_print(str(distance1))
if distance1 > self.dist+2 and distance1 > 4 or self.f_triedburn == True:
if (
distance1 > self.dist + 2
and distance1 > 4
or self.f_triedburn == True
):
self.burned = True
self.f_brownout = True
raise TypeError("Wire seems to have burned and satellite browned out")
raise TypeError(
"Wire seems to have burned and satellite browned out"
)
else:
self.dist=int(distance1)
self.burnarm=True
self.dist = int(distance1)
self.burnarm = True
if self.burnarm:
self.burnarm=False
self.burnarm = False
self.f_triedburn = True

# Configure the relay control pin & open relay
self.RGB=(0,165,0)
self.RGB = (0, 165, 0)

self._relayA.drive_mode=digitalio.DriveMode.PUSH_PULL
self.RGB=(255,165,0)
self._relayA.drive_mode = digitalio.DriveMode.PUSH_PULL
self.RGB = (255, 165, 0)
self._relayA.value = 1

# Pause to ensure relay is open
time.sleep(0.5)

#Start the Burn
burnwire.duty_cycle=dtycycl
# Start the Burn
burnwire.duty_cycle = dtycycl

#Burn Timer
# Burn Timer
start_time = time.monotonic()

#Monitor the burn
# Monitor the burn
while not self.burned:
distance2=self.distance()
distance2 = self.distance()
self.debug_print(str(distance2))
if distance2 > distance1+1 or distance2 > 10:
if distance2 > distance1 + 1 or distance2 > 10:
self._relayA.value = 0
burnwire.duty_cycle = 0
self.burned=True
self.burned = True
self.f_triedburn = False
else:
distance1=distance2
distance1 = distance2
time_elapsed = time.monotonic() - start_time
print("Time Elapsed: " + str(time_elapsed))
if time_elapsed > 4:
self._relayA.value = 0
burnwire.duty_cycle = 0
self.burned=False
self.RGB=(0,0,255)
self.burned = False
self.RGB = (0, 0, 255)
time.sleep(10)
self.f_triedburn = False
break

time.sleep(5)
distance2=self.distance()
distance2 = self.distance()
else:
pass
if distance2 > distance1+2 or distance2 > 10:
self.burned=True
if distance2 > distance1 + 2 or distance2 > 10:
self.burned = True
self.f_triedburn = False
except Exception as e:
self.debug_print("Error in Burn Sequence: " + ''.join(traceback.format_exception(e)))
self.debug_print(
"Error in Burn Sequence: " + "".join(traceback.format_exception(e))
)
self.debug_print("Error: " + str(e))
if "no attribute 'LiDAR'" in str(e):
self.debug_print("Burning without LiDAR")
time.sleep(120) #Set to 120 for flight
self.burnarm=False
self.burned=True
self.f_triedburn=True
self.burn("1",dutycycle,freq,4)
time.sleep(120) # Set to 120 for flight
self.burnarm = False
self.burned = True
self.f_triedburn = True
self.burn("1", dutycycle, freq, 4)
time.sleep(5)

finally:
self._relayA.value = 0
burnwire.duty_cycle=0
self.RGB=(0,0,0)
burnwire.duty_cycle = 0
self.RGB = (0, 0, 0)
burnwire.deinit()
self._relayA.drive_mode=digitalio.DriveMode.OPEN_DRAIN
self._relayA.drive_mode = digitalio.DriveMode.OPEN_DRAIN

return True
except Exception as e:
self.debug_print("Error with Burn Wire: " + ''.join(traceback.format_exception(e)))
self.debug_print(
"Error with Burn Wire: " + "".join(traceback.format_exception(e))
)
return False



print("Initializing Power Management Systems...")
cubesat = Satellite()
14 changes: 8 additions & 6 deletions FC_Board/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,23 @@

"""
Built for the PySquared FC Board
Version: 1.0.1 (Beta)
Published: July 26, 2024
Version: 1.1.1 (Beta)
Published: October 15, 2024
"""

import time

print("=" * 70)
print("Hello World!")
print("PySquared FC Board Circuit Python Software Version: 1.0.1 (Beta)")
print("Published: July 26, 2024")
print("PySquared FC Board Circuit Python Software Version: 1.1.1 (Beta)")
print("Published: October 15, 2024")
print("=" * 70)

loiter_time = 5

try:
for i in range(10):
print(f"Code Starting in {10-i} seconds")
for i in range(loiter_time):
print(f"Code Starting in {loiter_time-i} seconds")
time.sleep(1)

import main
Expand Down
Loading

0 comments on commit d3d44d8

Please sign in to comment.