Car state machine.
More...
#include "state.h"
#include <stdint.h>
#include <stdbool.h>
#include <math.h>
#include <stdlib.h>
#include <sys/types.h>
#include "can_rtos.h"
#include "can.h"
#include "can_1.h"
#include "can_2.h"
#include "constants.h"
#include "main.h"
#include "types.h"
#include "rtos.h"
#include "iem_utils.h"
Car state machine.
- Author
- Jamie Pruett :)
- Version
- 0.1
- Date
- 2024-11-01
◆ APPS_DEVIATION_THRESH
#define APPS_DEVIATION_THRESH 10.0F |
◆ APPS_MAX_THRESH
#define APPS_MAX_THRESH 50.0F |
◆ APPS_MIN_THRESH
#define APPS_MIN_THRESH -50.0F |
◆ BP_FRONT_OFFSET
#define BP_FRONT_OFFSET -32.0F |
◆ BP_REAR_OFFSET
#define BP_REAR_OFFSET 0.0F |
◆ BPS_OPEN_THRESH
#define BPS_OPEN_THRESH (uint16_t)((4.7F * (3.0F / 5.0F)) * (65535.0F / 3.3F)) |
◆ BPS_SHORT_THRESH
#define BPS_SHORT_THRESH (uint16_t)((0.3F * (3.0F / 5.0F)) * (65535.0F / 3.3F)) |
◆ BRAKE_THRESHOLD_PSI
#define BRAKE_THRESHOLD_PSI 70.0F |
◆ BTSF_APPS_ACTV_THRESH
#define BTSF_APPS_ACTV_THRESH 25.0F |
◆ BTSF_APPS_DEACTV_THRESH
#define BTSF_APPS_DEACTV_THRESH 5.0F |
◆ BTSF_EMA_DENOM
◆ FAULT_ACTIVE
#define FAULT_ACTIVE true |
◆ HV_CONNECTED_ACTIVE
#define HV_CONNECTED_ACTIVE false |
◆ PUMP_OFF_DUTY_CYCLE
#define PUMP_OFF_DUTY_CYCLE 0x10 |
◆ PUMP_ON_DUTY_CYCLE
#define PUMP_ON_DUTY_CYCLE 0xFF |
◆ SHUTDOWN_CLOSED_ACTIVE
#define SHUTDOWN_CLOSED_ACTIVE false |
◆ SOFT_FAULT_TIME_MS
#define SOFT_FAULT_TIME_MS 100 |
◆ TIMER_BLINK_LED_MIN
#define TIMER_BLINK_LED_MIN 500 |
◆ TIMER_BLINK_LED_RANGE
#define TIMER_BLINK_LED_RANGE 2000 |
◆ TIMER_RTDS_MS
#define TIMER_RTDS_MS 3000 |
◆ TIMER_RTDS_NAME
#define TIMER_RTDS_NAME "tim_rtds" |
◆ TSSI_CTRL_RED
#define TSSI_CTRL_RED true |
◆ TSSI_IMD_CLEAR_WINDOW
◆ __aligned()
◆ brake_raw_to_pressure_f()
◆ brake_raw_to_pressure_r()
◆ bspd_raw_to_current()
◆ car_state_machine()
Car state machine.
- Parameters
-
flags_ptr | Car state flags |
timer_rtds_hdl | RTDS FreeRTOS timer handle |
◆ check_apps()
Checks for an APPS soft fault.
- Parameters
-
a_raw | APPS A raw value |
b_raw | APPS B raw value |
- Returns
- bool true if there's an APPS fault
◆ check_btsf()
enum btsf_fault check_btsf |
( |
bool | brake_pressed, |
|
|
uint16_t | bps_raw, |
|
|
float | throttle_pos ) |
|
static |
Checks for a BTSF fault.
- Parameters
-
brake_pressed | Whether the brake is pressed |
bps_raw | Front brake pressure sensor raw ADC reading |
throttle_pos | Throttle position (percent) |
- Returns
- BTSF fault state
◆ get_brake_pressure()
float get_brake_pressure |
( |
| ) |
|
◆ log_car_status()
Sets values for, packs, and sends the safety_status message on CAN 1.
- Parameters
-
flags | |
adc_buffer_ptr | Pointer to the ADC DMA buffer struct |
◆ lv_batt_raw_to_voltage()
◆ read_gpio()
void read_gpio |
( |
union car_flags * | flags_ptr | ) |
|
|
static |
Polls GPIO fault and status pins for state machine inputs. This function accounts for pin active levels - that is, "true" in the flags struct indicates that the pin is in its active state whether the active state is high or low.
- Parameters
-
◆ task_state()
void task_state |
( |
void * | task_params_ptr | ) |
|
|
static |
Implements the state machine task.
- Parameters
-
task_params_ptr | Pointer to the FreeRTOS handles struct |
This task is scheduled periodically. It checks all state machine inputs (GPIO states, soft fault states, data from CAN messages, software timers) to see if they have changed. If they have, it runs the car state machine and any state-dependent code. The safety_status message is sent here on CAN 2 for logging every time the task is scheduled.
◆ task_state_init()
Initialize the state machine task and input queue.
- Parameters
-
handles_ptr | Pointer to FreeRTOS handles struct |
◆ timer_blink_led_callback()
Very important functionality.
- Parameters
-
timer_hdl | FreeRTOS timer handle |
◆ timer_rtds_callback()
◆ transmit_pump_enable_msg()
void transmit_pump_enable_msg |
( |
bool | enable | ) |
|
|
static |
◆ g_adc1_buffer
DMA_VAR struct adc1_buffer g_adc1_buffer |
◆ g_adc2_buffer
DMA_VAR struct adc2_buffer g_adc2_buffer |