1 parent
27b0386eac
commit
eb08493fdc
4 files changed
+5
-266
No files matched your search
@@ -103,11 +103,9 @@ export function Extruder2ControlPage() {
|
||||
<Label label="Target Pressure">
|
||||
<EditValue
|
||||
value={targetBar}
|
||||
defaultValue={0}
|
||||
defaultValue={200}
|
||||
unit="bar"
|
||||
title="Target Pressure"
|
||||
min={0.0}
|
||||
max={150.0}
|
||||
renderValue={(value) => roundToDecimals(value, 0)}
|
||||
onChange={screwSetTargetPressure}
|
||||
/>
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import React, { useEffect, useState } from "react";
|
||||
import { Page } from "@/components/Page";
|
||||
import { ControlCard } from "@/control/ControlCard";
|
||||
import { Label } from "@/control/Label";
|
||||
import { SelectionGroupBoolean } from "@/control/SelectionGroup";
|
||||
import React from "react";
|
||||
import { useExtruder2 } from "./useExtruder";
|
||||
import { EditValue } from "@/control/EditValue";
|
||||
import { roundToDecimals } from "@/lib/decimal";
|
||||
import { useExtruder2 } from "./useExtruder";
|
||||
|
||||
export function Extruder2SettingsPage() {
|
||||
const {
|
||||
@@ -15,38 +15,7 @@ export function Extruder2SettingsPage() {
|
||||
extruderSetPressureLimitIsEnabled,
|
||||
pressureLimitState,
|
||||
pressureLimitEnabledState,
|
||||
pressurePidSettings,
|
||||
temperaturePidSettings,
|
||||
setPressurePid,
|
||||
setTemperaturePid,
|
||||
} = useExtruder2();
|
||||
|
||||
const [showAdvanced, setShowAdvanced] = useState(false);
|
||||
|
||||
const [pid1, setPid1] = useState<{
|
||||
kp: number;
|
||||
ki: number;
|
||||
kd: number;
|
||||
} | null>(null);
|
||||
const [pid2, setPid2] = useState<{
|
||||
kp: number;
|
||||
ki: number;
|
||||
kd: number;
|
||||
} | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (!pid1 && temperaturePidSettings) {
|
||||
setPid1(temperaturePidSettings);
|
||||
}
|
||||
if (!pid2 && pressurePidSettings) {
|
||||
setPid2(pressurePidSettings);
|
||||
}
|
||||
}, [temperaturePidSettings, pressurePidSettings, pid1, pid2]);
|
||||
|
||||
if (!pid1 || !pid2) {
|
||||
return <div>Loading PID settings...</div>;
|
||||
}
|
||||
|
||||
return (
|
||||
<Page>
|
||||
<ControlCard className="bg-red" title="Inverter Settings">
|
||||
@@ -81,115 +50,7 @@ export function Extruder2SettingsPage() {
|
||||
onChange={extruderSetPressureLimitIsEnabled}
|
||||
/>
|
||||
</Label>
|
||||
<Label label="Show Advanced PID Settings">
|
||||
<SelectionGroupBoolean
|
||||
value={showAdvanced}
|
||||
optionTrue={{ children: "Show" }}
|
||||
optionFalse={{ children: "Hide" }}
|
||||
onChange={setShowAdvanced}
|
||||
/>
|
||||
</Label>
|
||||
</ControlCard>
|
||||
|
||||
{showAdvanced && (
|
||||
<>
|
||||
<ControlCard title="Temperature PID Settings">
|
||||
<Label label="Kp">
|
||||
<EditValue
|
||||
value={pid1.kp}
|
||||
defaultValue={0}
|
||||
min={0}
|
||||
max={100}
|
||||
step={0.01}
|
||||
renderValue={(v) => roundToDecimals(v, 2)}
|
||||
onChange={(v) => setPid1({ ...pid1, kp: v })}
|
||||
title="Temperature PID KP"
|
||||
/>
|
||||
</Label>
|
||||
<Label label="Ki">
|
||||
<EditValue
|
||||
value={pid1.ki}
|
||||
defaultValue={0}
|
||||
min={0}
|
||||
max={100}
|
||||
step={0.01}
|
||||
renderValue={(v) => roundToDecimals(v, 2)}
|
||||
onChange={(v) => setPid1({ ...pid1, ki: v })}
|
||||
title="Temperature PID KI"
|
||||
/>
|
||||
</Label>
|
||||
<Label label="Kd">
|
||||
<EditValue
|
||||
value={pid1.kd}
|
||||
defaultValue={0}
|
||||
min={0}
|
||||
max={100}
|
||||
step={0.01}
|
||||
renderValue={(v) => roundToDecimals(v, 2)}
|
||||
onChange={(v) => setPid1({ ...pid1, kd: v })}
|
||||
title="Temperature PID KD"
|
||||
/>
|
||||
</Label>
|
||||
|
||||
<div className="mt-2 flex justify-end">
|
||||
<button
|
||||
className="rounded bg-blue-600 px-4 py-2 text-white"
|
||||
onClick={() => setTemperaturePid(pid1)}
|
||||
>
|
||||
Save Temperature PID
|
||||
</button>
|
||||
</div>
|
||||
</ControlCard>
|
||||
|
||||
<ControlCard title="Pressure PID Settings Group 2">
|
||||
<Label label="Kp">
|
||||
<EditValue
|
||||
value={pid2.kp}
|
||||
defaultValue={0}
|
||||
min={0}
|
||||
max={100}
|
||||
step={0.01}
|
||||
renderValue={(v) => roundToDecimals(v, 2)}
|
||||
onChange={(v) => setPid2({ ...pid2, kp: v })}
|
||||
title="Pressure PID KP"
|
||||
/>
|
||||
</Label>
|
||||
<Label label="Ki">
|
||||
<EditValue
|
||||
value={pid2.ki}
|
||||
defaultValue={0}
|
||||
min={0}
|
||||
max={100}
|
||||
step={0.01}
|
||||
renderValue={(v) => roundToDecimals(v, 2)}
|
||||
onChange={(v) => setPid2({ ...pid2, ki: v })}
|
||||
title="Pressure PID KI"
|
||||
/>
|
||||
</Label>
|
||||
<Label label="Kd">
|
||||
<EditValue
|
||||
value={pid2.kd}
|
||||
defaultValue={0}
|
||||
min={0}
|
||||
max={100}
|
||||
step={0.01}
|
||||
renderValue={(v) => roundToDecimals(v, 2)}
|
||||
onChange={(v) => setPid2({ ...pid2, kd: v })}
|
||||
title="Pressure PID KD"
|
||||
/>
|
||||
</Label>
|
||||
|
||||
<div className="mt-2 flex justify-end">
|
||||
<button
|
||||
className="rounded bg-blue-600 px-4 py-2 text-white"
|
||||
onClick={() => setPressurePid(pid2)}
|
||||
>
|
||||
Save Pressure PID
|
||||
</button>
|
||||
</div>
|
||||
</ControlCard>
|
||||
</>
|
||||
)}
|
||||
</Page>
|
||||
);
|
||||
}
|
||||
@@ -33,8 +33,6 @@ export type Extruder2NamespaceStore = {
|
||||
|
||||
extruderSettingsState: ExtruderSettingsStateEvent | null;
|
||||
|
||||
pressurePidSettings: PidSettingsEvent | null;
|
||||
temperaturePidSettings: PidSettingsEvent | null;
|
||||
// Metric Events (cached for 1 hour )
|
||||
rpm: TimeSeries;
|
||||
bar: TimeSeries;
|
||||
@@ -104,22 +102,6 @@ export function extruder2MessageHandler(
|
||||
return (event: Event<any>) => {
|
||||
const eventName = event.name;
|
||||
try {
|
||||
if (eventName == "TemperaturePidSettingsEvent") {
|
||||
store.setState(
|
||||
produce(store.getState(), (state) => {
|
||||
state.temperaturePidSettings = pidSettingsEventSchema.parse(event);
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
if (eventName == "PressurePidSettingsEvent") {
|
||||
store.setState(
|
||||
produce(store.getState(), (state) => {
|
||||
state.pressurePidSettings = pidSettingsEventSchema.parse(event);
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
if (eventName == "ExtruderSettingsStateEvent") {
|
||||
store.setState(
|
||||
produce(store.getState(), (state) => {
|
||||
@@ -327,9 +309,6 @@ export const createExtruder2NamespaceStore =
|
||||
motorBarState: null,
|
||||
extruderSettingsState: null,
|
||||
|
||||
pressurePidSettings: null,
|
||||
temperaturePidSettings: null,
|
||||
|
||||
rpm,
|
||||
bar,
|
||||
|
||||
@@ -420,12 +399,6 @@ export const extruderSettingsStateEventDataSchema = z.object({
|
||||
pressure_limit_enabled: z.boolean(),
|
||||
});
|
||||
|
||||
export const pidSettingsEventDataSchema = z.object({
|
||||
ki: z.number(),
|
||||
kd: z.number(),
|
||||
kp: z.number(),
|
||||
});
|
||||
|
||||
// Event Schemas
|
||||
export const heatingTargetEventSchema = eventSchema(
|
||||
heatingTargetTemperatureDataSchema,
|
||||
@@ -453,8 +426,6 @@ export const extruderSettingsStateEventSchema = eventSchema(
|
||||
extruderSettingsStateEventDataSchema,
|
||||
);
|
||||
|
||||
export const pidSettingsEventSchema = eventSchema(pidSettingsEventDataSchema);
|
||||
|
||||
export const heatingPowerEventDataSchema = z.object({
|
||||
wattage: z.number(),
|
||||
});
|
||||
@@ -481,10 +452,8 @@ export type Heating = z.infer<typeof heatingStateDataSchema>;
|
||||
|
||||
export type MotorPressure = z.infer<typeof motorBarStateEventDataSchema>;
|
||||
export type MotorRpm = z.infer<typeof motorScrewStateEventDataSchema>;
|
||||
export type Mode = z.infer<typeof modeSchema>;
|
||||
|
||||
export type PidSettings = z.infer<typeof pidSettingsEventDataSchema>;
|
||||
export type PidSettingsEvent = z.infer<typeof pidSettingsEventSchema>;
|
||||
export type Mode = z.infer<typeof modeSchema>;
|
||||
|
||||
export type ExtruderSettingsStateEvent = z.infer<
|
||||
typeof extruderSettingsStateEventSchema
|
||||
|
||||
@@ -4,12 +4,7 @@ import { useStateOptimistic } from "@/lib/useStateOptimistic";
|
||||
import { MachineIdentificationUnique, extruder2 } from "@/machines/types";
|
||||
import { extruder2Route } from "@/routes/routes";
|
||||
import { z } from "zod";
|
||||
import {
|
||||
Heating,
|
||||
Mode,
|
||||
PidSettings,
|
||||
useExtruder2Namespace,
|
||||
} from "./extruder2Namespace";
|
||||
import { Heating, Mode, useExtruder2Namespace } from "./extruder2Namespace";
|
||||
import { useEffect, useMemo } from "react";
|
||||
import { TimeSeries } from "@/lib/timeseries";
|
||||
import { FPS_60, useThrottle } from "@/lib/useThrottle";
|
||||
@@ -48,8 +43,6 @@ export function useExtruder2() {
|
||||
const heating = useHeatingTemperature(machineIdentification);
|
||||
const heatingPower = useHeatingPower(machineIdentification);
|
||||
const settings = useSettings(machineIdentification);
|
||||
const pidSettings = usePidSettings(machineIdentification);
|
||||
|
||||
return {
|
||||
...inverter,
|
||||
...mode,
|
||||
@@ -57,7 +50,6 @@ export function useExtruder2() {
|
||||
...heating,
|
||||
...settings,
|
||||
...heatingPower,
|
||||
...pidSettings,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -331,86 +323,6 @@ export function useMotor(
|
||||
};
|
||||
}
|
||||
|
||||
export function usePidSettings(
|
||||
machine_identification_unique: MachineIdentificationUnique,
|
||||
): {
|
||||
temperaturePidSettings: PidSettings | undefined;
|
||||
pressurePidSettings: PidSettings | undefined;
|
||||
setPressurePid: (settings: PidSettings) => void;
|
||||
setTemperaturePid: (settings: PidSettings) => void;
|
||||
} {
|
||||
const { pressurePidSettings, temperaturePidSettings } = useExtruder2Namespace(
|
||||
machine_identification_unique,
|
||||
);
|
||||
|
||||
const temperaturePidSettingsState = useStateOptimistic<PidSettings>();
|
||||
const pressurePidSettingsState = useStateOptimistic<PidSettings>();
|
||||
|
||||
const SetTemperaturePidSchema = z.object({
|
||||
SetTemperaturePidSettings: z.object({
|
||||
ki: z.number(),
|
||||
kp: z.number(),
|
||||
kd: z.number(),
|
||||
}),
|
||||
});
|
||||
|
||||
const SetPressurePidSchema = z.object({
|
||||
SetPressurePidSettings: z.object({
|
||||
ki: z.number(),
|
||||
kp: z.number(),
|
||||
kd: z.number(),
|
||||
}),
|
||||
});
|
||||
|
||||
const { request: TemperaturePidSettingsRequest } = useMachineMutation(
|
||||
SetTemperaturePidSchema,
|
||||
);
|
||||
|
||||
const { request: PressurePidSettingsRequest } =
|
||||
useMachineMutation(SetPressurePidSchema);
|
||||
|
||||
const setPressurePid = async (value: PidSettings) => {
|
||||
pressurePidSettingsState.setOptimistic(value);
|
||||
PressurePidSettingsRequest({
|
||||
machine_identification_unique,
|
||||
data: { SetPressurePidSettings: value },
|
||||
})
|
||||
.then((response) => {
|
||||
if (!response.success) pressurePidSettingsState.resetToReal();
|
||||
})
|
||||
.catch(() => pressurePidSettingsState.resetToReal());
|
||||
};
|
||||
|
||||
const setTemperaturePid = async (value: PidSettings) => {
|
||||
temperaturePidSettingsState.setOptimistic(value);
|
||||
TemperaturePidSettingsRequest({
|
||||
machine_identification_unique,
|
||||
data: { SetTemperaturePidSettings: value },
|
||||
})
|
||||
.then((response) => {
|
||||
if (!response.success) temperaturePidSettingsState.resetToReal();
|
||||
})
|
||||
.catch(() => temperaturePidSettingsState.resetToReal());
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (pressurePidSettings?.data) {
|
||||
pressurePidSettingsState.setReal(pressurePidSettings?.data);
|
||||
}
|
||||
|
||||
if (temperaturePidSettings?.data) {
|
||||
temperaturePidSettingsState.setReal(temperaturePidSettings?.data);
|
||||
}
|
||||
});
|
||||
|
||||
return {
|
||||
pressurePidSettings: pressurePidSettingsState.value,
|
||||
temperaturePidSettings: temperaturePidSettingsState.value,
|
||||
setTemperaturePid,
|
||||
setPressurePid,
|
||||
};
|
||||
}
|
||||
|
||||
export function useHeatingTemperature(
|
||||
machine_identification_unique: MachineIdentificationUnique,
|
||||
): {
|
||||
@@ -580,7 +492,6 @@ export function useHeatingTemperature(
|
||||
heatingSetFrontTemp,
|
||||
heatingSetBackTemp,
|
||||
heatingSetMiddleTemp,
|
||||
|
||||
nozzleHeatingTarget: nozzleHeatingTargetState.value,
|
||||
frontHeatingTarget: frontHeatingTargetState.value,
|
||||
backHeatingTarget: backHeatingTargetState.value,
|
||||
|
||||
Reference in new issue
Block a user