Files
YAGSL/swervelib/parser/SwerveModulePhysicalCharacteristics.java

135 lines
5.5 KiB
Java
Raw Normal View History

2023-02-13 17:21:24 -06:00
package swervelib.parser;
2023-02-13 14:37:05 -06:00
2024-12-09 23:26:04 +00:00
import swervelib.parser.json.modules.ConversionFactorsJson;
2023-11-09 17:32:48 -06:00
2023-02-13 14:37:05 -06:00
/**
* Configuration class which stores physical characteristics shared between every swerve module.
*/
public class SwerveModulePhysicalCharacteristics
{
/**
* Current limits for the Swerve Module.
*/
public final int driveMotorCurrentLimit, angleMotorCurrentLimit;
2023-02-13 14:37:05 -06:00
/**
* The time it takes for the motor to go from 0 to full throttle in seconds.
*/
public final double driveMotorRampRate, angleMotorRampRate;
2024-12-09 23:26:04 +00:00
/**
* The minimum voltage to spin the module or wheel.
*/
public final double driveFrictionVoltage, angleFrictionVoltage;
2023-02-13 14:37:05 -06:00
/**
* Wheel grip tape coefficient of friction on carpet, as described by the vendor.
*/
2024-12-09 23:26:04 +00:00
public final double wheelGripCoefficientOfFriction;
/**
* Steer rotational inertia in (KilogramSquareMeters) kg/m_sq.
*/
public final double steerRotationalInertia;
/**
* Robot mass in Kilograms.
*/
public final double robotMassKg;
2023-11-09 17:32:48 -06:00
/**
* The voltage to use for the smart motor voltage compensation.
*/
2024-12-09 23:26:04 +00:00
public double optimalVoltage;
/**
2023-11-09 17:32:48 -06:00
* The conversion factors for the drive and angle motors, created by
* {@link swervelib.math.SwerveMath#calculateMetersPerRotation(double, double, double)} and
* {@link swervelib.math.SwerveMath#calculateDegreesPerSteeringRotation(double, double)}.
*/
2024-12-09 23:26:04 +00:00
public ConversionFactorsJson conversionFactor;
2023-02-13 14:37:05 -06:00
/**
* Construct the swerve module physical characteristics.
*
2023-11-09 17:32:48 -06:00
* @param conversionFactors The conversion factors for the drive and angle motors, created by
* {@link swervelib.math.SwerveMath#calculateMetersPerRotation(double, double,
* double)} and
* {@link swervelib.math.SwerveMath#calculateDegreesPerSteeringRotation(double,
* double)}.
2023-02-13 14:37:05 -06:00
* @param wheelGripCoefficientOfFriction Wheel grip coefficient of friction on carpet given by manufacturer.
* @param optimalVoltage Optimal robot voltage.
* @param driveMotorCurrentLimit Current limit for the drive motor.
* @param angleMotorCurrentLimit Current limit for the angle motor.
* @param driveMotorRampRate The time in seconds to go from 0 to full throttle on the motor. (Prevents
* over drawing power from battery)
* @param angleMotorRampRate The time in seconds to go from 0 to full throttle on the motor. (Prevents
* overdrawing power and power loss).
2024-12-09 23:26:04 +00:00
* @param angleFrictionVoltage Angle motor minimum voltage.
* @param driveFrictionVoltage Drive motor minimum voltage.
* @param steerRotationalInertia Steering rotational inertia in KilogramSquareMeters.
* @param robotMassKg Robot mass in kG.
2023-02-13 14:37:05 -06:00
*/
public SwerveModulePhysicalCharacteristics(
2024-12-09 23:26:04 +00:00
ConversionFactorsJson conversionFactors,
double wheelGripCoefficientOfFriction,
double optimalVoltage,
int driveMotorCurrentLimit,
int angleMotorCurrentLimit,
double driveMotorRampRate,
2024-12-09 23:26:04 +00:00
double angleMotorRampRate,
double driveFrictionVoltage,
double angleFrictionVoltage,
double steerRotationalInertia,
double robotMassKg)
2023-02-13 14:37:05 -06:00
{
this.wheelGripCoefficientOfFriction = wheelGripCoefficientOfFriction;
this.optimalVoltage = optimalVoltage;
2023-11-09 17:32:48 -06:00
this.conversionFactor = conversionFactors;
// Set the conversion factors to null if they are both 0.
if (conversionFactors != null)
{
2024-12-09 23:26:04 +00:00
if (conversionFactors.isAngleEmpty() && conversionFactors.isDriveEmpty())
2023-11-09 17:32:48 -06:00
{
this.conversionFactor = null;
}
}
2023-02-13 14:37:05 -06:00
this.driveMotorCurrentLimit = driveMotorCurrentLimit;
this.angleMotorCurrentLimit = angleMotorCurrentLimit;
this.driveMotorRampRate = driveMotorRampRate;
this.angleMotorRampRate = angleMotorRampRate;
2024-12-09 23:26:04 +00:00
this.driveFrictionVoltage = driveFrictionVoltage;
this.angleFrictionVoltage = angleFrictionVoltage;
this.steerRotationalInertia = steerRotationalInertia;
this.robotMassKg = robotMassKg;
2023-02-13 14:37:05 -06:00
}
/**
* Construct the swerve module physical characteristics. Assume coefficient of friction is 1.19 (taken from blue
* nitrile on carpet from Studica) and optimal voltage is 12v. Assumes the drive motor current limit is 40A, and the
* angle motor current limit is 20A.
*
2023-11-09 17:32:48 -06:00
* @param conversionFactors The conversion factors for the drive and angle motors, created by
* {@link swervelib.math.SwerveMath#calculateMetersPerRotation(double, double, double)} and
* {@link swervelib.math.SwerveMath#calculateDegreesPerSteeringRotation(double, double)}.
* @param driveMotorRampRate The time in seconds to go from 0 to full throttle on the motor. (Prevents over drawing
* power from battery)
* @param angleMotorRampRate The time in seconds to go from 0 to full throttle on the motor. (Prevents overdrawing
* power and power loss).
2023-02-13 14:37:05 -06:00
*/
public SwerveModulePhysicalCharacteristics(
2024-12-09 23:26:04 +00:00
ConversionFactorsJson conversionFactors,
double driveMotorRampRate,
2023-11-09 17:32:48 -06:00
double angleMotorRampRate)
2023-02-13 14:37:05 -06:00
{
this(
2023-11-09 17:32:48 -06:00
conversionFactors,
1.19,
12,
40,
20,
driveMotorRampRate,
2024-12-09 23:26:04 +00:00
angleMotorRampRate,
0.2,
0.3,
0.03,
50);
2023-02-13 14:37:05 -06:00
}
}