Updated swerve module optimizations and moved math to SwerveMath.

This commit is contained in:
thenetworkgrinch
2023-03-29 07:24:24 -05:00
parent 8d83836a8a
commit d160c01364
121 changed files with 813 additions and 597 deletions

View File

@@ -1,11 +1,11 @@
<!DOCTYPE HTML>
<html lang="en">
<head>
<!-- Generated by javadoc (17) on Tue Mar 28 10:14:05 CDT 2023 -->
<!-- Generated by javadoc (17) on Wed Mar 29 07:20:20 CDT 2023 -->
<title>SwerveMath</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="dc.created" content="2023-03-28">
<meta name="dc.created" content="2023-03-29">
<meta name="description" content="declaration: package: swervelib.math, class: SwerveMath">
<meta name="generator" content="javadoc/ClassWriterImpl">
<link rel="stylesheet" type="text/css" href="../../stylesheet.css" title="Style">
@@ -106,85 +106,105 @@ loadScripts(document, 'script');</script>
<div class="table-header col-first">Modifier and Type</div>
<div class="table-header col-second">Method</div>
<div class="table-header col-last">Description</div>
<div class="col-first even-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4"><code>static double</code></div>
<div class="col-second even-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4"><code><a href="#applyDeadband(double,boolean,double)" class="member-name-link">applyDeadband</a><wbr>(double&nbsp;value,
<div class="col-first even-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4"><code>static void</code></div>
<div class="col-second even-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4"><code><a href="#antiJitter(swervelib.math.SwerveModuleState2,swervelib.math.SwerveModuleState2,double)" class="member-name-link">antiJitter</a><wbr>(<a href="SwerveModuleState2.html" title="class in swervelib.math">SwerveModuleState2</a>&nbsp;moduleState,
<a href="SwerveModuleState2.html" title="class in swervelib.math">SwerveModuleState2</a>&nbsp;lastModuleState,
double&nbsp;maxSpeed)</code></div>
<div class="col-last even-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4">
<div class="block">Perform anti-jitter within modules if the speed requested is too low.</div>
</div>
<div class="col-first odd-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4"><code>static double</code></div>
<div class="col-second odd-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4"><code><a href="#applyDeadband(double,boolean,double)" class="member-name-link">applyDeadband</a><wbr>(double&nbsp;value,
boolean&nbsp;scaled,
double&nbsp;deadband)</code></div>
<div class="col-last even-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4">
<div class="col-last odd-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4">
<div class="block">Algebraically apply a deadband using a piece wise function.</div>
</div>
<div class="col-first odd-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4"><code>private static double</code></div>
<div class="col-second odd-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4"><code><a href="#calcMaxAccel(edu.wpi.first.math.geometry.Rotation2d,java.util.List,double,swervelib.parser.SwerveDriveConfiguration)" class="member-name-link">calcMaxAccel</a><wbr>(edu.wpi.first.math.geometry.Rotation2d&nbsp;angle,
<div class="col-first even-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4"><code>private static double</code></div>
<div class="col-second even-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4"><code><a href="#calcMaxAccel(edu.wpi.first.math.geometry.Rotation2d,java.util.List,double,swervelib.parser.SwerveDriveConfiguration)" class="member-name-link">calcMaxAccel</a><wbr>(edu.wpi.first.math.geometry.Rotation2d&nbsp;angle,
<a href="https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/List.html" title="class or interface in java.util" class="external-link">List</a>&lt;<a href="Matter.html" title="class in swervelib.math">Matter</a>&gt;&nbsp;matter,
double&nbsp;robotMass,
<a href="../parser/SwerveDriveConfiguration.html" title="class in swervelib.parser">SwerveDriveConfiguration</a>&nbsp;config)</code></div>
<div class="col-last odd-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4">
<div class="col-last even-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4">
<div class="block">Calculates the maximum acceleration allowed in a direction without tipping the robot.</div>
</div>
<div class="col-first even-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4"><code>static double</code></div>
<div class="col-second even-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4"><code><a href="#calculateAngleKV(double,double,double)" class="member-name-link">calculateAngleKV</a><wbr>(double&nbsp;optimalVoltage,
<div class="col-first odd-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4"><code>static double</code></div>
<div class="col-second odd-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4"><code><a href="#calculateAngleKV(double,double,double)" class="member-name-link">calculateAngleKV</a><wbr>(double&nbsp;optimalVoltage,
double&nbsp;motorFreeSpeedRPM,
double&nbsp;angleGearRatio)</code></div>
<div class="col-last even-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4">
<div class="col-last odd-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4">
<div class="block">Calculate the angle kV which will be multiplied by the radians per second for the feedforward.</div>
</div>
<div class="col-first odd-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4"><code>static double</code></div>
<div class="col-second odd-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4"><code><a href="#calculateDegreesPerSteeringRotation(double,double)" class="member-name-link">calculateDegreesPerSteeringRotation</a><wbr>(double&nbsp;angleGearRatio,
<div class="col-first even-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4"><code>static double</code></div>
<div class="col-second even-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4"><code><a href="#calculateDegreesPerSteeringRotation(double,double)" class="member-name-link">calculateDegreesPerSteeringRotation</a><wbr>(double&nbsp;angleGearRatio,
double&nbsp;pulsePerRotation)</code></div>
<div class="col-last odd-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4">
<div class="col-last even-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4">
<div class="block">Calculate the degrees per steering rotation for the integrated encoder.</div>
</div>
<div class="col-first even-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4"><code>static double</code></div>
<div class="col-second even-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4"><code><a href="#calculateMaxAcceleration(double)" class="member-name-link">calculateMaxAcceleration</a><wbr>(double&nbsp;cof)</code></div>
<div class="col-last even-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4">
<div class="col-first odd-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4"><code>static double</code></div>
<div class="col-second odd-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4"><code><a href="#calculateMaxAcceleration(double)" class="member-name-link">calculateMaxAcceleration</a><wbr>(double&nbsp;cof)</code></div>
<div class="col-last odd-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4">
<div class="block">Calculate the practical maximum acceleration of the robot using the wheel coefficient of friction.</div>
</div>
<div class="col-first odd-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4"><code>static double</code></div>
<div class="col-second odd-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4"><code><a href="#calculateMaxAcceleration(double,double,double,double,double)" class="member-name-link">calculateMaxAcceleration</a><wbr>(double&nbsp;stallTorqueNm,
<div class="col-first even-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4"><code>static double</code></div>
<div class="col-second even-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4"><code><a href="#calculateMaxAcceleration(double,double,double,double,double)" class="member-name-link">calculateMaxAcceleration</a><wbr>(double&nbsp;stallTorqueNm,
double&nbsp;gearRatio,
double&nbsp;moduleCount,
double&nbsp;wheelDiameter,
double&nbsp;robotMass)</code></div>
<div class="col-last odd-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4">
<div class="col-last even-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4">
<div class="block">Calculate the maximum theoretical acceleration without friction.</div>
</div>
<div class="col-first even-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4"><code>static double</code></div>
<div class="col-second even-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4"><code><a href="#calculateMaxAngularVelocity(double,double,double)" class="member-name-link">calculateMaxAngularVelocity</a><wbr>(double&nbsp;maxSpeed,
<div class="col-first odd-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4"><code>static double</code></div>
<div class="col-second odd-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4"><code><a href="#calculateMaxAngularVelocity(double,double,double)" class="member-name-link">calculateMaxAngularVelocity</a><wbr>(double&nbsp;maxSpeed,
double&nbsp;furthestModuleX,
double&nbsp;furthestModuleY)</code></div>
<div class="col-last even-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4">
<div class="col-last odd-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4">
<div class="block">Calculate the maximum angular velocity.</div>
</div>
<div class="col-first odd-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4"><code>static double</code></div>
<div class="col-second odd-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4"><code><a href="#calculateMetersPerRotation(double,double,double)" class="member-name-link">calculateMetersPerRotation</a><wbr>(double&nbsp;wheelDiameter,
<div class="col-first even-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4"><code>static double</code></div>
<div class="col-second even-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4"><code><a href="#calculateMetersPerRotation(double,double,double)" class="member-name-link">calculateMetersPerRotation</a><wbr>(double&nbsp;wheelDiameter,
double&nbsp;driveGearRatio,
double&nbsp;pulsePerRotation)</code></div>
<div class="col-last odd-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4">
<div class="col-last even-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4">
<div class="block">Calculate the meters per rotation for the integrated encoder.</div>
</div>
<div class="col-first even-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4"><code>static <a href="../parser/SwerveModuleConfiguration.html" title="class in swervelib.parser">SwerveModuleConfiguration</a></code></div>
<div class="col-second even-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4"><code><a href="#getSwerveModule(swervelib.SwerveModule%5B%5D,boolean,boolean)" class="member-name-link">getSwerveModule</a><wbr>(<a href="../SwerveModule.html" title="class in swervelib">SwerveModule</a>[]&nbsp;modules,
<div class="col-first odd-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4"><code>static <a href="../parser/SwerveModuleConfiguration.html" title="class in swervelib.parser">SwerveModuleConfiguration</a></code></div>
<div class="col-second odd-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4"><code><a href="#getSwerveModule(swervelib.SwerveModule%5B%5D,boolean,boolean)" class="member-name-link">getSwerveModule</a><wbr>(<a href="../SwerveModule.html" title="class in swervelib">SwerveModule</a>[]&nbsp;modules,
boolean&nbsp;front,
boolean&nbsp;left)</code></div>
<div class="col-last even-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4">
<div class="col-last odd-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4">
<div class="block">Get the fruthest module from center based on the module locations.</div>
</div>
<div class="col-first odd-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4"><code>static edu.wpi.first.math.geometry.Translation2d</code></div>
<div class="col-second odd-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4"><code><a href="#limitVelocity(edu.wpi.first.math.geometry.Translation2d,edu.wpi.first.math.kinematics.ChassisSpeeds,edu.wpi.first.math.geometry.Pose2d,double,double,java.util.List,swervelib.parser.SwerveDriveConfiguration)" class="member-name-link">limitVelocity</a><wbr>(edu.wpi.first.math.geometry.Translation2d&nbsp;commandedVelocity,
<div class="col-first even-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4"><code>static edu.wpi.first.math.geometry.Translation2d</code></div>
<div class="col-second even-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4"><code><a href="#limitVelocity(edu.wpi.first.math.geometry.Translation2d,edu.wpi.first.math.kinematics.ChassisSpeeds,edu.wpi.first.math.geometry.Pose2d,double,double,java.util.List,swervelib.parser.SwerveDriveConfiguration)" class="member-name-link">limitVelocity</a><wbr>(edu.wpi.first.math.geometry.Translation2d&nbsp;commandedVelocity,
edu.wpi.first.math.kinematics.ChassisSpeeds&nbsp;fieldVelocity,
edu.wpi.first.math.geometry.Pose2d&nbsp;robotPose,
double&nbsp;loopTime,
double&nbsp;robotMass,
<a href="https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/List.html" title="class or interface in java.util" class="external-link">List</a>&lt;<a href="Matter.html" title="class in swervelib.math">Matter</a>&gt;&nbsp;matter,
<a href="../parser/SwerveDriveConfiguration.html" title="class in swervelib.parser">SwerveDriveConfiguration</a>&nbsp;config)</code></div>
<div class="col-last odd-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4">
<div class="col-last even-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4">
<div class="block">Limits a commanded velocity to prevent exceeding the maximum acceleration given by <a href="#calcMaxAccel(edu.wpi.first.math.geometry.Rotation2d,java.util.List,double,swervelib.parser.SwerveDriveConfiguration)"><code>calcMaxAccel(edu.wpi.first.math.geometry.Rotation2d, java.util.List&lt;swervelib.math.Matter&gt;, double, swervelib.parser.SwerveDriveConfiguration)</code></a>.</div>
</div>
<div class="col-first even-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4"><code>static double</code></div>
<div class="col-second even-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4"><code><a href="#normalizeAngle(double)" class="member-name-link">normalizeAngle</a><wbr>(double&nbsp;angle)</code></div>
<div class="col-last even-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4">
<div class="col-first odd-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4"><code>static double</code></div>
<div class="col-second odd-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4"><code><a href="#normalizeAngle(double)" class="member-name-link">normalizeAngle</a><wbr>(double&nbsp;angle)</code></div>
<div class="col-last odd-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4">
<div class="block">Normalize an angle to be within 0 to 360.</div>
</div>
<div class="col-first even-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4"><code>static <a href="SwerveModuleState2.html" title="class in swervelib.math">SwerveModuleState2</a></code></div>
<div class="col-second even-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4"><code><a href="#optimize(swervelib.math.SwerveModuleState2,edu.wpi.first.math.geometry.Rotation2d,double)" class="member-name-link">optimize</a><wbr>(<a href="SwerveModuleState2.html" title="class in swervelib.math">SwerveModuleState2</a>&nbsp;desiredState,
edu.wpi.first.math.geometry.Rotation2d&nbsp;currentAngle,
double&nbsp;secondOrderOffsetDegrees)</code></div>
<div class="col-last even-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4">
<div class="block">Optimize the angle of the <a href="SwerveModuleState2.html" title="class in swervelib.math"><code>SwerveModuleState2</code></a> to be the closest angle to the current angle.</div>
</div>
<div class="col-first odd-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4"><code>static double</code></div>
<div class="col-second odd-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4"><code><a href="#placeInAppropriate0To360Scope(double,double)" class="member-name-link">placeInAppropriate0To360Scope</a><wbr>(double&nbsp;scopeReference,
double&nbsp;newAngle)</code></div>
<div class="col-last odd-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4">
<div class="block">Put an angle within the 360 deg scope of a reference.</div>
</div>
</div>
</div>
</div>
@@ -415,6 +435,55 @@ loadScripts(document, 'script');</script>
</dl>
</section>
</li>
<li>
<section class="detail" id="optimize(swervelib.math.SwerveModuleState2,edu.wpi.first.math.geometry.Rotation2d,double)">
<h3>optimize</h3>
<div class="member-signature"><span class="modifiers">public static</span>&nbsp;<span class="return-type"><a href="SwerveModuleState2.html" title="class in swervelib.math">SwerveModuleState2</a></span>&nbsp;<span class="element-name">optimize</span><wbr><span class="parameters">(<a href="SwerveModuleState2.html" title="class in swervelib.math">SwerveModuleState2</a>&nbsp;desiredState,
edu.wpi.first.math.geometry.Rotation2d&nbsp;currentAngle,
double&nbsp;secondOrderOffsetDegrees)</span></div>
<div class="block">Optimize the angle of the <a href="SwerveModuleState2.html" title="class in swervelib.math"><code>SwerveModuleState2</code></a> to be the closest angle to the current angle. Taken from <a href="https://github.com/pittsfordrobotics/REVSwerve2023/blob/master/src/main/java/com/team3181/lib/swerve
/SwerveOptimizer.java">Team 3181.</a></div>
<dl class="notes">
<dt>Parameters:</dt>
<dd><code>desiredState</code> - Desired <a href="SwerveModuleState2.html" title="class in swervelib.math"><code>SwerveModuleState2</code></a> to achieve.</dd>
<dd><code>currentAngle</code> - Current angle as a <code>Rotation2d</code>.</dd>
<dd><code>secondOrderOffsetDegrees</code> - Offset calculated using 2nd order kinematics.</dd>
<dt>Returns:</dt>
<dd>Optimized <a href="SwerveModuleState2.html" title="class in swervelib.math"><code>SwerveModuleState2</code></a></dd>
</dl>
</section>
</li>
<li>
<section class="detail" id="placeInAppropriate0To360Scope(double,double)">
<h3>placeInAppropriate0To360Scope</h3>
<div class="member-signature"><span class="modifiers">public static</span>&nbsp;<span class="return-type">double</span>&nbsp;<span class="element-name">placeInAppropriate0To360Scope</span><wbr><span class="parameters">(double&nbsp;scopeReference,
double&nbsp;newAngle)</span></div>
<div class="block">Put an angle within the 360 deg scope of a reference. For example, given a scope reference of 756 degrees, assumes
the full scope is (720-1080), and places an angle of 22 degrees into it, returning 742 deg.</div>
<dl class="notes">
<dt>Parameters:</dt>
<dd><code>scopeReference</code> - Current Angle (deg)</dd>
<dd><code>newAngle</code> - Target Angle (deg)</dd>
<dt>Returns:</dt>
<dd>Closest angle within scope (deg)</dd>
</dl>
</section>
</li>
<li>
<section class="detail" id="antiJitter(swervelib.math.SwerveModuleState2,swervelib.math.SwerveModuleState2,double)">
<h3>antiJitter</h3>
<div class="member-signature"><span class="modifiers">public static</span>&nbsp;<span class="return-type">void</span>&nbsp;<span class="element-name">antiJitter</span><wbr><span class="parameters">(<a href="SwerveModuleState2.html" title="class in swervelib.math">SwerveModuleState2</a>&nbsp;moduleState,
<a href="SwerveModuleState2.html" title="class in swervelib.math">SwerveModuleState2</a>&nbsp;lastModuleState,
double&nbsp;maxSpeed)</span></div>
<div class="block">Perform anti-jitter within modules if the speed requested is too low.</div>
<dl class="notes">
<dt>Parameters:</dt>
<dd><code>moduleState</code> - Current <a href="SwerveModuleState2.html" title="class in swervelib.math"><code>SwerveModuleState2</code></a> requested.</dd>
<dd><code>lastModuleState</code> - Previous <a href="SwerveModuleState2.html" title="class in swervelib.math"><code>SwerveModuleState2</code></a> used.</dd>
<dd><code>maxSpeed</code> - Maximum speed of the modules, should be in <a href="../parser/SwerveDriveConfiguration.html#maxSpeed"><code>SwerveDriveConfiguration.maxSpeed</code></a>.</dd>
</dl>
</section>
</li>
</ul>
</section>
</li>