mirror of
https://github.com/BroncBotz3481/YAGSL
synced 2026-07-05 07:31:41 +00:00
Upgrading to 2025.1.0
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package swervelib.parser;
|
||||
|
||||
import edu.wpi.first.wpilibj.RobotBase;
|
||||
import edu.wpi.first.wpilibj.RobotController;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@@ -95,7 +96,7 @@ public class Cache<T>
|
||||
*/
|
||||
public T getValue()
|
||||
{
|
||||
if (isStale())
|
||||
if (isStale() || RobotBase.isSimulation())
|
||||
{
|
||||
update();
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ public class SwerveControllerConfiguration
|
||||
public final double
|
||||
angleJoyStickRadiusDeadband; // Deadband for the minimum hypot for the heading joystick.
|
||||
/**
|
||||
* Maximum angular velocity in rad/s
|
||||
* Maximum chassis angular velocity in rad/s
|
||||
*/
|
||||
public double maxAngularVelocity;
|
||||
|
||||
|
||||
@@ -1,9 +1,14 @@
|
||||
package swervelib.parser;
|
||||
|
||||
import edu.wpi.first.math.controller.SimpleMotorFeedforward;
|
||||
import edu.wpi.first.math.geometry.Translation2d;
|
||||
import edu.wpi.first.math.system.plant.DCMotor;
|
||||
import java.util.function.Supplier;
|
||||
import org.ironmaple.simulation.drivesims.GyroSimulation;
|
||||
import swervelib.SwerveModule;
|
||||
import swervelib.imu.NavXSwerve;
|
||||
import swervelib.imu.Pigeon2Swerve;
|
||||
import swervelib.imu.SwerveIMU;
|
||||
import swervelib.math.SwerveMath;
|
||||
|
||||
/**
|
||||
* Swerve drive configurations used during SwerveDrive construction.
|
||||
@@ -38,20 +43,18 @@ public class SwerveDriveConfiguration
|
||||
* @param moduleConfigs Module configuration.
|
||||
* @param swerveIMU Swerve IMU.
|
||||
* @param invertedIMU Invert the IMU.
|
||||
* @param driveFeedforward The drive motor feedforward to use for the {@link SwerveModule}.
|
||||
* @param physicalCharacteristics {@link SwerveModulePhysicalCharacteristics} to store in association with self.
|
||||
*/
|
||||
public SwerveDriveConfiguration(
|
||||
SwerveModuleConfiguration[] moduleConfigs,
|
||||
SwerveIMU swerveIMU,
|
||||
boolean invertedIMU,
|
||||
SimpleMotorFeedforward driveFeedforward,
|
||||
SwerveModulePhysicalCharacteristics physicalCharacteristics)
|
||||
{
|
||||
this.moduleCount = moduleConfigs.length;
|
||||
this.imu = swerveIMU;
|
||||
swerveIMU.setInverted(invertedIMU);
|
||||
this.modules = createModules(moduleConfigs, driveFeedforward);
|
||||
this.modules = createModules(moduleConfigs);
|
||||
this.moduleLocationsMeters = new Translation2d[moduleConfigs.length];
|
||||
for (SwerveModule module : modules)
|
||||
{
|
||||
@@ -63,17 +66,15 @@ public class SwerveDriveConfiguration
|
||||
/**
|
||||
* Create modules based off of the SwerveModuleConfiguration.
|
||||
*
|
||||
* @param swerves Swerve constants.
|
||||
* @param driveFeedforward Drive feedforward created using
|
||||
* {@link swervelib.math.SwerveMath#createDriveFeedforward(double, double, double)}.
|
||||
* @param swerves Swerve constants.
|
||||
* @return Swerve Modules.
|
||||
*/
|
||||
public SwerveModule[] createModules(SwerveModuleConfiguration[] swerves, SimpleMotorFeedforward driveFeedforward)
|
||||
public SwerveModule[] createModules(SwerveModuleConfiguration[] swerves)
|
||||
{
|
||||
SwerveModule[] modArr = new SwerveModule[swerves.length];
|
||||
for (int i = 0; i < swerves.length; i++)
|
||||
{
|
||||
modArr[i] = new SwerveModule(i, swerves[i], driveFeedforward);
|
||||
modArr[i] = new SwerveModule(i, swerves[i]);
|
||||
}
|
||||
return modArr;
|
||||
}
|
||||
@@ -96,4 +97,68 @@ public class SwerveDriveConfiguration
|
||||
//Return Largest Radius
|
||||
return centerOfModules.getDistance(moduleLocationsMeters[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the trackwidth of the swerve modules.
|
||||
*
|
||||
* @return Effective trackwdtih in Meters
|
||||
*/
|
||||
public double getTrackwidth()
|
||||
{
|
||||
SwerveModuleConfiguration fr = SwerveMath.getSwerveModule(modules, true, false);
|
||||
SwerveModuleConfiguration fl = SwerveMath.getSwerveModule(modules, true, true);
|
||||
return fr.moduleLocation.getDistance(fl.moduleLocation);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the tracklength of the swerve modules.
|
||||
*
|
||||
* @return Effective tracklength in Meters
|
||||
*/
|
||||
public double getTracklength()
|
||||
{
|
||||
SwerveModuleConfiguration br = SwerveMath.getSwerveModule(modules, false, false);
|
||||
SwerveModuleConfiguration bl = SwerveMath.getSwerveModule(modules, false, true);
|
||||
return br.moduleLocation.getDistance(bl.moduleLocation);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the {@link DCMotor} corresponding to the first module's configuration.
|
||||
*
|
||||
* @return {@link DCMotor} of the drive motor.
|
||||
*/
|
||||
public DCMotor getDriveMotorSim()
|
||||
{
|
||||
SwerveModuleConfiguration fl = SwerveMath.getSwerveModule(modules, true, true);
|
||||
return fl.driveMotor.getSimMotor();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the {@link DCMotor} corresponding to the first module configuration.
|
||||
*
|
||||
* @return {@link DCMotor} of the angle motor.
|
||||
*/
|
||||
public DCMotor getAngleMotorSim()
|
||||
{
|
||||
SwerveModuleConfiguration fl = SwerveMath.getSwerveModule(modules, true, true);
|
||||
return fl.angleMotor.getSimMotor();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the gyro simulation for the robot.
|
||||
*
|
||||
* @return {@link GyroSimulation} gyro simulation.
|
||||
*/
|
||||
public Supplier<GyroSimulation> getGyroSim()
|
||||
{
|
||||
if (imu instanceof Pigeon2Swerve)
|
||||
{
|
||||
return GyroSimulation.getPigeon2();
|
||||
} else if (imu instanceof NavXSwerve)
|
||||
{
|
||||
return GyroSimulation.getNav2X();
|
||||
}
|
||||
return GyroSimulation.getGeneric();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package swervelib.parser;
|
||||
import edu.wpi.first.math.geometry.Translation2d;
|
||||
import swervelib.encoders.SwerveAbsoluteEncoder;
|
||||
import swervelib.motors.SwerveMotor;
|
||||
import swervelib.parser.json.MotorConfigDouble;
|
||||
import swervelib.parser.json.modules.ConversionFactorsJson;
|
||||
|
||||
/**
|
||||
* Swerve Module configuration class which is used to configure {@link swervelib.SwerveModule}.
|
||||
@@ -17,7 +17,7 @@ public class SwerveModuleConfiguration
|
||||
* {@link swervelib.math.SwerveMath#calculateDegreesPerSteeringRotation(double, double)} respectively to calculate the
|
||||
* conversion factors.
|
||||
*/
|
||||
public final MotorConfigDouble conversionFactors;
|
||||
public final ConversionFactorsJson conversionFactors;
|
||||
/**
|
||||
* Angle offset in degrees for the Swerve Module.
|
||||
*/
|
||||
@@ -89,7 +89,7 @@ public class SwerveModuleConfiguration
|
||||
public SwerveModuleConfiguration(
|
||||
SwerveMotor driveMotor,
|
||||
SwerveMotor angleMotor,
|
||||
MotorConfigDouble conversionFactors,
|
||||
ConversionFactorsJson conversionFactors,
|
||||
SwerveAbsoluteEncoder absoluteEncoder,
|
||||
double angleOffset,
|
||||
double xMeters,
|
||||
@@ -139,7 +139,7 @@ public class SwerveModuleConfiguration
|
||||
public SwerveModuleConfiguration(
|
||||
SwerveMotor driveMotor,
|
||||
SwerveMotor angleMotor,
|
||||
MotorConfigDouble conversionFactors,
|
||||
ConversionFactorsJson conversionFactors,
|
||||
SwerveAbsoluteEncoder absoluteEncoder,
|
||||
double angleOffset,
|
||||
double xMeters,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package swervelib.parser;
|
||||
|
||||
import swervelib.parser.json.MotorConfigDouble;
|
||||
import swervelib.parser.json.modules.ConversionFactorsJson;
|
||||
|
||||
/**
|
||||
* Configuration class which stores physical characteristics shared between every swerve module.
|
||||
@@ -16,20 +16,32 @@ public class SwerveModulePhysicalCharacteristics
|
||||
* The time it takes for the motor to go from 0 to full throttle in seconds.
|
||||
*/
|
||||
public final double driveMotorRampRate, angleMotorRampRate;
|
||||
/**
|
||||
* The minimum voltage to spin the module or wheel.
|
||||
*/
|
||||
public final double driveFrictionVoltage, angleFrictionVoltage;
|
||||
/**
|
||||
* Wheel grip tape coefficient of friction on carpet, as described by the vendor.
|
||||
*/
|
||||
public final double wheelGripCoefficientOfFriction;
|
||||
public final double wheelGripCoefficientOfFriction;
|
||||
/**
|
||||
* Steer rotational inertia in (KilogramSquareMeters) kg/m_sq.
|
||||
*/
|
||||
public final double steerRotationalInertia;
|
||||
/**
|
||||
* Robot mass in Kilograms.
|
||||
*/
|
||||
public final double robotMassKg;
|
||||
/**
|
||||
* The voltage to use for the smart motor voltage compensation.
|
||||
*/
|
||||
public double optimalVoltage;
|
||||
public double optimalVoltage;
|
||||
/**
|
||||
* 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)}.
|
||||
*/
|
||||
public MotorConfigDouble conversionFactor;
|
||||
public ConversionFactorsJson conversionFactor;
|
||||
|
||||
/**
|
||||
* Construct the swerve module physical characteristics.
|
||||
@@ -47,15 +59,23 @@ public class SwerveModulePhysicalCharacteristics
|
||||
* 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).
|
||||
* @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.
|
||||
*/
|
||||
public SwerveModulePhysicalCharacteristics(
|
||||
MotorConfigDouble conversionFactors,
|
||||
ConversionFactorsJson conversionFactors,
|
||||
double wheelGripCoefficientOfFriction,
|
||||
double optimalVoltage,
|
||||
int driveMotorCurrentLimit,
|
||||
int angleMotorCurrentLimit,
|
||||
double driveMotorRampRate,
|
||||
double angleMotorRampRate)
|
||||
double angleMotorRampRate,
|
||||
double driveFrictionVoltage,
|
||||
double angleFrictionVoltage,
|
||||
double steerRotationalInertia,
|
||||
double robotMassKg)
|
||||
{
|
||||
this.wheelGripCoefficientOfFriction = wheelGripCoefficientOfFriction;
|
||||
this.optimalVoltage = optimalVoltage;
|
||||
@@ -64,7 +84,7 @@ public class SwerveModulePhysicalCharacteristics
|
||||
// Set the conversion factors to null if they are both 0.
|
||||
if (conversionFactors != null)
|
||||
{
|
||||
if (conversionFactors.angle == 0 && conversionFactors.drive == 0)
|
||||
if (conversionFactors.isAngleEmpty() && conversionFactors.isDriveEmpty())
|
||||
{
|
||||
this.conversionFactor = null;
|
||||
}
|
||||
@@ -74,6 +94,10 @@ public class SwerveModulePhysicalCharacteristics
|
||||
this.angleMotorCurrentLimit = angleMotorCurrentLimit;
|
||||
this.driveMotorRampRate = driveMotorRampRate;
|
||||
this.angleMotorRampRate = angleMotorRampRate;
|
||||
this.driveFrictionVoltage = driveFrictionVoltage;
|
||||
this.angleFrictionVoltage = angleFrictionVoltage;
|
||||
this.steerRotationalInertia = steerRotationalInertia;
|
||||
this.robotMassKg = robotMassKg;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -90,7 +114,7 @@ public class SwerveModulePhysicalCharacteristics
|
||||
* power and power loss).
|
||||
*/
|
||||
public SwerveModulePhysicalCharacteristics(
|
||||
MotorConfigDouble conversionFactors,
|
||||
ConversionFactorsJson conversionFactors,
|
||||
double driveMotorRampRate,
|
||||
double angleMotorRampRate)
|
||||
{
|
||||
@@ -101,6 +125,10 @@ public class SwerveModulePhysicalCharacteristics
|
||||
40,
|
||||
20,
|
||||
driveMotorRampRate,
|
||||
angleMotorRampRate);
|
||||
angleMotorRampRate,
|
||||
0.2,
|
||||
0.3,
|
||||
0.03,
|
||||
50);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ package swervelib.parser;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import edu.wpi.first.math.controller.SimpleMotorFeedforward;
|
||||
import edu.wpi.first.math.geometry.Pose2d;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
@@ -135,10 +135,7 @@ public class SwerveParser
|
||||
*/
|
||||
public SwerveDrive createSwerveDrive(double maxSpeed)
|
||||
{
|
||||
return createSwerveDrive(SwerveMath.createDriveFeedforward(physicalPropertiesJson.optimalVoltage,
|
||||
maxSpeed,
|
||||
physicalPropertiesJson.wheelGripCoefficientOfFriction),
|
||||
maxSpeed);
|
||||
return createSwerveDrive(maxSpeed, Pose2d.kZero);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -157,48 +154,20 @@ public class SwerveParser
|
||||
*/
|
||||
public SwerveDrive createSwerveDrive(double maxSpeed, double angleMotorConversionFactor, double driveMotorConversion)
|
||||
{
|
||||
physicalPropertiesJson.conversionFactor.angle = angleMotorConversionFactor;
|
||||
physicalPropertiesJson.conversionFactor.drive = driveMotorConversion;
|
||||
return createSwerveDrive(SwerveMath.createDriveFeedforward(physicalPropertiesJson.optimalVoltage,
|
||||
maxSpeed,
|
||||
physicalPropertiesJson.wheelGripCoefficientOfFriction),
|
||||
maxSpeed);
|
||||
physicalPropertiesJson.conversionFactors.angle.factor = angleMotorConversionFactor;
|
||||
physicalPropertiesJson.conversionFactors.drive.factor = driveMotorConversion;
|
||||
return createSwerveDrive(maxSpeed, Pose2d.kZero);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create {@link SwerveDrive} from JSON configuration directory.
|
||||
*
|
||||
* @param driveFeedforward Drive feedforward to use for swerve modules, should be created using
|
||||
* {@link swervelib.math.SwerveMath#createDriveFeedforward(double, double,
|
||||
* double)}.
|
||||
* @param maxSpeed Maximum speed of the robot in meters per second for normal+angular acceleration
|
||||
* in {@link swervelib.SwerveController} of the robot.
|
||||
* @param angleMotorConversionFactor Angle (AKA azimuth) motor conversion factor to convert motor controller PID loop
|
||||
* units to degrees, usually created using
|
||||
* {@link SwerveMath#calculateDegreesPerSteeringRotation(double, double)}.
|
||||
* @param driveMotorConversion Drive motor conversion factor to convert motor controller PID loop units to
|
||||
* meters per rotation, usually created using
|
||||
* {@link SwerveMath#calculateMetersPerRotation(double, double, double)}.
|
||||
* @param maxSpeed Maximum speed of the robot in meters per second for normal+angular acceleration in
|
||||
* {@link swervelib.SwerveController} of the robot
|
||||
* @param initialPose {@link Pose2d} initial pose.
|
||||
* @return {@link SwerveDrive} instance.
|
||||
*/
|
||||
public SwerveDrive createSwerveDrive(SimpleMotorFeedforward driveFeedforward, double maxSpeed,
|
||||
double angleMotorConversionFactor, double driveMotorConversion)
|
||||
{
|
||||
physicalPropertiesJson.conversionFactor.angle = angleMotorConversionFactor;
|
||||
physicalPropertiesJson.conversionFactor.drive = driveMotorConversion;
|
||||
return createSwerveDrive(driveFeedforward, maxSpeed);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create {@link SwerveDrive} from JSON configuration directory.
|
||||
*
|
||||
* @param driveFeedforward Drive feedforward to use for swerve modules, should be created using
|
||||
* {@link swervelib.math.SwerveMath#createDriveFeedforward(double, double, double)}.
|
||||
* @param maxSpeed Maximum speed of the robot in meters per second for normal+angular acceleration in
|
||||
* {@link swervelib.SwerveController} of the robot
|
||||
* @return {@link SwerveDrive} instance.
|
||||
*/
|
||||
public SwerveDrive createSwerveDrive(SimpleMotorFeedforward driveFeedforward, double maxSpeed)
|
||||
public SwerveDrive createSwerveDrive(double maxSpeed, Pose2d initialPose)
|
||||
{
|
||||
SwerveModuleConfiguration[] moduleConfigurations =
|
||||
new SwerveModuleConfiguration[moduleJsons.length];
|
||||
@@ -217,11 +186,12 @@ public class SwerveParser
|
||||
moduleConfigurations,
|
||||
swerveDriveJson.imu.createIMU(),
|
||||
swerveDriveJson.invertedIMU,
|
||||
driveFeedforward,
|
||||
physicalPropertiesJson.createPhysicalProperties());
|
||||
|
||||
return new SwerveDrive(
|
||||
swerveDriveConfiguration,
|
||||
controllerPropertiesJson.createControllerConfiguration(swerveDriveConfiguration, maxSpeed), maxSpeed);
|
||||
controllerPropertiesJson.createControllerConfiguration(swerveDriveConfiguration, maxSpeed),
|
||||
maxSpeed,
|
||||
initialPose);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,11 +4,10 @@ import static swervelib.telemetry.SwerveDriveTelemetry.canIdWarning;
|
||||
import static swervelib.telemetry.SwerveDriveTelemetry.i2cLockupWarning;
|
||||
import static swervelib.telemetry.SwerveDriveTelemetry.serialCommsIssueWarning;
|
||||
|
||||
import com.revrobotics.SparkRelativeEncoder.Type;
|
||||
import com.ctre.phoenix.motorcontrol.FeedbackDevice;
|
||||
import com.studica.frc.AHRS.NavXComType;
|
||||
import edu.wpi.first.math.system.plant.DCMotor;
|
||||
import edu.wpi.first.wpilibj.DriverStation;
|
||||
import edu.wpi.first.wpilibj.I2C;
|
||||
import edu.wpi.first.wpilibj.SPI;
|
||||
import edu.wpi.first.wpilibj.SerialPort.Port;
|
||||
import swervelib.encoders.AnalogAbsoluteEncoderSwerve;
|
||||
import swervelib.encoders.CANCoderSwerve;
|
||||
import swervelib.encoders.CanAndMagSwerve;
|
||||
@@ -16,6 +15,7 @@ import swervelib.encoders.PWMDutyCycleEncoderSwerve;
|
||||
import swervelib.encoders.SparkMaxAnalogEncoderSwerve;
|
||||
import swervelib.encoders.SparkMaxEncoderSwerve;
|
||||
import swervelib.encoders.SwerveAbsoluteEncoder;
|
||||
import swervelib.encoders.TalonSRXEncoderSwerve;
|
||||
import swervelib.imu.ADIS16448Swerve;
|
||||
import swervelib.imu.ADIS16470Swerve;
|
||||
import swervelib.imu.ADXRS450Swerve;
|
||||
@@ -27,6 +27,7 @@ import swervelib.imu.PigeonSwerve;
|
||||
import swervelib.imu.SwerveIMU;
|
||||
import swervelib.motors.SparkFlexSwerve;
|
||||
import swervelib.motors.SparkMaxBrushedMotorSwerve;
|
||||
import swervelib.motors.SparkMaxBrushedMotorSwerve.Type;
|
||||
import swervelib.motors.SparkMaxSwerve;
|
||||
import swervelib.motors.SwerveMotor;
|
||||
import swervelib.motors.TalonFXSwerve;
|
||||
@@ -92,6 +93,10 @@ public class DeviceJson
|
||||
return new AnalogAbsoluteEncoderSwerve(id);
|
||||
case "cancoder":
|
||||
return new CANCoderSwerve(id, canbus != null ? canbus : "");
|
||||
case "talonsrx_pwm":
|
||||
return new TalonSRXEncoderSwerve(motor, FeedbackDevice.PulseWidthEncodedPosition);
|
||||
case "talonsrx_analog":
|
||||
return new TalonSRXEncoderSwerve(motor, FeedbackDevice.Analog);
|
||||
default:
|
||||
throw new RuntimeException(type + " is not a recognized absolute encoder type.");
|
||||
}
|
||||
@@ -122,7 +127,7 @@ public class DeviceJson
|
||||
return new CanandgyroSwerve(id);
|
||||
case "navx":
|
||||
case "navx_spi":
|
||||
return new NavXSwerve(SPI.Port.kMXP);
|
||||
return new NavXSwerve(NavXComType.kMXP_SPI);
|
||||
case "navx_i2c":
|
||||
DriverStation.reportWarning(
|
||||
"WARNING: There exists an I2C lockup issue on the roboRIO that could occur, more information here: " +
|
||||
@@ -130,15 +135,15 @@ public class DeviceJson
|
||||
".html#onboard-i2c-causing-system-lockups",
|
||||
false);
|
||||
i2cLockupWarning.set(true);
|
||||
return new NavXSwerve(I2C.Port.kMXP);
|
||||
return new NavXSwerve(NavXComType.kI2C);
|
||||
case "navx_usb":
|
||||
DriverStation.reportWarning("WARNING: There is issues when using USB camera's and the NavX like this!\n" +
|
||||
"https://pdocs.kauailabs.com/navx-mxp/guidance/selecting-an-interface/", false);
|
||||
serialCommsIssueWarning.set(true);
|
||||
return new NavXSwerve(Port.kUSB);
|
||||
return new NavXSwerve(NavXComType.kUSB1);
|
||||
case "navx_mxp_serial":
|
||||
serialCommsIssueWarning.set(true);
|
||||
return new NavXSwerve(Port.kMXP);
|
||||
return new NavXSwerve(NavXComType.kMXP_UART);
|
||||
case "pigeon":
|
||||
return new PigeonSwerve(id);
|
||||
case "pigeon2":
|
||||
@@ -162,39 +167,56 @@ public class DeviceJson
|
||||
}
|
||||
switch (type)
|
||||
{
|
||||
case "sparkmax_neo":
|
||||
case "neo":
|
||||
case "sparkmax":
|
||||
return new SparkMaxSwerve(id, isDriveMotor, DCMotor.getNEO(1));
|
||||
case "sparkmax_neo550":
|
||||
case "neo550":
|
||||
return new SparkMaxSwerve(id, isDriveMotor, DCMotor.getNeo550(1));
|
||||
case "sparkflex_vortex":
|
||||
case "vortex":
|
||||
case "sparkflex":
|
||||
return new SparkFlexSwerve(id, isDriveMotor, DCMotor.getNeoVortex(1));
|
||||
case "sparkflex_neo":
|
||||
return new SparkFlexSwerve(id, isDriveMotor, DCMotor.getNEO(1));
|
||||
case "sparkflex_neo550":
|
||||
return new SparkFlexSwerve(id, isDriveMotor, DCMotor.getNeo550(1));
|
||||
case "falcon500":
|
||||
case "falcon":
|
||||
return new TalonFXSwerve(id, canbus != null ? canbus : "", isDriveMotor, DCMotor.getFalcon500(1));
|
||||
case "falcon500foc":
|
||||
return new TalonFXSwerve(id, canbus != null ? canbus : "", isDriveMotor, DCMotor.getFalcon500Foc(1));
|
||||
case "krakenx60":
|
||||
case "talonfx":
|
||||
return new TalonFXSwerve(id, canbus != null ? canbus : "", isDriveMotor, DCMotor.getKrakenX60(1));
|
||||
case "krakenx60foc":
|
||||
return new TalonFXSwerve(id, canbus != null ? canbus : "", isDriveMotor, DCMotor.getKrakenX60Foc(1));
|
||||
case "talonsrx":
|
||||
return new TalonSRXSwerve(id, isDriveMotor, DCMotor.getCIM(1));
|
||||
case "sparkmax_brushed":
|
||||
switch (canbus)
|
||||
{
|
||||
case "greyhill_63r256":
|
||||
return new SparkMaxBrushedMotorSwerve(id, isDriveMotor, Type.kQuadrature, 1024, false);
|
||||
return new SparkMaxBrushedMotorSwerve(id, isDriveMotor, Type.kQuadrature, 1024, false, DCMotor.getCIM(1));
|
||||
case "srx_mag_encoder":
|
||||
return new SparkMaxBrushedMotorSwerve(id, isDriveMotor, Type.kQuadrature, 4096, false);
|
||||
return new SparkMaxBrushedMotorSwerve(id, isDriveMotor, Type.kQuadrature, 4096, false, DCMotor.getCIM(1));
|
||||
case "throughbore":
|
||||
return new SparkMaxBrushedMotorSwerve(id, isDriveMotor, Type.kQuadrature, 8192, false);
|
||||
return new SparkMaxBrushedMotorSwerve(id, isDriveMotor, Type.kQuadrature, 8192, false, DCMotor.getCIM(1));
|
||||
case "throughbore_dataport":
|
||||
return new SparkMaxBrushedMotorSwerve(id, isDriveMotor, Type.kNoSensor, 8192, true);
|
||||
return new SparkMaxBrushedMotorSwerve(id, isDriveMotor, Type.kNoSensor, 8192, true, DCMotor.getCIM(1));
|
||||
case "greyhill_63r256_dataport":
|
||||
return new SparkMaxBrushedMotorSwerve(id, isDriveMotor, Type.kQuadrature, 1024, true);
|
||||
return new SparkMaxBrushedMotorSwerve(id, isDriveMotor, Type.kQuadrature, 1024, true, DCMotor.getCIM(1));
|
||||
case "srx_mag_encoder_dataport":
|
||||
return new SparkMaxBrushedMotorSwerve(id, isDriveMotor, Type.kQuadrature, 4096, true);
|
||||
return new SparkMaxBrushedMotorSwerve(id, isDriveMotor, Type.kQuadrature, 4096, true, DCMotor.getCIM(1));
|
||||
default:
|
||||
if (isDriveMotor)
|
||||
{
|
||||
throw new RuntimeException("Spark MAX " + id + " MUST have a encoder attached to the motor controller.");
|
||||
}
|
||||
// We are creating a motor for an angle motor which will use the absolute encoder attached to the data port.
|
||||
return new SparkMaxBrushedMotorSwerve(id, isDriveMotor, Type.kNoSensor, 0, false);
|
||||
return new SparkMaxBrushedMotorSwerve(id, isDriveMotor, Type.kNoSensor, 0, false, DCMotor.getCIM(1));
|
||||
}
|
||||
case "neo":
|
||||
case "sparkmax":
|
||||
return new SparkMaxSwerve(id, isDriveMotor);
|
||||
case "sparkflex":
|
||||
return new SparkFlexSwerve(id, isDriveMotor);
|
||||
case "falcon":
|
||||
case "talonfx":
|
||||
return new TalonFXSwerve(id, canbus != null ? canbus : "", isDriveMotor);
|
||||
case "talonsrx":
|
||||
return new TalonSRXSwerve(id, isDriveMotor);
|
||||
default:
|
||||
throw new RuntimeException(type + " is not a recognized motor type.");
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package swervelib.parser.json;
|
||||
|
||||
import com.revrobotics.CANSparkMax;
|
||||
import com.revrobotics.MotorFeedbackSensor;
|
||||
import com.revrobotics.spark.SparkMax;
|
||||
import edu.wpi.first.math.util.Units;
|
||||
import swervelib.encoders.SparkMaxEncoderSwerve;
|
||||
import swervelib.encoders.SwerveAbsoluteEncoder;
|
||||
import swervelib.motors.SwerveMotor;
|
||||
import swervelib.parser.PIDFConfig;
|
||||
@@ -26,14 +26,6 @@ public class ModuleJson
|
||||
* Angle motor device configuration.
|
||||
*/
|
||||
public DeviceJson angle;
|
||||
/**
|
||||
* Conversion factor for the module, if different from the one in swervedrive.json
|
||||
* <p>
|
||||
* Conversion factor applied to the motor controllers PID loops. Can be calculated with
|
||||
* {@link swervelib.math.SwerveMath#calculateDegreesPerSteeringRotation(double, double)} for angle motors or
|
||||
* {@link swervelib.math.SwerveMath#calculateMetersPerRotation(double, double, double)} for drive motors.
|
||||
*/
|
||||
public MotorConfigDouble conversionFactor = new MotorConfigDouble(0, 0);
|
||||
/**
|
||||
* Conversion Factors composition. Auto-calculates the conversion factors.
|
||||
*/
|
||||
@@ -81,37 +73,8 @@ public class ModuleJson
|
||||
SwerveMotor angleMotor = angle.createMotor(false);
|
||||
SwerveAbsoluteEncoder absEncoder = encoder.createEncoder(angleMotor);
|
||||
|
||||
// Setup deprecation notice.
|
||||
// if (this.conversionFactor.drive != 0 && this.conversionFactor.angle != 0)
|
||||
// {
|
||||
// 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.WARNING).set(true);
|
||||
// }
|
||||
|
||||
// Override with composite conversion factor.
|
||||
if (!conversionFactors.isAngleEmpty())
|
||||
{
|
||||
conversionFactor.angle = conversionFactors.angle.calculate();
|
||||
}
|
||||
if (!conversionFactors.isDriveEmpty())
|
||||
{
|
||||
conversionFactor.drive = conversionFactors.drive.calculate();
|
||||
}
|
||||
|
||||
// Set the conversion factors to null if they are both 0.
|
||||
if (this.conversionFactor != null)
|
||||
{
|
||||
if (this.conversionFactor.angle == 0 && this.conversionFactor.drive == 0)
|
||||
{
|
||||
this.conversionFactor = null;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.conversionFactor == null && physicalCharacteristics.conversionFactor == null)
|
||||
if (!conversionFactors.works() && physicalCharacteristics.conversionFactor == null)
|
||||
{
|
||||
throw new RuntimeException("No Conversion Factor configured! Please create SwerveDrive using \n" +
|
||||
"SwerveParser.createSwerveDrive(driveFeedforward, maxSpeed, angleMotorConversionFactor, driveMotorConversion)\n" +
|
||||
@@ -120,27 +83,27 @@ public class ModuleJson
|
||||
"OR\n" +
|
||||
"Set the conversion factor in physicalproperties.json OR the module JSON file." +
|
||||
"REMEMBER: You can calculate the conversion factors using SwerveMath.calculateMetersPerRotation AND SwerveMath.calculateDegreesPerSteeringRotation\n");
|
||||
} else if (physicalCharacteristics.conversionFactor != null && this.conversionFactor == null)
|
||||
} else if (physicalCharacteristics.conversionFactor.works() && !conversionFactors.works())
|
||||
{
|
||||
this.conversionFactor = physicalCharacteristics.conversionFactor;
|
||||
} else if (physicalCharacteristics.conversionFactor !=
|
||||
null) // If both are defined, override 0 with the physical characterstics input.
|
||||
conversionFactors = physicalCharacteristics.conversionFactor;
|
||||
} else if (physicalCharacteristics.conversionFactor.works())
|
||||
// If both are defined, override 0 with the physical characterstics input.
|
||||
{
|
||||
this.conversionFactor.angle = this.conversionFactor.angle == 0 ? physicalCharacteristics.conversionFactor.angle
|
||||
: this.conversionFactor.angle;
|
||||
this.conversionFactor.drive = this.conversionFactor.drive == 0 ? physicalCharacteristics.conversionFactor.drive
|
||||
: this.conversionFactor.drive;
|
||||
conversionFactors.angle = conversionFactors.isAngleEmpty() ? physicalCharacteristics.conversionFactor.angle
|
||||
: conversionFactors.angle;
|
||||
conversionFactors.drive = conversionFactors.isDriveEmpty() ? physicalCharacteristics.conversionFactor.drive
|
||||
: conversionFactors.drive;
|
||||
}
|
||||
|
||||
if (this.conversionFactor.drive == 0 || this.conversionFactor.angle == 0)
|
||||
if (conversionFactors.isDriveEmpty() || conversionFactors.isAngleEmpty())
|
||||
{
|
||||
throw new RuntimeException(
|
||||
"Conversion factors cannot be 0, please configure conversion factors in physicalproperties.json or the module JSON files.");
|
||||
}
|
||||
|
||||
// Backwards compatibility, auto-optimization.
|
||||
if (conversionFactor.angle == 360 && absEncoder != null &&
|
||||
absEncoder.getAbsoluteEncoder() instanceof MotorFeedbackSensor && angleMotor.getMotor() instanceof CANSparkMax)
|
||||
if (conversionFactors.angle.factor == 360 && absEncoder != null &&
|
||||
absEncoder instanceof SparkMaxEncoderSwerve && angleMotor.getMotor() instanceof SparkMax)
|
||||
{
|
||||
angleMotor.setAbsoluteEncoder(absEncoder);
|
||||
}
|
||||
@@ -148,7 +111,7 @@ public class ModuleJson
|
||||
return new SwerveModuleConfiguration(
|
||||
drive.createMotor(true),
|
||||
angleMotor,
|
||||
conversionFactor,
|
||||
conversionFactors,
|
||||
absEncoder,
|
||||
absoluteEncoderOffset,
|
||||
Units.inchesToMeters(Math.round(location.x) == 0 ? location.front : location.x),
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package swervelib.parser.json;
|
||||
|
||||
import edu.wpi.first.units.Units;
|
||||
import edu.wpi.first.wpilibj.Alert;
|
||||
import edu.wpi.first.wpilibj.Alert.AlertType;
|
||||
import swervelib.parser.SwerveModulePhysicalCharacteristics;
|
||||
import swervelib.parser.json.modules.ConversionFactorsJson;
|
||||
|
||||
@@ -9,13 +12,23 @@ import swervelib.parser.json.modules.ConversionFactorsJson;
|
||||
public class PhysicalPropertiesJson
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* Conversion factor applied to the motor controllers PID loops. Can be calculated with
|
||||
* {@link swervelib.math.SwerveMath#calculateDegreesPerSteeringRotation(double, double)} for angle motors or
|
||||
* {@link swervelib.math.SwerveMath#calculateMetersPerRotation(double, double, double)} for drive motors.
|
||||
* DEPRECATED! Use {@link PhysicalPropertiesJson#conversionFactors} instead.
|
||||
*/
|
||||
public MotorConfigDouble conversionFactor = new MotorConfigDouble(0, 0);
|
||||
@Deprecated(since = "2025", forRemoval = true)
|
||||
public MotorConfigDouble conversionFactor = new MotorConfigDouble();
|
||||
/**
|
||||
* Minimum voltage to spin the module or wheel.
|
||||
*/
|
||||
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;
|
||||
/**
|
||||
* Conversion Factors composition. Auto-calculates the conversion factors.
|
||||
*/
|
||||
@@ -45,35 +58,29 @@ public class PhysicalPropertiesJson
|
||||
public SwerveModulePhysicalCharacteristics createPhysicalProperties()
|
||||
{
|
||||
// Setup deprecation notice.
|
||||
// if (conversionFactor.drive != 0 && conversionFactor.angle != 0 && conversionFactors.isDriveEmpty() &&
|
||||
// conversionFactors.isAngleEmpty())
|
||||
// {
|
||||
// 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.ERROR_TRACE).set(true);
|
||||
// }
|
||||
|
||||
if (!conversionFactors.isAngleEmpty())
|
||||
if (conversionFactor.drive != 0 && conversionFactor.angle != 0 && conversionFactors.isDriveEmpty() &&
|
||||
conversionFactors.isAngleEmpty())
|
||||
{
|
||||
conversionFactor.angle = conversionFactors.angle.calculate();
|
||||
}
|
||||
|
||||
if (!conversionFactors.isDriveEmpty())
|
||||
{
|
||||
conversionFactor.drive = conversionFactors.drive.calculate();
|
||||
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);
|
||||
}
|
||||
|
||||
return new SwerveModulePhysicalCharacteristics(
|
||||
conversionFactor,
|
||||
conversionFactors,
|
||||
wheelGripCoefficientOfFriction,
|
||||
optimalVoltage,
|
||||
currentLimit.drive,
|
||||
currentLimit.angle,
|
||||
rampRate.drive,
|
||||
rampRate.angle);
|
||||
rampRate.angle,
|
||||
friction.drive,
|
||||
friction.angle,
|
||||
steerRotationalInertia,
|
||||
Units.Pounds.of(robotMass).in(Units.Kilogram));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package swervelib.parser.json.modules;
|
||||
|
||||
import swervelib.math.SwerveMath;
|
||||
import swervelib.telemetry.Alert;
|
||||
import swervelib.telemetry.Alert.AlertType;
|
||||
|
||||
/**
|
||||
* Angle motor conversion factors composite JSON parse class.
|
||||
@@ -13,11 +11,11 @@ public class AngleConversionFactorsJson
|
||||
/**
|
||||
* Gear ratio for the angle/steering/azimuth motor on the Swerve Module. Motor rotations to 1 wheel rotation.
|
||||
*/
|
||||
public double gearRatio = 0;
|
||||
public double gearRatio;
|
||||
/**
|
||||
* Calculated or given conversion factor.
|
||||
*/
|
||||
public double factor = 0;
|
||||
public double factor = 0;
|
||||
|
||||
/**
|
||||
* Calculate the drive conversion factor.
|
||||
@@ -26,12 +24,6 @@ public class AngleConversionFactorsJson
|
||||
*/
|
||||
public double calculate()
|
||||
{
|
||||
if (factor != 0 && gearRatio != 0)
|
||||
{
|
||||
new Alert("Configuration",
|
||||
"The given angle conversion factor takes precedence over the composite conversion factor, please remove 'factor' if you want to use the composite factor instead.",
|
||||
AlertType.WARNING).set(true);
|
||||
}
|
||||
if (factor == 0)
|
||||
{
|
||||
factor = SwerveMath.calculateDegreesPerSteeringRotation(gearRatio);
|
||||
|
||||
@@ -22,7 +22,8 @@ public class ConversionFactorsJson
|
||||
*/
|
||||
public boolean isDriveEmpty()
|
||||
{
|
||||
return drive.factor == 0 && drive.diameter == 0 && drive.gearRatio == 0;
|
||||
drive.calculate();
|
||||
return drive.factor == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -32,6 +33,18 @@ public class ConversionFactorsJson
|
||||
*/
|
||||
public boolean isAngleEmpty()
|
||||
{
|
||||
return angle.factor == 0 && angle.gearRatio == 0;
|
||||
angle.calculate();
|
||||
return angle.factor == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the conversion factor can be found.
|
||||
*
|
||||
* @return If the conversion factors can be found.
|
||||
*/
|
||||
public boolean works()
|
||||
{
|
||||
return (angle.factor != 0 && drive.factor != 0) ||
|
||||
((drive.gearRatio != 0 && drive.diameter != 0)) && (angle.gearRatio != 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,6 @@ package swervelib.parser.json.modules;
|
||||
|
||||
import edu.wpi.first.math.util.Units;
|
||||
import swervelib.math.SwerveMath;
|
||||
import swervelib.telemetry.Alert;
|
||||
import swervelib.telemetry.Alert.AlertType;
|
||||
|
||||
/**
|
||||
* Drive motor composite JSON parse class.
|
||||
@@ -14,15 +12,15 @@ public class DriveConversionFactorsJson
|
||||
/**
|
||||
* Gear ratio for the drive motor rotations to turn the wheel 1 complete rotation.
|
||||
*/
|
||||
public double gearRatio = 0;
|
||||
public double gearRatio;
|
||||
/**
|
||||
* Diameter of the wheel in inches.
|
||||
*/
|
||||
public double diameter = 0;
|
||||
public double diameter;
|
||||
/**
|
||||
* Calculated conversion factor.
|
||||
*/
|
||||
public double factor = 0;
|
||||
public double factor = 0;
|
||||
|
||||
/**
|
||||
* Calculate the drive conversion factor.
|
||||
@@ -31,12 +29,6 @@ public class DriveConversionFactorsJson
|
||||
*/
|
||||
public double calculate()
|
||||
{
|
||||
if (factor != 0 && (diameter != 0 || gearRatio != 0))
|
||||
{
|
||||
new Alert("Configuration",
|
||||
"The given drive conversion factor takes precedence over the composite conversion factor, please remove 'factor' if you want to use the composite factor instead.",
|
||||
AlertType.WARNING).set(true);
|
||||
}
|
||||
if (factor == 0)
|
||||
{
|
||||
factor = SwerveMath.calculateMetersPerRotation(Units.inchesToMeters(this.diameter), this.gearRatio);
|
||||
|
||||
Reference in New Issue
Block a user