Skip to content

Commit

Permalink
Merge pull request #110 from Northeastern-Electric-Racing/format-and-…
Browse files Browse the repository at this point in the history
…check-2

Format & Check
  • Loading branch information
Sabramz authored Aug 3, 2024
2 parents 027271a + aa08bcb commit 6eb3f86
Show file tree
Hide file tree
Showing 19 changed files with 1,213 additions and 949 deletions.
18 changes: 0 additions & 18 deletions .clang-format

This file was deleted.

4 changes: 2 additions & 2 deletions .github/workflows/build-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
timeout-minutes: 10
steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
submodules: recursive

Expand All @@ -17,4 +17,4 @@ jobs:
if ! make; then
echo "The application has failed to build."
exit 1 # This will cause the workflow to fail
fi
fi
20 changes: 20 additions & 0 deletions .github/workflows/format-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Code Style Check

on: [push]

jobs:
formatting-check:
name: Check format of C
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Run clang-format style check for C/C++ sources
uses: Northeastern-Electric-Racing/clang-format-action@main
with:
clang-format-version: '18'
# only check core, embedded base covered internally
check-path: "Core/"
# use the clang-format from embedded base
format-filepath: "./Drivers/Embedded-Base/clang-format"
6 changes: 6 additions & 0 deletions Core/.clang-format-ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
./*/stm32*
./*/sys*
./*/FreeRTOS*
./*/freertos*
./*/main*
./Startup/*
14 changes: 8 additions & 6 deletions Core/Inc/analyzer.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "datastructs.h"
#include "segment.h"

// this is a simple empirical mapping of which therms are returning good data
// this is a simple empirical mapping of which therms are returning good data
// Only in use because we can not seem to correclty map incoming therms - this allows us to forcibley select those that we visually noticed were good
extern uint8_t THERM_DISABLE[NUM_CHIPS][NUM_THERMS_PER_CHIP];

Expand All @@ -17,14 +17,16 @@ extern const uint8_t MUX_OFFSET;
* @note 0xFF indicates the end of the relevant therms
* @note Low side
*/
extern const uint8_t RELEVANT_THERM_MAP_L[NUM_CELLS_PER_CHIP][NUM_RELEVANT_THERMS];
extern const uint8_t RELEVANT_THERM_MAP_L[NUM_CELLS_PER_CHIP]
[NUM_RELEVANT_THERMS];

/**
* @brief Mapping the Relevant Thermistors for each cell based on cell #
* @note 0xFF indicates the end of the relevant therms
* @note High side
*/
extern const uint8_t RELEVANT_THERM_MAP_H[NUM_CELLS_PER_CHIP][NUM_RELEVANT_THERMS];
extern const uint8_t RELEVANT_THERM_MAP_H[NUM_CELLS_PER_CHIP]
[NUM_RELEVANT_THERMS];

/*
* List of therms that we actually read from, NOT reordered by cell
Expand All @@ -47,7 +49,7 @@ extern const uint8_t POPULATED_THERM_LIST_H[NUM_THERMS_PER_CHIP];
*
* @param data
*/
void analyzer_push(acc_data_t* data);
void analyzer_push(acc_data_t *data);

/**
* @brief Calculates the PWM required to drive the fans at the current moment in time
Expand All @@ -60,8 +62,8 @@ uint8_t analyzer_calc_fan_pwm();
/**
* @brief Pointer to the address of the most recent data point
*/
extern acc_data_t* bmsdata;
extern acc_data_t *bmsdata;

extern acc_data_t* prevbmsdata;
extern acc_data_t *prevbmsdata;

#endif
63 changes: 33 additions & 30 deletions Core/Inc/bmsConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,59 +2,62 @@
#define BMS_CONFIG_H

// Hardware definition
#define NUM_SEGMENTS 6
#define NUM_CHIPS NUM_SEGMENTS* 2
#define NUM_SEGMENTS 6
#define NUM_CHIPS NUM_SEGMENTS * 2
#define NUM_CELLS_PER_CHIP 10
#define NUM_THERMS_PER_CHIP 32
#define NUM_RELEVANT_THERMS 3

// Firmware limits
#define MAX_TEMP 65 //degrees C
#define MIN_TEMP -25 // deg C
#define MAX_VOLT_MEAS 65535
#define MIN_VOLT_MEAS 0
#define MAX_TEMP 65 //degrees C
#define MIN_TEMP -25 // deg C
#define MAX_VOLT_MEAS 65535
#define MIN_VOLT_MEAS 0

// Boosting Parameters
#define BOOST_TIME 5 // seconds
#define BOOST_RECHARGE_TIME 30 // seconds
#define BOOST_TIME 5 // seconds
#define BOOST_RECHARGE_TIME 30 // seconds
#define CONTDCL_MULTIPLIER 3

//cell limits
#define MIN_VOLT 2.5
#define MAX_VOLT 4.2
#define MAX_CHARGE_VOLT 4.21
#define MAX_DELTA_V 0.015
#define BAL_MIN_V 4.00
#define MAX_CELL_TEMP 55
#define MIN_CELL_TEMP 15
#define MAX_CELL_CURR 500 // Amps per BMS cell
#define MAX_CELL_TEMP_BAL 45
#define MAX_CHG_CELL_CURR 20
#define MIN_VOLT 2.5
#define MAX_VOLT 4.2
#define MAX_CHARGE_VOLT 4.21
#define MAX_DELTA_V 0.015
#define BAL_MIN_V 4.00
#define MAX_CELL_TEMP 55
#define MIN_CELL_TEMP 15
#define MAX_CELL_CURR 500 // Amps per BMS cell
#define MAX_CELL_TEMP_BAL 45
#define MAX_CHG_CELL_CURR 20

// Algorithm settings
#define CHARGE_SETL_TIMEOUT 60000 // 1 minute, may need adjustment
#define CHARGE_SETL_TIMEUP 300000 // 5 minutes, may need adjustment
#define CHARGE_VOLT_TIMEOUT 300000 // 5 minutes, may need adjustment
#define VOLT_SAG_MARGIN 0.45 // Volts above the minimum cell voltage we would like to aim for
#define OCV_CURR_THRESH 1.5
#define VOLT_SAG_MARGIN \
0.45 // Volts above the minimum cell voltage we would like to aim for
#define OCV_CURR_THRESH 1.5

#define OCV_AVG 3
#define OCV_AVG 3

#define MAX_STANDARD_DEV 3 // only used for standard deviation for therms calc
#define MAX_STANDARD_DEV 3 // only used for standard deviation for therms calc

//Fault times
#define OVER_CURR_TIME 5000 //todo adjust these based on testing and/or counter values
#define OVER_CURR_TIME \
5000 //todo adjust these based on testing and/or counter values
#define PRE_OVER_CURR_TIME 1000
#define OVER_CHG_CURR_TIME 1000
#define UNDER_VOLT_TIME 45000
#define UNDER_VOLT_TIME 45000
#define PRE_UNDER_VOLT_TIME 12000
#define OVER_VOLT_TIME 45000
#define LOW_CELL_TIME 45000
#define HIGH_TEMP_TIME 60000
#define CURR_ERR_MARG 1.1 // scaling factor, ie 1.1 = 10% error
#define OVER_VOLT_TIME 45000
#define LOW_CELL_TIME 45000
#define HIGH_TEMP_TIME 60000
#define CURR_ERR_MARG 1.1 // scaling factor, ie 1.1 = 10% error

#define DCDC_CURRENT_DRAW 0 // in A, was used because our DCDC was drawing current
#define DCDC_CURRENT_DRAW \
0 // in A, was used because our DCDC was drawing current

#define CAN_MESSAGE_WAIT 5
#define CAN_MESSAGE_WAIT 5

#endif
6 changes: 2 additions & 4 deletions Core/Inc/can_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@
#include <stdint.h>
#include "ringbuffer.h"


#define NUM_INBOUND_CAN1_IDS 1
#define NUM_INBOUND_CAN2_IDS 1

extern CAN_HandleTypeDef hcan1;
extern CAN_HandleTypeDef hcan2;

extern ringbuffer_t* can1_rx_queue;
extern ringbuffer_t* can2_rx_queue;
extern ringbuffer_t *can1_rx_queue;
extern ringbuffer_t *can2_rx_queue;

static const uint32_t can1_id_list[NUM_INBOUND_CAN1_IDS] = {
//CANID_X,
Expand All @@ -26,7 +25,6 @@ static const uint32_t can2_id_list[NUM_INBOUND_CAN2_IDS] = {
0x18FF50E5
};


void can_receive_callback(CAN_HandleTypeDef *hcan);

/* for 1st CAN bus */
Expand Down
56 changes: 25 additions & 31 deletions Core/Inc/compute.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,15 @@

#define CURRENT_SENSOR_PIN_L A1
#define CURRENT_SENSOR_PIN_H A0
#define MEAS_5VREF_PIN A7
#define FAULT_PIN 2
#define CHARGE_SAFETY_RELAY 4
#define CHARGE_DETECT 5
#define CHARGER_BAUD 250000U
#define MC_BAUD 1000000U
#define MAX_ADC_RESOLUTION 4095 // 12 bit ADC
#define MEAS_5VREF_PIN A7
#define FAULT_PIN 2
#define CHARGE_SAFETY_RELAY 4
#define CHARGE_DETECT 5
#define CHARGER_BAUD 250000U
#define MC_BAUD 1000000U
#define MAX_ADC_RESOLUTION 4095 // 12 bit ADC



typedef enum {
FAN1,
FAN2,
FAN3,
FAN4,
FAN5,
FAN6,
FANMAX
} fan_select_t;
typedef enum { FAN1, FAN2, FAN3, FAN4, FAN5, FAN6, FANMAX } fan_select_t;

/**
* @brief inits the compute interface
Expand All @@ -47,7 +37,9 @@ void compute_enable_charging(bool enable_charging);
*
* @return Returns a fault if we are not able to communicate with charger
*/
int compute_send_charging_message(uint16_t voltage_to_set, uint16_t current_to_set, acc_data_t* bms_data);
int compute_send_charging_message(uint16_t voltage_to_set,
uint16_t current_to_set,
acc_data_t *bms_data);

/**
* @brief Returns if charger interlock is engaged, indicating charger LV connector is plugged in
Expand All @@ -74,7 +66,8 @@ bool compute_charger_connected();
*
* @return uint8_t 0 = success, 1 = fan_select is out of range, 2 = PWM channel not able to be configured
*/
uint8_t compute_set_fan_speed(TIM_HandleTypeDef* pwmhandle, fan_select_t fan_select, uint8_t duty_cycle);
uint8_t compute_set_fan_speed(TIM_HandleTypeDef *pwmhandle,
fan_select_t fan_select, uint8_t duty_cycle);

/**
* @brief Returns the pack current sensor reading
Expand All @@ -88,14 +81,14 @@ int16_t compute_get_pack_current();
*
* @param bmsdata
*/
void compute_send_mc_discharge_message(acc_data_t* bmsdata);
void compute_send_mc_discharge_message(acc_data_t *bmsdata);

/**
* @brief sends max charge/discharge current to Motor Controller
*
* @param bmsdata
*/
void compute_send_mc_charge_message(acc_data_t* bmsdata);
void compute_send_mc_charge_message(acc_data_t *bmsdata);

/**
* @brief updates fault relay
Expand All @@ -115,7 +108,7 @@ void compute_set_fault(int fault_state);
*
* @return Returns a fault if we are not able to send
*/
void compute_send_acc_status_message(acc_data_t* bmsdata);
void compute_send_acc_status_message(acc_data_t *bmsdata);

/**
* @brief sends BMS status message
Expand All @@ -127,7 +120,8 @@ void compute_send_acc_status_message(acc_data_t* bmsdata);
*
* @return Returns a fault if we are not able to send
*/
void compute_send_bms_status_message(acc_data_t* bmsdata, int bms_state, bool balance);
void compute_send_bms_status_message(acc_data_t *bmsdata, int bms_state,
bool balance);

/**
* @brief sends shutdown control message
Expand All @@ -147,7 +141,7 @@ void compute_send_shutdown_ctrl_message(uint8_t mpe_state);
*
* @return Returns a fault if we are not able to send
*/
void compute_send_cell_data_message(acc_data_t* bmsdata);
void compute_send_cell_data_message(acc_data_t *bmsdata);

/**
* @brief sends cell voltage message
Expand All @@ -161,8 +155,8 @@ void compute_send_cell_data_message(acc_data_t* bmsdata);
* @return Returns a fault if we are not able to send
*/
void compute_send_cell_voltage_message(uint8_t cell_id, uint16_t instant_volt,
uint16_t internal_res, uint8_t shunted,
uint16_t open_voltage);
uint16_t internal_res, uint8_t shunted,
uint16_t open_voltage);

/**
* @brief sends out the calculated values of currents
Expand All @@ -171,14 +165,14 @@ void compute_send_cell_voltage_message(uint8_t cell_id, uint16_t instant_volt,
* @param charge
* @param current
*/
void compute_send_current_message(acc_data_t* bmsdata);
void compute_send_current_message(acc_data_t *bmsdata);

/**
* @brief sends cell temperature message
*
* @return Returns a fault if we are not able to send
*/
void compute_send_cell_temp_message(acc_data_t* bmsdata);
void compute_send_cell_temp_message(acc_data_t *bmsdata);

/**
* @brief sends the average segment temperatures
Expand All @@ -187,9 +181,9 @@ void compute_send_cell_temp_message(acc_data_t* bmsdata);
*
* @return Returns a fault if we are not able to send
*/
void compute_send_segment_temp_message(acc_data_t* bmsdata);
void compute_send_segment_temp_message(acc_data_t *bmsdata);

void compute_send_fault_message(uint8_t status, int16_t curr, int16_t in_dcl);
void compute_send_voltage_noise_message(acc_data_t* bmsdata);
void compute_send_voltage_noise_message(acc_data_t *bmsdata);

#endif // COMPUTE_H
Loading

0 comments on commit 6eb3f86

Please sign in to comment.