Skip to content

Commit

Permalink
force pinion sizes in ratio finder
Browse files Browse the repository at this point in the history
  • Loading branch information
tervay committed Dec 18, 2023
1 parent 68a4bdf commit 2643f89
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 8 deletions.
6 changes: 6 additions & 0 deletions src/common/models/Gearbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,12 @@ export class Gearbox {
);
}

startsWithTeeth(teeth: number): boolean {
return (
this.stages[0].drivingMethods.filter((m) => m.teeth === teeth).length > 0
);
}

containsPinionInBadPlace(): boolean {
if (this.stages.length === 1) {
return (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import SimpleHeading from "common/components/heading/SimpleHeading";
import SingleInputLine from "common/components/io/inputs/SingleInputLine";
import { NumberInput } from "common/components/io/new/inputs";
import { BooleanInput, NumberInput } from "common/components/io/new/inputs";
import L0MultiBoolean from "common/components/io/new/inputs/L0/L0MultiBoolean";
import BoreInput from "common/components/io/new/inputs/L3/BoreInput";
import { Column, Columns, Divider } from "common/components/styling/Building";
Expand Down Expand Up @@ -248,6 +248,8 @@ export default function RatioFinderCalculator(): JSX.Element {
get.enableBearingBore,
get.enable875Bore,
get.enableMaxSpline,
get.startingPinionSize,
get.forceStartingPinionSize,
]);

const [displayNum, setDisplayNum] = useState(20);
Expand Down Expand Up @@ -326,6 +328,31 @@ export default function RatioFinderCalculator(): JSX.Element {
</Column>
</Columns>

<Columns formColumns>
<Column>
<SingleInputLine label="Force Pinion Size">
<BooleanInput
stateHook={[
get.forceStartingPinionSize,
set.setForceStartingPinionSize,
]}
/>
</SingleInputLine>
</Column>
{get.forceStartingPinionSize && (
<Column>
<SingleInputLine label="Starting Pinion Size">
<NumberInput
stateHook={[
get.startingPinionSize,
set.setStartingPinionSize,
]}
/>
</SingleInputLine>
</Column>
)}
</Columns>

<Columns>
<Column>
<Divider extraClasses="mt-0">Gear Tooth Range</Divider>
Expand Down
2 changes: 2 additions & 0 deletions src/web/calculators/ratioFinder/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ export const RatioFinderParamsV1 = {
minStages: withDefault(NumberParam, 1),
maxStages: withDefault(NumberParam, 2),
startingBore: withDefault(BoreParam, "NEO"),
forceStartingPinionSize: withDefault(BooleanParam, false),
startingPinionSize: withDefault(NumberParam, 14),

enableVPs: withDefault(BooleanParam, false),
enableMPs: withDefault(BooleanParam, true),
Expand Down
41 changes: 34 additions & 7 deletions src/web/calculators/ratioFinder/math.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ import vexGears from "common/models/data/cots/vex/gears.json";
import vexPulleys from "common/models/data/cots/vex/pulleys.json";
import vexSprockets from "common/models/data/cots/vex/sprockets.json";

function stagesFromMinToMax(min: number, max: number): Stage[] {
function stagesFromMinToMax(
min: number,
max: number,
additionalStartingSizes: number[],
): Stage[] {
const stages: Stage[] = [];
for (let i = min; i <= max; i++) {
for (let j = min; j <= max; j++) {
Expand All @@ -51,6 +55,12 @@ function stagesFromMinToMax(min: number, max: number): Stage[] {
}
}

for (let i = 0; i < additionalStartingSizes.length; i++) {
for (let j = min; j <= max; j++) {
stages.push(new Stage(additionalStartingSizes[i], j, [], []));
}
}

return stages;
}

Expand All @@ -60,6 +70,7 @@ export function allPossibleSingleGearStages(state: RatioFinderStateV1) {
8,
max([state.maxGearTeeth, state.maxPulleyTeeth, state.maxSprocketTeeth]) ||
80,
state.forceStartingPinionSize ? [state.startingPinionSize] : [],
);
}

Expand Down Expand Up @@ -126,8 +137,12 @@ function filterGears(
}))
.filter((g) => state.enable20DPGears || g.dp !== 20)
.filter((g) => state.enable32DPGears || g.dp !== 32)
.filter((g) => state.minGearTeeth <= g.teeth)
.filter((g) => state.maxGearTeeth >= g.teeth);
.filter(
(g) =>
(state.forceStartingPinionSize &&
g.teeth === state.startingPinionSize) ||
(state.minGearTeeth <= g.teeth && state.maxGearTeeth >= g.teeth),
);
}

function filterPulleys(
Expand All @@ -147,8 +162,12 @@ function filterPulleys(
.filter((p) => state.enableHTD || p.beltType !== "HTD")
.filter((p) => state.enableGT2 || p.beltType !== "GT2")
.filter((p) => state.enableRT25 || p.beltType !== "RT25")
.filter((p) => state.minPulleyTeeth <= p.teeth)
.filter((p) => state.maxPulleyTeeth >= p.teeth);
.filter(
(g) =>
(state.forceStartingPinionSize &&
g.teeth === state.startingPinionSize) ||
(state.minPulleyTeeth <= g.teeth && state.maxPulleyTeeth >= g.teeth),
);
}
function filterSprockets(
state: RatioFinderStateV1,
Expand All @@ -165,8 +184,13 @@ function filterSprockets(
}))
.filter((s) => state.enable25Chain || s.chainType !== "#25")
.filter((s) => state.enable35Chain || s.chainType !== "#35")
.filter((s) => state.minSprocketTeeth <= s.teeth)
.filter((s) => state.maxSprocketTeeth >= s.teeth);
.filter(
(g) =>
(state.forceStartingPinionSize &&
g.teeth === state.startingPinionSize) ||
(state.minSprocketTeeth <= g.teeth &&
state.maxSprocketTeeth >= g.teeth),
);
}

export function generateOptions(state: RatioFinderStateV1) {
Expand Down Expand Up @@ -302,6 +326,9 @@ export function generateOptions(state: RatioFinderStateV1) {
if (
gb.hasMotionModes() &&
gb.startsWithBore(state.startingBore) &&
(state.forceStartingPinionSize
? gb.startsWithTeeth(state.startingPinionSize)
: true) &&
!gb.containsPinionInBadPlace()
) {
gbs.push(gb);
Expand Down

1 comment on commit 2643f89

@tervay
Copy link
Owner Author

@tervay tervay commented on 2643f89 Dec 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deploy preview for recalc ready!

✅ Preview
https://recalc-e4bmimsye-tervay.vercel.app

Built with commit 2643f89.
This pull request is being automatically deployed with vercel-action

Please sign in to comment.