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

Add fan & pump thresholds to ctrl config struct #235

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
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
6 changes: 4 additions & 2 deletions src/SUFST/Inc/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ typedef struct {
uint32_t precharge_timeout_ticks; // ticks after which waiting for precharge times out
uint32_t ready_wait_led_toggle_ticks; // ticks between toggling the TS on LED while waiting for 'TS ready' from relay controller
uint32_t error_led_toggle_ticks; // ticks between toggling TS on LED in activation error
uint16_t apps_bps_high_threshold; // apps reading to fault when brake also pressed
uint16_t apps_bps_low_threshold; // apps reading to recover from fault
uint16_t apps_bps_high_threshold; // apps reading to fault when brake also pressed
uint16_t apps_bps_low_threshold; // apps reading to recover from fault
uint16_t fan_on_threshold; // temperature at which to turn on the fan
uint16_t fan_off_threshold; // temperature at which to turn off the fan
} config_ctrl_t;

/**
Expand Down
71 changes: 54 additions & 17 deletions src/SUFST/Src/Services/ctrl.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,26 +125,61 @@ void ctrl_thread_entry(ULONG input)

while (1)
{
uint32_t start_time = tx_time_get();
dash_update_buttons(ctrl_ptr->dash_ptr);

ctrl_ptr->shdn_reading = trc_ready();
//ctrl_ptr->motor_temp = pm100_motor_temp(ctrl_ptr->pm100_ptr);
//ctrl_ptr->inv_temp = pm100_max_inverter_temp(ctrl_ptr->pm100_ptr);
//LOG_INFO(log_h, "Motor temp: %d Inverter temp: %d\n", ctrl_ptr->motor_temp,
// ctrl_ptr->inv_temp);

ctrl_ptr->fan_pwr = 0;
ctrl_ptr->pump_pwr = ((tx_time_get() / TX_TIMER_TICKS_PER_SECOND / 5) % 5) == 0;

ctrl_state_machine_tick(ctrl_ptr);
ctrl_update_canbc_states(ctrl_ptr);
uint32_t run_time = tx_time_get() - start_time;

tx_thread_sleep(ctrl_ptr->config_ptr->schedule_ticks);
uint32_t start_time = tx_time_get();
dash_update_buttons(ctrl_ptr->dash_ptr);

ctrl_ptr->shdn_reading = trc_ready();
ctrl_ptr->motor_temp = pm100_motor_temp(ctrl_ptr->pm100_ptr);
ctrl_ptr->inv_temp = pm100_max_inverter_temp(ctrl_ptr->pm100_ptr);
LOG_INFO(log_h, "Motor temp: %d Inverter temp: %d\n", ctrl_ptr->motor_temp,
ctrl_ptr->inv_temp);

if (ctrl_fan_passed_threshold(ctrl_ptr))
{
ctrl_ptr->fan_pwr = 1;
}
else if(ctrl_ptr->fan_pwr)
{
if (ctrl_fan_passed_off_threshold(ctrl_ptr))
{
ctrl_ptr->fan_pwr = 0;
}
}
else
{
ctrl_ptr->fan_pwr = 0;
}

ctrl_state_machine_tick(ctrl_ptr);
ctrl_update_canbc_states(ctrl_ptr);

tx_thread_sleep(ctrl_ptr->config_ptr->schedule_ticks);
}
}

/**
* @brief Checks the motor and inverter temperatures to determine if the fan should be turned on
*
* @param[in] ctrl_ptr Control service pointer
*
* @return True if the fan should be turned on
*/
bool ctrl_fan_passed_on_threshold(ctrl_context_t* ctrl_ptr)
{
return ctrl_ptr->motor_temp > ctrl_ptr->config_ptr->fan_on_threshold || ctrl_ptr->inv_temp > ctrl_ptr->config_ptr->fan_on_threshold;
}

/**
* @brief Checks the motor and inverter temperatures to determine if the fan should be turned off
*
* @param[in] ctrl_ptr Control service pointer
*
* @return True if the fan should be turned off
*/
bool ctrl_fan_passed_off_threshold(ctrl_context_t* ctrl_ptr) {
return ctrl_ptr->motor_temp < ctrl_ptr->config_ptr->fan_off_threshold || ctrl_ptr->inv_temp < ctrl_ptr->config_ptr->fan_off_threshold;
}

/**
* @brief Runs one tick of the state machine for the control service
*
Expand Down Expand Up @@ -257,6 +292,7 @@ void ctrl_state_machine_tick(ctrl_context_t* ctrl_ptr)
dash_set_r2d_led_state(dash_ptr, GPIO_PIN_SET);
pm100_disable(ctrl_ptr->pm100_ptr);
rtds_activate(ctrl_ptr->rtds_config_ptr, log_h);
ctrl_ptr->pump_pwr = 1;

next_state = CTRL_STATE_TS_ON;

Expand Down Expand Up @@ -339,6 +375,7 @@ void ctrl_state_machine_tick(ctrl_context_t* ctrl_ptr)
ctrl_ptr->torque_request = 0;
status_t pm100_status = pm100_request_torque(ctrl_ptr->pm100_ptr, 0);
ctrl_ptr->motor_torque_zero_start = tx_time_get();
ctrl_ptr->pump_pwr = 0;

if (pm100_status != STATUS_OK)
{
Expand Down
2 changes: 2 additions & 0 deletions src/SUFST/Src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ static const config_t config_instance = {
.r2d_requires_brake = true,
.apps_bps_low_threshold = 5,
.apps_bps_high_threshold = 20,
.fan_on_threshold = 60, // to be adjusted to the actual value
.fan_off_threshold = 50, // to be adjusted to the actual value
.ts_ready_poll_ticks = SECONDS_TO_TICKS(0.1),
.ts_ready_timeout_ticks = SECONDS_TO_TICKS(5),
.precharge_timeout_ticks = SECONDS_TO_TICKS(5),
Expand Down