Skip to content

Commit

Permalink
Added configurable angle motor kV to JSON files.
Browse files Browse the repository at this point in the history
Signed-off-by: thenetworkgrinch <[email protected]>
  • Loading branch information
thenetworkgrinch committed Mar 27, 2023
1 parent 9ab4ea6 commit ff4ab2b
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 8 deletions.
6 changes: 6 additions & 0 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,12 @@ <h1 class="d-inline display-6">Module Properties</h1>
<label class="form-label" for="rampRate_angle-input">Ramp Rate Angle</label>
</div>
<hr/>
<div class="form-floating mb-3">
<input class="form-control" id="angleMotorsKV-input" name="angleMotorsKV"
placeholder="0" type="number" value="0">
<label class="form-label" for="angleMotorsKV-input">Angle Motor kV</label>
</div>
<hr/>
<div class="form-floating mb-3">
<input class="form-control" id="encoderPulsePerRotation_drive-input"
name="encoderPulsePerRotation_drive" placeholder="1" type="number"
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/swervelib/parser/SwerveModuleConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,11 @@ public 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -78,7 +84,8 @@ public SwerveModulePhysicalCharacteristics(
double driveMotorRampRate,
double angleMotorRampRate,
int driveEncoderPulsePerRotation,
int angleEncoderPulsePerRotation)
int angleEncoderPulsePerRotation,
double angleMotorKV)
{
this.wheelGripCoefficientOfFriction = wheelGripCoefficientOfFriction;
this.optimalVoltage = optimalVoltage;
Expand All @@ -94,6 +101,7 @@ public SwerveModulePhysicalCharacteristics(
this.angleMotorCurrentLimit = angleMotorCurrentLimit;
this.driveMotorRampRate = driveMotorRampRate;
this.angleMotorRampRate = angleMotorRampRate;
this.angleMotorKV = angleMotorKV;
}

/**
Expand Down Expand Up @@ -134,6 +142,6 @@ public SwerveModulePhysicalCharacteristics(
driveMotorRampRate,
angleMotorRampRate,
driveEncoderPulsePerRotation,
angleEncoderPulsePerRotation);
angleEncoderPulsePerRotation, 0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -58,7 +64,8 @@ public SwerveModulePhysicalCharacteristics createPhysicalProperties(double optim
rampRate.drive,
rampRate.angle,
encoderPulsePerRotation.drive,
encoderPulsePerRotation.angle);
encoderPulsePerRotation.angle,
angleMotorsKV);
}
}

Expand Down

0 comments on commit ff4ab2b

Please sign in to comment.