Skip to content

Commit

Permalink
Removed Vector2d in favor of using Translation2d polar to cartesian…
Browse files Browse the repository at this point in the history
… conversion.

Signed-off-by: thenetworkgrinch <thenetworkgrinch@users.noreply.github.com>
  • Loading branch information
thenetworkgrinch committed Jun 12, 2024
1 parent 75996c9 commit 6c94892
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 111 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import swervelib.SwerveDrive;
import swervelib.SwerveDriveTest;
import swervelib.math.SwerveMath;
import swervelib.math.Vector2d;
import swervelib.parser.SwerveControllerConfiguration;
import swervelib.parser.SwerveDriveConfiguration;
import swervelib.parser.SwerveParser;
Expand All @@ -49,7 +48,7 @@ public class SwerveSubsystem extends SubsystemBase
/**
* Swerve drive object.
*/
private final SwerveDrive swerveDrive;
private final SwerveDrive swerveDrive;
/**
* AprilTag field layout.
*/
Expand Down Expand Up @@ -252,8 +251,9 @@ public Command driveCommand(DoubleSupplier translationX, DoubleSupplier translat
{
// swerveDrive.setHeadingCorrection(true); // Normally you would want heading correction for this kind of control.
return run(() -> {
Translation2d scaledInputs = new Vector2d(translationX.getAsDouble(), translationY.getAsDouble()).pow(3)
.getTranslation();

Translation2d scaledInputs = SwerveMath.cubeTranslation(new Translation2d(translationX.getAsDouble(),
translationY.getAsDouble()));

// Make the robot move
driveFieldOriented(swerveDrive.swerveController.getTargetSpeeds(scaledInputs.getX(), scaledInputs.getY(),
Expand Down Expand Up @@ -325,9 +325,9 @@ public Command driveCommand(DoubleSupplier translationX, DoubleSupplier translat
{
return run(() -> {
// Make the robot move
swerveDrive.drive(new Vector2d(new Translation2d(translationX.getAsDouble() * swerveDrive.getMaximumVelocity(),
translationY.getAsDouble() *
swerveDrive.getMaximumVelocity())).pow(3).getTranslation(),
swerveDrive.drive(SwerveMath.cubeTranslation(new Translation2d(
translationX.getAsDouble() * swerveDrive.getMaximumVelocity(),
translationY.getAsDouble() * swerveDrive.getMaximumVelocity())),
Math.pow(angularRotationX.getAsDouble(), 3) * swerveDrive.getMaximumAngularVelocity(),
true,
false);
Expand Down Expand Up @@ -508,7 +508,7 @@ public Rotation2d getHeading()
*/
public ChassisSpeeds getTargetSpeeds(double xInput, double yInput, double headingX, double headingY)
{
Translation2d scaledInputs = new Vector2d(xInput, yInput).pow(3).getTranslation();
Translation2d scaledInputs = SwerveMath.cubeTranslation(new Translation2d(xInput, yInput));
return swerveDrive.swerveController.getTargetSpeeds(scaledInputs.getX(),
scaledInputs.getY(),
headingX,
Expand All @@ -528,7 +528,7 @@ public ChassisSpeeds getTargetSpeeds(double xInput, double yInput, double headin
*/
public ChassisSpeeds getTargetSpeeds(double xInput, double yInput, Rotation2d angle)
{
Translation2d scaledInputs = new Vector2d(xInput, yInput).pow(3).getTranslation();
Translation2d scaledInputs = SwerveMath.cubeTranslation(new Translation2d(xInput, yInput));

return swerveDrive.swerveController.getTargetSpeeds(scaledInputs.getX(),
scaledInputs.getY(),
Expand Down
11 changes: 5 additions & 6 deletions src/main/java/swervelib/math/SwerveMath.java
Original file line number Diff line number Diff line change
Expand Up @@ -412,14 +412,13 @@ public static void antiJitter(SwerveModuleState moduleState, SwerveModuleState l
}

/**
* Get the scaled {@link Translation2d} with the given scalar to change the magnitude of the {@link Vector2d}.
* Cube the {@link Translation2d} magnitude given in Polar coordinates.
*
* @param cartesian {@link Translation2d} cartesian coordinates.
* @param scalar Scalar to change the polar radius of the {@link Vector2d} by.
* @return {@link Translation2d} scaled by the given input.
* @param translation {@link Translation2d} to manipulate.
* @return Cubed magnitude from {@link Translation2d}.
*/
public static Translation2d scaleTranslation2d(Translation2d cartesian, double scalar)
public static Translation2d cubeTranslation(Translation2d translation)
{
return new Vector2d(cartesian).scale(scalar).getTranslation();
return new Translation2d(Math.pow(translation.getNorm(), 3), translation.getAngle());
}
}
96 changes: 0 additions & 96 deletions src/main/java/swervelib/math/Vector2d.java

This file was deleted.

0 comments on commit 6c94892

Please sign in to comment.