From 420194fb8969a237b15dcbe48e5243f4714cae26 Mon Sep 17 00:00:00 2001 From: Michael Jansen Date: Mon, 7 Oct 2024 13:25:52 -0400 Subject: [PATCH 1/2] Prevent torque loss from being negative --- pathplannerlib-python/pathplannerlib/config.py | 2 +- .../java/com/pathplanner/lib/config/ModuleConfig.java | 3 ++- .../include/pathplanner/lib/config/ModuleConfig.h | 10 ++++++---- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/pathplannerlib-python/pathplannerlib/config.py b/pathplannerlib-python/pathplannerlib/config.py index 6b557b5d..461baf20 100644 --- a/pathplannerlib-python/pathplannerlib/config.py +++ b/pathplannerlib-python/pathplannerlib/config.py @@ -59,7 +59,7 @@ def __init__(self, wheelRadiusMeters: float, maxDriveVelocityMPS: float, wheelCO self.maxDriveVelocityRadPerSec = self.maxDriveVelocityMPS / self.wheelRadiusMeters maxSpeedCurrentDraw = self.driveMotor.current(self.maxDriveVelocityRadPerSec, 12.0) - self.torqueLoss = self.driveMotor.torque(min(maxSpeedCurrentDraw, self.driveCurrentLimit)) + self.torqueLoss = max(self.driveMotor.torque(min(maxSpeedCurrentDraw, self.driveCurrentLimit)), 0.0) class RobotConfig: diff --git a/pathplannerlib/src/main/java/com/pathplanner/lib/config/ModuleConfig.java b/pathplannerlib/src/main/java/com/pathplanner/lib/config/ModuleConfig.java index e948f5bd..29559a95 100644 --- a/pathplannerlib/src/main/java/com/pathplanner/lib/config/ModuleConfig.java +++ b/pathplannerlib/src/main/java/com/pathplanner/lib/config/ModuleConfig.java @@ -53,6 +53,7 @@ public ModuleConfig( this.maxDriveVelocityRadPerSec = this.maxDriveVelocityMPS / this.wheelRadiusMeters; double maxSpeedCurrentDraw = this.driveMotor.getCurrent(this.maxDriveVelocityRadPerSec, 12.0); this.torqueLoss = - this.driveMotor.getTorque(Math.min(maxSpeedCurrentDraw, this.driveCurrentLimit)); + Math.max( + this.driveMotor.getTorque(Math.min(maxSpeedCurrentDraw, this.driveCurrentLimit)), 0.0); } } diff --git a/pathplannerlib/src/main/native/include/pathplanner/lib/config/ModuleConfig.h b/pathplannerlib/src/main/native/include/pathplanner/lib/config/ModuleConfig.h index e7c496e4..3a363dff 100644 --- a/pathplannerlib/src/main/native/include/pathplanner/lib/config/ModuleConfig.h +++ b/pathplannerlib/src/main/native/include/pathplanner/lib/config/ModuleConfig.h @@ -44,10 +44,12 @@ class ModuleConfig { maxDriveVelocityMPS), wheelCOF(wheelCOF), driveMotor(driveMotor), driveCurrentLimit( driveCurrentLimit * numMotors), maxDriveVelocityRadPerSec { maxDriveVelocityMPS() / wheelRadius() }, torqueLoss( - driveMotor.Torque( - units::math::min( - driveMotor.Current(maxDriveVelocityRadPerSec, 12_V), - driveCurrentLimit))) { + units::math::max( + driveMotor.Torque( + units::math::min( + driveMotor.Current( + maxDriveVelocityRadPerSec, 12_V), + driveCurrentLimit)), 0_Nm)) { } }; } From 87e72ed6e40d80efdd8c7b7a66f9fafe1454d0f2 Mon Sep 17 00:00:00 2001 From: Michael Jansen Date: Mon, 7 Oct 2024 13:30:07 -0400 Subject: [PATCH 2/2] prevent negative torque loss in GUI --- lib/trajectory/trajectory.dart | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/trajectory/trajectory.dart b/lib/trajectory/trajectory.dart index 33fc7a1c..c96b18da 100644 --- a/lib/trajectory/trajectory.dart +++ b/lib/trajectory/trajectory.dart @@ -154,6 +154,7 @@ class PathPlannerTrajectory { robotConfig.moduleConfig.driveCurrentLimit); num torqueLoss = robotConfig.moduleConfig.driveMotor.getTorque(maxVelCurrent); + torqueLoss = max(torqueLoss, 0.0); num moduleFrictionForce = (robotConfig.moduleConfig.wheelCOF * (robotConfig.massKG * 9.8)) /