Skip to content
Draft
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
1 change: 1 addition & 0 deletions firmware/boot/bootloader.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once
#include <stdint.h>
#include <stdnoreturn.h>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

damn I didn't even know about that


// Keep CAN protocol in sync with:
// canup/bootloader.py
Expand Down
2 changes: 2 additions & 0 deletions firmware/quintuna/VC/src/app/states/app_driveState.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "app_regen.h"
#include "app_vehicleDynamicsConstants.h"
#include "app_torqueVectoring.h"
#include "app_powerLimiting.h"
#include "app_vehicleDynamics.h"
#include "app_torqueDistribution.h"
#include "app_driveHandling.h"
Expand Down Expand Up @@ -160,6 +161,7 @@ static void driveStateRunOnEntry()
app_enable_inv();
app_switchInit();
app_reset_torqueToMotors(&torqueOutputToMotors);
app_pwer_limiting_TestRun_OverCurrent_Timer_Init();
app_torqueVectoring_init();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ void app_driveMode_run(const float apps_pedal_percentage, TorqueAllocationOutput
}
case DRIVE_MODE_POWER_AND_ACTIVE:
{
if (!sensor_status.steeringOk)
if (!sensor_status.steeringOk) // TODO: NEED TO CHANGE THIS TO JUST TORQUE 0
{
app_canAlerts_VC_Info_DriveModeOverride_set(true);
app_vanillaDrive_run(apps_pedal_percentage, torqueOutputToMotors);
Expand All @@ -106,8 +106,7 @@ void app_driveMode_run(const float apps_pedal_percentage, TorqueAllocationOutput
powerLimitingInputs.power_limit = power_limit;
powerLimitingInputs.torqueToMotors = torqueOutputToMotors;
powerLimitingInputs.total_requestedPower = app_totalPower(torqueOutputToMotors);
app_powerLimiting_torqueReduction(&powerLimitingInputs);
/// dont use torque allocation here
app_power_limiting_TestRun_Torque_Reduction(&powerLimitingInputs); /// dont use torque allocation here
app_canTx_VC_VcDriveMode_set(DRIVE_MODE_POWER_AND_ACTIVE);
LOG_INFO("DriveHandling: Active Diff Power Limit Mode Active");
break;
Expand Down
41 changes: 41 additions & 0 deletions firmware/quintuna/VC/src/app/vehicle_dynamics/app_powerLimiting.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,18 @@
#include "app_canRx.h"
#include "app_vehicleDynamics.h"
#include "app_utils.h"
#include "app_timer.h"

//--------------Defines-----------------//
#define MAX_CURRENT_LIMIT_A 175.0f
#define CONTINOUS_CURRENT_LIMIT_A 75.0f
#define POWER_CALC(tractive_voltage, current) ((tractive_voltage) * (current) / 1000.0f)
#define OVER_CURRENT_TIME_OUT_MS 3000

//--------------Static Variables-----------------//
static TimerChannel quintuna_test_run_pl_timer;

//--------------Function Definitions-----------------//
float app_totalPower(TorqueAllocationOutputs *torques)
{
return (float)(TORQUE_TO_POWER(torques->front_left_torque, fabsf((float)app_canRx_INVFL_ActualVelocity_get())) +
Expand Down Expand Up @@ -94,3 +105,33 @@ void app_powerLimiting_torqueReduction(PowerLimitingInputs *inputs)
inputs->torqueToMotors->rear_right_torque =
(float)CLAMP(inputs->torqueToMotors->rear_right_torque, MAX_REGEN_Nm, MAX_TORQUE_REQUEST_NM);
}

// I know this doesn't look the prettiest but I was unsure where to put this

void app_pwer_limiting_TestRun_OverCurrent_Timer_Init(void)
{
app_timer_init(&quintuna_test_run_pl_timer, OVER_CURRENT_TIME_OUT_MS);
}

void app_power_limiting_TestRun_Torque_Reduction(PowerLimitingInputs *inputs)
{
// Fatima mentioned the max voltage is 120 * 3 thus even with our max current draw of 175 A, we are well below our rules requirement of 80kw
// thus the check is not done here
static float prev_curr_req = 0.0f;
const float current_req = app_canRx_BMS_TractiveSystemCurrent_get();
const bool run_over_current_timer = prev_curr_req >= MAX_CURRENT_LIMIT_A && current_req >= MAX_CURRENT_LIMIT_A;

const bool over_current_warning = app_timer_runIfCondition(&quintuna_test_run_pl_timer, run_over_current_timer) == TIMER_STATE_EXPIRED;

// if we are hitting slow blow fuse req then bring current draw down to continous draw limit
if(true == over_current_warning)
{
const float avg_torque_reduction = (inputs->total_requestedPower - POWER_CALC(app_canRx_BMS_TractiveSystemVoltage_get(), CONTINOUS_CURRENT_LIMIT_A)) / app_totalWheelSpeed();
inputs->torqueToMotors->front_left_torque -= avg_torque_reduction;
inputs->torqueToMotors->front_right_torque -= avg_torque_reduction;
inputs->torqueToMotors->rear_left_torque -= avg_torque_reduction;
inputs->torqueToMotors->rear_right_torque -= avg_torque_reduction;
}

prev_curr_req = current_req; // for debouncing
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@ float getMaxMotorTemp(void);

void app_powerLimiting_torqueReduction(PowerLimitingInputs *inputs);

void app_power_limiting_TestRun_Torque_Reduction(PowerLimitingInputs *inputs);
app_pwer_limiting_TestRun_OverCurrent_Timer_Init(void);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return value pls?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my bad big bro


float app_totalPower(TorqueAllocationOutputs *torques);
Loading