firmware
IEM Firmware Documentation
|
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"
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. |
Torque vectoring and AMK control.
#define APPS_DEADBAND 0.0F |
#define APPS_MAX 100.0F |
#define LINEAR_TQ_FRONT_COEFF ((1.0F - LINEAR_TQ_REAR_RATIO) / LINEAR_TQ_REAR_RATIO) |
#define LINEAR_TQ_REAR_RATIO 0.8F |
#define TORQUE_LIMIT_NEG 0.0F |
#define TORQUE_LIMIT_POS 21.0F |
enum amk_state |
AMK inverter states.
enum tractive_ctrl |
|
static |
|
static |
Runs the AMK state machine for all four inverters, then sends command CAN messages.
car_flags | Car status flags (received from the state machine task) |
status_ptr | AMK status structs |
|
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.
amk_ptr | AMK status struct (for one inverter) |
|
static |
status_ptr |
|
static |
Packs and sends tractive system status information on CAN 1 in the safety_tractive_status message.
status_ptr | Tractive status struct |
|
static |
Packs and sends an AMK command message on CAN 3, then echoes it on CAN 2.
flags | AMK command flags (error reset, driver enable, HV enable, inverter enable) |
tq_setpoint | Motor torque setpoint in Nm |
tq_limit_pos | Positive torque limit in Nm (only applied if in AMK_ZOOM state) |
tq_limit_neg | Negative torque limit in Nm (only applied if in AMK_ZOOM state) |
id | CAN 3 message ID for the target inverter |
|
static |
Initializes constant configuration values in the TV model inputs struct.
|
inlinestatic |
|
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.
task_params_ptr | Pointer to the FreeRTOS handles struct |
void task_tractive_init | ( | Global_Handles_t * | hdls_ptr | ) |
Initialize the tractive task and input queue.
handles_ptr | Pointer to FreeRTOS handles struct |
|
static |
|
static |
Packs and sends TV logging messages on CAN 2.
|
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)
can_queue_hdl | Tractive CAN queue handle |
car_flags | Car status flags (received from the state machine task) |
status_ptr | AMK status structs |