Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EPS: periodic logging of power usage and disabling channels when issues are discovered. #259

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions firmware/Core/Inc/rtos_tasks/rtos_eps_tasks.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@

void TASK_service_eps_watchdog(void *argument);
void TASK_time_sync(void *argument);
void TASK_EPS_power_monitoring(void *argument);
#endif // __INCLUDE_GUARD_RTOS_EPS_TASKS_H__`
14 changes: 14 additions & 0 deletions firmware/Core/Src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,13 @@ const osThreadAttr_t TASK_time_sync_Attributes = {
.priority = (osPriority_t) osPriorityNormal, //TODO: Figure out which priority makes sense for this task
};

osThreadId_t TASK_EPS_power_monitoring_Handle;
const osThreadAttr_t TASK_EPS_power_monitoring_Attributes = {
.name = "TASK_EPS_power_monitoring",
.stack_size = 512, //in bytes
.priority = (osPriority_t) osPriorityNormal, //TODO: Figure out which priority makes sense for this task
};

osThreadId_t TASK_monitor_freertos_memory_Handle;
const osThreadAttr_t TASK_monitor_freertos_memory_Attributes = {
.name = "TASK_monitor_freertos_memory",
Expand Down Expand Up @@ -158,6 +165,11 @@ FREERTOS_task_info_struct_t FREERTOS_task_handles_array [] = {
.task_handle = &TASK_time_sync_Handle,
.task_attribute = &TASK_time_sync_Attributes,
.lowest_stack_bytes_remaining = UINT32_MAX
},
{
.task_handle = &TASK_EPS_power_monitoring_Handle,
.task_attribute = &TASK_EPS_power_monitoring_Attributes,
.lowest_stack_bytes_remaining = UINT32_MAX
},
{
.task_handle = &TASK_monitor_freertos_memory_Handle,
Expand Down Expand Up @@ -294,6 +306,8 @@ int main(void)
TASK_service_eps_watchdog_Handle = osThreadNew(TASK_service_eps_watchdog, NULL, &TASK_service_eps_watchdog_Attributes);

TASK_time_sync_Handle = osThreadNew(TASK_time_sync, NULL, &TASK_time_sync_Attributes);

TASK_EPS_power_monitoring_Handle = osThreadNew(TASK_EPS_power_monitoring, NULL, &TASK_EPS_power_monitoring_Attributes);
/* USER CODE END RTOS_THREADS */

/* USER CODE BEGIN RTOS_EVENTS */
Expand Down
83 changes: 83 additions & 0 deletions firmware/Core/Src/rtos_tasks/rtos_eps_tasks.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
#include "rtos_tasks/rtos_task_helpers.h"
#include "log/log.h"
#include "timekeeping/timekeeping.h"
#include "eps_drivers/eps_types_to_json.h"

#include "cmsis_os.h"

#include <string.h>
#include <inttypes.h>
#include <stdint.h>

Expand Down Expand Up @@ -140,3 +142,84 @@ void TASK_time_sync(void *argument) {
}
} // End of task while loop
}

void TASK_EPS_power_monitoring(void *argument) {

TASK_HELP_start_of_task();

uint32_t sleep_duration_ms = 30000; // 30s

osDelay(sleep_duration_ms);
sleep_duration_ms = 1000; // 1 second
2BlackCats marked this conversation as resolved.
Show resolved Hide resolved

EPS_struct_pdu_housekeeping_data_eng_t prev_EPS_pdu_housekeeping_data_eng;
EPS_CMD_get_pdu_housekeeping_data_eng(&prev_EPS_pdu_housekeeping_data_eng);
2BlackCats marked this conversation as resolved.
Show resolved Hide resolved
EPS_vpid_eng_t prev_vpid_eng[32];
memcpy(prev_vpid_eng, prev_EPS_pdu_housekeeping_data_eng.vip_each_channel, sizeof(EPS_vpid_eng_t) * 32);

while (1) {
osDelay(sleep_duration_ms);

char json_str[1000];

EPS_struct_pdu_housekeeping_data_eng_t EPS_pdu_housekeeping_data_eng;
EPS_CMD_get_pdu_housekeeping_data_eng(&EPS_pdu_housekeeping_data_eng);
2BlackCats marked this conversation as resolved.
Show resolved Hide resolved
EPS_vpid_eng_t vpid_eng[32];
memcpy(vpid_eng, EPS_pdu_housekeeping_data_eng.vip_each_channel, sizeof(EPS_vpid_eng_t) * 32);

//Power Logging
EPS_struct_pdu_housekeeping_data_eng_TO_json(&EPS_pdu_housekeeping_data_eng, json_str, 1000);
2BlackCats marked this conversation as resolved.
Show resolved Hide resolved

LOG_message(
LOG_SYSTEM_EPS,
LOG_SEVERITY_NORMAL,
LOG_SINK_ALL,
"EPS PDU housekeeping data:\n %s",
json_str
);

uint32_t ch_bitfield = (EPS_pdu_housekeeping_data_eng.stat_ch_ext_on_bitfield << 16) & EPS_pdu_housekeeping_data_eng.stat_ch_on_bitfield;

//Power Monitoring
for (int channel = 0; channel < 32; channel++) {
if (ch_bitfield & 1) {

if (vpid_eng[channel].power_cW - prev_vpid_eng[channel].power_cW > 1000 //TODO: Check if the pdu values are correct
|| vpid_eng[channel].voltage_mV - prev_vpid_eng[channel].voltage_mV > 1000
2BlackCats marked this conversation as resolved.
Show resolved Hide resolved
|| vpid_eng[channel].current_mA - prev_vpid_eng[channel].current_mA > 1000
|| vpid_eng[channel].power_cW - prev_vpid_eng[channel].power_cW < -1000
|| vpid_eng[channel].voltage_mV - prev_vpid_eng[channel].voltage_mV < -1000
|| vpid_eng[channel].current_mA - prev_vpid_eng[channel].current_mA < -1000) {


uint8_t result = EPS_CMD_output_bus_channel_off(channel);

if (result != 0) {
2BlackCats marked this conversation as resolved.
Show resolved Hide resolved
LOG_message(
LOG_SYSTEM_EPS,
LOG_SEVERITY_CRITICAL,
LOG_SINK_ALL,
"EPS_CMD_output_bus_channel_off(%d) -> Error: %d",
channel,
result
);
}
else{
LOG_message(
LOG_SYSTEM_EPS,
LOG_SEVERITY_CRITICAL,
LOG_SINK_ALL,
"Channel %d was turned off. Due to a power issue.",
channel
);
}

}
}
ch_bitfield = ch_bitfield >> 1;
}

memcpy(prev_vpid_eng, vpid_eng, sizeof(prev_vpid_eng));
prev_EPS_pdu_housekeeping_data_eng = EPS_pdu_housekeeping_data_eng;
}
}
Loading