2023-02-13 17:21:24 -06:00
|
|
|
package swervelib.parser.json;
|
2023-02-13 14:37:05 -06:00
|
|
|
|
|
|
|
|
import edu.wpi.first.math.util.Units;
|
2023-02-13 17:21:24 -06:00
|
|
|
import swervelib.parser.SwerveModulePhysicalCharacteristics;
|
2023-04-08 12:31:07 -05:00
|
|
|
import swervelib.telemetry.SwerveDriveTelemetry;
|
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
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Wheel diameter in inches.
|
|
|
|
|
*/
|
|
|
|
|
public double wheelDiameter;
|
|
|
|
|
/**
|
|
|
|
|
* Gear ratio for the motors, number of times the motor has to spin before the wheel rotates a single time.
|
|
|
|
|
*/
|
|
|
|
|
public MotorConfigDouble gearRatio;
|
|
|
|
|
/**
|
|
|
|
|
* Encoder pulse per rotation for non-integrated encoders. 1 for integrated encoders.
|
|
|
|
|
*/
|
|
|
|
|
public MotorConfigInt encoderPulsePerRotation = new MotorConfigInt(1, 1);
|
|
|
|
|
/**
|
|
|
|
|
* The current limit in AMPs to apply to the motors.
|
|
|
|
|
*/
|
|
|
|
|
public MotorConfigInt currentLimit = new MotorConfigInt(40, 20);
|
|
|
|
|
/**
|
|
|
|
|
* The minimum number of seconds to take for the motor to go from 0 to full throttle.
|
|
|
|
|
*/
|
|
|
|
|
public MotorConfigDouble rampRate = new MotorConfigDouble(0.25, 0.25);
|
|
|
|
|
/**
|
|
|
|
|
* The grip tape coefficient of friction on carpet. Used to calculate the practical maximum acceleration.
|
|
|
|
|
*/
|
|
|
|
|
public double wheelGripCoefficientOfFriction = 1.19;
|
|
|
|
|
/**
|
2023-04-08 12:31:07 -05:00
|
|
|
* 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. Default value is 0. If
|
|
|
|
|
* robot arcs while translating and rotating negate this.
|
2023-02-13 14:37:05 -06:00
|
|
|
*/
|
2023-08-09 13:15:02 -05:00
|
|
|
public double moduleFeedForwardClosedLoop = SwerveDriveTelemetry.isSimulation ? 0.33 : 0;
|
2023-03-29 07:24:24 -05:00
|
|
|
/**
|
2023-04-08 12:31:07 -05:00
|
|
|
* DEPRECATED: No longer needed, tune {@link PhysicalPropertiesJson#moduleFeedForwardClosedLoop} instead.
|
2023-03-29 07:24:24 -05:00
|
|
|
*/
|
2023-04-08 12:31:07 -05:00
|
|
|
public double angleMotorFreeSpeedRPM = 0;
|
2023-02-13 14:37:05 -06:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Create the physical characteristics based off the parsed data.
|
|
|
|
|
*
|
|
|
|
|
* @param optimalVoltage Optimal voltage to compensate for and use to calculate drive motor feedforward.
|
|
|
|
|
* @return {@link SwerveModulePhysicalCharacteristics} based on parsed data.
|
|
|
|
|
*/
|
|
|
|
|
public SwerveModulePhysicalCharacteristics createPhysicalProperties(double optimalVoltage)
|
|
|
|
|
{
|
2023-02-20 20:59:31 -06:00
|
|
|
return new SwerveModulePhysicalCharacteristics(
|
|
|
|
|
gearRatio.drive,
|
|
|
|
|
gearRatio.angle,
|
|
|
|
|
Units.inchesToMeters(wheelDiameter),
|
|
|
|
|
wheelGripCoefficientOfFriction,
|
|
|
|
|
optimalVoltage,
|
|
|
|
|
currentLimit.drive,
|
|
|
|
|
currentLimit.angle,
|
|
|
|
|
rampRate.drive,
|
|
|
|
|
rampRate.angle,
|
|
|
|
|
encoderPulsePerRotation.drive,
|
2023-03-29 07:24:24 -05:00
|
|
|
encoderPulsePerRotation.angle,
|
2023-04-08 12:31:07 -05:00
|
|
|
moduleFeedForwardClosedLoop);
|
2023-02-13 14:37:05 -06:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Used to store doubles for motor configuration.
|
|
|
|
|
*/
|
|
|
|
|
class MotorConfigDouble
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Drive motor.
|
|
|
|
|
*/
|
|
|
|
|
public double drive;
|
|
|
|
|
/**
|
|
|
|
|
* Angle motor.
|
|
|
|
|
*/
|
|
|
|
|
public double angle;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Default constructor.
|
|
|
|
|
*/
|
|
|
|
|
public MotorConfigDouble()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Default constructor.
|
|
|
|
|
*
|
|
|
|
|
* @param angle Angle data.
|
|
|
|
|
* @param drive Drive data.
|
|
|
|
|
*/
|
|
|
|
|
public MotorConfigDouble(double angle, double drive)
|
|
|
|
|
{
|
|
|
|
|
this.angle = angle;
|
|
|
|
|
this.drive = drive;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Used to store ints for motor configuration.
|
|
|
|
|
*/
|
|
|
|
|
class MotorConfigInt
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Drive motor.
|
|
|
|
|
*/
|
|
|
|
|
public int drive;
|
|
|
|
|
/**
|
|
|
|
|
* Angle motor.
|
|
|
|
|
*/
|
|
|
|
|
public int angle;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Default constructor.
|
|
|
|
|
*/
|
|
|
|
|
public MotorConfigInt()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Default constructor with values.
|
|
|
|
|
*
|
|
|
|
|
* @param drive Drive data.
|
|
|
|
|
* @param angle Angle data.
|
|
|
|
|
*/
|
|
|
|
|
public MotorConfigInt(int drive, int angle)
|
|
|
|
|
{
|
|
|
|
|
this.angle = angle;
|
|
|
|
|
this.drive = drive;
|
|
|
|
|
}
|
2023-02-20 20:59:31 -06:00
|
|
|
}
|