Skip to content

Commit

Permalink
Add more field settings
Browse files Browse the repository at this point in the history
Surely there's a better method right
  • Loading branch information
jfabellera committed Sep 17, 2024
1 parent cd96e20 commit 88a8c4d
Show file tree
Hide file tree
Showing 4 changed files with 192 additions and 29 deletions.
91 changes: 83 additions & 8 deletions front-end/src/seasons/fgc-2024/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,23 @@ import {
centerWledWebSocketAddressAtom,
fieldFaultColorAtom,
fieldOptionsSelector,
foodProductionMotorDurationSecondsAtom,
foodProductionDelayMsAtom,
foodProductionMotorDurationMsAtom,
foodProductionMotorSetpointAtom,
foodResetMotorSetpointAtom,
goalBlueOnlyColorAtom,
goalEmptyColorAtom,
goalFullColorAtom,
goalGreenOnlyColorAtom,
goalLedLengthAtom,
matchEndBlueNexusGoalColorAtom,
matchEndRampColorAtom,
matchEndRedNexusGoalColorAtom,
prepareFieldColorAtom,
rampBalancedColorAtom,
rampHysteresisWindowMsAtom,
rampLedLengthAtom,
rampUnbalancedColorAtom,
redWledWebSocketAddressAtom
} from './stores/settings-store';
import { NumberSetting } from 'src/apps/settings/components/number-setting';
Expand Down Expand Up @@ -49,13 +57,32 @@ export const Settings: FC = () => {
useRecoilState(centerWledWebSocketAddressAtom);
const [foodProductionMotorSetpoint, setFoodProductionMotorSetpoint] =
useRecoilState(foodProductionMotorSetpointAtom);
const [
foodProductionMotorDurationSeconds,
setFoodProductionMotorDurationSeconds
] = useRecoilState(foodProductionMotorDurationSecondsAtom);
const [foodProductionMotorDurationMs, setFoodProductionMotorDurationMs] =
useRecoilState(foodProductionMotorDurationMsAtom);
const [foodResetMotorSetpoint, setFoodResetMotorSetpoint] = useRecoilState(
foodResetMotorSetpointAtom
);
const [foodProductionDelayMs, setFoodProductionDelayMs] = useRecoilState(
foodProductionDelayMsAtom
);
const [rampHysteresisWindowMs, setRampHysteresisWindowMs] = useRecoilState(
rampHysteresisWindowMsAtom
);
const [goalEmptyColor, setGoalEmptyColor] =
useRecoilState(goalEmptyColorAtom);
const [goalBlueOnlyColor, setGoalBlueOnlyColor] = useRecoilState(
goalBlueOnlyColorAtom
);
const [goalGreenOnlyColor, setGoalGreenOnlyColor] = useRecoilState(
goalGreenOnlyColorAtom
);
const [goalFullColor, setGoalFullColor] = useRecoilState(goalFullColorAtom);
const [rampBalancedColor, setRampBalancedColor] = useRecoilState(
rampBalancedColorAtom
);
const [rampUnbalancedColor, setRampUnbalancedColor] = useRecoilState(
rampUnbalancedColorAtom
);

const fieldOptions: FieldOptions = useRecoilValue(fieldOptionsSelector);

Expand Down Expand Up @@ -138,9 +165,9 @@ export const Settings: FC = () => {
inline
/>
<NumberSetting
name='Food Production Moto rDuration Seconds'
value={foodProductionMotorDurationSeconds}
onChange={setFoodProductionMotorDurationSeconds}
name='Food Production Motor Duration (ms)'
value={foodProductionMotorDurationMs}
onChange={setFoodProductionMotorDurationMs}
inline
/>
<NumberSetting
Expand All @@ -149,6 +176,54 @@ export const Settings: FC = () => {
onChange={setFoodResetMotorSetpoint}
inline
/>
<NumberSetting
name='Food Production Delay (ms)'
value={foodProductionDelayMs}
onChange={setFoodProductionDelayMs}
inline
/>
<NumberSetting
name='Ramp Hysteresis Window (ms)'
value={rampHysteresisWindowMs}
onChange={setRampHysteresisWindowMs}
inline
/>
<TextSetting
name='Empty Goal Color'
value={goalEmptyColor}
onChange={setGoalEmptyColor}
inline
/>
<TextSetting
name='Blue Only Goal Color'
value={goalBlueOnlyColor}
onChange={setGoalBlueOnlyColor}
inline
/>
<TextSetting
name='Green Only Goal Color'
value={goalGreenOnlyColor}
onChange={setGoalGreenOnlyColor}
inline
/>
<TextSetting
name='Full Goal Color'
value={goalFullColor}
onChange={setGoalFullColor}
inline
/>
<TextSetting
name='Ramp Balanced Color'
value={rampBalancedColor}
onChange={setRampBalancedColor}
inline
/>
<TextSetting
name='Ramp Unbalanced Color'
value={rampUnbalancedColor}
onChange={setRampUnbalancedColor}
inline
/>
</Box>
);
};
70 changes: 62 additions & 8 deletions front-end/src/seasons/fgc-2024/stores/settings-store.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ export const foodProductionMotorSetpointAtom = atom<number>({
effects: [localStorageEffect('ftf.foodProductionMotorSetpoint')]
});

export const foodProductionMotorDurationSecondsAtom = atom<number>({
key: 'ftf.foodProductionMotorDurationSeconds',
default: defaultFieldOptions.foodProductionMotorDurationSeconds,
effects: [localStorageEffect('ftf.foodProductionMotorDurationSeconds')]
export const foodProductionMotorDurationMsAtom = atom<number>({
key: 'ftf.foodProductionMotorDurationMs',
default: defaultFieldOptions.foodProductionMotorDurationMs,
effects: [localStorageEffect('ftf.foodProductionMotorDurationMs')]
});

export const foodResetMotorSetpointAtom = atom<number>({
Expand All @@ -86,6 +86,54 @@ export const foodResetMotorSetpointAtom = atom<number>({
effects: [localStorageEffect('ftf.foodResetMotorSetpoint')]
});

export const foodProductionDelayMsAtom = atom<number>({
key: 'ftf.foodProductionDelayMs',
default: defaultFieldOptions.foodProductionDelayMs,
effects: [localStorageEffect('ftf.foodProductionDelayMs')]
});

export const rampHysteresisWindowMsAtom = atom<number>({
key: 'ftf.rampHysteresisWindowMs',
default: defaultFieldOptions.rampHysteresisWindowMs,
effects: [localStorageEffect('ftf.rampHysteresisWindowMs')]
});

export const goalEmptyColorAtom = atom<string>({
key: 'ftf.goalEmptyColor',
default: defaultFieldOptions.goalEmptyColor,
effects: [localStorageEffect('ftf.goalEmptyColor')]
});

export const goalBlueOnlyColorAtom = atom<string>({
key: 'ftf.goalBlueOnlyColor',
default: defaultFieldOptions.goalBlueOnlyColor,
effects: [localStorageEffect('ftf.goalBlueOnlyColor')]
});

export const goalGreenOnlyColorAtom = atom<string>({
key: 'ftf.goalGreenOnlyColor',
default: defaultFieldOptions.goalGreenOnlyColor,
effects: [localStorageEffect('ftf.goalGreenOnlyColor')]
});

export const goalFullColorAtom = atom<string>({
key: 'ftf.goalFullColor',
default: defaultFieldOptions.goalFullColor,
effects: [localStorageEffect('ftf.goalFullColor')]
});

export const rampBalancedColorAtom = atom<string>({
key: 'ftf.rampBalancedColor',
default: defaultFieldOptions.rampBalancedColor,
effects: [localStorageEffect('ftf.rampBalancedColor')]
});

export const rampUnbalancedColorAtom = atom<string>({
key: 'ftf.rampUnbalancedColor',
default: defaultFieldOptions.rampUnbalancedColor,
effects: [localStorageEffect('ftf.rampUnbalancedColor')]
});

export const fieldOptionsSelector: RecoilValueReadOnly<FieldOptions> = selector(
{
key: 'ftf.fieldOptions',
Expand All @@ -103,10 +151,16 @@ export const fieldOptionsSelector: RecoilValueReadOnly<FieldOptions> = selector(
blueWledWebSocketAddress: get(blueWledWebSocketAddressAtom),
centerWledWebSocketAddress: get(centerWledWebSocketAddressAtom),
foodProductionMotorSetpoint: get(foodProductionMotorSetpointAtom),
foodProductionMotorDurationSeconds: get(
foodProductionMotorDurationSecondsAtom
),
foodResetMotorSetpoint: get(foodResetMotorSetpointAtom)
foodProductionMotorDurationMs: get(foodProductionMotorDurationMsAtom),
foodResetMotorSetpoint: get(foodResetMotorSetpointAtom),
foodProductionDelayMs: get(foodProductionDelayMsAtom),
rampHysteresisWindowMs: get(rampHysteresisWindowMsAtom),
goalEmptyColor: get(goalEmptyColorAtom),
goalBlueOnlyColor: get(goalBlueOnlyColorAtom),
goalGreenOnlyColor: get(goalGreenOnlyColorAtom),
goalFullColor: get(goalFullColorAtom),
rampBalancedColor: get(rampBalancedColorAtom),
rampUnbalancedColor: get(rampUnbalancedColorAtom)
};
}
}
Expand Down
22 changes: 19 additions & 3 deletions lib/models/src/base/FieldControl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,16 @@ export interface FieldOptions {
blueWledWebSocketAddress: string;
centerWledWebSocketAddress: string;
foodProductionMotorSetpoint: number;
foodProductionMotorDurationSeconds: number;
foodProductionMotorDurationMs: number;
foodResetMotorSetpoint: number;
foodProductionDelayMs: number;
rampHysteresisWindowMs: number;
goalEmptyColor: string;
goalBlueOnlyColor: string;
goalGreenOnlyColor: string;
goalFullColor: string;
rampBalancedColor: string;
rampUnbalancedColor: string;
}

export const defaultFieldOptions: FieldOptions = {
Expand All @@ -139,6 +147,14 @@ export const defaultFieldOptions: FieldOptions = {
blueWledWebSocketAddress: '',
centerWledWebSocketAddress: '',
foodProductionMotorSetpoint: 1.0,
foodProductionMotorDurationSeconds: 5,
foodResetMotorSetpoint: -0.5
foodProductionMotorDurationMs: 5000,
foodResetMotorSetpoint: -0.5,
foodProductionDelayMs: 5000,
rampHysteresisWindowMs: 500,
goalEmptyColor: '000000',
goalBlueOnlyColor: '0000ff',
goalGreenOnlyColor: '00ff00',
goalFullColor: 'ffa500',
rampBalancedColor: 'ff00ff',
rampUnbalancedColor: '000000'
};
38 changes: 28 additions & 10 deletions lib/models/src/fcs/FeedingTheFutureFCS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,11 @@ export class PacketManager {
this.matchInProgress = true;

const result: FieldControlUpdatePacket = { hubs: {}, wleds: {} };
applyPatternToStrips('000000', LedStripA.ALL_STRIPS, result);
applyPatternToStrips(
this.fieldOptions.goalEmptyColor,
LedStripA.ALL_STRIPS,
result
);

this.broadcastCallback(result);
};
Expand Down Expand Up @@ -557,16 +561,24 @@ export class PacketManager {

switch (currentState) {
case NexusGoalState.Full:
applyPatternToStrips('ffa500', [strip], result);
applyPatternToStrips(this.fieldOptions.goalFullColor, [strip], result);
break;
case NexusGoalState.BlueOnly:
applyPatternToStrips('0000ff', [strip], result);
applyPatternToStrips(
this.fieldOptions.goalBlueOnlyColor,
[strip],
result
);
break;
case NexusGoalState.GreenOnly:
applyPatternToStrips('00ff00', [strip], result);
applyPatternToStrips(
this.fieldOptions.goalGreenOnlyColor,
[strip],
result
);
break;
default:
applyPatternToStrips('000000', [strip], result);
applyPatternToStrips(this.fieldOptions.goalEmptyColor, [strip], result);
}

if (
Expand All @@ -582,14 +594,18 @@ export class PacketManager {
// Set pattern
const result: FieldControlUpdatePacket = { hubs: {}, wleds: {} };
applyPatternToStrips('ffffff', [strip], result);
applySetpointToMotors(1.0, [motor], result);
applySetpointToMotors(
this.fieldOptions.foodProductionMotorSetpoint,
[motor],
result
);
broadcast(result);

setTimeout(() => {
const result: FieldControlUpdatePacket = { hubs: {}, wleds: {} };
applySetpointToMotors(0, [motor], result);
broadcast(result);
}, 5000); // TODO(jan): Use field options
}, this.fieldOptions.foodProductionMotorDurationMs);

this.matchEmitter.emit(MatchSocketEvent.MATCH_ADJUST_DETAILS_NUMBER, {
key: `${side}FoodProduced`,
Expand All @@ -600,7 +616,7 @@ export class PacketManager {
key: goal,
value: NexusGoalState.Produced
});
}, 5000) // TODO(jan): Make this time configurable
}, this.fieldOptions.foodProductionDelayMs)
);
} else if (
currentState !== NexusGoalState.Full &&
Expand Down Expand Up @@ -628,12 +644,14 @@ export class PacketManager {
setTimeout(() => {
const result: FieldControlUpdatePacket = { hubs: {}, wleds: {} };
applyPatternToStrips(
currentBalanced ? 'ff00ff' : '000000',
currentBalanced
? this.fieldOptions.rampBalancedColor
: this.fieldOptions.rampUnbalancedColor,
[LedStripA.RAMP],
result
);
broadcast(result);
}, 500) // TODO(jan): Make this configurable
}, this.fieldOptions.rampHysteresisWindowMs)
);
};

Expand Down

0 comments on commit 88a8c4d

Please sign in to comment.