Skip to content

Commit

Permalink
Updated the configurator.
Browse files Browse the repository at this point in the history
Signed-off-by: thenetworkgrinch <thenetworkgrinch@users.noreply.github.com>
  • Loading branch information
thenetworkgrinch committed Jul 29, 2024
1 parent 3195184 commit 5480a02
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 56 deletions.
58 changes: 37 additions & 21 deletions docs/assets/js/v2.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@



function getFreeSpeedFromMotors() {
let motor_count = {}
let modules = ['frontright', 'frontleft', 'backright', 'backleft'];
Expand Down Expand Up @@ -52,14 +49,31 @@ function jsonify(name) {
let formdata = $(`#${name}-form`).serializeArray();
formdata.forEach((val) => {
if (val.name.includes('_')) {
let struct = val.name.substring(0, val.name.indexOf('_'));
let structStart = val.name.indexOf('_')
let struct = val.name.substring(0, structStart);
let subStruct = null;
if (data[struct] === undefined) {
data[struct] = {};
}
data[struct][val.name.substring(val.name.indexOf('_') + 1)] =
isNumeric(val.value) ?
parseFloat(val.value) :
(val.value === "" ? null : val.value);
let subStructStart = val.name.indexOf('_', structStart + 1);
if (subStructStart !== -1) {
subStruct = val.name.substring(structStart + 1, subStructStart)
if (data[struct][subStruct] === undefined) {
data[struct][subStruct] = {}
}
}
if (subStruct == null) {
data[struct][val.name.substring(val.name.lastIndexOf('_') + 1)] =
isNumeric(val.value) ?
parseFloat(val.value) :
(val.value === "" ? null : val.value);
} else {
data[struct][subStruct][val.name.substring(
val.name.lastIndexOf('_') + 1)] =
isNumeric(val.value) ?
parseFloat(val.value) :
(val.value === "" ? null : val.value);
}
} else {
data[val.name] = isNumeric(val.value) ?
parseFloat(val.value) :
Expand Down Expand Up @@ -103,7 +117,6 @@ function copyText(name) {
navigator.clipboard.writeText(text);
}


function getText(name) {
let text = $(`#${name}-json`).text();
return text;
Expand All @@ -123,18 +136,21 @@ const saveAs = (blob, name) => {

function zipDownload() {
const zip = new JSZip();
let swf = zip.folder("swerve")
let cp = swf.file("controllerproperties.json", getText("controllerproperties"));
let sd = swf.file("swervedrive.json", getText("swervedrive"));
let mod = swf.folder("modules")
let pp = mod.file("physicalproperties.json", getText("physicalproperties"));
let fl = mod.file("frontleft.json", getText("frontleft"));
let fr = mod.file("frontright.json", getText("frontright"));
let bl = mod.file("backleft.json", getText("backleft"));
let br = mod.file("backright.json", getText("backright"));
let pidf = mod.file("pidfproperties.json", getText("pidfproperties"));

zip.generateAsync({type:"blob"}).then(function (blob) {saveAs(blob, "YAGSL Config.zip")});
let swf = zip.folder("swerve")
let cp = swf.file("controllerproperties.json",
getText("controllerproperties"));
let sd = swf.file("swervedrive.json", getText("swervedrive"));
let mod = swf.folder("modules")
let pp = mod.file("physicalproperties.json", getText("physicalproperties"));
let fl = mod.file("frontleft.json", getText("frontleft"));
let fr = mod.file("frontright.json", getText("frontright"));
let bl = mod.file("backleft.json", getText("backleft"));
let br = mod.file("backright.json", getText("backright"));
let pidf = mod.file("pidfproperties.json", getText("pidfproperties"));

zip.generateAsync({type: "blob"}).then(function (blob) {
saveAs(blob, "YAGSL Config.zip")
});
console.log("Downloaded YAGSL Config zip");
}

Expand Down
60 changes: 25 additions & 35 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -120,50 +120,40 @@ <h1 class="d-inline display-6">Module Properties</h1>
placeholder="20" type="number" value="20">
<label class="form-label" for="currentLimit_angle-input">Current Limit Angle</label>
</div>
<hr/>
<div class="alert alert-secondary" role="alert">
The formula for the conversion factors is described in depth <a
href="https://yagsl.gitbook.io/yagsl/fundamentals/swerve-modules#conversion-factor">here</a>.
<br/>
IF you are using an absolute encoder attached to your SparkMAX this should be <code>360</code>
for the angle motor conversion factor.
You can also generate these by using <br/>
<code>SwerveMath.calculateMetersPerRotation</code>
<br/>
As in this example bellow. <br/>
<pre><code>
// Angle conversion factor is 360 / (GEAR RATIO * ENCODER RESOLUTION)
// In this case the gear ratio is 12.8 motor revolutions per wheel rotation.
// The encoder resolution per motor revolution is 1 per motor revolution.
double <var>angleConversionFactor</var> = SwerveMath.calculateDegreesPerSteeringRotation(<var>12.8</var>, <var>1</var>);

// Motor conversion factor is (PI * WHEEL DIAMETER IN METERS) / (GEAR RATIO * ENCODER RESOLUTION).
// In this case the wheel diameter is 4 inches, which must be converted to meters to get meters/second.
// The gear ratio is 6.75 motor revolutions per wheel rotation.
// The encoder resolution per motor revolution is 1 per motor revolution.
double <var>driveConversionFactor</var> = SwerveMath.calculateMetersPerRotation(<var>Units.inchesToMeters(4)</var>, <var>6.75</var>, <var>1</var>);
<div class="form-floating mb-3">

// If you did not want to specify conversion factors in these JSON files you can place them as parameters for <var>createSwerveDrive</var>. <br/>
SwerveDrive swerveDrive = new SwerveParser(directory).createSwerveDrive(maximumSpeed, angleConversionFactor, driveConversionFactor);
</code></pre>
These conversion factor is applied to the PID on the motor controller.
<input class="form-control" id="swervedriveconversion_angle-input"
name="conversionFactor_angle_gearRatio" placeholder=""
type="number" value="0">
<label class="form-label" for="swervedriveconversion_angle-input">Angle/Steering/Azimuth Gear Ratio</label>
</div>
<hr/>
<div class="form-floating mb-3">

<input class="form-control" id="swervedriveconversion_angle-input"
name="conversionFactor_angle" placeholder=""
<input class="form-control" id="swervedriveconversion_angle_factor-input"
name="conversionFactor_angle_factor" placeholder=""
type="number" value="0">
<label class="form-label" for="swervedriveconversion_angle-input">Angle Motor
Conversion Factor</label>
<label class="form-label" for="swervedriveconversion_angle_factor-input">Angle/Steering/Azimuth Conversion Factor (optional)</label>
</div>
<div class="form-floating mb-3">
<input class="form-control" id="swervedriveconversion_drive-input"
name="conversionFactor_drive"
placeholder="(Math.PI * wheelDiameterInMeters) / (driveGearRatio)"
name="conversionFactor_drive_diameter"
placeholder="0in"
type="number" value="0">
<label class="form-label" for="swervedriveconversion_drive-input">Drive Motor
Conversion Factor</label>
<label class="form-label" for="swervedriveconversion_drive-input">Wheel Diameter (in)</label>
</div>
<div class="form-floating mb-3">
<input class="form-control" id="swervedriveconversion_drive_gearRatio-input"
name="conversionFactor_drive_gearRatio"
placeholder="0"
type="number" value="0">
<label class="form-label" for="swervedriveconversion_drive_gearRatio-input">Drive Gear Ratio</label>
</div>
<div class="form-floating mb-3">
<input class="form-control" id="swervedriveconversion_drive_factor-input"
name="conversionFactor_drive_factor"
placeholder="0"
type="number" value="0">
<label class="form-label" for="swervedriveconversion_drive_factor-input">Drive Conversion Factor (optional)</label>
</div>
<hr/>
<div class="form-floating mb-3">
Expand Down

0 comments on commit 5480a02

Please sign in to comment.