Skip to content

Commit 7c3e576

Browse files
committed
new boot sequence to use mkdir function
1 parent 83708bd commit 7c3e576

File tree

13 files changed

+739
-37
lines changed

13 files changed

+739
-37
lines changed

src/flight-software/boot.py

Lines changed: 3 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,4 @@
1-
import os
2-
import time
1+
from lib.pysquared.boot.filesystem import mkdir
32

4-
import storage
5-
6-
mount_points = [
7-
"/sd",
8-
]
9-
10-
wait_time = 0.02
11-
12-
storage.disable_usb_drive()
13-
print("Disabling USB drive")
14-
time.sleep(wait_time)
15-
16-
storage.mount("/", False)
17-
print("Remounting root filesystem")
18-
time.sleep(wait_time)
19-
20-
attempts = 0
21-
while attempts < 5:
22-
attempts += 1
23-
try:
24-
for path in mount_points:
25-
try:
26-
os.mkdir(path)
27-
print(f"Mount point {path} created.")
28-
except OSError:
29-
print(f"Mount point {path} already exists.")
30-
except Exception as e:
31-
print(f"Error creating mount point {path}: {e}")
32-
time.sleep(wait_time)
33-
continue
34-
35-
break
36-
37-
storage.enable_usb_drive()
38-
print("Enabling USB drive")
3+
# Create the SD card directory so we can mount it later
4+
mkdir("/sd")

usbmodem101/boot.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from lib.pysquared.boot.filesystem import mkdir
2+
3+
# Create the SD card directory so we can mount it later
4+
mkdir("/sd")

usbmodem101/config.json

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
{
2+
"critical_battery_voltage": 6.6,
3+
"cubesat_name": "PROVES-MY_SATELLITE_NAME",
4+
"current_draw": 240.5,
5+
"debug": true,
6+
"degraded_battery_voltage": 5.4,
7+
"detumble_enable_x": true,
8+
"detumble_enable_y": true,
9+
"detumble_enable_z": true,
10+
"heating": false,
11+
"jokes": [
12+
"Hey it is pretty cold up here, did someone forget to pay the electric bill?",
13+
"sudo rf - rf*",
14+
"Why did the astronaut break up with his girlfriend? He needed space.",
15+
"Why did the sun go to school? To get a little brighter.",
16+
"why is the mall called the mall? because instead of going to one store you go to them all",
17+
"Alien detected. Blurring photo...",
18+
"Wait it is all open source? Always has been... www.github.com/proveskit",
19+
"What did 0 say to 1? You're a bit too much.",
20+
"Pleiades - Orpheus has been recently acquired by the Onion News Network",
21+
"This jokesat was brought to you by the Bronco Space Ministry of Labor and Job Placement",
22+
"Catch you on the next pass!",
23+
"Pleiades - Orpheus was not The Impostor",
24+
"Sorry for messing with your long-exposure astrophoto!",
25+
"Better buy a telescope. Wanna see me. Buy a telescope. Gonna be in space.",
26+
"According to all known laws of aviation, there is no way bees should be able to fly...",
27+
"You lost the game ",
28+
"Bobby Tables is a good friend of mine",
29+
"Why did the computer cross the road? To get a byte to eat!",
30+
"Why are the astronauts not hungry when they got to space? They had a big launch.",
31+
"Why did the computer get glasses? To improve its web sight!",
32+
"What are computers favorite snacks? Chips!",
33+
"Wait! I think I see a White 2019 Subaru Crosstrek 2.0i Premium",
34+
"IS THAT A SUPRA?!",
35+
"Finally escpaed the LA Traffic",
36+
"My CubeSat is really good at jokes, but its delivery is always delayed.",
37+
"exec order 66",
38+
"I had a joke about UDP, but I am not sure if you'd get it.",
39+
"I am not saying FSK modulation is the best way to send jokes, but at least it is never monotone!",
40+
"I am sorry David, I am afrain I can not do that.",
41+
"My memory is volatile like RAM, so it only makes sense that I forget things.",
42+
"Imagine it gets stuck and just keeps repeating this joke every 2 mins",
43+
"Check Engine: Error Code 404: Joke Not Found",
44+
"CQ CQ KN6NAQ ... KN6NAT are you out there?",
45+
"Woah is that the Launcher Orbiter?????",
46+
"Everything in life is a spring if you think hard enough!",
47+
"Your Mom",
48+
"Your Mum",
49+
"Your Face",
50+
"not True lol",
51+
"I have brought peace, freedom, justice, and security to my new empire! Your New Empire?"
52+
],
53+
"last_battery_temp": 20.0,
54+
"longest_allowable_sleep_time": 600,
55+
"normal_battery_temp": 1,
56+
"normal_battery_voltage": 6.9,
57+
"normal_charge_current": 0.5,
58+
"normal_micro_temp": 20,
59+
"normal_temp": 20,
60+
"radio": {
61+
"fsk": {
62+
"broadcast_address": 255,
63+
"modulation_type": 0,
64+
"node_address": 1
65+
},
66+
"license": "KK4PDM",
67+
"lora": {
68+
"ack_delay": 0.2,
69+
"coding_rate": 8,
70+
"cyclic_redundancy_check": true,
71+
"max_output": true,
72+
"spreading_factor": 8,
73+
"transmit_power": 23
74+
},
75+
"modulation": "LoRa",
76+
"start_time": 80000,
77+
"transmit_frequency": 437.4
78+
},
79+
"reboot_time": 3600,
80+
"repeat_code": "RP",
81+
"sleep_duration": 30,
82+
"super_secret_code": "ABCD",
83+
"turbo_clock": false
84+
}

usbmodem101/main.py

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
# This is where the magic happens!
2+
# This file is executed on every boot (including wake-boot from deepsleep)
3+
# Created By: Michael Pham
4+
5+
"""
6+
Built for the PySquared FC Board
7+
Version: 2.0.0
8+
Published: Nov 19, 2024
9+
"""
10+
11+
import gc
12+
import os
13+
import time
14+
15+
import digitalio
16+
import microcontroller
17+
from busio import SPI
18+
19+
try:
20+
from board_definitions import proveskit_rp2040_v4 as board
21+
except ImportError:
22+
import board
23+
24+
from lib.proveskit_rp2040_v4.register import Register
25+
from lib.pysquared.beacon import Beacon
26+
from lib.pysquared.cdh import CommandDataHandler
27+
from lib.pysquared.config.config import Config
28+
from lib.pysquared.hardware.busio import _spi_init, initialize_i2c_bus
29+
from lib.pysquared.hardware.digitalio import initialize_pin
30+
from lib.pysquared.hardware.imu.manager.lsm6dsox import LSM6DSOXManager
31+
from lib.pysquared.hardware.magnetometer.manager.lis2mdl import LIS2MDLManager
32+
from lib.pysquared.hardware.radio.manager.rfm9x import RFM9xManager
33+
from lib.pysquared.hardware.radio.packetizer.packet_manager import PacketManager
34+
from lib.pysquared.hardware.sd_card.manager.sd_card import SDCardManager
35+
from lib.pysquared.logger import Logger, LogLevel
36+
from lib.pysquared.nvm.counter import Counter
37+
from lib.pysquared.rtc.manager.microcontroller import MicrocontrollerManager
38+
from lib.pysquared.sleep_helper import SleepHelper
39+
from lib.pysquared.watchdog import Watchdog
40+
from version import __version__
41+
42+
boot_time: float = time.time()
43+
44+
rtc = MicrocontrollerManager()
45+
46+
(boot_count := Counter(index=Register.boot_count)).increment()
47+
error_count: Counter = Counter(index=Register.error_count)
48+
49+
50+
logger: Logger = Logger(
51+
error_counter=error_count,
52+
colorized=False,
53+
log_level=LogLevel.INFO,
54+
)
55+
56+
logger.info(
57+
"Booting",
58+
hardware_version=os.uname().version,
59+
software_version=__version__,
60+
)
61+
62+
try:
63+
loiter_time: int = 5
64+
for i in range(loiter_time):
65+
logger.info(f"Code Starting in {loiter_time-i} seconds")
66+
time.sleep(1)
67+
68+
watchdog = Watchdog(logger, board.WDT_WDI)
69+
watchdog.pet()
70+
71+
logger.debug("Initializing Config")
72+
config: Config = Config("config.json")
73+
74+
# TODO(nateinaction): fix spi init
75+
spi0: SPI = _spi_init(
76+
logger,
77+
board.SPI0_SCK,
78+
board.SPI0_MOSI,
79+
board.SPI0_MISO,
80+
)
81+
82+
sdCard: SDCardManager = SDCardManager(spi0, board.SPI0_CS1)
83+
84+
logger.set_log_dir("/sd")
85+
86+
radio = RFM9xManager(
87+
logger,
88+
config.radio,
89+
spi0,
90+
initialize_pin(logger, board.SPI0_CS0, digitalio.Direction.OUTPUT, True),
91+
initialize_pin(logger, board.RF1_RST, digitalio.Direction.OUTPUT, True),
92+
)
93+
94+
packet_manager = PacketManager(
95+
logger,
96+
radio,
97+
config.radio.license,
98+
Counter(Register.message_count),
99+
0.2,
100+
)
101+
102+
i2c1 = initialize_i2c_bus(
103+
logger,
104+
board.I2C1_SCL,
105+
board.I2C1_SDA,
106+
100000,
107+
)
108+
109+
magnetometer = LIS2MDLManager(logger, i2c1)
110+
111+
imu = LSM6DSOXManager(logger, i2c1, 0x6B)
112+
113+
sleep_helper = SleepHelper(logger, config, watchdog)
114+
115+
cdh = CommandDataHandler(logger, config, packet_manager)
116+
117+
beacon = Beacon(
118+
logger,
119+
config.cubesat_name,
120+
packet_manager,
121+
boot_time,
122+
imu,
123+
magnetometer,
124+
radio,
125+
error_count,
126+
boot_count,
127+
)
128+
129+
def nominal_power_loop():
130+
logger.debug(
131+
"FC Board Stats",
132+
bytes_remaining=gc.mem_free(),
133+
)
134+
135+
packet_manager.send(config.radio.license.encode("utf-8"))
136+
137+
beacon.send()
138+
139+
cdh.listen_for_commands(10)
140+
141+
sleep_helper.safe_sleep(config.sleep_duration)
142+
143+
try:
144+
logger.info("Entering main loop")
145+
while True:
146+
# TODO(nateinaction): Modify behavior based on power state
147+
nominal_power_loop()
148+
149+
except Exception as e:
150+
logger.critical("Critical in Main Loop", e)
151+
time.sleep(10)
152+
microcontroller.on_next_reset(microcontroller.RunMode.NORMAL)
153+
microcontroller.reset()
154+
finally:
155+
logger.info("Going Neutral!")
156+
157+
except Exception as e:
158+
logger.critical("An exception occured within main.py", e)

0 commit comments

Comments
 (0)