From 33fddd21fee0ea7701fb54edc03f4273d7e9032e Mon Sep 17 00:00:00 2001 From: tomyyyD Date: Thu, 27 Jun 2024 10:06:39 -0400 Subject: [PATCH 1/5] making telemtry task downlink beacon automatically --- applications/flight/Tasks/telemetry.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/applications/flight/Tasks/telemetry.py b/applications/flight/Tasks/telemetry.py index 935425b5..00efd9e3 100644 --- a/applications/flight/Tasks/telemetry.py +++ b/applications/flight/Tasks/telemetry.py @@ -1,10 +1,15 @@ # Transmit "Hello World" beacon -from Tasks.log import LogTask as Task -from pycubed import cubesat +import time + import files import logs -import time +from pycubed import cubesat +from radio_utils import headers +from radio_utils.message import Message +from radio_utils.transmission_queue import transmission_queue as tq +from Tasks.log import LogTask as Task + class task(Task): name = 'beacon' @@ -33,6 +38,11 @@ def write_telemetry(self): boot = cubesat.c_boot current_file = f"/sd/logs/telemetry/{boot:05}/{hour_stamp}" telemetry_packet = logs.telemetry_packet(t) + self.downlink_beacon() file = open(current_file, "ab+") file.write(telemetry_packet) file.close() + + def downlink_beacon(self, beacon): + beacon_packet = logs.beacon_packet() + tq.push(Message(priority=10, data=beacon_packet, header=headers.BEACON, with_ack=False)) From e0468751f553f65e0d0df816193375a25b42c15e Mon Sep 17 00:00:00 2001 From: tomyyyD Date: Thu, 27 Jun 2024 15:23:47 -0400 Subject: [PATCH 2/5] adding acceleration data to beacon --- applications/flight/lib/logs.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/applications/flight/lib/logs.py b/applications/flight/lib/logs.py index 5a5e1951..0d41f8b4 100644 --- a/applications/flight/lib/logs.py +++ b/applications/flight/lib/logs.py @@ -11,13 +11,13 @@ # 3 uint8 + 1 uint16 + 11 float32 # = 49 bytes of data # = 52 byte c struct (1 extra to align chars, 2 extra to align short) -beacon_format = 3 * 'B' + 'H' + 'f' * 11 +beacon_format = 3 * 'B' + 'H' + 'f' * 14 # Defines what the unpack_beacon will return beacon_tuple = namedtuple("beacon_tuple", ("state_index", "datetime_valid_flag", "contact_flag", "burn_flag", "software_error_count", "boot_count", "battery_voltage", "cpu_temperature_C", "imu_temperature_C", - "gyro", "mag", "RSSI_dB", "FEI_Hz")) + "gyro", "mag", "accel", "RSSI_dB", "FEI_Hz")) # 6 float32 # = 24 bytes of data @@ -55,6 +55,7 @@ def beacon_packet(): imu_temp = cubesat.temperature_imu if cubesat.imu and cubesat.has_imu_temp else nan gyro = cubesat.gyro if cubesat.imu else array([nan, nan, nan]) mag = cubesat.magnetic if cubesat.imu else array([nan, nan, nan]) + accel = cubesat.acceleration if cubesat.imu else array([nan, nan, nan]) rssi = cubesat.radio.last_rssi if cubesat.radio else nan fei = cubesat.radio.frequency_error if cubesat.radio else nan return struct.pack(beacon_format, @@ -62,6 +63,7 @@ def beacon_packet(): vbatt, cpu_temp, imu_temp, gyro[0], gyro[1], gyro[2], mag[0], mag[1], mag[2], + accel[0], accel[1], accel[2], rssi, fei) def system_packet(): @@ -118,16 +120,18 @@ def unpack_beacon(bytes): vbatt, cpu_temp, imu_temp, gyro0, gyro1, gyro2, mag0, mag1, mag2, + accel0, accel1, accel2, rssi, fei) = struct.unpack(beacon_format, bytes) gyro = array([gyro0, gyro1, gyro2]) mag = array([mag0, mag1, mag2]) + accel = array([accel0, accel1, accel2]) return beacon_tuple(state_byte, bool(flags & (0b1 << 2)), bool(flags & (0b1 << 1)), bool(flags & (0b1 << 0)), software_error, boot_count, vbatt, cpu_temp, imu_temp, gyro, mag, - rssi, fei) + accel, rssi, fei) def unpack_system(bytes): From c1f05e9ba945072b7920c670cf28d3ab9ec68af9 Mon Sep 17 00:00:00 2001 From: Thomas Damiani Date: Thu, 27 Jun 2024 16:16:16 -0400 Subject: [PATCH 3/5] making beacon transmit every time telemetry task runs --- applications/flight/Tasks/radio.py | 4 ++-- applications/flight/Tasks/telemetry.py | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/applications/flight/Tasks/radio.py b/applications/flight/Tasks/radio.py index 5b11fec2..56a5da56 100644 --- a/applications/flight/Tasks/radio.py +++ b/applications/flight/Tasks/radio.py @@ -26,11 +26,11 @@ def should_transmit(): Return if we should transmit """ tx_ready = settings.TX_ALLOWED and not tq.empty() and cubesat.radio.fifo_empty() - tx_time_ready = time.time() < tx_before_time + # tx_time_ready = time.time() < tx_before_time if tx_ready: global tx_ready_counter tx_ready_counter += 1 - return tx_ready and (tx_ready_counter % TX_SKIP != 0) and tx_time_ready + return tx_ready and (tx_ready_counter % TX_SKIP != 0) class task(Task): name = 'radio' diff --git a/applications/flight/Tasks/telemetry.py b/applications/flight/Tasks/telemetry.py index 00efd9e3..22eab998 100644 --- a/applications/flight/Tasks/telemetry.py +++ b/applications/flight/Tasks/telemetry.py @@ -43,6 +43,7 @@ def write_telemetry(self): file.write(telemetry_packet) file.close() - def downlink_beacon(self, beacon): + def downlink_beacon(self): beacon_packet = logs.beacon_packet() - tq.push(Message(priority=10, data=beacon_packet, header=headers.BEACON, with_ack=False)) + tq.push(Message(10, beacon_packet, header=headers.BEACON, with_ack=False)) + self.debug("beacon added to transmission queue") From 4007d3f482ae315c1af9be400e865b032ebcedbc Mon Sep 17 00:00:00 2001 From: tomyyyD Date: Thu, 27 Jun 2024 21:33:03 -0400 Subject: [PATCH 4/5] downlinking entire telemetry packet will need to be interpretted as the 3 different structs --- applications/flight/Tasks/telemetry.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/applications/flight/Tasks/telemetry.py b/applications/flight/Tasks/telemetry.py index 22eab998..cabc9ef2 100644 --- a/applications/flight/Tasks/telemetry.py +++ b/applications/flight/Tasks/telemetry.py @@ -38,12 +38,11 @@ def write_telemetry(self): boot = cubesat.c_boot current_file = f"/sd/logs/telemetry/{boot:05}/{hour_stamp}" telemetry_packet = logs.telemetry_packet(t) - self.downlink_beacon() + self.downlink_telemetry(telemetry_packet) file = open(current_file, "ab+") file.write(telemetry_packet) file.close() - def downlink_beacon(self): - beacon_packet = logs.beacon_packet() - tq.push(Message(10, beacon_packet, header=headers.BEACON, with_ack=False)) + def downlink_beacon(self, packet): + tq.push(Message(10, packet, header=headers.BEACON, with_ack=False)) self.debug("beacon added to transmission queue") From e7d4017daeb7df321b630d73d653c7473ea0c18d Mon Sep 17 00:00:00 2001 From: tomyyyD Date: Mon, 1 Jul 2024 09:45:32 -0400 Subject: [PATCH 5/5] function rename --- applications/flight/Tasks/telemetry.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/applications/flight/Tasks/telemetry.py b/applications/flight/Tasks/telemetry.py index cabc9ef2..14500a51 100644 --- a/applications/flight/Tasks/telemetry.py +++ b/applications/flight/Tasks/telemetry.py @@ -43,6 +43,6 @@ def write_telemetry(self): file.write(telemetry_packet) file.close() - def downlink_beacon(self, packet): + def downlink_telemetry(self, packet): tq.push(Message(10, packet, header=headers.BEACON, with_ack=False)) self.debug("beacon added to transmission queue")