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

Feat/expand apps error states 243 #245

Merged
merged 8 commits into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from 5 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
6 changes: 5 additions & 1 deletion src/SUFST/Inc/Interfaces/bps.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <stdint.h>

#include "config.h"
#include "log.h"
#include "scs.h"
#include "status.h"

Expand All @@ -22,12 +23,15 @@ typedef struct
scs_t signal;
uint16_t fully_pressed_threshold;
const config_bps_t* config_ptr;
log_context_t* log_ptr;
} bps_context_t;

/*
* public functions
*/
status_t bps_init(bps_context_t* bps_ptr, const config_bps_t* config_ptr);
status_t bps_init(bps_context_t* bps_ptr,
log_context_t* log_ptr,
const config_bps_t* config_ptr);
status_t bps_read(bps_context_t* bps_ptr, uint16_t* reading_ptr);
bool bps_fully_pressed(bps_context_t* bps_ptr);
bool bps_valid(bps_context_t* bps_ptr);
Expand Down
3 changes: 2 additions & 1 deletion src/SUFST/Inc/Interfaces/scs.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ typedef struct
float scale_factor; // cached scale factor for mapping
uint32_t max_bounds_diff; // cached bounds difference for validation
const config_scs_t* config_ptr; // configuration

status_t status;
status_t status_verbose;
} scs_t;

/*
Expand Down
10 changes: 5 additions & 5 deletions src/SUFST/Inc/Services/canbc.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@
*/
typedef struct
{
struct can_s_vcu_sensors_t sensors;
struct can_s_vcu_temps_t temps;
struct can_s_vcu_state_t state;
struct can_s_vcu_error_t errors;
struct can_s_vcu_pdm_t pdm;
struct can_s_vcu_sensors_t sensors;
struct can_s_vcu_temps_t temps;
struct can_s_vcu_state_t state;
struct can_s_vcu_error_t errors;
struct can_s_vcu_pdm_t pdm;
} canbc_states_t;

/**
Expand Down
82 changes: 41 additions & 41 deletions src/SUFST/Inc/Services/ctrl.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
#include "dash.h"
#include "log.h"
#include "pm100.h"
#include "tick.h"
#include "status.h"
#include "tick.h"
#include "torque_map.h"

/*
Expand All @@ -38,55 +38,55 @@
*/
typedef enum
{
CTRL_STATE_TS_BUTTON_WAIT,
CTRL_STATE_WAIT_NEG_AIR,
CTRL_STATE_PRECHARGE_WAIT,
CTRL_STATE_R2D_WAIT,
CTRL_STATE_TS_ON,
CTRL_STATE_R2D_OFF,
CTRL_STATE_R2D_OFF_WAIT,
CTRL_STATE_TS_ACTIVATION_FAILURE,
CTRL_STATE_TS_RUN_FAULT,
CTRL_STATE_SPIN,
CTRL_STATE_APPS_SCS_FAULT,
CTRL_STATE_APPS_BPS_FAULT
CTRL_STATE_TS_BUTTON_WAIT,
CTRL_STATE_WAIT_NEG_AIR,
CTRL_STATE_PRECHARGE_WAIT,
CTRL_STATE_R2D_WAIT,
CTRL_STATE_TS_ON,
CTRL_STATE_R2D_OFF,
CTRL_STATE_R2D_OFF_WAIT,
CTRL_STATE_TS_ACTIVATION_FAILURE,
CTRL_STATE_TS_RUN_FAULT,
CTRL_STATE_SPIN,
CTRL_STATE_APPS_SCS_FAULT,
CTRL_STATE_APPS_BPS_FAULT
} ctrl_state_t;

/**
* @brief Control service context
*/
typedef struct
{
ctrl_state_t state; // state machine state
TX_THREAD thread; // service thread
uint16_t apps_reading; // APPS reading (% * 10)
uint16_t bps_reading; // BPS reading (% * 10)
int16_t sagl_reading; // steering angle reading (deg * 10)
uint16_t torque_request; // last torque request
uint8_t shdn_reading;
int16_t motor_temp;
int16_t inv_temp;
int8_t max_temp;

bool inverter_pwr;
bool pump_pwr;
bool fan_pwr;
ctrl_state_t state; // state machine state
TX_THREAD thread; // service thread
uint16_t apps_reading; // APPS reading (% * 10)
uint16_t bps_reading; // BPS reading (% * 10)
int16_t sagl_reading; // steering angle reading (deg * 10)
uint16_t torque_request; // last torque request
uint8_t shdn_reading;
int16_t motor_temp;
int16_t inv_temp;
int8_t max_temp;

bool inverter_pwr;
bool pump_pwr;
bool fan_pwr;

uint32_t neg_air_start;
uint32_t precharge_start; // precharge start time in ticks
uint32_t motor_torque_zero_start;
uint32_t apps_bps_start;

uint32_t neg_air_start;
uint32_t precharge_start; // precharge start time in ticks
uint32_t motor_torque_zero_start;
uint32_t apps_bps_start;

dash_context_t* dash_ptr; // dash service
pm100_context_t* pm100_ptr; // PM100 service
canbc_context_t* canbc_ptr; // CANBC service
tick_context_t *tick_ptr; // tick thread (reads certain sensors)
torque_map_t torque_map; // torque map (APPS -> torque request)
dash_context_t* dash_ptr; // dash service
pm100_context_t* pm100_ptr; // PM100 service
canbc_context_t* canbc_ptr; // CANBC service
tick_context_t* tick_ptr; // tick thread (reads certain sensors)
torque_map_t torque_map; // torque map (APPS -> torque request)

const config_ctrl_t* config_ptr; // config
const config_rtds_t* rtds_config_ptr; // RTDS config
const config_ctrl_t* config_ptr; // config
const config_rtds_t* rtds_config_ptr; // RTDS config

uint8_t error; // error code
uint8_t error; // error code

} ctrl_context_t;

Expand All @@ -96,7 +96,7 @@ typedef struct
status_t ctrl_init(ctrl_context_t* ctrl_ptr,
dash_context_t* dash_ptr,
pm100_context_t* pm100_ptr,
tick_context_t *tick_ptr,
tick_context_t* tick_ptr,
canbc_context_t* canbc_ptr,
log_context_t* log_ptr,
TX_BYTE_POOL* stack_pool_ptr,
Expand Down
8 changes: 8 additions & 0 deletions src/SUFST/Inc/status.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,12 @@ typedef enum
STATUS_ERROR
} status_t;

typedef enum
{
STATUS_THRESHOLD_OK,
STATUS_THRESHOLD_MISMATCH,
STATUS_THRESHOLD_WARNING,
STATUS_THRESHOLD_ERROR
} scs_status_t;

#endif
44 changes: 35 additions & 9 deletions src/SUFST/Src/Interfaces/apps.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
* @param[in] apps_ptr APPS context
*/
status_t apps_init(apps_context_t* apps_ptr,
log_context_t *log_ptr, const config_apps_t* config_ptr)
log_context_t* log_ptr,
const config_apps_t* config_ptr)
{
apps_ptr->config_ptr = config_ptr;
apps_ptr->scs_error = SCS_ERROR_NONE;
apps_ptr->log_ptr = log_ptr;

// initialise both SCS instances
status_t status
= scs_create(&apps_ptr->apps_1_signal, &config_ptr->apps_1_scs);
Expand Down Expand Up @@ -47,57 +48,82 @@ status_t apps_read(apps_context_t* apps_ptr, uint16_t* reading_ptr)
/* uint8_t time_s = 30; */

/* *reading_ptr */
/* = (uint16_t) ((1000 * (max_torque_percentage / 100)) / (time_s * 100)) */
/* = (uint16_t) ((1000 * (max_torque_percentage / 100)) / (time_s *
* 100)) */
/* * count; // At 100Hz */
/* // 1000 is the max mapped value for APPS (config.c) */

/* count = (count >= (time_s * 100)) ? count : count + 1; */

// read both signals
status_t status_1 = scs_read(&apps_ptr->apps_1_signal, &reading_1);
scs_status_t status_1_verbose = apps_ptr->apps_1_signal.status_verbose;
status_t status_2 = scs_read(&apps_ptr->apps_2_signal, &reading_2);
scs_status_t status_2_verbose = apps_ptr->apps_2_signal.status_verbose;

if (status_1 != STATUS_OK)
{
LOG_INFO(apps_ptr->log_ptr, "APPS1 error; ");
if (status_1_verbose == STATUS_THRESHOLD_ERROR)
{
LOG_INFO(apps_ptr->log_ptr, "APPS1 threshold error; ");
}
else
{
LOG_INFO(apps_ptr->log_ptr, "APPS1 unknown error; ");
}
status = STATUS_ERROR;
apps_ptr->scs_error |= SCS_ERROR_APPS1;
}
else if (status_1_verbose == STATUS_THRESHOLD_WARNING)
{
LOG_INFO(apps_ptr->log_ptr, "APPS1 threshold warning; ");
}

LOG_INFO(apps_ptr->log_ptr, "APPS1 reading: %d; ", reading_1);

if (status_2 != STATUS_OK)
{
LOG_INFO(apps_ptr->log_ptr, "APPS2 error; ");
if (status_2_verbose == STATUS_THRESHOLD_ERROR)
{
LOG_INFO(apps_ptr->log_ptr, "APPS2 threshold error; ");
}
else
{
LOG_INFO(apps_ptr->log_ptr, "APPS2 unknown error; ");
}
status = STATUS_ERROR;
apps_ptr->scs_error |= SCS_ERROR_APPS2;
}
else if (status_2_verbose == STATUS_THRESHOLD_WARNING)
{
LOG_INFO(apps_ptr->log_ptr, "APPS2 threshold warning; ");
}

LOG_INFO(apps_ptr->log_ptr, "APPS2 reading: %d; ", reading_2);

// // check for discrepancy
uint16_t diff = (reading_1 > reading_2) ? (reading_1 - reading_2)
: (reading_2 - reading_1);
: (reading_2 - reading_1);

if (diff > apps_ptr->config_ptr->max_discrepancy)
{
LOG_INFO(apps_ptr->log_ptr, "DIFF error; ");
LOG_INFO(apps_ptr->log_ptr, "DIFF error; ");
status = STATUS_ERROR;
apps_ptr->scs_error |= SCS_ERROR_APPS_DISCREPANCY;
}

// return reading
if (status == STATUS_OK)
{
*reading_ptr = reading_2; //(reading_1 + reading_2) / 2;
*reading_ptr = reading_2; //(reading_1 + reading_2) / 2;
}
else
{
*reading_ptr = 0;
}

LOG_INFO(apps_ptr->log_ptr, "\n");

return status;
}

Expand Down
31 changes: 28 additions & 3 deletions src/SUFST/Src/Interfaces/bps.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
* @param[in] bps_ptr BPS context
* @param[in] config_ptr Configuration
*/
status_t bps_init(bps_context_t* bps_ptr, const config_bps_t* config_ptr)
status_t bps_init(bps_context_t* bps_ptr,
log_context_t* log_ptr,
const config_bps_t* config_ptr)
{
bps_ptr->config_ptr = config_ptr;
bps_ptr->log_ptr = log_ptr;

// compute pressure thresholds
const uint16_t range
Expand All @@ -33,7 +36,29 @@ status_t bps_init(bps_context_t* bps_ptr, const config_bps_t* config_ptr)
*/
status_t bps_read(bps_context_t* bps_ptr, uint16_t* reading_ptr)
{
return scs_read(&bps_ptr->signal, reading_ptr);
status_t status = scs_read(&bps_ptr->signal, reading_ptr);
scs_status_t status_verbose = bps_ptr->signal.status_verbose;

if (status != STATUS_OK)
{
if (status_verbose == STATUS_THRESHOLD_ERROR)
{
LOG_INFO(bps_ptr->log_ptr, "BPS threshold error; ");
}
else
{
LOG_INFO(bps_ptr->log_ptr, "BPS unknown error; ");
}
status = STATUS_ERROR;
}
else if (status_verbose == STATUS_THRESHOLD_WARNING)
{
LOG_INFO(bps_ptr->log_ptr, "BPS threshold warning; ");
}

LOG_INFO(bps_ptr->log_ptr, "BPS reading: %d; ", *reading_ptr);

return status;
}

/**
Expand Down Expand Up @@ -62,7 +87,7 @@ bool bps_fully_pressed(bps_context_t* bps_ptr)
* @retval true BPS is pressed
* @retval false BPS is not pressed, or SCS fault
*/
bool bps_valid(bps_context_t* bps_ptr)
bool bps_valid(bps_context_t* bps_ptr)
{
uint16_t reading = 0;
status_t status = bps_read(bps_ptr, &reading);
Expand Down
Loading