From 0ecad94380d0a4eab70692654d80aa4291d5bfb3 Mon Sep 17 00:00:00 2001 From: PepperLola Date: Fri, 19 Jul 2024 12:14:36 -0700 Subject: [PATCH 01/20] preliminary ws data parsing TODO: figure out how to integrate with external config like exporter and brain configs --- fission/src/mirabuf/MirabufSceneObject.ts | 6 +- .../systems/simulation/behavior/Behavior.ts | 4 +- .../{ => synthesis}/ArcadeDriveBehavior.ts | 6 +- .../{ => synthesis}/GenericArmBehavior.ts | 6 +- .../GenericElevatorBehavior.ts | 6 +- .../wpilib/WPILibArcadeDriveBehavior.ts | 33 ++++ .../behavior/wpilib/WPILibArmBehavior.ts | 41 +++++ .../behavior/wpilib/WPILibElevatorBehavior.ts | 41 +++++ .../systems/simulation/driver/WheelDriver.ts | 15 +- .../synthesis_brain/SynthesisBrain.ts | 6 +- .../simulation/wpilib_brain/WPILibBrain.ts | 157 +++++++++++++++++- simulation/SyntheSimJava/gradlew | 0 simulation/samples/JavaSample/gradlew | 0 13 files changed, 295 insertions(+), 26 deletions(-) rename fission/src/systems/simulation/behavior/{ => synthesis}/ArcadeDriveBehavior.ts (88%) rename fission/src/systems/simulation/behavior/{ => synthesis}/GenericArmBehavior.ts (84%) rename fission/src/systems/simulation/behavior/{ => synthesis}/GenericElevatorBehavior.ts (84%) create mode 100644 fission/src/systems/simulation/behavior/wpilib/WPILibArcadeDriveBehavior.ts create mode 100644 fission/src/systems/simulation/behavior/wpilib/WPILibArmBehavior.ts create mode 100644 fission/src/systems/simulation/behavior/wpilib/WPILibElevatorBehavior.ts mode change 100644 => 100755 simulation/SyntheSimJava/gradlew mode change 100644 => 100755 simulation/samples/JavaSample/gradlew diff --git a/fission/src/mirabuf/MirabufSceneObject.ts b/fission/src/mirabuf/MirabufSceneObject.ts index cb31941043..a17eefb4bd 100644 --- a/fission/src/mirabuf/MirabufSceneObject.ts +++ b/fission/src/mirabuf/MirabufSceneObject.ts @@ -17,6 +17,8 @@ import PreferencesSystem from "@/systems/preferences/PreferencesSystem" import { MiraType } from "./MirabufLoader" import IntakeSensorSceneObject from "./IntakeSensorSceneObject" import EjectableSceneObject from "./EjectableSceneObject" +import Brain from "@/systems/simulation/Brain" +import WPILibBrain from "@/systems/simulation/wpilib_brain/WPILibBrain" const DEBUG_BODIES = false @@ -29,7 +31,7 @@ class MirabufSceneObject extends SceneObject { private _assemblyName: string private _mirabufInstance: MirabufInstance private _mechanism: Mechanism - private _brain: SynthesisBrain | undefined + private _brain: Brain | undefined private _debugBodies: Map | null private _physicsLayerReserve: LayerReserve | undefined @@ -126,7 +128,7 @@ class MirabufSceneObject extends SceneObject { // Simulation World.SimulationSystem.RegisterMechanism(this._mechanism) const simLayer = World.SimulationSystem.GetSimulationLayer(this._mechanism)! - this._brain = new SynthesisBrain(this._mechanism, this._assemblyName) + this._brain = new WPILibBrain(this._mechanism) simLayer.SetBrain(this._brain) // Intake diff --git a/fission/src/systems/simulation/behavior/Behavior.ts b/fission/src/systems/simulation/behavior/Behavior.ts index 2dd0fcb190..9b1f6149ff 100644 --- a/fission/src/systems/simulation/behavior/Behavior.ts +++ b/fission/src/systems/simulation/behavior/Behavior.ts @@ -1,5 +1,5 @@ -import Driver from "../driver/Driver" -import Stimulus from "../stimulus/Stimulus" +import Driver from "@/systems/simulation/driver/Driver" +import Stimulus from "@/systems/simulation/stimulus/Stimulus" abstract class Behavior { private _drivers: Driver[] diff --git a/fission/src/systems/simulation/behavior/ArcadeDriveBehavior.ts b/fission/src/systems/simulation/behavior/synthesis/ArcadeDriveBehavior.ts similarity index 88% rename from fission/src/systems/simulation/behavior/ArcadeDriveBehavior.ts rename to fission/src/systems/simulation/behavior/synthesis/ArcadeDriveBehavior.ts index 374f5684d9..60794e564f 100644 --- a/fission/src/systems/simulation/behavior/ArcadeDriveBehavior.ts +++ b/fission/src/systems/simulation/behavior/synthesis/ArcadeDriveBehavior.ts @@ -1,6 +1,6 @@ -import WheelDriver from "../driver/WheelDriver" -import WheelRotationStimulus from "../stimulus/WheelStimulus" -import Behavior from "./Behavior" +import WheelDriver from "@/systems/simulation/driver/WheelDriver" +import WheelRotationStimulus from "@/systems/simulation/stimulus/WheelStimulus" +import Behavior from "@/systems/simulation/behavior/Behavior" import InputSystem from "@/systems/input/InputSystem" class ArcadeDriveBehavior extends Behavior { diff --git a/fission/src/systems/simulation/behavior/GenericArmBehavior.ts b/fission/src/systems/simulation/behavior/synthesis/GenericArmBehavior.ts similarity index 84% rename from fission/src/systems/simulation/behavior/GenericArmBehavior.ts rename to fission/src/systems/simulation/behavior/synthesis/GenericArmBehavior.ts index fc9e9bbd5d..a193ba6fcf 100644 --- a/fission/src/systems/simulation/behavior/GenericArmBehavior.ts +++ b/fission/src/systems/simulation/behavior/synthesis/GenericArmBehavior.ts @@ -1,6 +1,6 @@ -import HingeDriver from "../driver/HingeDriver" -import HingeStimulus from "../stimulus/HingeStimulus" -import Behavior from "./Behavior" +import HingeDriver from "@/systems/simulation/driver/HingeDriver" +import HingeStimulus from "@/systems/simulation/stimulus/HingeStimulus" +import Behavior from "@/systems/simulation/behavior/Behavior" import InputSystem from "@/systems/input/InputSystem" class GenericArmBehavior extends Behavior { diff --git a/fission/src/systems/simulation/behavior/GenericElevatorBehavior.ts b/fission/src/systems/simulation/behavior/synthesis/GenericElevatorBehavior.ts similarity index 84% rename from fission/src/systems/simulation/behavior/GenericElevatorBehavior.ts rename to fission/src/systems/simulation/behavior/synthesis/GenericElevatorBehavior.ts index f1c01bde56..fe5a3b03cc 100644 --- a/fission/src/systems/simulation/behavior/GenericElevatorBehavior.ts +++ b/fission/src/systems/simulation/behavior/synthesis/GenericElevatorBehavior.ts @@ -1,6 +1,6 @@ -import SliderDriver from "../driver/SliderDriver" -import SliderStimulus from "../stimulus/SliderStimulus" -import Behavior from "./Behavior" +import SliderDriver from "@/systems/simulation/driver/SliderDriver" +import SliderStimulus from "@/systems/simulation/stimulus/SliderStimulus" +import Behavior from "@/systems/simulation/behavior/Behavior" import InputSystem from "@/systems/input/InputSystem" class GenericElevatorBehavior extends Behavior { diff --git a/fission/src/systems/simulation/behavior/wpilib/WPILibArcadeDriveBehavior.ts b/fission/src/systems/simulation/behavior/wpilib/WPILibArcadeDriveBehavior.ts new file mode 100644 index 0000000000..023c9c353b --- /dev/null +++ b/fission/src/systems/simulation/behavior/wpilib/WPILibArcadeDriveBehavior.ts @@ -0,0 +1,33 @@ +import WheelDriver from "@/systems/simulation/driver/WheelDriver" +import WheelRotationStimulus from "@/systems/simulation/stimulus/WheelStimulus" +import Behavior from "@/systems/simulation/behavior/Behavior" +import WPILibBrain, { SimCAN, SimGeneric, simMap } from "../../wpilib_brain/WPILibBrain" + +class WPILibArcadeDriveBehavior extends Behavior { + private leftWheels: WheelDriver[] + private rightWheels: WheelDriver[] + + private _driveSpeed = 30 + private _turnSpeed = 30 + + constructor( + leftWheels: WheelDriver[], + rightWheels: WheelDriver[], + leftStimuli: WheelRotationStimulus[], + rightStimuli: WheelRotationStimulus[], + ) { + super(leftWheels.concat(rightWheels), leftStimuli.concat(rightStimuli)) + + this.leftWheels = leftWheels + this.rightWheels = rightWheels + } + + public Update(_: number): void { + // TODO: better checks for device field existence + // TODO: differentiate between fields for CAN, PWM ( wheel.targetWheelSpeed = SimGeneric.Get(wheel.deviceType!, wheel.device!, " wheel.targetWheelSpeed = SimGeneric.Get(wheel.deviceType!, wheel.device!, "> = new Map( + Object.entries({ + "CANMotor": { + "CANSparkMax[0]": { + " [key as SimType, new Map(Object.entries(value))]) +) + export const simMap = new Map>() export class SimGeneric { - private constructor() {} + private constructor() { } public static Get(simType: SimType, device: string, field: string, defaultValue?: T): T | undefined { const fieldType = GetFieldType(field) @@ -101,7 +137,7 @@ export class SimGeneric { } export class SimPWM { - private constructor() {} + private constructor() { } public static GetSpeed(device: string): number | undefined { return SimGeneric.Get("PWM", device, PWM_SPEED, 0.0) @@ -112,8 +148,30 @@ export class SimPWM { } } +export class SimCAN { + private constructor() { } + + public static GetDeviceWithID(id: number): any { + const id_exp = /.*\[(\d+)\]/g; + const entries = [...simMap.entries()].filter(([simType, _data]) => simType.startsWith("CAN")) + entries.forEach(([_simType, data]) => { + [...data.keys()].forEach(key => { + let result; + if ((result = [...key.matchAll(id_exp)]) != undefined) { + if (result.length > 0 && result[0].length > 1) { + const parsed_id = parseInt(result[0][1]); + if (parsed_id == id) + return data.get(key) + } + } + }) + }) + return undefined + } +} + export class SimCANMotor { - private constructor() {} + private constructor() { } public static GetDutyCycle(device: string): number | undefined { return SimGeneric.Get("CANMotor", device, CANMOTOR_DUTY_CYCLE, 0.0) @@ -125,7 +183,7 @@ export class SimCANMotor { } export class SimCANEncoder { - private constructor() {} + private constructor() { } public static SetRawInputPosition(device: string, rawInputPosition: number): boolean { return SimGeneric.Set("CANEncoder", device, CANENCODER_RAW_INPUT_POSITION, rawInputPosition) @@ -193,17 +251,42 @@ function UpdateSimMap(type: SimType, device: string, updateData: any) { currentData = {} typeMap.set(device, currentData) } - Object.entries(updateData).forEach(kvp => (currentData[kvp[0]] = kvp[1])) + Object.entries(updateData).forEach(([key, value]) => (currentData[key] = value)) window.dispatchEvent(new SimMapUpdateEvent(false)) } class WPILibBrain extends Brain { - constructor(mech: Mechanism) { - super(mech) + private _behaviors: Behavior[] = [] + private _simLayer: SimulationLayer + + private _driverDevices: Map> = new Map() + + public static robotsSpawned: string[] = [] + + private static _currentRobotIndex: number = 0 + + constructor(mechanism: Mechanism) { + super(mechanism) + + this._simLayer = World.SimulationSystem.GetSimulationLayer(mechanism)! + + if (!this._simLayer) { + console.warn("SimulationLayer is undefined") + return + } + + // if (mechanism.controllable) { + // WPILibBrain.robotsSpawned.push(this.getNumberedAssemblyName()) + // } + + // WPILibBrain._currentRobotIndex++ + this.configureArcadeDriveBehavior() } - public Update(_: number): void {} + public Update(deltaT: number): void { + this._behaviors.forEach(b => b.Update(deltaT)) + } public Enable(): void { worker.postMessage({ command: "connect" }) @@ -212,6 +295,64 @@ class WPILibBrain extends Brain { public Disable(): void { worker.postMessage({ command: "disconnect" }) } + + public configureArcadeDriveBehavior() { + const wheelDrivers: WheelDriver[] = this._simLayer.drivers.filter( + driver => driver instanceof WheelDriver + ) as WheelDriver[] + wheelDrivers.forEach((wheel, idx) => { + wheel.deviceType = 'SimDevice' + wheel.device = `SYN CANSparkMax[${idx}]` + }) + const wheelStimuli: WheelRotationStimulus[] = this._simLayer.stimuli.filter( + stimulus => stimulus instanceof WheelRotationStimulus + ) as WheelRotationStimulus[] + + // Two body constraints are part of wheels and are used to determine which way a wheel is facing + const fixedConstraints: Jolt.TwoBodyConstraint[] = this._mechanism.constraints + .filter(mechConstraint => mechConstraint.constraint instanceof JOLT.TwoBodyConstraint) + .map(mechConstraint => mechConstraint.constraint as Jolt.TwoBodyConstraint) + + const leftWheels: WheelDriver[] = [] + const leftStimuli: WheelRotationStimulus[] = [] + + const rightWheels: WheelDriver[] = [] + const rightStimuli: WheelRotationStimulus[] = [] + + // Determines which wheels and stimuli belong to which side of the robot + for (let i = 0; i < wheelDrivers.length; i++) { + const wheelPos = fixedConstraints[i].GetConstraintToBody1Matrix().GetTranslation() + + const robotCOM = World.PhysicsSystem.GetBody( + this._mechanism.constraints[0].childBody + ).GetCenterOfMassPosition() as Jolt.Vec3 + const rightVector = new JOLT.Vec3(1, 0, 0) + + const dotProduct = rightVector.Dot(wheelPos.Sub(robotCOM)) + + if (dotProduct < 0) { + rightWheels.push(wheelDrivers[i]) + rightStimuli.push(wheelStimuli[i]) + } else { + leftWheels.push(wheelDrivers[i]) + leftStimuli.push(wheelStimuli[i]) + } + } + + // TODO: all this is very temporary + this._driverDevices.set("CANMotor", new Map()); + leftWheels.forEach(wheel => this._driverDevices.get(wheel.deviceType!)!.set(wheel.device!, wheel)) + rightWheels.forEach(wheel => this._driverDevices.get(wheel.deviceType!)!.set(wheel.device!, wheel)) + + this._behaviors.push( + new WPILibArcadeDriveBehavior( + leftWheels, + rightWheels, + leftStimuli, + rightStimuli + ) + ) + } } export class SimMapUpdateEvent extends Event { diff --git a/simulation/SyntheSimJava/gradlew b/simulation/SyntheSimJava/gradlew old mode 100644 new mode 100755 diff --git a/simulation/samples/JavaSample/gradlew b/simulation/samples/JavaSample/gradlew old mode 100644 new mode 100755 From c2a1807ad0ef9413a76775a5fa21a109b75f0d5a Mon Sep 17 00:00:00 2001 From: PepperLola Date: Mon, 22 Jul 2024 17:24:56 -0700 Subject: [PATCH 02/20] added SimDevice class and RCConfigPwmGroupModal now selects from drivers --- .../simulation/wpilib_brain/WPILibBrain.ts | 142 ++++++++++-------- fission/src/ui/components/Modal.tsx | 4 +- .../rio-config/RCConfigPwmGroupModal.tsx | 35 +++-- 3 files changed, 109 insertions(+), 72 deletions(-) diff --git a/fission/src/systems/simulation/wpilib_brain/WPILibBrain.ts b/fission/src/systems/simulation/wpilib_brain/WPILibBrain.ts index 65f7abdcd0..7503666a19 100644 --- a/fission/src/systems/simulation/wpilib_brain/WPILibBrain.ts +++ b/fission/src/systems/simulation/wpilib_brain/WPILibBrain.ts @@ -13,6 +13,7 @@ import Jolt from "@barclah/jolt-physics" import JOLT from "@/util/loading/JoltSyncLoader" import ArcadeDriveBehavior from "../behavior/synthesis/ArcadeDriveBehavior" import WPILibArcadeDriveBehavior from "../behavior/wpilib/WPILibArcadeDriveBehavior" +import { mirabuf } from "@/proto/mirabuf" const worker = new WPILibWSWorker() @@ -260,7 +261,9 @@ class WPILibBrain extends Brain { private _behaviors: Behavior[] = [] private _simLayer: SimulationLayer - private _driverDevices: Map> = new Map() + private _simDevices: SimDevice[] = [] + + // private _driverDevices: Map> = new Map() public static robotsSpawned: string[] = [] @@ -281,11 +284,12 @@ class WPILibBrain extends Brain { // } // WPILibBrain._currentRobotIndex++ - this.configureArcadeDriveBehavior() + // this.configureArcadeDriveBehavior() } public Update(deltaT: number): void { - this._behaviors.forEach(b => b.Update(deltaT)) + // this._behaviors.forEach(b => b.Update(deltaT)) + this._simDevices.forEach(d => d.Update(deltaT)) } public Enable(): void { @@ -296,63 +300,63 @@ class WPILibBrain extends Brain { worker.postMessage({ command: "disconnect" }) } - public configureArcadeDriveBehavior() { - const wheelDrivers: WheelDriver[] = this._simLayer.drivers.filter( - driver => driver instanceof WheelDriver - ) as WheelDriver[] - wheelDrivers.forEach((wheel, idx) => { - wheel.deviceType = 'SimDevice' - wheel.device = `SYN CANSparkMax[${idx}]` - }) - const wheelStimuli: WheelRotationStimulus[] = this._simLayer.stimuli.filter( - stimulus => stimulus instanceof WheelRotationStimulus - ) as WheelRotationStimulus[] - - // Two body constraints are part of wheels and are used to determine which way a wheel is facing - const fixedConstraints: Jolt.TwoBodyConstraint[] = this._mechanism.constraints - .filter(mechConstraint => mechConstraint.constraint instanceof JOLT.TwoBodyConstraint) - .map(mechConstraint => mechConstraint.constraint as Jolt.TwoBodyConstraint) - - const leftWheels: WheelDriver[] = [] - const leftStimuli: WheelRotationStimulus[] = [] - - const rightWheels: WheelDriver[] = [] - const rightStimuli: WheelRotationStimulus[] = [] - - // Determines which wheels and stimuli belong to which side of the robot - for (let i = 0; i < wheelDrivers.length; i++) { - const wheelPos = fixedConstraints[i].GetConstraintToBody1Matrix().GetTranslation() - - const robotCOM = World.PhysicsSystem.GetBody( - this._mechanism.constraints[0].childBody - ).GetCenterOfMassPosition() as Jolt.Vec3 - const rightVector = new JOLT.Vec3(1, 0, 0) - - const dotProduct = rightVector.Dot(wheelPos.Sub(robotCOM)) - - if (dotProduct < 0) { - rightWheels.push(wheelDrivers[i]) - rightStimuli.push(wheelStimuli[i]) - } else { - leftWheels.push(wheelDrivers[i]) - leftStimuli.push(wheelStimuli[i]) - } - } - - // TODO: all this is very temporary - this._driverDevices.set("CANMotor", new Map()); - leftWheels.forEach(wheel => this._driverDevices.get(wheel.deviceType!)!.set(wheel.device!, wheel)) - rightWheels.forEach(wheel => this._driverDevices.get(wheel.deviceType!)!.set(wheel.device!, wheel)) - - this._behaviors.push( - new WPILibArcadeDriveBehavior( - leftWheels, - rightWheels, - leftStimuli, - rightStimuli - ) - ) - } + // public configureArcadeDriveBehavior() { + // const wheelDrivers: WheelDriver[] = this._simLayer.drivers.filter( + // driver => driver instanceof WheelDriver + // ) as WheelDriver[] + // wheelDrivers.forEach((wheel, idx) => { + // wheel.deviceType = 'SimDevice' + // wheel.device = `SYN CANSparkMax[${idx}]` + // }) + // const wheelStimuli: WheelRotationStimulus[] = this._simLayer.stimuli.filter( + // stimulus => stimulus instanceof WheelRotationStimulus + // ) as WheelRotationStimulus[] + + // // Two body constraints are part of wheels and are used to determine which way a wheel is facing + // const fixedConstraints: Jolt.TwoBodyConstraint[] = this._mechanism.constraints + // .filter(mechConstraint => mechConstraint.constraint instanceof JOLT.TwoBodyConstraint) + // .map(mechConstraint => mechConstraint.constraint as Jolt.TwoBodyConstraint) + + // const leftWheels: WheelDriver[] = [] + // const leftStimuli: WheelRotationStimulus[] = [] + + // const rightWheels: WheelDriver[] = [] + // const rightStimuli: WheelRotationStimulus[] = [] + + // // Determines which wheels and stimuli belong to which side of the robot + // for (let i = 0; i < wheelDrivers.length; i++) { + // const wheelPos = fixedConstraints[i].GetConstraintToBody1Matrix().GetTranslation() + + // const robotCOM = World.PhysicsSystem.GetBody( + // this._mechanism.constraints[0].childBody + // ).GetCenterOfMassPosition() as Jolt.Vec3 + // const rightVector = new JOLT.Vec3(1, 0, 0) + + // const dotProduct = rightVector.Dot(wheelPos.Sub(robotCOM)) + + // if (dotProduct < 0) { + // rightWheels.push(wheelDrivers[i]) + // rightStimuli.push(wheelStimuli[i]) + // } else { + // leftWheels.push(wheelDrivers[i]) + // leftStimuli.push(wheelStimuli[i]) + // } + // } + + // // TODO: all this is very temporary + // this._driverDevices.set("CANMotor", new Map()); + // leftWheels.forEach(wheel => this._driverDevices.get(wheel.deviceType!)!.set(wheel.device!, wheel)) + // rightWheels.forEach(wheel => this._driverDevices.get(wheel.deviceType!)!.set(wheel.device!, wheel)) + + // this._behaviors.push( + // new WPILibArcadeDriveBehavior( + // leftWheels, + // rightWheels, + // leftStimuli, + // rightStimuli + // ) + // ) + // } } export class SimMapUpdateEvent extends Event { @@ -372,3 +376,21 @@ export class SimMapUpdateEvent extends Event { } export default WPILibBrain + +export class SimDevice { + public name: string + public ports: number[] + public drivers: Driver[] + public type: SimType + + public constructor(name: string, ports: number[], drivers: Driver[], type: SimType) { + this.name = name + this.ports = ports + this.drivers = drivers + this.type = type + } + + public Update(deltaT: number) { + console.log('SimDevice update...') + } +} diff --git a/fission/src/ui/components/Modal.tsx b/fission/src/ui/components/Modal.tsx index 04a9577a25..97152494b2 100644 --- a/fission/src/ui/components/Modal.tsx +++ b/fission/src/ui/components/Modal.tsx @@ -69,8 +69,8 @@ const Modal: React.FC = ({
{children}
diff --git a/fission/src/ui/modals/configuring/rio-config/RCConfigPwmGroupModal.tsx b/fission/src/ui/modals/configuring/rio-config/RCConfigPwmGroupModal.tsx index cad2c099fa..79f20c0c47 100644 --- a/fission/src/ui/modals/configuring/rio-config/RCConfigPwmGroupModal.tsx +++ b/fission/src/ui/modals/configuring/rio-config/RCConfigPwmGroupModal.tsx @@ -8,15 +8,30 @@ import Checkbox from "@/components/Checkbox" import Container from "@/components/Container" import Label, { LabelSize } from "@/components/Label" import Input from "@/components/Input" +import WPILibBrain from "@/systems/simulation/wpilib_brain/WPILibBrain" +import World from "@/systems/World" +import MirabufSceneObject from "@/mirabuf/MirabufSceneObject" +import Driver from "@/systems/simulation/driver/Driver" const RCConfigPwmGroupModal: React.FC = ({ modalId }) => { const { openModal } = useModalControlContext() const [name, setName] = useState("") const [checkedPorts, setCheckedPorts] = useState([]) - const [checkedSignals, setCheckedSignals] = useState([]) + const [checkedDrivers, setCheckedDrivers] = useState([]) const numPorts = 8 - const signals = ["Rev0 (uuid)", "Rev1 (uuid)", "Rev2 (uuid)", "Rev3 (uuid)"] + let drivers: Driver[] = [] + + const miraObjs = [...World.SceneRenderer.sceneObjects.entries()].filter( + x => x[1] instanceof MirabufSceneObject + ) + console.log(`Number of mirabuf scene objects: ${miraObjs.length}`) + if (miraObjs.length > 0) { + const mechanism = (miraObjs[0][1] as MirabufSceneObject).mechanism + const simLayer = World.SimulationSystem.GetSimulationLayer(mechanism) + drivers = simLayer?.drivers ?? [] + simLayer?.SetBrain(new WPILibBrain(mechanism)) + } return ( = ({ modalId }) => { acceptName="Done" onAccept={() => { // no eslint complain - console.log(name, checkedPorts, checkedSignals) + console.log(name, checkedPorts, checkedDrivers) }} onCancel={() => { openModal("roborio") @@ -57,16 +72,16 @@ const RCConfigPwmGroupModal: React.FC = ({ modalId }) => { - {signals.map(p => ( + {drivers.map((driver, idx) => ( { - if (checked && !checkedSignals.includes(p)) { - setCheckedSignals([...checkedSignals, p]) - } else if (!checked && checkedSignals.includes(p)) { - setCheckedSignals(checkedSignals.filter(a => a != p)) + if (checked && !checkedDrivers.includes(driver)) { + setCheckedDrivers([...checkedDrivers, driver]) + } else if (!checked && checkedDrivers.includes(driver)) { + setCheckedDrivers(checkedDrivers.filter(a => a != driver)) } }} /> From e20204a78f548c8ebb7264d178efc18d78867f5a Mon Sep 17 00:00:00 2001 From: PepperLola Date: Tue, 23 Jul 2024 14:51:04 -0700 Subject: [PATCH 03/20] working mapping for pwm, can still needs work --- fission/src/Synthesis.tsx | 6 +- .../simulation/wpilib_brain/WPILibBrain.ts | 117 +++++++----------- .../rio-config/RCConfigCANGroupModal.tsx | 108 ++++++++++++++++ .../rio-config/RCConfigPwmGroupModal.tsx | 14 ++- .../rio-config/RCCreateDeviceModal.tsx | 7 +- 5 files changed, 174 insertions(+), 78 deletions(-) create mode 100644 fission/src/ui/modals/configuring/rio-config/RCConfigCANGroupModal.tsx diff --git a/fission/src/Synthesis.tsx b/fission/src/Synthesis.tsx index 7879c4d45e..fc2a2ff9d2 100644 --- a/fission/src/Synthesis.tsx +++ b/fission/src/Synthesis.tsx @@ -34,7 +34,7 @@ import PracticeSettingsModal from "@/modals/configuring/PracticeSettingsModal" import RoboRIOModal from "@/modals/configuring/RoboRIOModal" import SettingsModal from "@/modals/configuring/SettingsModal" import RCConfigEncoderModal from "@/modals/configuring/rio-config/RCConfigEncoderModal" -import RCConfigPwmGroupModal from "@/modals/configuring/rio-config/RCConfigPwmGroupModal" +import RCConfigPWMGroupModal from "@/modals/configuring/rio-config/RCConfigPWMGroupModal" import RCCreateDeviceModal from "@/modals/configuring/rio-config/RCCreateDeviceModal" import DeleteAllThemesModal from "@/modals/configuring/theme-editor/DeleteAllThemesModal" import DeleteThemeModal from "@/modals/configuring/theme-editor/DeleteThemeModal" @@ -63,6 +63,7 @@ import ResetAllInputsModal from "./ui/modals/configuring/ResetAllInputsModal.tsx import WPILibWSWorker from "@/systems/simulation/wpilib_brain/WPILibWSWorker.ts?worker" import WSViewPanel from "./ui/panels/WSViewPanel.tsx" import Lazy from "./util/Lazy.ts" +import RCConfigCANGroupModal from "./ui/modals/configuring/rio-config/RCConfigCANGroupModal.tsx" const DEFAULT_MIRA_PATH = "/api/mira/Robots/Team 2471 (2018)_v7.mira" @@ -217,7 +218,8 @@ const initialModals = [ , , , - , + , + , , , , diff --git a/fission/src/systems/simulation/wpilib_brain/WPILibBrain.ts b/fission/src/systems/simulation/wpilib_brain/WPILibBrain.ts index 7503666a19..c4839662b5 100644 --- a/fission/src/systems/simulation/wpilib_brain/WPILibBrain.ts +++ b/fission/src/systems/simulation/wpilib_brain/WPILibBrain.ts @@ -152,21 +152,22 @@ export class SimPWM { export class SimCAN { private constructor() { } - public static GetDeviceWithID(id: number): any { + public static GetDeviceWithID(id: number, type: SimType): any { const id_exp = /.*\[(\d+)\]/g; - const entries = [...simMap.entries()].filter(([simType, _data]) => simType.startsWith("CAN")) - entries.forEach(([_simType, data]) => { - [...data.keys()].forEach(key => { + const entries = [...simMap.entries()].filter(([simType, _data]) => simType == type || simType == "SimDevice") + for (const [_simType, data] of entries) { + for (const key of data.keys()) { let result; if ((result = [...key.matchAll(id_exp)]) != undefined) { if (result.length > 0 && result[0].length > 1) { const parsed_id = parseInt(result[0][1]); - if (parsed_id == id) + if (parsed_id == id) { return data.get(key) + } } } - }) - }) + } + } return undefined } } @@ -261,9 +262,7 @@ class WPILibBrain extends Brain { private _behaviors: Behavior[] = [] private _simLayer: SimulationLayer - private _simDevices: SimDevice[] = [] - - // private _driverDevices: Map> = new Map() + private _simDevices: SimOutputGroup[] = [] public static robotsSpawned: string[] = [] @@ -287,6 +286,10 @@ class WPILibBrain extends Brain { // this.configureArcadeDriveBehavior() } + public addSimOutputGroup(device: SimOutputGroup) { + this._simDevices.push(device) + } + public Update(deltaT: number): void { // this._behaviors.forEach(b => b.Update(deltaT)) this._simDevices.forEach(d => d.Update(deltaT)) @@ -299,64 +302,6 @@ class WPILibBrain extends Brain { public Disable(): void { worker.postMessage({ command: "disconnect" }) } - - // public configureArcadeDriveBehavior() { - // const wheelDrivers: WheelDriver[] = this._simLayer.drivers.filter( - // driver => driver instanceof WheelDriver - // ) as WheelDriver[] - // wheelDrivers.forEach((wheel, idx) => { - // wheel.deviceType = 'SimDevice' - // wheel.device = `SYN CANSparkMax[${idx}]` - // }) - // const wheelStimuli: WheelRotationStimulus[] = this._simLayer.stimuli.filter( - // stimulus => stimulus instanceof WheelRotationStimulus - // ) as WheelRotationStimulus[] - - // // Two body constraints are part of wheels and are used to determine which way a wheel is facing - // const fixedConstraints: Jolt.TwoBodyConstraint[] = this._mechanism.constraints - // .filter(mechConstraint => mechConstraint.constraint instanceof JOLT.TwoBodyConstraint) - // .map(mechConstraint => mechConstraint.constraint as Jolt.TwoBodyConstraint) - - // const leftWheels: WheelDriver[] = [] - // const leftStimuli: WheelRotationStimulus[] = [] - - // const rightWheels: WheelDriver[] = [] - // const rightStimuli: WheelRotationStimulus[] = [] - - // // Determines which wheels and stimuli belong to which side of the robot - // for (let i = 0; i < wheelDrivers.length; i++) { - // const wheelPos = fixedConstraints[i].GetConstraintToBody1Matrix().GetTranslation() - - // const robotCOM = World.PhysicsSystem.GetBody( - // this._mechanism.constraints[0].childBody - // ).GetCenterOfMassPosition() as Jolt.Vec3 - // const rightVector = new JOLT.Vec3(1, 0, 0) - - // const dotProduct = rightVector.Dot(wheelPos.Sub(robotCOM)) - - // if (dotProduct < 0) { - // rightWheels.push(wheelDrivers[i]) - // rightStimuli.push(wheelStimuli[i]) - // } else { - // leftWheels.push(wheelDrivers[i]) - // leftStimuli.push(wheelStimuli[i]) - // } - // } - - // // TODO: all this is very temporary - // this._driverDevices.set("CANMotor", new Map()); - // leftWheels.forEach(wheel => this._driverDevices.get(wheel.deviceType!)!.set(wheel.device!, wheel)) - // rightWheels.forEach(wheel => this._driverDevices.get(wheel.deviceType!)!.set(wheel.device!, wheel)) - - // this._behaviors.push( - // new WPILibArcadeDriveBehavior( - // leftWheels, - // rightWheels, - // leftStimuli, - // rightStimuli - // ) - // ) - // } } export class SimMapUpdateEvent extends Event { @@ -377,7 +322,7 @@ export class SimMapUpdateEvent extends Event { export default WPILibBrain -export class SimDevice { +abstract class SimOutputGroup { public name: string public ports: number[] public drivers: Driver[] @@ -390,7 +335,39 @@ export class SimDevice { this.type = type } + public abstract Update(deltaT: number): void +} + +export class PWMGroup extends SimOutputGroup { + public constructor(name: string, ports: number[], drivers: Driver[]) { + super(name, ports, drivers, "PWM") + } + public Update(deltaT: number) { - console.log('SimDevice update...') + // 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) + // }) + } +} + +export class CANGroup extends SimOutputGroup { + public constructor(name: string, ports: number[], drivers: Driver[]) { + super(name, ports, drivers, "CANMotor") + } + + public Update(_deltaT: number) { + for (const port of this.ports) { + const device = SimCAN.GetDeviceWithID(port, this.type); + console.log(port, device) + } } } diff --git a/fission/src/ui/modals/configuring/rio-config/RCConfigCANGroupModal.tsx b/fission/src/ui/modals/configuring/rio-config/RCConfigCANGroupModal.tsx new file mode 100644 index 0000000000..e01e43051b --- /dev/null +++ b/fission/src/ui/modals/configuring/rio-config/RCConfigCANGroupModal.tsx @@ -0,0 +1,108 @@ +import React, { useState } from "react" +import Modal, { ModalPropsImpl } from "@/components/Modal" +import { useModalControlContext } from "@/ui/ModalContext" +import { FaPlus } from "react-icons/fa6" +import ScrollView from "@/components/ScrollView" +import Stack, { StackDirection } from "@/components/Stack" +import Checkbox from "@/components/Checkbox" +import Container from "@/components/Container" +import Label, { LabelSize } from "@/components/Label" +import Input from "@/components/Input" +import WPILibBrain, { CANGroup, simMap } from "@/systems/simulation/wpilib_brain/WPILibBrain" +import World from "@/systems/World" +import MirabufSceneObject from "@/mirabuf/MirabufSceneObject" +import Driver from "@/systems/simulation/driver/Driver" + +const RCConfigCANGroupModal: React.FC = ({ modalId }) => { + const { openModal } = useModalControlContext() + const [name, setName] = useState("") + const [checkedPorts, setCheckedPorts] = useState([]) + const [checkedDrivers, setCheckedDrivers] = useState([]) + + const numPorts = 8 + let drivers: Driver[] = [] + let simLayer; + let brain: WPILibBrain; + + const miraObjs = [...World.SceneRenderer.sceneObjects.entries()].filter( + x => x[1] instanceof MirabufSceneObject + ) + console.log(`Number of mirabuf scene objects: ${miraObjs.length}`) + if (miraObjs.length > 0) { + const mechanism = (miraObjs[0][1] as MirabufSceneObject).mechanism + simLayer = World.SimulationSystem.GetSimulationLayer(mechanism) + drivers = simLayer?.drivers ?? [] + brain = new WPILibBrain(mechanism) + simLayer?.SetBrain(brain) + } + + return ( + } + modalId={modalId} + acceptName="Done" + onAccept={() => { + // no eslint complain + brain.addSimOutputGroup(new CANGroup(name, checkedPorts, checkedDrivers)) + console.log(name, checkedPorts, checkedDrivers) + const replacer = (key, value) => { + if (value instanceof Map) { + return Object.fromEntries(value) + } else { + return value + } + } + console.log(JSON.stringify(simMap, replacer)) + }} + onCancel={() => { + openModal("roborio") + }} + > + + + + + + + {[...Array(numPorts).keys()].map(p => ( + { + if (checked && !checkedPorts.includes(p)) { + setCheckedPorts([...checkedPorts, p]) + } else if (!checked && checkedPorts.includes(p)) { + setCheckedPorts(checkedPorts.filter(a => a != p)) + } + }} + /> + ))} + + + + + + {drivers.map((driver, idx) => ( + { + if (checked && !checkedDrivers.includes(driver)) { + setCheckedDrivers([...checkedDrivers, driver]) + } else if (!checked && checkedDrivers.includes(driver)) { + setCheckedDrivers(checkedDrivers.filter(a => a != driver)) + } + }} + /> + ))} + + + + + ) +} + +export default RCConfigCANGroupModal diff --git a/fission/src/ui/modals/configuring/rio-config/RCConfigPwmGroupModal.tsx b/fission/src/ui/modals/configuring/rio-config/RCConfigPwmGroupModal.tsx index 79f20c0c47..66f01ec69b 100644 --- a/fission/src/ui/modals/configuring/rio-config/RCConfigPwmGroupModal.tsx +++ b/fission/src/ui/modals/configuring/rio-config/RCConfigPwmGroupModal.tsx @@ -8,12 +8,12 @@ import Checkbox from "@/components/Checkbox" import Container from "@/components/Container" import Label, { LabelSize } from "@/components/Label" import Input from "@/components/Input" -import WPILibBrain from "@/systems/simulation/wpilib_brain/WPILibBrain" +import WPILibBrain, { PWMGroup } from "@/systems/simulation/wpilib_brain/WPILibBrain" import World from "@/systems/World" import MirabufSceneObject from "@/mirabuf/MirabufSceneObject" import Driver from "@/systems/simulation/driver/Driver" -const RCConfigPwmGroupModal: React.FC = ({ modalId }) => { +const RCConfigPWMGroupModal: React.FC = ({ modalId }) => { const { openModal } = useModalControlContext() const [name, setName] = useState("") const [checkedPorts, setCheckedPorts] = useState([]) @@ -21,6 +21,8 @@ const RCConfigPwmGroupModal: React.FC = ({ modalId }) => { const numPorts = 8 let drivers: Driver[] = [] + let simLayer; + let brain: WPILibBrain; const miraObjs = [...World.SceneRenderer.sceneObjects.entries()].filter( x => x[1] instanceof MirabufSceneObject @@ -28,9 +30,10 @@ const RCConfigPwmGroupModal: React.FC = ({ modalId }) => { console.log(`Number of mirabuf scene objects: ${miraObjs.length}`) if (miraObjs.length > 0) { const mechanism = (miraObjs[0][1] as MirabufSceneObject).mechanism - const simLayer = World.SimulationSystem.GetSimulationLayer(mechanism) + simLayer = World.SimulationSystem.GetSimulationLayer(mechanism) drivers = simLayer?.drivers ?? [] - simLayer?.SetBrain(new WPILibBrain(mechanism)) + brain = new WPILibBrain(mechanism) + simLayer?.SetBrain(brain) } return ( @@ -41,6 +44,7 @@ const RCConfigPwmGroupModal: React.FC = ({ modalId }) => { acceptName="Done" onAccept={() => { // no eslint complain + brain.addSimOutputGroup(new PWMGroup(name, checkedPorts, checkedDrivers)) console.log(name, checkedPorts, checkedDrivers) }} onCancel={() => { @@ -93,4 +97,4 @@ const RCConfigPwmGroupModal: React.FC = ({ modalId }) => { ) } -export default RCConfigPwmGroupModal +export default RCConfigPWMGroupModal diff --git a/fission/src/ui/modals/configuring/rio-config/RCCreateDeviceModal.tsx b/fission/src/ui/modals/configuring/rio-config/RCCreateDeviceModal.tsx index 8a1d4f71a5..5a2d2c7ae3 100644 --- a/fission/src/ui/modals/configuring/rio-config/RCCreateDeviceModal.tsx +++ b/fission/src/ui/modals/configuring/rio-config/RCCreateDeviceModal.tsx @@ -15,10 +15,15 @@ const RCCreateDeviceModal: React.FC = ({ modalId }) => { modalId={modalId} acceptName="Next" onAccept={() => { + console.log(type) switch (type) { case "PWM": + console.log('opening pwm') openModal("config-pwm") break + case "CAN": + openModal("config-can") + break case "Encoder": openModal("config-encoder") break @@ -32,7 +37,7 @@ const RCCreateDeviceModal: React.FC = ({ modalId }) => { > { setType(selected) }} From a414245114593ddf70f4dd9db43e3dcf5306ee9c Mon Sep 17 00:00:00 2001 From: PepperLola Date: Wed, 24 Jul 2024 10:54:56 -0700 Subject: [PATCH 04/20] only show initialized pwm ports in RCConfigPWMGroupModal --- .../rio-config/RCConfigPwmGroupModal.tsx | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/fission/src/ui/modals/configuring/rio-config/RCConfigPwmGroupModal.tsx b/fission/src/ui/modals/configuring/rio-config/RCConfigPwmGroupModal.tsx index 66f01ec69b..2f3070ebc1 100644 --- a/fission/src/ui/modals/configuring/rio-config/RCConfigPwmGroupModal.tsx +++ b/fission/src/ui/modals/configuring/rio-config/RCConfigPwmGroupModal.tsx @@ -8,7 +8,7 @@ import Checkbox from "@/components/Checkbox" import Container from "@/components/Container" import Label, { LabelSize } from "@/components/Label" import Input from "@/components/Input" -import WPILibBrain, { PWMGroup } from "@/systems/simulation/wpilib_brain/WPILibBrain" +import WPILibBrain, { PWMGroup, simMap } from "@/systems/simulation/wpilib_brain/WPILibBrain" import World from "@/systems/World" import MirabufSceneObject from "@/mirabuf/MirabufSceneObject" import Driver from "@/systems/simulation/driver/Driver" @@ -19,7 +19,6 @@ const RCConfigPWMGroupModal: React.FC = ({ modalId }) => { const [checkedPorts, setCheckedPorts] = useState([]) const [checkedDrivers, setCheckedDrivers] = useState([]) - const numPorts = 8 let drivers: Driver[] = [] let simLayer; let brain: WPILibBrain; @@ -32,10 +31,13 @@ const RCConfigPWMGroupModal: React.FC = ({ modalId }) => { const mechanism = (miraObjs[0][1] as MirabufSceneObject).mechanism simLayer = World.SimulationSystem.GetSimulationLayer(mechanism) drivers = simLayer?.drivers ?? [] + // TODO: set brain elsewhere when sim mode is better brain = new WPILibBrain(mechanism) simLayer?.SetBrain(brain) } + const devices = [...simMap.get("PWM")!.entries()].filter(([_, data]) => data[" = ({ modalId }) => { - {[...Array(numPorts).keys()].map(p => ( + {devices.map(([p, _]) => ( { - if (checked && !checkedPorts.includes(p)) { - setCheckedPorts([...checkedPorts, p]) - } else if (!checked && checkedPorts.includes(p)) { - setCheckedPorts(checkedPorts.filter(a => a != p)) + const port = parseInt(p) + if (checked && !checkedPorts.includes(port)) { + setCheckedPorts([...checkedPorts, port]) + } else if (!checked && checkedPorts.includes(port)) { + setCheckedPorts(checkedPorts.filter(a => a != port)) } }} /> From 3d0356f660fd1aebf6939315ef40cf6b13d73674 Mon Sep 17 00:00:00 2001 From: PepperLola Date: Wed, 24 Jul 2024 11:12:03 -0700 Subject: [PATCH 05/20] store joint info in driver for name display in PWM/CAN group modal - also default to PWM in RCCreateDeviceModal without needing to reselect for PWM --- fission/src/systems/physics/Mechanism.ts | 2 ++ fission/src/systems/physics/PhysicsSystem.ts | 1 + fission/src/systems/simulation/SimulationSystem.ts | 6 +++--- fission/src/systems/simulation/driver/Driver.ts | 12 ++++++++++++ fission/src/systems/simulation/driver/HingeDriver.ts | 5 +++-- .../src/systems/simulation/driver/SliderDriver.ts | 5 +++-- fission/src/systems/simulation/driver/WheelDriver.ts | 5 +++-- .../configuring/rio-config/RCConfigPwmGroupModal.tsx | 8 ++++++-- .../configuring/rio-config/RCCreateDeviceModal.tsx | 9 +++++---- 9 files changed, 38 insertions(+), 15 deletions(-) diff --git a/fission/src/systems/physics/Mechanism.ts b/fission/src/systems/physics/Mechanism.ts index 447445827e..bf6502b4f5 100644 --- a/fission/src/systems/physics/Mechanism.ts +++ b/fission/src/systems/physics/Mechanism.ts @@ -1,11 +1,13 @@ import Jolt from "@barclah/jolt-physics" import { LayerReserve } from "./PhysicsSystem" import { RigidNodeId } from "@/mirabuf/MirabufParser" +import { mirabuf } from "@/proto/mirabuf" export interface MechanismConstraint { parentBody: Jolt.BodyID childBody: Jolt.BodyID constraint: Jolt.Constraint + info?: mirabuf.IInfo } class Mechanism { diff --git a/fission/src/systems/physics/PhysicsSystem.ts b/fission/src/systems/physics/PhysicsSystem.ts index 4736323d12..0bc6528083 100644 --- a/fission/src/systems/physics/PhysicsSystem.ts +++ b/fission/src/systems/physics/PhysicsSystem.ts @@ -386,6 +386,7 @@ class PhysicsSystem extends WorldSystem { parentBody: bodyIdA, childBody: bodyIdB, constraint: x, + info: jInst.info ?? undefined // remove possibility for null }) ) } diff --git a/fission/src/systems/simulation/SimulationSystem.ts b/fission/src/systems/simulation/SimulationSystem.ts index 331739f8a7..5f67f04e04 100644 --- a/fission/src/systems/simulation/SimulationSystem.ts +++ b/fission/src/systems/simulation/SimulationSystem.ts @@ -77,19 +77,19 @@ class SimulationLayer { this._mechanism.constraints.forEach(x => { if (x.constraint.GetSubType() == JOLT.EConstraintSubType_Hinge) { const hinge = JOLT.castObject(x.constraint, JOLT.HingeConstraint) - const driver = new HingeDriver(hinge) + const driver = new HingeDriver(hinge, x.info) this._drivers.push(driver) const stim = new HingeStimulus(hinge) this._stimuli.push(stim) } else if (x.constraint.GetSubType() == JOLT.EConstraintSubType_Vehicle) { const vehicle = JOLT.castObject(x.constraint, JOLT.VehicleConstraint) - const driver = new WheelDriver(vehicle) + const driver = new WheelDriver(vehicle, x.info) this._drivers.push(driver) const stim = new WheelRotationStimulus(vehicle.GetWheel(0)) this._stimuli.push(stim) } else if (x.constraint.GetSubType() == JOLT.EConstraintSubType_Slider) { const slider = JOLT.castObject(x.constraint, JOLT.SliderConstraint) - const driver = new SliderDriver(slider) + const driver = new SliderDriver(slider, x.info) this._drivers.push(driver) const stim = new SliderStimulus(slider) this._stimuli.push(stim) diff --git a/fission/src/systems/simulation/driver/Driver.ts b/fission/src/systems/simulation/driver/Driver.ts index d7c27e292e..a6fbdb39f3 100644 --- a/fission/src/systems/simulation/driver/Driver.ts +++ b/fission/src/systems/simulation/driver/Driver.ts @@ -1,5 +1,17 @@ +import { mirabuf } from "@/proto/mirabuf" + abstract class Driver { + private _info?: mirabuf.IInfo + + constructor(info?: mirabuf.IInfo) { + this._info = info + } + public abstract Update(deltaT: number): void + + public get info() { + return this._info + } } export enum DriverControlMode { diff --git a/fission/src/systems/simulation/driver/HingeDriver.ts b/fission/src/systems/simulation/driver/HingeDriver.ts index 6940afbc8c..29ab7fc6af 100644 --- a/fission/src/systems/simulation/driver/HingeDriver.ts +++ b/fission/src/systems/simulation/driver/HingeDriver.ts @@ -2,6 +2,7 @@ import Jolt from "@barclah/jolt-physics" import Driver, { DriverControlMode } from "./Driver" import { GetLastDeltaT } from "@/systems/physics/PhysicsSystem" import JOLT from "@/util/loading/JoltSyncLoader" +import { mirabuf } from "@/proto/mirabuf" class HingeDriver extends Driver { private _constraint: Jolt.HingeConstraint @@ -52,8 +53,8 @@ class HingeDriver extends Driver { } } - public constructor(constraint: Jolt.HingeConstraint) { - super() + public constructor(constraint: Jolt.HingeConstraint, info?: mirabuf.IInfo) { + super(info) this._constraint = constraint diff --git a/fission/src/systems/simulation/driver/SliderDriver.ts b/fission/src/systems/simulation/driver/SliderDriver.ts index 6bf361d445..dd442b38aa 100644 --- a/fission/src/systems/simulation/driver/SliderDriver.ts +++ b/fission/src/systems/simulation/driver/SliderDriver.ts @@ -2,6 +2,7 @@ import Jolt from "@barclah/jolt-physics" import Driver, { DriverControlMode } from "./Driver" import { GetLastDeltaT } from "@/systems/physics/PhysicsSystem" import JOLT from "@/util/loading/JoltSyncLoader" +import { mirabuf } from "@/proto/mirabuf" class SliderDriver extends Driver { private _constraint: Jolt.SliderConstraint @@ -55,8 +56,8 @@ class SliderDriver extends Driver { } } - public constructor(constraint: Jolt.SliderConstraint) { - super() + public constructor(constraint: Jolt.SliderConstraint, info?: mirabuf.IInfo) { + super(info) this._constraint = constraint diff --git a/fission/src/systems/simulation/driver/WheelDriver.ts b/fission/src/systems/simulation/driver/WheelDriver.ts index bdfdc7cbb9..ea579c967d 100644 --- a/fission/src/systems/simulation/driver/WheelDriver.ts +++ b/fission/src/systems/simulation/driver/WheelDriver.ts @@ -2,6 +2,7 @@ import Jolt from "@barclah/jolt-physics" import Driver from "./Driver" import JOLT from "@/util/loading/JoltSyncLoader" import { SimType } from "../wpilib_brain/WPILibBrain" +import { mirabuf } from "@/proto/mirabuf" const LATERIAL_FRICTION = 0.6 const LONGITUDINAL_FRICTION = 0.8 @@ -26,8 +27,8 @@ class WheelDriver extends Driver { return this._constraint } - public constructor(constraint: Jolt.VehicleConstraint, deviceType?: SimType, device?: string, reversed: boolean = false) { - super() + public constructor(constraint: Jolt.VehicleConstraint, info?: mirabuf.IInfo, deviceType?: SimType, device?: string, reversed: boolean = false) { + super(info) this._constraint = constraint this._reversed = reversed diff --git a/fission/src/ui/modals/configuring/rio-config/RCConfigPwmGroupModal.tsx b/fission/src/ui/modals/configuring/rio-config/RCConfigPwmGroupModal.tsx index 2f3070ebc1..16f96daeea 100644 --- a/fission/src/ui/modals/configuring/rio-config/RCConfigPwmGroupModal.tsx +++ b/fission/src/ui/modals/configuring/rio-config/RCConfigPwmGroupModal.tsx @@ -36,7 +36,11 @@ const RCConfigPWMGroupModal: React.FC = ({ modalId }) => { simLayer?.SetBrain(brain) } - const devices = [...simMap.get("PWM")!.entries()].filter(([_, data]) => data[" data[" = ({ modalId }) => { {drivers.map((driver, idx) => ( { if (checked && !checkedDrivers.includes(driver)) { diff --git a/fission/src/ui/modals/configuring/rio-config/RCCreateDeviceModal.tsx b/fission/src/ui/modals/configuring/rio-config/RCCreateDeviceModal.tsx index 5a2d2c7ae3..a78b5d4f66 100644 --- a/fission/src/ui/modals/configuring/rio-config/RCCreateDeviceModal.tsx +++ b/fission/src/ui/modals/configuring/rio-config/RCCreateDeviceModal.tsx @@ -4,9 +4,11 @@ import { useModalControlContext } from "@/ui/ModalContext" import { FaPlus } from "react-icons/fa6" import Dropdown from "@/components/Dropdown" +type DeviceType = "PWM" | "CAN" | "Encoder" + const RCCreateDeviceModal: React.FC = ({ modalId }) => { const { openModal } = useModalControlContext() - const [type, setType] = useState("") + const [type, setType] = useState("PWM") return ( = ({ modalId }) => { console.log(type) switch (type) { case "PWM": - console.log('opening pwm') openModal("config-pwm") break case "CAN": @@ -37,9 +38,9 @@ const RCCreateDeviceModal: React.FC = ({ modalId }) => { > { - setType(selected) + setType(selected as DeviceType) }} /> From 6de71229adbacec1326b9c79167fc6537dbbbd34 Mon Sep 17 00:00:00 2001 From: PepperLola Date: Wed, 24 Jul 2024 11:42:14 -0700 Subject: [PATCH 06/20] formatted and fixed lint warnings --- fission/src/mirabuf/MirabufSceneObject.ts | 1 - fission/src/systems/physics/PhysicsSystem.ts | 2 +- .../wpilib/WPILibArcadeDriveBehavior.ts | 18 ++++-- .../systems/simulation/driver/WheelDriver.ts | 8 ++- .../simulation/wpilib_brain/WPILibBrain.ts | 57 ++++--------------- .../rio-config/RCConfigCANGroupModal.tsx | 8 +-- .../rio-config/RCConfigPwmGroupModal.tsx | 10 ++-- 7 files changed, 40 insertions(+), 64 deletions(-) diff --git a/fission/src/mirabuf/MirabufSceneObject.ts b/fission/src/mirabuf/MirabufSceneObject.ts index a17eefb4bd..4146edd2c9 100644 --- a/fission/src/mirabuf/MirabufSceneObject.ts +++ b/fission/src/mirabuf/MirabufSceneObject.ts @@ -9,7 +9,6 @@ import * as THREE from "three" import JOLT from "@/util/loading/JoltSyncLoader" import { BodyAssociate, LayerReserve } from "@/systems/physics/PhysicsSystem" import Mechanism from "@/systems/physics/Mechanism" -import SynthesisBrain from "@/systems/simulation/synthesis_brain/SynthesisBrain" import InputSystem from "@/systems/input/InputSystem" import TransformGizmos from "@/ui/components/TransformGizmos" import { EjectorPreferences, IntakePreferences } from "@/systems/preferences/PreferenceTypes" diff --git a/fission/src/systems/physics/PhysicsSystem.ts b/fission/src/systems/physics/PhysicsSystem.ts index 0bc6528083..9a382dbb91 100644 --- a/fission/src/systems/physics/PhysicsSystem.ts +++ b/fission/src/systems/physics/PhysicsSystem.ts @@ -386,7 +386,7 @@ class PhysicsSystem extends WorldSystem { parentBody: bodyIdA, childBody: bodyIdB, constraint: x, - info: jInst.info ?? undefined // remove possibility for null + info: jInst.info ?? undefined, // remove possibility for null }) ) } diff --git a/fission/src/systems/simulation/behavior/wpilib/WPILibArcadeDriveBehavior.ts b/fission/src/systems/simulation/behavior/wpilib/WPILibArcadeDriveBehavior.ts index 023c9c353b..5e38f83bcb 100644 --- a/fission/src/systems/simulation/behavior/wpilib/WPILibArcadeDriveBehavior.ts +++ b/fission/src/systems/simulation/behavior/wpilib/WPILibArcadeDriveBehavior.ts @@ -1,20 +1,20 @@ import WheelDriver from "@/systems/simulation/driver/WheelDriver" import WheelRotationStimulus from "@/systems/simulation/stimulus/WheelStimulus" import Behavior from "@/systems/simulation/behavior/Behavior" -import WPILibBrain, { SimCAN, SimGeneric, simMap } from "../../wpilib_brain/WPILibBrain" +import { SimGeneric } from "../../wpilib_brain/WPILibBrain" class WPILibArcadeDriveBehavior extends Behavior { private leftWheels: WheelDriver[] private rightWheels: WheelDriver[] private _driveSpeed = 30 - private _turnSpeed = 30 + // private _turnSpeed = 30 constructor( leftWheels: WheelDriver[], rightWheels: WheelDriver[], leftStimuli: WheelRotationStimulus[], - rightStimuli: WheelRotationStimulus[], + rightStimuli: WheelRotationStimulus[] ) { super(leftWheels.concat(rightWheels), leftStimuli.concat(rightStimuli)) @@ -25,8 +25,16 @@ class WPILibArcadeDriveBehavior extends Behavior { public Update(_: number): void { // TODO: better checks for device field existence // TODO: differentiate between fields for CAN, PWM ( wheel.targetWheelSpeed = SimGeneric.Get(wheel.deviceType!, wheel.device!, " wheel.targetWheelSpeed = SimGeneric.Get(wheel.deviceType!, wheel.device!, " + (wheel.targetWheelSpeed = + SimGeneric.Get(wheel.deviceType!, wheel.device!, " + (wheel.targetWheelSpeed = + SimGeneric.Get(wheel.deviceType!, wheel.device!, "> = new Map( - Object.entries({ - "CANMotor": { - "CANSparkMax[0]": { - " [key as SimType, new Map(Object.entries(value))]) -) - export const simMap = new Map>() export class SimGeneric { - private constructor() { } + private constructor() {} public static Get(simType: SimType, device: string, field: string, defaultValue?: T): T | undefined { const fieldType = GetFieldType(field) @@ -138,7 +105,7 @@ export class SimGeneric { } export class SimPWM { - private constructor() { } + private constructor() {} public static GetSpeed(device: string): number | undefined { return SimGeneric.Get("PWM", device, PWM_SPEED, 0.0) @@ -150,17 +117,17 @@ export class SimPWM { } export class SimCAN { - private constructor() { } + private constructor() {} public static GetDeviceWithID(id: number, type: SimType): any { - const id_exp = /.*\[(\d+)\]/g; + const id_exp = /.*\[(\d+)\]/g const entries = [...simMap.entries()].filter(([simType, _data]) => simType == type || simType == "SimDevice") for (const [_simType, data] of entries) { for (const key of data.keys()) { - let result; + let result if ((result = [...key.matchAll(id_exp)]) != undefined) { if (result.length > 0 && result[0].length > 1) { - const parsed_id = parseInt(result[0][1]); + const parsed_id = parseInt(result[0][1]) if (parsed_id == id) { return data.get(key) } @@ -173,7 +140,7 @@ export class SimCAN { } export class SimCANMotor { - private constructor() { } + private constructor() {} public static GetDutyCycle(device: string): number | undefined { return SimGeneric.Get("CANMotor", device, CANMOTOR_DUTY_CYCLE, 0.0) @@ -185,7 +152,7 @@ export class SimCANMotor { } export class SimCANEncoder { - private constructor() { } + private constructor() {} public static SetRawInputPosition(device: string, rawInputPosition: number): boolean { return SimGeneric.Set("CANEncoder", device, CANENCODER_RAW_INPUT_POSITION, rawInputPosition) @@ -343,10 +310,10 @@ export class PWMGroup extends SimOutputGroup { super(name, ports, drivers, "PWM") } - public Update(deltaT: number) { + public Update(_deltaT: number) { // let average = 0; for (const port of this.ports) { - const speed = SimPWM.GetSpeed(`${port}`) ?? 0; + const speed = SimPWM.GetSpeed(`${port}`) ?? 0 // average += speed; console.log(port, speed) } @@ -354,7 +321,7 @@ export class PWMGroup extends SimOutputGroup { // this.drivers.forEach(d => { // (d as WheelDriver).targetWheelSpeed = average * 40 - // d.Update(deltaT) + // d.Update(_deltaT) // }) } } @@ -366,7 +333,7 @@ export class CANGroup extends SimOutputGroup { public Update(_deltaT: number) { for (const port of this.ports) { - const device = SimCAN.GetDeviceWithID(port, this.type); + const device = SimCAN.GetDeviceWithID(port, this.type) console.log(port, device) } } diff --git a/fission/src/ui/modals/configuring/rio-config/RCConfigCANGroupModal.tsx b/fission/src/ui/modals/configuring/rio-config/RCConfigCANGroupModal.tsx index e01e43051b..82fbc99ad5 100644 --- a/fission/src/ui/modals/configuring/rio-config/RCConfigCANGroupModal.tsx +++ b/fission/src/ui/modals/configuring/rio-config/RCConfigCANGroupModal.tsx @@ -21,12 +21,10 @@ const RCConfigCANGroupModal: React.FC = ({ modalId }) => { const numPorts = 8 let drivers: Driver[] = [] - let simLayer; - let brain: WPILibBrain; + let simLayer + let brain: WPILibBrain - const miraObjs = [...World.SceneRenderer.sceneObjects.entries()].filter( - x => x[1] instanceof MirabufSceneObject - ) + const miraObjs = [...World.SceneRenderer.sceneObjects.entries()].filter(x => x[1] instanceof MirabufSceneObject) console.log(`Number of mirabuf scene objects: ${miraObjs.length}`) if (miraObjs.length > 0) { const mechanism = (miraObjs[0][1] as MirabufSceneObject).mechanism diff --git a/fission/src/ui/modals/configuring/rio-config/RCConfigPwmGroupModal.tsx b/fission/src/ui/modals/configuring/rio-config/RCConfigPwmGroupModal.tsx index 16f96daeea..b60b7987a9 100644 --- a/fission/src/ui/modals/configuring/rio-config/RCConfigPwmGroupModal.tsx +++ b/fission/src/ui/modals/configuring/rio-config/RCConfigPwmGroupModal.tsx @@ -20,12 +20,10 @@ const RCConfigPWMGroupModal: React.FC = ({ modalId }) => { const [checkedDrivers, setCheckedDrivers] = useState([]) let drivers: Driver[] = [] - let simLayer; - let brain: WPILibBrain; + let simLayer + let brain: WPILibBrain - const miraObjs = [...World.SceneRenderer.sceneObjects.entries()].filter( - x => x[1] instanceof MirabufSceneObject - ) + const miraObjs = [...World.SceneRenderer.sceneObjects.entries()].filter(x => x[1] instanceof MirabufSceneObject) console.log(`Number of mirabuf scene objects: ${miraObjs.length}`) if (miraObjs.length > 0) { const mechanism = (miraObjs[0][1] as MirabufSceneObject).mechanism @@ -37,7 +35,7 @@ const RCConfigPWMGroupModal: React.FC = ({ modalId }) => { } let devices: [string, unknown][] = [] - let pwms; + let pwms if ((pwms = simMap.get("PWM")) != undefined) { devices = [...pwms.entries()].filter(([_, data]) => data[" Date: Wed, 24 Jul 2024 11:48:40 -0700 Subject: [PATCH 07/20] fix build and spelling --- fission/src/mirabuf/MirabufSceneObject.ts | 6 ++++-- fission/src/systems/physics/PhysicsSystem.ts | 2 +- fission/src/systems/simulation/wpilib_brain/WPILibBrain.ts | 4 ---- .../modals/configuring/rio-config/RCConfigCANGroupModal.tsx | 2 +- 4 files changed, 6 insertions(+), 8 deletions(-) diff --git a/fission/src/mirabuf/MirabufSceneObject.ts b/fission/src/mirabuf/MirabufSceneObject.ts index 4cb7552278..1652e147b6 100644 --- a/fission/src/mirabuf/MirabufSceneObject.ts +++ b/fission/src/mirabuf/MirabufSceneObject.ts @@ -20,6 +20,7 @@ import Brain from "@/systems/simulation/Brain" import WPILibBrain from "@/systems/simulation/wpilib_brain/WPILibBrain" import { SceneOverlayTag } from "@/ui/components/SceneOverlayEvents" import { ProgressHandle } from "@/ui/components/ProgressNotificationData" +import SynthesisBrain from "@/systems/simulation/synthesis_brain/SynthesisBrain" const DEBUG_BODIES = false @@ -243,7 +244,7 @@ class MirabufSceneObject extends SceneObject { } this._mechanism.nodeToBody.forEach(bodyId => { - World.PhysicsSystem.RemoveBodyAssocation(bodyId) + World.PhysicsSystem.RemoveBodyAssociation(bodyId) }) this._nameTag?.Dispose() @@ -261,7 +262,8 @@ class MirabufSceneObject extends SceneObject { this._debugBodies?.clear() this._physicsLayerReserve?.Release() - this._brain?.clearControls() + if (this._brain && this._brain instanceof SynthesisBrain) + this._brain?.clearControls() } public Eject() { diff --git a/fission/src/systems/physics/PhysicsSystem.ts b/fission/src/systems/physics/PhysicsSystem.ts index 9a382dbb91..4598ac2d6a 100644 --- a/fission/src/systems/physics/PhysicsSystem.ts +++ b/fission/src/systems/physics/PhysicsSystem.ts @@ -123,7 +123,7 @@ class PhysicsSystem extends WorldSystem { this._bodyAssociations.set(assocation.associatedBody, assocation) } - public RemoveBodyAssocation(bodyId: Jolt.BodyID) { + public RemoveBodyAssociation(bodyId: Jolt.BodyID) { this._bodyAssociations.delete(bodyId.GetIndexAndSequenceNumber()) } diff --git a/fission/src/systems/simulation/wpilib_brain/WPILibBrain.ts b/fission/src/systems/simulation/wpilib_brain/WPILibBrain.ts index 0ba515c650..4526f51545 100644 --- a/fission/src/systems/simulation/wpilib_brain/WPILibBrain.ts +++ b/fission/src/systems/simulation/wpilib_brain/WPILibBrain.ts @@ -3,7 +3,6 @@ import Mechanism from "@/systems/physics/Mechanism" import Brain from "../Brain" import WPILibWSWorker from "./WPILibWSWorker?worker" -import Behavior from "../behavior/Behavior" import { SimulationLayer } from "../SimulationSystem" import World from "@/systems/World" import Driver from "../driver/Driver" @@ -226,15 +225,12 @@ function UpdateSimMap(type: SimType, device: string, updateData: any) { } class WPILibBrain extends Brain { - private _behaviors: Behavior[] = [] private _simLayer: SimulationLayer private _simDevices: SimOutputGroup[] = [] public static robotsSpawned: string[] = [] - private static _currentRobotIndex: number = 0 - constructor(mechanism: Mechanism) { super(mechanism) diff --git a/fission/src/ui/modals/configuring/rio-config/RCConfigCANGroupModal.tsx b/fission/src/ui/modals/configuring/rio-config/RCConfigCANGroupModal.tsx index 82fbc99ad5..8da3bec73c 100644 --- a/fission/src/ui/modals/configuring/rio-config/RCConfigCANGroupModal.tsx +++ b/fission/src/ui/modals/configuring/rio-config/RCConfigCANGroupModal.tsx @@ -44,7 +44,7 @@ const RCConfigCANGroupModal: React.FC = ({ modalId }) => { // no eslint complain brain.addSimOutputGroup(new CANGroup(name, checkedPorts, checkedDrivers)) console.log(name, checkedPorts, checkedDrivers) - const replacer = (key, value) => { + const replacer = (_: unknown, value: unknown) => { if (value instanceof Map) { return Object.fromEntries(value) } else { From 3e8d98fc87d611c732cc232b2644927898784e42 Mon Sep 17 00:00:00 2001 From: PepperLola Date: Wed, 24 Jul 2024 11:52:00 -0700 Subject: [PATCH 08/20] format again :/ --- fission/src/mirabuf/MirabufSceneObject.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fission/src/mirabuf/MirabufSceneObject.ts b/fission/src/mirabuf/MirabufSceneObject.ts index 1652e147b6..0c5fc9947a 100644 --- a/fission/src/mirabuf/MirabufSceneObject.ts +++ b/fission/src/mirabuf/MirabufSceneObject.ts @@ -262,8 +262,7 @@ class MirabufSceneObject extends SceneObject { this._debugBodies?.clear() this._physicsLayerReserve?.Release() - if (this._brain && this._brain instanceof SynthesisBrain) - this._brain?.clearControls() + if (this._brain && this._brain instanceof SynthesisBrain) this._brain?.clearControls() } public Eject() { From 20d1fe8b3b7728a339a5e00af68204479497f63e Mon Sep 17 00:00:00 2001 From: PepperLola Date: Wed, 24 Jul 2024 11:59:13 -0700 Subject: [PATCH 09/20] reimport RCConfigPWMGroupModal to fix resolution error? --- fission/src/Synthesis.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fission/src/Synthesis.tsx b/fission/src/Synthesis.tsx index a01e129834..9963345d3d 100644 --- a/fission/src/Synthesis.tsx +++ b/fission/src/Synthesis.tsx @@ -34,7 +34,6 @@ import PracticeSettingsModal from "@/modals/configuring/PracticeSettingsModal" import RoboRIOModal from "@/modals/configuring/RoboRIOModal" import SettingsModal from "@/modals/configuring/SettingsModal" import RCConfigEncoderModal from "@/modals/configuring/rio-config/RCConfigEncoderModal" -import RCConfigPWMGroupModal from "@/modals/configuring/rio-config/RCConfigPWMGroupModal" import RCCreateDeviceModal from "@/modals/configuring/rio-config/RCCreateDeviceModal" import DeleteAllThemesModal from "@/modals/configuring/theme-editor/DeleteAllThemesModal" import DeleteThemeModal from "@/modals/configuring/theme-editor/DeleteThemeModal" @@ -66,7 +65,8 @@ import SceneOverlay from "./ui/components/SceneOverlay.tsx" import WPILibWSWorker from "@/systems/simulation/wpilib_brain/WPILibWSWorker.ts?worker" import WSViewPanel from "./ui/panels/WSViewPanel.tsx" import Lazy from "./util/Lazy.ts" -import RCConfigCANGroupModal from "./ui/modals/configuring/rio-config/RCConfigCANGroupModal.tsx" +import RCConfigCANGroupModal from "@/modals/configuring/rio-config/RCConfigCANGroupModal.tsx" +import RCConfigPWMGroupModal from "@/modals/configuring/rio-config/RCConfigPWMGroupModal.tsx" const DEFAULT_MIRA_PATH = "/api/mira/Robots/Team 2471 (2018)_v7.mira" From 65605ab80e8e523a6d788c243001599f9421738c Mon Sep 17 00:00:00 2001 From: PepperLola Date: Wed, 24 Jul 2024 12:02:00 -0700 Subject: [PATCH 10/20] change to relative import instead of alias --- fission/src/Synthesis.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fission/src/Synthesis.tsx b/fission/src/Synthesis.tsx index 9963345d3d..d4106a4632 100644 --- a/fission/src/Synthesis.tsx +++ b/fission/src/Synthesis.tsx @@ -65,8 +65,8 @@ import SceneOverlay from "./ui/components/SceneOverlay.tsx" import WPILibWSWorker from "@/systems/simulation/wpilib_brain/WPILibWSWorker.ts?worker" import WSViewPanel from "./ui/panels/WSViewPanel.tsx" import Lazy from "./util/Lazy.ts" -import RCConfigCANGroupModal from "@/modals/configuring/rio-config/RCConfigCANGroupModal.tsx" -import RCConfigPWMGroupModal from "@/modals/configuring/rio-config/RCConfigPWMGroupModal.tsx" +import RCConfigPWMGroupModal from "./ui/modals/configuring/rio-config/RCConfigPWMGroupModal.tsx" +import RCConfigCANGroupModal from "./ui/modals/configuring/rio-config/RCConfigCANGroupModal.tsx" const DEFAULT_MIRA_PATH = "/api/mira/Robots/Team 2471 (2018)_v7.mira" From 8bdc7a28afcf86c367449b2cf12818221bd3e267 Mon Sep 17 00:00:00 2001 From: PepperLola Date: Wed, 24 Jul 2024 12:06:21 -0700 Subject: [PATCH 11/20] Rename RCConfigPwmGroupModal.tsx to RCConfigPWMGroupModal.tsx weird --- .../{RCConfigPwmGroupModal.tsx => RCConfigPWMGroupModal.tsx} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename fission/src/ui/modals/configuring/rio-config/{RCConfigPwmGroupModal.tsx => RCConfigPWMGroupModal.tsx} (100%) diff --git a/fission/src/ui/modals/configuring/rio-config/RCConfigPwmGroupModal.tsx b/fission/src/ui/modals/configuring/rio-config/RCConfigPWMGroupModal.tsx similarity index 100% rename from fission/src/ui/modals/configuring/rio-config/RCConfigPwmGroupModal.tsx rename to fission/src/ui/modals/configuring/rio-config/RCConfigPWMGroupModal.tsx From 06ca91c6cb467c865ad9dffe49d2a35c16a04f39 Mon Sep 17 00:00:00 2001 From: PepperLola Date: Wed, 24 Jul 2024 12:07:56 -0700 Subject: [PATCH 12/20] back to path alias after rename --- fission/src/Synthesis.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fission/src/Synthesis.tsx b/fission/src/Synthesis.tsx index d4106a4632..dcd4e2fd4b 100644 --- a/fission/src/Synthesis.tsx +++ b/fission/src/Synthesis.tsx @@ -65,8 +65,8 @@ import SceneOverlay from "./ui/components/SceneOverlay.tsx" import WPILibWSWorker from "@/systems/simulation/wpilib_brain/WPILibWSWorker.ts?worker" import WSViewPanel from "./ui/panels/WSViewPanel.tsx" import Lazy from "./util/Lazy.ts" -import RCConfigPWMGroupModal from "./ui/modals/configuring/rio-config/RCConfigPWMGroupModal.tsx" -import RCConfigCANGroupModal from "./ui/modals/configuring/rio-config/RCConfigCANGroupModal.tsx" +import RCConfigPWMGroupModal from "@/modals/configuring/rio-config/RCConfigPWMGroupModal.tsx" +import RCConfigCANGroupModal from "@/modals/configuring/rio-config/RCConfigCANGroupModal.tsx" const DEFAULT_MIRA_PATH = "/api/mira/Robots/Team 2471 (2018)_v7.mira" From 2dd59af03980020badc5c31a0571dcc2c98ed6e1 Mon Sep 17 00:00:00 2001 From: PepperLola Date: Wed, 24 Jul 2024 13:07:59 -0700 Subject: [PATCH 13/20] deleted unused wpilib behaviors --- .../wpilib/WPILibArcadeDriveBehavior.ts | 41 ------------------- .../behavior/wpilib/WPILibArmBehavior.ts | 41 ------------------- .../behavior/wpilib/WPILibElevatorBehavior.ts | 41 ------------------- 3 files changed, 123 deletions(-) delete mode 100644 fission/src/systems/simulation/behavior/wpilib/WPILibArcadeDriveBehavior.ts delete mode 100644 fission/src/systems/simulation/behavior/wpilib/WPILibArmBehavior.ts delete mode 100644 fission/src/systems/simulation/behavior/wpilib/WPILibElevatorBehavior.ts diff --git a/fission/src/systems/simulation/behavior/wpilib/WPILibArcadeDriveBehavior.ts b/fission/src/systems/simulation/behavior/wpilib/WPILibArcadeDriveBehavior.ts deleted file mode 100644 index 5e38f83bcb..0000000000 --- a/fission/src/systems/simulation/behavior/wpilib/WPILibArcadeDriveBehavior.ts +++ /dev/null @@ -1,41 +0,0 @@ -import WheelDriver from "@/systems/simulation/driver/WheelDriver" -import WheelRotationStimulus from "@/systems/simulation/stimulus/WheelStimulus" -import Behavior from "@/systems/simulation/behavior/Behavior" -import { SimGeneric } from "../../wpilib_brain/WPILibBrain" - -class WPILibArcadeDriveBehavior extends Behavior { - private leftWheels: WheelDriver[] - private rightWheels: WheelDriver[] - - private _driveSpeed = 30 - // private _turnSpeed = 30 - - constructor( - leftWheels: WheelDriver[], - rightWheels: WheelDriver[], - leftStimuli: WheelRotationStimulus[], - rightStimuli: WheelRotationStimulus[] - ) { - super(leftWheels.concat(rightWheels), leftStimuli.concat(rightStimuli)) - - this.leftWheels = leftWheels - this.rightWheels = rightWheels - } - - public Update(_: number): void { - // TODO: better checks for device field existence - // TODO: differentiate between fields for CAN, PWM ( - (wheel.targetWheelSpeed = - SimGeneric.Get(wheel.deviceType!, wheel.device!, " - (wheel.targetWheelSpeed = - SimGeneric.Get(wheel.deviceType!, wheel.device!, " Date: Wed, 24 Jul 2024 15:39:38 -0700 Subject: [PATCH 14/20] Update fission/src/systems/simulation/wpilib_brain/WPILibBrain.ts Co-authored-by: Azalea Colburn <62953415+azaleacolburn@users.noreply.github.com> --- .../simulation/wpilib_brain/WPILibBrain.ts | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/fission/src/systems/simulation/wpilib_brain/WPILibBrain.ts b/fission/src/systems/simulation/wpilib_brain/WPILibBrain.ts index 4526f51545..2886893896 100644 --- a/fission/src/systems/simulation/wpilib_brain/WPILibBrain.ts +++ b/fission/src/systems/simulation/wpilib_brain/WPILibBrain.ts @@ -123,15 +123,12 @@ export class SimCAN { const entries = [...simMap.entries()].filter(([simType, _data]) => simType == type || simType == "SimDevice") for (const [_simType, data] of entries) { for (const key of data.keys()) { - let result - if ((result = [...key.matchAll(id_exp)]) != undefined) { - if (result.length > 0 && result[0].length > 1) { - const parsed_id = parseInt(result[0][1]) - if (parsed_id == id) { - return data.get(key) - } - } - } + let result = [...key.matchAll(id_exp)] + if (result?.length <= 0 || result?[0].length <= 1) continue + const parsed_id = parseInt(result[0][1]) + if (parsed_id != id) continue + + return data.get(key) } } return undefined From df47101c38be166ebcf636a2c0ef085afb9abd0e Mon Sep 17 00:00:00 2001 From: PepperLola Date: Wed, 24 Jul 2024 15:39:45 -0700 Subject: [PATCH 15/20] Update fission/src/ui/modals/configuring/rio-config/RCConfigPWMGroupModal.tsx Co-authored-by: Azalea Colburn <62953415+azaleacolburn@users.noreply.github.com> --- .../modals/configuring/rio-config/RCConfigPWMGroupModal.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fission/src/ui/modals/configuring/rio-config/RCConfigPWMGroupModal.tsx b/fission/src/ui/modals/configuring/rio-config/RCConfigPWMGroupModal.tsx index b60b7987a9..b4caab61da 100644 --- a/fission/src/ui/modals/configuring/rio-config/RCConfigPWMGroupModal.tsx +++ b/fission/src/ui/modals/configuring/rio-config/RCConfigPWMGroupModal.tsx @@ -35,8 +35,8 @@ const RCConfigPWMGroupModal: React.FC = ({ modalId }) => { } let devices: [string, unknown][] = [] - let pwms - if ((pwms = simMap.get("PWM")) != undefined) { + let pwms = simMap.get("PWM") + if (pwms) { devices = [...pwms.entries()].filter(([_, data]) => data[" Date: Wed, 24 Jul 2024 15:41:47 -0700 Subject: [PATCH 16/20] fixed syntax error --- fission/src/systems/simulation/wpilib_brain/WPILibBrain.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fission/src/systems/simulation/wpilib_brain/WPILibBrain.ts b/fission/src/systems/simulation/wpilib_brain/WPILibBrain.ts index 2886893896..c64ac7c936 100644 --- a/fission/src/systems/simulation/wpilib_brain/WPILibBrain.ts +++ b/fission/src/systems/simulation/wpilib_brain/WPILibBrain.ts @@ -123,8 +123,8 @@ export class SimCAN { const entries = [...simMap.entries()].filter(([simType, _data]) => simType == type || simType == "SimDevice") for (const [_simType, data] of entries) { for (const key of data.keys()) { - let result = [...key.matchAll(id_exp)] - if (result?.length <= 0 || result?[0].length <= 1) continue + const result = [...key.matchAll(id_exp)] + if (result?.length <= 0 || result[0].length <= 1) continue const parsed_id = parseInt(result[0][1]) if (parsed_id != id) continue From eaa403b122632d6c907b56452b544d3e115cd95c Mon Sep 17 00:00:00 2001 From: PepperLola Date: Wed, 24 Jul 2024 15:42:12 -0700 Subject: [PATCH 17/20] formatted --- fission/src/systems/simulation/wpilib_brain/WPILibBrain.ts | 2 +- .../ui/modals/configuring/rio-config/RCConfigPWMGroupModal.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/fission/src/systems/simulation/wpilib_brain/WPILibBrain.ts b/fission/src/systems/simulation/wpilib_brain/WPILibBrain.ts index c64ac7c936..117eb23be3 100644 --- a/fission/src/systems/simulation/wpilib_brain/WPILibBrain.ts +++ b/fission/src/systems/simulation/wpilib_brain/WPILibBrain.ts @@ -127,7 +127,7 @@ export class SimCAN { if (result?.length <= 0 || result[0].length <= 1) continue const parsed_id = parseInt(result[0][1]) if (parsed_id != id) continue - + return data.get(key) } } diff --git a/fission/src/ui/modals/configuring/rio-config/RCConfigPWMGroupModal.tsx b/fission/src/ui/modals/configuring/rio-config/RCConfigPWMGroupModal.tsx index b4caab61da..a663abfb14 100644 --- a/fission/src/ui/modals/configuring/rio-config/RCConfigPWMGroupModal.tsx +++ b/fission/src/ui/modals/configuring/rio-config/RCConfigPWMGroupModal.tsx @@ -35,7 +35,7 @@ const RCConfigPWMGroupModal: React.FC = ({ modalId }) => { } let devices: [string, unknown][] = [] - let pwms = simMap.get("PWM") + const pwms = simMap.get("PWM") if (pwms) { devices = [...pwms.entries()].filter(([_, data]) => data[" Date: Wed, 24 Jul 2024 15:47:26 -0700 Subject: [PATCH 18/20] fixed build error with SynthesisBrain usage --- fission/src/Synthesis.tsx | 2 -- fission/src/mirabuf/MirabufSceneObject.ts | 4 +++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/fission/src/Synthesis.tsx b/fission/src/Synthesis.tsx index a0708711f5..a650d8a838 100644 --- a/fission/src/Synthesis.tsx +++ b/fission/src/Synthesis.tsx @@ -65,8 +65,6 @@ import RCConfigCANGroupModal from "@/modals/configuring/rio-config/RCConfigCANGr import NewInputSchemeModal from "./ui/modals/configuring/theme-editor/NewInputSchemeModal.tsx" import AssignNewSchemeModal from "./ui/modals/configuring/theme-editor/AssignNewSchemeModal.tsx" -const DEFAULT_MIRA_PATH = "/api/mira/Robots/Team 2471 (2018)_v7.mira" - const worker = new Lazy(() => new WPILibWSWorker()) function Synthesis() { diff --git a/fission/src/mirabuf/MirabufSceneObject.ts b/fission/src/mirabuf/MirabufSceneObject.ts index 111c261853..f744a6f038 100644 --- a/fission/src/mirabuf/MirabufSceneObject.ts +++ b/fission/src/mirabuf/MirabufSceneObject.ts @@ -107,7 +107,9 @@ class MirabufSceneObject extends SceneObject { // creating nametag for robots if (this.miraType === MiraType.ROBOT) { - this._nameTag = new SceneOverlayTag(() => (this._brain ? this._brain.inputSchemeName : "Not Configured")) + this._nameTag = new SceneOverlayTag(() => + this._brain instanceof SynthesisBrain ? this._brain.inputSchemeName : "Not Configured" + ) } } From 4c25491b6f0e60b899e14b9397edd9ca5baff821 Mon Sep 17 00:00:00 2001 From: PepperLola Date: Fri, 26 Jul 2024 13:20:02 -0700 Subject: [PATCH 19/20] deleted commented/unused code and debug logs --- .../simulation/wpilib_brain/WPILibBrain.ts | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/fission/src/systems/simulation/wpilib_brain/WPILibBrain.ts b/fission/src/systems/simulation/wpilib_brain/WPILibBrain.ts index 117eb23be3..3d9ee7d65e 100644 --- a/fission/src/systems/simulation/wpilib_brain/WPILibBrain.ts +++ b/fission/src/systems/simulation/wpilib_brain/WPILibBrain.ts @@ -172,34 +172,26 @@ worker.addEventListener("message", (eventData: MessageEvent) => { return } - // console.debug(data) - const device = data.device const updateData = data.data switch (data.type) { case "PWM": - console.debug("pwm") UpdateSimMap("PWM", device, updateData) break case "Solenoid": - console.debug("solenoid") UpdateSimMap("Solenoid", device, updateData) break case "SimDevice": - console.debug("simdevice") UpdateSimMap("SimDevice", device, updateData) break case "CANMotor": - console.debug("canmotor") UpdateSimMap("CANMotor", device, updateData) break case "CANEncoder": - console.debug("canencoder") UpdateSimMap("CANEncoder", device, updateData) break default: - // console.debug(`Unrecognized Message:\n${data}`) break } }) @@ -226,8 +218,6 @@ class WPILibBrain extends Brain { private _simDevices: SimOutputGroup[] = [] - public static robotsSpawned: string[] = [] - constructor(mechanism: Mechanism) { super(mechanism) @@ -237,13 +227,6 @@ class WPILibBrain extends Brain { console.warn("SimulationLayer is undefined") return } - - // if (mechanism.controllable) { - // WPILibBrain.robotsSpawned.push(this.getNumberedAssemblyName()) - // } - - // WPILibBrain._currentRobotIndex++ - // this.configureArcadeDriveBehavior() } public addSimOutputGroup(device: SimOutputGroup) { @@ -251,7 +234,6 @@ class WPILibBrain extends Brain { } public Update(deltaT: number): void { - // this._behaviors.forEach(b => b.Update(deltaT)) this._simDevices.forEach(d => d.Update(deltaT)) } From a78113e0c99f2c92863cd0d17388c2d3fac65548 Mon Sep 17 00:00:00 2001 From: PepperLola Date: Fri, 26 Jul 2024 15:38:38 -0700 Subject: [PATCH 20/20] fixed build errors --- fission/src/mirabuf/IntakeSensorSceneObject.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/fission/src/mirabuf/IntakeSensorSceneObject.ts b/fission/src/mirabuf/IntakeSensorSceneObject.ts index e852ae7bdc..517ab86423 100644 --- a/fission/src/mirabuf/IntakeSensorSceneObject.ts +++ b/fission/src/mirabuf/IntakeSensorSceneObject.ts @@ -12,6 +12,7 @@ import { } from "@/util/TypeConversions" import { OnContactPersistedEvent } from "@/systems/physics/ContactEvents" import InputSystem from "@/systems/input/InputSystem" +import SynthesisBrain from "@/systems/simulation/synthesis_brain/SynthesisBrain" class IntakeSensorSceneObject extends SceneObject { private _parentAssembly: MirabufSceneObject @@ -53,7 +54,9 @@ class IntakeSensorSceneObject extends SceneObject { World.SceneRenderer.scene.add(this._mesh) this._collision = (event: OnContactPersistedEvent) => { - if (InputSystem.getInput("intake", this._parentAssembly.brain?.brainIndex ?? -1)) { + const brain = this._parentAssembly.brain + const brainIndex = brain instanceof SynthesisBrain ? brain.brainIndex ?? -1 : -1 + if (InputSystem.getInput("intake", brainIndex)) { if (this._joltBodyId && !World.PhysicsSystem.isPaused) { const body1 = event.message.body1 const body2 = event.message.body2