diff --git a/fission/src/systems/simulation/wpilib_brain/WPILibBrain.ts b/fission/src/systems/simulation/wpilib_brain/WPILibBrain.ts index 3d9ee7d65e..57ca1a40bd 100644 --- a/fission/src/systems/simulation/wpilib_brain/WPILibBrain.ts +++ b/fission/src/systems/simulation/wpilib_brain/WPILibBrain.ts @@ -6,6 +6,9 @@ import WPILibWSWorker from "./WPILibWSWorker?worker" import { SimulationLayer } from "../SimulationSystem" import World from "@/systems/World" import Driver from "../driver/Driver" +import WheelDriver from "../driver/WheelDriver" +import HingeDriver from "../driver/HingeDriver" +import SliderDriver from "../driver/SliderDriver" const worker = new WPILibWSWorker() @@ -286,18 +289,21 @@ export class PWMGroup extends SimOutputGroup { } public Update(_deltaT: number) { - // let average = 0; - for (const port of this.ports) { - const speed = SimPWM.GetSpeed(`${port}`) ?? 0 - // average += speed; - console.log(port, speed) - } - // average /= this.ports.length - - // this.drivers.forEach(d => { - // (d as WheelDriver).targetWheelSpeed = average * 40 - // d.Update(_deltaT) - // }) + const average = + this.ports.reduce((sum, port) => { + const speed = SimPWM.GetSpeed(`${port}`) ?? 0 + console.debug(port, speed) + return sum + speed + }, 0) / this.ports.length + + this.drivers.forEach(d => { + if (d instanceof WheelDriver) { + d.targetWheelSpeed = average * 40 + } else if (d instanceof HingeDriver || d instanceof SliderDriver) { + d.targetVelocity = average * 40 + } + d.Update(_deltaT) + }) } } diff --git a/fission/src/ui/panels/DebugPanel.tsx b/fission/src/ui/panels/DebugPanel.tsx index c8494cb87e..9b2187a8b1 100644 --- a/fission/src/ui/panels/DebugPanel.tsx +++ b/fission/src/ui/panels/DebugPanel.tsx @@ -16,6 +16,7 @@ import Jolt from "@barclah/jolt-physics" import Label from "../components/Label" import { colorNameToVar } from "../ThemeContext" import { FaScrewdriverWrench } from "react-icons/fa6" +import { useModalControlContext } from "../ModalContext" const LabelStyled = styled(Label)({ fontWeight: 700, @@ -50,6 +51,7 @@ async function TestGodMode() { const DebugPanel: React.FC = ({ panelId }) => { const { openPanel } = usePanelControlContext() + const { openModal } = useModalControlContext() return ( = ({ panelId }) => { } }} /> -