Skip to content

Commit

Permalink
this might work? also updated final drive
Browse files Browse the repository at this point in the history
  • Loading branch information
jstri114 committed May 30, 2024
1 parent cb3eb79 commit 2f30896
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 17 deletions.
4 changes: 2 additions & 2 deletions include/parameters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
const unsigned long LAUNCHCONTROL_RELEASE_DELAY = 1500;
#define WHEELSPEED_TOOTH_COUNT 18 // Wheel Speed sensor tooth coutn
const float WHEEL_CIRCUMFERENCE = 0.229*PI*2;
const float FRONT_SPROCKET_TEETH = 10;
const float REAR_SPROCKET_TEETH = 29;
const float FRONT_SPROCKET_TEETH = 16; // Updated 5/29/24 for 228hv
const float REAR_SPROCKET_TEETH = 29; // Updated 5/29/24 for 228hv
const float FINAL_DRIVE = FRONT_SPROCKET_TEETH/REAR_SPROCKET_TEETH;
#define RPM_TIMEOUT 1000 // Timeout for wheel speed RPM to reset to 0
#define MIN_BRAKE_PEDAL 400 // ~0.5v, set on 2-29-2024
Expand Down
6 changes: 3 additions & 3 deletions include/tc_system.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
class torque_control_system
{
public:
torque_control_system(std::initializer_list<torque_control_types_e> enabledTypes = {torque_control_types_e::TC_DRIVERCONTROL, torque_control_types_e::TC_PID, torque_control_types_e::TC_TimeSlip})
torque_control_system(std::initializer_list<torque_control_types_e> enabledTypes = {torque_control_types_e::TC_DRIVERCONTROL, torque_control_types_e::TC_PID, torque_control_types_e::TC_SlipTime})
{
for (auto type : enabledTypes)
{
Expand All @@ -34,13 +34,13 @@ class torque_control_system
torque_control_types_e tcType = torque_control_types_e::TC_DRIVERCONTROL;
torque_controller tc_base;
torque_controllerPID tc_pid = torque_controllerPID(1.0, 0, 0);
torque_controllerTimeSlip tc_timeslip;
torque_controllerSlipTime tc_sliptime;

// This map should contain ALL types
std::unordered_map<torque_control_types_e, void *> tc_map = {
{torque_control_types_e::TC_DRIVERCONTROL, &tc_base},
{torque_control_types_e::TC_PID, &tc_pid},
{torque_control_types_e::TC_TimeSlip, &tc_timeslip}};
{torque_control_types_e::TC_SlipTime, &tc_sliptime}};

// This map will only have enabled types
std::unordered_map<torque_control_types_e, void *> enabled_tc_map;
Expand Down
12 changes: 4 additions & 8 deletions include/torque_controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,19 +104,15 @@ class torque_controllerSlipTime : public torque_controller
const double tireSlipHigh = 0.05; // Slip threshold
unsigned long _lastSlip = 0; // Time slip began
unsigned long slip_dT = 0; // Time delta since slip first began
double slipTime = 0; // Slip * time, the x axis
bool slipActive = false; // Flag to indicate if slip is active
static const int numPoints = 5; // Number of data points
double xSlipTime[numPoints] = {10, 20, 30, 40, 50}; // x-coordinates of data points
double yTorqueRTD[numPoints] = {0.0, 0.5, 0.6, 0.2, 0.0}; // y-coordinates of data points
static const int numPoints = 6; // Number of data points
double yTorqueRTD[numPoints] = {10, 20, 30, 50, 80, 160}; // TQ in Nm to reduce the output by
double xSlipTime[numPoints] = {50, 100, 200, 400, 600, 1000}; // SlipTime, is % slip * time (ms)
double slopes[numPoints]; // Slopes at each point for interpolation
double outputTorqueRTD = 0; // Torque Retard due to controller
double slipTime = 0;


public:
int16_t calculate_torque(unsigned long elapsedTime, int16_t maxTorque, wheelSpeeds_s &wheelSpeedData);
torque_control_types_e getType() {return torque_control_types_e::TC_SlipTime;}


};
#endif
4 changes: 2 additions & 2 deletions src/tc_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ void torque_control_system::printControllerType()
printf("Controller type is tc_PID");
break;
}
case (torque_control_types_e::TC_TimeSlip):
case (torque_control_types_e::TC_SlipTime):
{
printf("Controller type is tc_TimeSlip");
printf("Controller type is tc_SlipTime");
break;
}
case (torque_control_types_e::TC_NUM_CONTROLLERS):
Expand Down
3 changes: 1 addition & 2 deletions src/torque_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ int16_t torque_controllerSlipTime::calculate_torque(unsigned long elapsedTime, i
slipActive = false; // Catch all, should disable whenever slip ratio falls below threshold and slip active was true
}


// Check bounds
if (slipTime < xSlipTime[0] || slipTime > xSlipTime[numPoints - 1]) {
Serial.println("slipTime out of bounds");
Expand All @@ -110,6 +109,7 @@ int16_t torque_controllerSlipTime::calculate_torque(unsigned long elapsedTime, i
outputTorqueRTD = yTorqueRTD[numPoints - 1];
}

// Limit torque outputs like normal
torqueOut = outputTorqueRTD;
lcTorqueRequest = static_cast<int16_t>(torqueOut); // Pre clamping
if (torqueOut > maxTorque)
Expand All @@ -121,7 +121,6 @@ int16_t torque_controllerSlipTime::calculate_torque(unsigned long elapsedTime, i
torqueOut = 0;
}


outputTorqueCommand = static_cast<int16_t>(torqueOut); // Post-clamping
return outputTorqueCommand;
}

0 comments on commit 2f30896

Please sign in to comment.