Skip to content
Open
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
4 changes: 4 additions & 0 deletions src/flight-software/boot.py
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's bring this into the pysquared repo. How about we create a new module inside of pysquared called boot and we can add this as a callable function from that module. It looks like the function might take 3 arguments: mount_points, wait_time, and attempts. Once it's in pysquared, we can write tests and reuse this in the other board repos.

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from lib.pysquared.boot.filesystem import mkdir

# Create the SD card directory so we can mount it later
mkdir("/sd")
10 changes: 10 additions & 0 deletions src/flight-software/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
from lib.pysquared.rtc.manager.microcontroller import MicrocontrollerManager
from lib.pysquared.sleep_helper import SleepHelper
from lib.pysquared.watchdog import Watchdog
from lib.pysquared.sd_card import SDCardManager
from version import __version__

boot_time: float = time.time()
Expand All @@ -45,6 +46,7 @@
(boot_count := Counter(index=Register.boot_count)).increment()
error_count: Counter = Counter(index=Register.error_count)


logger: Logger = Logger(
error_counter=error_count,
colorized=False,
Expand Down Expand Up @@ -77,6 +79,13 @@
board.SPI0_MISO,
)

sdCard: SDCardManager = SDCardManager(
spi0,
board.SPI0_CS1
)

logger.sd_card = sdCard

radio = RFM9xManager(
logger,
config.radio,
Expand All @@ -85,6 +94,7 @@
initialize_pin(logger, board.RF1_RST, digitalio.Direction.OUTPUT, True),
)


packet_manager = PacketManager(
logger,
radio,
Expand Down
8 changes: 8 additions & 0 deletions src/flight-software/repl.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from lib.pysquared.rtc.manager.microcontroller import MicrocontrollerManager
from lib.pysquared.sleep_helper import SleepHelper
from lib.pysquared.watchdog import Watchdog
from lib.pysquared.sd_card import SDCardManager
from version import __version__

boot_time: float = time.time()
Expand Down Expand Up @@ -63,6 +64,13 @@
board.SPI0_MISO,
)

sdCard: SDCardManager = SDCardManager(
spi0,
board.SPI0_CS1
)

logger.sd_card = sdCard

radio = RFM9xManager(
logger,
config.radio,
Expand Down
4 changes: 4 additions & 0 deletions usbmodem101/boot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from lib.pysquared.boot.filesystem import mkdir

# Create the SD card directory so we can mount it later
mkdir("/sd")
84 changes: 84 additions & 0 deletions usbmodem101/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
{
"critical_battery_voltage": 6.6,
"cubesat_name": "PROVES-MY_SATELLITE_NAME",
"current_draw": 240.5,
"debug": true,
"degraded_battery_voltage": 5.4,
"detumble_enable_x": true,
"detumble_enable_y": true,
"detumble_enable_z": true,
"heating": false,
"jokes": [
"Hey it is pretty cold up here, did someone forget to pay the electric bill?",
"sudo rf - rf*",
"Why did the astronaut break up with his girlfriend? He needed space.",
"Why did the sun go to school? To get a little brighter.",
"why is the mall called the mall? because instead of going to one store you go to them all",
"Alien detected. Blurring photo...",
"Wait it is all open source? Always has been... www.github.com/proveskit",
"What did 0 say to 1? You're a bit too much.",
"Pleiades - Orpheus has been recently acquired by the Onion News Network",
"This jokesat was brought to you by the Bronco Space Ministry of Labor and Job Placement",
"Catch you on the next pass!",
"Pleiades - Orpheus was not The Impostor",
"Sorry for messing with your long-exposure astrophoto!",
"Better buy a telescope. Wanna see me. Buy a telescope. Gonna be in space.",
"According to all known laws of aviation, there is no way bees should be able to fly...",
"You lost the game ",
"Bobby Tables is a good friend of mine",
"Why did the computer cross the road? To get a byte to eat!",
"Why are the astronauts not hungry when they got to space? They had a big launch.",
"Why did the computer get glasses? To improve its web sight!",
"What are computers favorite snacks? Chips!",
"Wait! I think I see a White 2019 Subaru Crosstrek 2.0i Premium",
"IS THAT A SUPRA?!",
"Finally escpaed the LA Traffic",
"My CubeSat is really good at jokes, but its delivery is always delayed.",
"exec order 66",
"I had a joke about UDP, but I am not sure if you'd get it.",
"I am not saying FSK modulation is the best way to send jokes, but at least it is never monotone!",
"I am sorry David, I am afrain I can not do that.",
"My memory is volatile like RAM, so it only makes sense that I forget things.",
"Imagine it gets stuck and just keeps repeating this joke every 2 mins",
"Check Engine: Error Code 404: Joke Not Found",
"CQ CQ KN6NAQ ... KN6NAT are you out there?",
"Woah is that the Launcher Orbiter?????",
"Everything in life is a spring if you think hard enough!",
"Your Mom",
"Your Mum",
"Your Face",
"not True lol",
"I have brought peace, freedom, justice, and security to my new empire! Your New Empire?"
],
"last_battery_temp": 20.0,
"longest_allowable_sleep_time": 600,
"normal_battery_temp": 1,
"normal_battery_voltage": 6.9,
"normal_charge_current": 0.5,
"normal_micro_temp": 20,
"normal_temp": 20,
"radio": {
"fsk": {
"broadcast_address": 255,
"modulation_type": 0,
"node_address": 1
},
"license": "KK4PDM",
"lora": {
"ack_delay": 0.2,
"coding_rate": 8,
"cyclic_redundancy_check": true,
"max_output": true,
"spreading_factor": 8,
"transmit_power": 23
},
"modulation": "LoRa",
"start_time": 80000,
"transmit_frequency": 437.4
},
"reboot_time": 3600,
"repeat_code": "RP",
"sleep_duration": 30,
"super_secret_code": "ABCD",
"turbo_clock": false
}
158 changes: 158 additions & 0 deletions usbmodem101/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
# This is where the magic happens!
# This file is executed on every boot (including wake-boot from deepsleep)
# Created By: Michael Pham

"""
Built for the PySquared FC Board
Version: 2.0.0
Published: Nov 19, 2024
"""

import gc
import os
import time

import digitalio
import microcontroller
from busio import SPI

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

from lib.proveskit_rp2040_v4.register import Register
from lib.pysquared.beacon import Beacon
from lib.pysquared.cdh import CommandDataHandler
from lib.pysquared.config.config import Config
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.magnetometer.manager.lis2mdl import LIS2MDLManager
from lib.pysquared.hardware.radio.manager.rfm9x import RFM9xManager
from lib.pysquared.hardware.radio.packetizer.packet_manager import PacketManager
from lib.pysquared.hardware.sd_card.manager.sd_card import SDCardManager
from lib.pysquared.logger import Logger, LogLevel
from lib.pysquared.nvm.counter import Counter
from lib.pysquared.rtc.manager.microcontroller import MicrocontrollerManager
from lib.pysquared.sleep_helper import SleepHelper
from lib.pysquared.watchdog import Watchdog
from version import __version__

boot_time: float = time.time()

rtc = MicrocontrollerManager()

(boot_count := Counter(index=Register.boot_count)).increment()
error_count: Counter = Counter(index=Register.error_count)


logger: Logger = Logger(
error_counter=error_count,
colorized=False,
log_level=LogLevel.INFO,
)

logger.info(
"Booting",
hardware_version=os.uname().version,
software_version=__version__,
)

try:
loiter_time: int = 5
for i in range(loiter_time):
logger.info(f"Code Starting in {loiter_time-i} seconds")
time.sleep(1)

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

logger.debug("Initializing Config")
config: Config = Config("config.json")

# TODO(nateinaction): fix spi init
spi0: SPI = _spi_init(
logger,
board.SPI0_SCK,
board.SPI0_MOSI,
board.SPI0_MISO,
)

sdCard: SDCardManager = SDCardManager(spi0, board.SPI0_CS1)

logger.set_log_dir("/sd")

radio = RFM9xManager(
logger,
config.radio,
spi0,
initialize_pin(logger, board.SPI0_CS0, digitalio.Direction.OUTPUT, True),
initialize_pin(logger, board.RF1_RST, digitalio.Direction.OUTPUT, True),
)

packet_manager = PacketManager(
logger,
radio,
config.radio.license,
Counter(Register.message_count),
0.2,
)

i2c1 = initialize_i2c_bus(
logger,
board.I2C1_SCL,
board.I2C1_SDA,
100000,
)

magnetometer = LIS2MDLManager(logger, i2c1)

imu = LSM6DSOXManager(logger, i2c1, 0x6B)

sleep_helper = SleepHelper(logger, config, watchdog)

cdh = CommandDataHandler(logger, config, packet_manager)

beacon = Beacon(
logger,
config.cubesat_name,
packet_manager,
boot_time,
imu,
magnetometer,
radio,
error_count,
boot_count,
)

def nominal_power_loop():
logger.debug(
"FC Board Stats",
bytes_remaining=gc.mem_free(),
)

packet_manager.send(config.radio.license.encode("utf-8"))

beacon.send()

cdh.listen_for_commands(10)

sleep_helper.safe_sleep(config.sleep_duration)

try:
logger.info("Entering main loop")
while True:
# TODO(nateinaction): Modify behavior based on power state
nominal_power_loop()

except Exception as e:
logger.critical("Critical in Main Loop", e)
time.sleep(10)
microcontroller.on_next_reset(microcontroller.RunMode.NORMAL)
microcontroller.reset()
finally:
logger.info("Going Neutral!")

except Exception as e:
logger.critical("An exception occured within main.py", e)
Loading
Loading