Files
YAGSL/swervelib/parser/json/PhysicalPropertiesJson.java

87 lines
3.1 KiB
Java
Raw Normal View History

2023-02-13 17:21:24 -06:00
package swervelib.parser.json;
2023-02-13 14:37:05 -06:00
2024-12-09 23:26:04 +00:00
import edu.wpi.first.units.Units;
import edu.wpi.first.wpilibj.Alert;
import edu.wpi.first.wpilibj.Alert.AlertType;
2023-02-13 17:21:24 -06:00
import swervelib.parser.SwerveModulePhysicalCharacteristics;
2024-07-29 15:14:25 -05:00
import swervelib.parser.json.modules.ConversionFactorsJson;
2023-02-13 14:37:05 -06:00
/**
2023-02-13 17:21:24 -06:00
* {@link swervelib.parser.SwerveModulePhysicalCharacteristics} parsed data. Used to configure the SwerveModule.
2023-02-13 14:37:05 -06:00
*/
public class PhysicalPropertiesJson
{
/**
2024-12-09 23:26:04 +00:00
* DEPRECATED! Use {@link PhysicalPropertiesJson#conversionFactors} instead.
*/
@Deprecated(since = "2025", forRemoval = true)
public MotorConfigDouble conversionFactor = new MotorConfigDouble();
/**
* Minimum voltage to spin the module or wheel.
2023-02-13 14:37:05 -06:00
*/
2024-12-09 23:26:04 +00:00
public MotorConfigDouble friction = new MotorConfigDouble(0.3, 0.2);
/**
* Steer rotational inertia in KilogramMetersSquare.
*/
public double steerRotationalInertia = 0.03;
/**
* Robot mass in lb (pounds)
*/
public double robotMass = 110.2311;
2024-07-29 15:14:25 -05:00
/**
* Conversion Factors composition. Auto-calculates the conversion factors.
*/
public ConversionFactorsJson conversionFactors = new ConversionFactorsJson();
2023-02-13 14:37:05 -06:00
/**
* The current limit in AMPs to apply to the motors.
*/
2024-07-29 15:14:25 -05:00
public MotorConfigInt currentLimit = new MotorConfigInt(40, 20);
2023-02-13 14:37:05 -06:00
/**
* The minimum number of seconds to take for the motor to go from 0 to full throttle.
*/
2024-07-29 15:14:25 -05:00
public MotorConfigDouble rampRate = new MotorConfigDouble(0.25, 0.25);
2023-02-13 14:37:05 -06:00
/**
* The grip tape coefficient of friction on carpet. Used to calculate the practical maximum acceleration.
*/
2024-07-29 15:14:25 -05:00
public double wheelGripCoefficientOfFriction = 1.19;
2023-02-13 14:37:05 -06:00
/**
2023-11-09 17:32:48 -06:00
* The voltage to use for the smart motor voltage compensation, default is 12.
*/
2024-07-29 15:14:25 -05:00
public double optimalVoltage = 12;
2023-02-13 14:37:05 -06:00
/**
* Create the physical characteristics based off the parsed data.
*
* @return {@link SwerveModulePhysicalCharacteristics} based on parsed data.
*/
2023-11-09 17:32:48 -06:00
public SwerveModulePhysicalCharacteristics createPhysicalProperties()
2023-02-13 14:37:05 -06:00
{
2024-07-29 15:14:25 -05:00
// Setup deprecation notice.
2024-12-09 23:26:04 +00:00
if (conversionFactor.drive != 0 && conversionFactor.angle != 0 && conversionFactors.isDriveEmpty() &&
conversionFactors.isAngleEmpty())
2024-07-29 15:14:25 -05:00
{
2024-12-09 23:26:04 +00:00
new Alert("Configuration",
"\n'conversionFactor': {'drive': " + conversionFactor.drive + ", 'angle': " + conversionFactor.angle +
"} \nis deprecated, please use\n" +
"'conversionFactors': {'drive': {'factor': " + conversionFactor.drive + "}, 'angle': {'factor': " +
conversionFactor.angle + "} }",
AlertType.kError).set(true);
2024-07-29 15:14:25 -05:00
}
return new SwerveModulePhysicalCharacteristics(
2024-12-09 23:26:04 +00:00
conversionFactors,
wheelGripCoefficientOfFriction,
optimalVoltage,
currentLimit.drive,
currentLimit.angle,
rampRate.drive,
2024-12-09 23:26:04 +00:00
rampRate.angle,
friction.drive,
friction.angle,
steerRotationalInertia,
Units.Pounds.of(robotMass).in(Units.Kilogram));
2023-02-13 14:37:05 -06:00
}
}