firmware
IEM Firmware Documentation
Loading...
Searching...
No Matches
tractive.c File Reference

Torque vectoring and AMK control. More...

#include "tractive.h"
#include <stdbool.h>
#include "iem_utils.h"
#include "state.h"
#include "vnav.h"
#include "can_rtos.h"
#include "can.h"
#include "can_1.h"
#include "can_2.h"
#include "can_3.h"
#include "main.h"
#include "IEM25_TV_v_2_2.h"
Include dependency graph for tractive.c:

Data Structures

struct  amk_status
struct  amk_cmd_flags
struct  tractive_status

Macros

#define APPS_DEADBAND   0.0F
#define APPS_MAX   100.0F
#define TORQUE_LIMIT_POS   21.0F
#define TORQUE_LIMIT_NEG   0.0F
#define LINEAR_TQ_REAR_RATIO   0.8F
#define LINEAR_TQ_FRONT_COEFF   ((1.0F - LINEAR_TQ_REAR_RATIO) / LINEAR_TQ_REAR_RATIO)

Enumerations

enum  amk_state {
  AMK_INACTIVE , AMK_HV_ENABLE , AMK_INVERTER_ENABLE , AMK_ZOOM ,
  AMK_ERROR
}
 AMK inverter states. More...
enum  tractive_ctrl {
  CTRL_TQ_VECTORING , CTRL_LINEAR_SPLIT_FR , CTRL_RWD , CTRL_FWD ,
  CTRL_LIMP_MODE , CTRL_INACTIVE
}

Functions

static __always_inline float throttle_to_tq (float pos)
static float steering_angle_offset (float pos)
static void task_tractive (void *task_params_ptr)
 Implements the tractive task.
static void set_tv_constants ()
 Initializes constant configuration values in the TV model inputs struct.
static void update_inputs (QueueHandle_t can_queue_hdl, struct tractive_status *status_ptr)
 Receives TV-related CAN message data from the tractive inputs queue, unpacks them and applies any needed post-processing, then updates the TV model inputs struct and AMK status structs (for AMK status messages)
static void check_timeouts (struct tractive_status *status_ptr)
static enum tractive_ctrl amk_ctrl (union car_flags car_flags, struct tractive_status *status_ptr)
static void amk_state_machine (struct amk_status *amk_ptr, bool hv_enable, bool inv_enable, struct amk_cmd_flags *cmd_flags_ptr)
 AMK state machine function Sets flags (error reset, driver enable, HV enable, and inverter enable) in the unpacked AMK command CAN message depending on the inverter state and updates the inverter state in the AMK status struct.
static void send_amk_cmd (struct amk_cmd_flags flags, enum amk_state state, float tq_setpoint, float tq_limit_pos, float tq_limit_neg, uint32_t id)
 Packs and sends an AMK command message on CAN 3, then echoes it on CAN 2.
static void log_tractive_status (struct tractive_status *status_ptr, enum tractive_ctrl ctrl_type)
 Packs and sends tractive system status information on CAN 1 in the safety_tractive_status message.
static void tv_logging ()
 Packs and sends TV logging messages on CAN 2.
void task_tractive_init (Global_Handles_t *hdls_ptr)
 Initialize the tractive task and input queue.
static enum tractive_ctrl amk_ctrl (union car_flags car_flags, struct tractive_status *status_ptr)
 Runs the AMK state machine for all four inverters, then sends command CAN messages.

Detailed Description

Torque vectoring and AMK control.

Author
Jamie Pruett :)
Version
0.1
Date
2024-11-01

Macro Definition Documentation

◆ APPS_DEADBAND

#define APPS_DEADBAND   0.0F

◆ APPS_MAX

#define APPS_MAX   100.0F

◆ LINEAR_TQ_FRONT_COEFF

#define LINEAR_TQ_FRONT_COEFF   ((1.0F - LINEAR_TQ_REAR_RATIO) / LINEAR_TQ_REAR_RATIO)

◆ LINEAR_TQ_REAR_RATIO

#define LINEAR_TQ_REAR_RATIO   0.8F

◆ TORQUE_LIMIT_NEG

#define TORQUE_LIMIT_NEG   0.0F

◆ TORQUE_LIMIT_POS

#define TORQUE_LIMIT_POS   21.0F

Enumeration Type Documentation

◆ amk_state

enum amk_state

AMK inverter states.

Enumerator
AMK_INACTIVE 

AMK is inactive, either because we aren't in a car state where it should be active, we aren't receiving status messages over CAN, or we just recovered from an error.

AMK_HV_ENABLE 

Enabling HV (car state >= PRECHARGED)

AMK_INVERTER_ENABLE 

Enabling the inverter (HV enable is complete, car state >= RTDS)

AMK_ZOOM 

AMK is active with no errors - OK to drive.

AMK_ERROR 

AMK errored outside of AMK_INACTIVE. Try to clear the error and return to AMK_INACTIVE if successful.

◆ tractive_ctrl

Enumerator
CTRL_TQ_VECTORING 
CTRL_LINEAR_SPLIT_FR 
CTRL_RWD 
CTRL_FWD 
CTRL_LIMP_MODE 
CTRL_INACTIVE 

Function Documentation

◆ amk_ctrl() [1/2]

enum tractive_ctrl amk_ctrl ( union car_flags car_flags,
struct tractive_status * status_ptr )
static
Here is the caller graph for this function:

◆ amk_ctrl() [2/2]

enum tractive_ctrl amk_ctrl ( union car_flags car_flags,
struct tractive_status * status_ptr )
static

Runs the AMK state machine for all four inverters, then sends command CAN messages.

Parameters
car_flagsCar status flags (received from the state machine task)
status_ptrAMK status structs
Here is the call graph for this function:

◆ amk_state_machine()

void amk_state_machine ( struct amk_status * amk_ptr,
bool hv_enable,
bool inv_enable,
struct amk_cmd_flags * cmd_flags_ptr )
static

AMK state machine function Sets flags (error reset, driver enable, HV enable, and inverter enable) in the unpacked AMK command CAN message depending on the inverter state and updates the inverter state in the AMK status struct.

Parameters
amk_ptrAMK status struct (for one inverter)
Here is the caller graph for this function:

◆ check_timeouts()

void check_timeouts ( struct tractive_status * status_ptr)
static
Parameters
status_ptr
Here is the call graph for this function:
Here is the caller graph for this function:

◆ log_tractive_status()

void log_tractive_status ( struct tractive_status * status_ptr,
enum tractive_ctrl ctrl_type )
static

Packs and sends tractive system status information on CAN 1 in the safety_tractive_status message.

Parameters
status_ptrTractive status struct
Here is the call graph for this function:
Here is the caller graph for this function:

◆ send_amk_cmd()

void send_amk_cmd ( struct amk_cmd_flags flags,
enum amk_state state,
float tq_setpoint,
float tq_limit_pos,
float tq_limit_neg,
uint32_t id )
static

Packs and sends an AMK command message on CAN 3, then echoes it on CAN 2.

Parameters
flagsAMK command flags (error reset, driver enable, HV enable, inverter enable)
tq_setpointMotor torque setpoint in Nm
tq_limit_posPositive torque limit in Nm (only applied if in AMK_ZOOM state)
tq_limit_negNegative torque limit in Nm (only applied if in AMK_ZOOM state)
idCAN 3 message ID for the target inverter
Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_tv_constants()

void set_tv_constants ( void )
static

Initializes constant configuration values in the TV model inputs struct.

Here is the caller graph for this function:

◆ steering_angle_offset()

float steering_angle_offset ( float pos)
inlinestatic
Here is the caller graph for this function:

◆ task_tractive()

void task_tractive ( void * task_params_ptr)
static

Implements the tractive task.

After initialization, this task sets constant values in the TV model input struct, then waits until values have been received for all sensor/external inputs before continuing. The task is scheduled periodically on a consistent interval - each time it's scheduled, it updates the TV input struct with any new values and runs the model step function, runs the AMK state machine for all four inverters, then sends command messages to each (with torque limits/setpoint set if the car is in ZOOM state and all the inverters are active). Command messages are echoed on CAN 2.

Parameters
task_params_ptrPointer to the FreeRTOS handles struct
Here is the call graph for this function:
Here is the caller graph for this function:

◆ task_tractive_init()

void task_tractive_init ( Global_Handles_t * hdls_ptr)

Initialize the tractive task and input queue.

Parameters
handles_ptrPointer to FreeRTOS handles struct
Here is the call graph for this function:
Here is the caller graph for this function:

◆ throttle_to_tq()

__always_inline float throttle_to_tq ( float pos)
static
Here is the caller graph for this function:

◆ tv_logging()

void tv_logging ( void )
static

Packs and sends TV logging messages on CAN 2.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ update_inputs()

void update_inputs ( QueueHandle_t can_queue_hdl,
struct tractive_status * status_ptr )
static

Receives TV-related CAN message data from the tractive inputs queue, unpacks them and applies any needed post-processing, then updates the TV model inputs struct and AMK status structs (for AMK status messages)

Parameters
can_queue_hdlTractive CAN queue handle
car_flagsCar status flags (received from the state machine task)
status_ptrAMK status structs
Here is the call graph for this function:
Here is the caller graph for this function: