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

BPS Fault Indicator #284

Closed
wants to merge 1 commit into from
Closed
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
1 change: 1 addition & 0 deletions projects/bms_carrier/inc/bms.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,5 @@ typedef enum {
BMS_FAULT_UNDERVOLTAGE,
BMS_FAULT_KILLSWITCH,
BMS_FAULT_RELAY_CLOSE_FAILED,
BMS_FAULT_DISCONNECTED
} BmsFault;
1 change: 1 addition & 0 deletions projects/power_distribution/inc/outputs.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ typedef enum {
OUTPUT_GROUP_POWER_OFF,
OUTPUT_GROUP_POWER_DRIVE,
OUTPUT_GROUP_POWER_FAULT,
OUTPUT_GROUP_BPS,
NUM_OUTPUT_GROUPS,
} OutputGroup;

Expand Down
3 changes: 3 additions & 0 deletions projects/power_distribution/inc/pd_fault.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
#include <stdint.h>

#include "status.h"

#define BPS_FAULT_LIGHT_PERIOD_MS 500 // Signal blink frequency of 1Hz
/*
* @brief Checks for PD fault states and updates fault bitset CAN message
* @return STATUS_CODE_OK on success or appropriate error code
*/
uint8_t check_pd_fault(void);
StatusCode init_bps_fault(void);
2 changes: 2 additions & 0 deletions projects/power_distribution/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "log.h"
#include "master_task.h"
#include "output_current_sense.h"
#include "pd_fault.h"
#include "pin_defs.h"
#include "power_seq_fsm.h"
#include "tasks.h"
Expand Down Expand Up @@ -64,6 +65,7 @@ int main() {
// set_medium_cycle_count(2); // adjust medium cycle count to run once per 500ms
init_power_seq();
init_lights();
init_bps_fault();

LOG_DEBUG("Welcome to PD!\n");
init_master_task();
Expand Down
5 changes: 4 additions & 1 deletion projects/power_distribution/src/output_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -322,9 +322,11 @@ static OutputGroupDef s_output_group_power_drive = { .num_outputs = 9,
DRIVER_FAN, REAR_CAM_LCD } };

static OutputGroupDef s_output_group_power_fault = {
.num_outputs = 5, .outputs = { CENTER_CONSOLE, BMS_DCDC, PEDAL, STEERING, BPS_LIGHT }
.num_outputs = 4, .outputs = { CENTER_CONSOLE, BMS_DCDC, PEDAL, STEERING }
};

static OutputGroupDef s_output_group_bps = { .num_outputs = 1, .outputs = { BPS_LIGHT } };

static OutputGroupDef s_output_group_test = { .num_outputs = 2, .outputs = { STEERING, PEDAL } };

const OutputGroupDef *g_output_group_map[NUM_OUTPUT_GROUPS] = {
Expand All @@ -336,4 +338,5 @@ const OutputGroupDef *g_output_group_map[NUM_OUTPUT_GROUPS] = {
[OUTPUT_GROUP_POWER_OFF] = &s_output_group_power_off,
[OUTPUT_GROUP_POWER_DRIVE] = &s_output_group_power_drive,
[OUTPUT_GROUP_POWER_FAULT] = &s_output_group_power_fault,
[OUTPUT_GROUP_BPS] = &s_output_group_bps,
};
21 changes: 21 additions & 0 deletions projects/power_distribution/src/pd_fault.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@
#include "exported_enums.h"
#include "gpio.h"
#include "log.h"
#include "outputs.h"
#include "pin_defs.h"
#include "power_distribution_getters.h"
#include "power_distribution_setters.h"
#include "soft_timer.h"

static uint8_t s_fault_bitset = 0;
static OutputState bps_light_state = OUTPUT_STATE_OFF;
static SoftTimer bps_timer;

// Fault pin address definitions
static const GpioAddress aux_valid1 = AUX_VALID1;
Expand Down Expand Up @@ -43,9 +48,25 @@ static bool prv_check_dcdc_fault(void) {
return (dcdc_valid1_state == GPIO_STATE_HIGH || dcdc_valid2_state == GPIO_STATE_HIGH);
}

static void prv_lights_bps_fault(SoftTimerId id) {
if (get_battery_status_fault() || g_tx_struct.pd_status_bps_persist) {
bps_light_state ^= 1;
pd_set_output_group(OUTPUT_GROUP_BPS, bps_light_state);
} else {
bps_light_state = 0;
pd_set_output_group(OUTPUT_GROUP_BPS, bps_light_state);
}
soft_timer_start(&bps_timer);
}

uint8_t check_pd_fault(void) {
prv_set_fault_bit(EE_PD_STATUS_FAULT_BITSET_AUX_FAULT_MASK, prv_check_aux_fault());
prv_set_fault_bit(EE_PD_STATUS_FAULT_BITSET_DCDC_FAULT_MASK, prv_check_dcdc_fault());
set_pd_status_fault_bitset(s_fault_bitset);
return s_fault_bitset;
}

StatusCode init_bps_fault(void) {
soft_timer_init_and_start(BPS_FAULT_LIGHT_PERIOD_MS, prv_lights_bps_fault, &bps_timer);
return STATUS_CODE_OK;
}
3 changes: 3 additions & 0 deletions projects/power_distribution/src/power_seq_fsm.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ static void prv_fault_state_output(void *context) {
s_bps_storage.fault_bitset = get_battery_status_fault();
s_bps_storage.vehicle_speed =
(get_motor_velocity_velocity_l() + get_motor_velocity_velocity_r()) / 2;
if (s_bps_storage.fault_bitset == 0) {
s_bps_storage.fault_bitset = (1 << 10); // BMS NOT CONNECTED
}
persist_commit(&s_persist);
pd_set_active_output_group(OUTPUT_GROUP_POWER_FAULT);
set_pd_status_bps_persist(s_bps_storage.fault_bitset);
Expand Down
Loading