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

@@ -11,11 +11,11 @@ public class SwerveControllerConfiguration
/**
* Maximum robot speed in meters per second.
*/
public final double maxSpeed;
public double maxSpeed;
/**
* Maximum angular velocity in rad/s
*/
public final double maxAngularVelocity;
public double maxAngularVelocity;
/**
* PIDF for the heading of the robot.
*/

View File

@@ -4,7 +4,6 @@ import static swervelib.math.SwerveMath.calculateAngleKV;
import static swervelib.math.SwerveMath.calculateDegreesPerSteeringRotation;
import static swervelib.math.SwerveMath.calculateMaxAcceleration;
import static swervelib.math.SwerveMath.calculateMetersPerRotation;
import edu.wpi.first.math.controller.SimpleMotorFeedforward;
import edu.wpi.first.math.geometry.Translation2d;
import swervelib.encoders.SwerveAbsoluteEncoder;
@@ -35,7 +34,7 @@ public class SwerveModuleConfiguration
/**
* Maximum robot speed in meters per second.
*/
public final double maxSpeed;
public double maxSpeed;
/**
* PIDF configuration options for the angle motor closed-loop PID controller.
*/
@@ -116,11 +115,11 @@ public class SwerveModuleConfiguration
this.anglePIDF = anglePIDF;
this.velocityPIDF = velocityPIDF;
this.maxSpeed = maxSpeed;
this.angleKV =
calculateAngleKV(
physicalCharacteristics.optimalVoltage,
angleMotorFreeSpeedRPM,
physicalCharacteristics.angleGearRatio);
this.angleKV = physicalCharacteristics.angleMotorKV == 0 ?
calculateAngleKV(
physicalCharacteristics.optimalVoltage,
angleMotorFreeSpeedRPM,
physicalCharacteristics.angleGearRatio) : physicalCharacteristics.angleMotorKV;
this.physicalCharacteristics = physicalCharacteristics;
this.angleMotorEncoderPulsePerRevolution = angleMotorEncoderPulsePerRevolution;
}

View File

@@ -46,6 +46,12 @@ public class SwerveModulePhysicalCharacteristics
* Free speed rotations per minute of the motor, as described by the vendor.
*/
public final double angleMotorFreeSpeedRPM;
/**
* Angle motor kV used for second order kinematics to tune the feedforward, this variable should be adjusted so that
* your drive train does not drift towards the direction you are rotating while you translate. When set to 0 the
* calculated kV will be used.
*/
public final double angleMotorKV;
/**
* Construct the swerve module physical characteristics.
@@ -78,7 +84,8 @@ public class SwerveModulePhysicalCharacteristics
double driveMotorRampRate,
double angleMotorRampRate,
int driveEncoderPulsePerRotation,
int angleEncoderPulsePerRotation)
int angleEncoderPulsePerRotation,
double angleMotorKV)
{
this.wheelGripCoefficientOfFriction = wheelGripCoefficientOfFriction;
this.optimalVoltage = optimalVoltage;
@@ -94,6 +101,7 @@ public class SwerveModulePhysicalCharacteristics
this.angleMotorCurrentLimit = angleMotorCurrentLimit;
this.driveMotorRampRate = driveMotorRampRate;
this.angleMotorRampRate = angleMotorRampRate;
this.angleMotorKV = angleMotorKV;
}
/**
@@ -134,6 +142,6 @@ public class SwerveModulePhysicalCharacteristics
driveMotorRampRate,
angleMotorRampRate,
driveEncoderPulsePerRotation,
angleEncoderPulsePerRotation);
angleEncoderPulsePerRotation, 0);
}
}

View File

@@ -37,6 +37,12 @@ public class PhysicalPropertiesJson
* Angle motor free speed rotations per minute.
*/
public double angleMotorFreeSpeedRPM;
/**
* Angle motor kV used for second order kinematics to tune the feedforward, this variable should be adjusted so that
* your drive train does not drift towards the direction you are rotating while you translate. When set to 0 the
* calculated kV will be used.
*/
public double angleMotorsKV = 0;
/**
* Create the physical characteristics based off the parsed data.
@@ -58,7 +64,8 @@ public class PhysicalPropertiesJson
rampRate.drive,
rampRate.angle,
encoderPulsePerRotation.drive,
encoderPulsePerRotation.angle);
encoderPulsePerRotation.angle,
angleMotorsKV);
}
}