From 01e889dfb9c0f30618531b10a1be0931520a892a Mon Sep 17 00:00:00 2001 From: a-crowell Date: Wed, 31 Jul 2024 13:25:45 -0700 Subject: [PATCH 01/34] Uses velocity and force from mirabuf --- fission/src/mirabuf/MirabufParser.ts | 2 +- fission/src/systems/physics/Mechanism.ts | 1 + fission/src/systems/physics/PhysicsSystem.ts | 30 +++++++++++++------ .../systems/simulation/SimulationSystem.ts | 2 +- .../synthesis/GenericElevatorBehavior.ts | 5 ++-- .../systems/simulation/driver/SliderDriver.ts | 18 ++++++++--- 6 files changed, 40 insertions(+), 18 deletions(-) diff --git a/fission/src/mirabuf/MirabufParser.ts b/fission/src/mirabuf/MirabufParser.ts index dd7df1e7cf..ae1607b97c 100644 --- a/fission/src/mirabuf/MirabufParser.ts +++ b/fission/src/mirabuf/MirabufParser.ts @@ -240,7 +240,7 @@ class MirabufParser { console.log("Failed to get part definitions") return } - console.log(partDefinitions) + console.debug(partDefinitions) } private NewRigidNode(suffix?: string): RigidNode { diff --git a/fission/src/systems/physics/Mechanism.ts b/fission/src/systems/physics/Mechanism.ts index bf6502b4f5..4a240576ed 100644 --- a/fission/src/systems/physics/Mechanism.ts +++ b/fission/src/systems/physics/Mechanism.ts @@ -8,6 +8,7 @@ export interface MechanismConstraint { childBody: Jolt.BodyID constraint: Jolt.Constraint info?: mirabuf.IInfo + maxVelocity: number } class Mechanism { diff --git a/fission/src/systems/physics/PhysicsSystem.ts b/fission/src/systems/physics/PhysicsSystem.ts index 42c43f213a..fce7525811 100644 --- a/fission/src/systems/physics/PhysicsSystem.ts +++ b/fission/src/systems/physics/PhysicsSystem.ts @@ -323,7 +323,7 @@ class PhysicsSystem extends WorldSystem { const jointData = parser.assembly.data!.joints! for (const [jGuid, jInst] of Object.entries(jointData.jointInstances!) as [ string, - mirabuf.joint.JointInstance, + mirabuf.joint.JointInstance ][]) { if (jGuid == GROUNDED_JOINT_ID) continue @@ -350,9 +350,13 @@ class PhysicsSystem extends WorldSystem { const bodyA = this.GetBody(bodyIdA) const bodyB = this.GetBody(bodyIdB) - const constraints: Jolt.Constraint[] = [] + const constraints: [Jolt.Constraint, number][] = [] let listener: Jolt.PhysicsStepListener | undefined = undefined + const motor = jointData.motorDefinitions![jDef.motorReference] + + const maxVel = parser.assembly.data?.joints?.motorDefinitions![jDef.motorReference].simpleMotor?.maxVelocity + switch (jDef.jointMotionType!) { case mirabuf.joint.JointMotion.REVOLUTE: if (this.IsWheel(jDef)) { @@ -364,8 +368,8 @@ class PhysicsSystem extends WorldSystem { bodyB, parser.assembly.info!.version! ) - constraints.push(res[0]) - constraints.push(res[1]) + constraints.push([res[0], maxVel ?? 40]) + constraints.push([res[1], maxVel ?? 40]) listener = res[2] } else { const res = this.CreateWheelConstraint( @@ -375,18 +379,18 @@ class PhysicsSystem extends WorldSystem { bodyA, parser.assembly.info!.version! ) - constraints.push(res[0]) - constraints.push(res[1]) + constraints.push([res[0], maxVel ?? 40]) + constraints.push([res[1], maxVel ?? 40]) listener = res[2] } } else { constraints.push( - this.CreateHingeConstraint(jInst, jDef, bodyA, bodyB, parser.assembly.info!.version!) + [this.CreateHingeConstraint(jInst, jDef, bodyA, bodyB, parser.assembly.info!.version!), maxVel ?? 40] ) } break case mirabuf.joint.JointMotion.SLIDER: - constraints.push(this.CreateSliderConstraint(jInst, jDef, bodyA, bodyB)) + constraints.push([this.CreateSliderConstraint(jInst, jDef, motor, bodyA, bodyB), maxVel ?? 40]) break default: console.debug("Unsupported joint detected. Skipping...") @@ -398,8 +402,10 @@ class PhysicsSystem extends WorldSystem { mechanism.AddConstraint({ parentBody: bodyIdA, childBody: bodyIdB, - constraint: x, + constraint: x[0], + maxVelocity: x[1], info: jInst.info ?? undefined, // remove possibility for null + }) ) } @@ -490,6 +496,7 @@ class PhysicsSystem extends WorldSystem { private CreateSliderConstraint( jointInstance: mirabuf.joint.JointInstance, jointDefinition: mirabuf.joint.Joint, + motor: mirabuf.motor.IMotor, bodyA: Jolt.Body, bodyB: Jolt.Body ): Jolt.Constraint { @@ -535,6 +542,11 @@ class PhysicsSystem extends WorldSystem { sliderConstraintSettings.mLimitsMin = -halfRange } + if (motor.simpleMotor?.stallTorque) { + sliderConstraintSettings.mMotorSettings.mMaxForceLimit = motor.simpleMotor?.stallTorque * 5 + sliderConstraintSettings.mMotorSettings.mMinForceLimit = -sliderConstraintSettings.mMotorSettings.mMaxForceLimit + } + const constraint = sliderConstraintSettings.Create(bodyA, bodyB) this._constraints.push(constraint) diff --git a/fission/src/systems/simulation/SimulationSystem.ts b/fission/src/systems/simulation/SimulationSystem.ts index f0feeba8b2..cd141d98ba 100644 --- a/fission/src/systems/simulation/SimulationSystem.ts +++ b/fission/src/systems/simulation/SimulationSystem.ts @@ -97,7 +97,7 @@ class SimulationLayer { 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, x.info) + const driver = new SliderDriver(slider, x.maxVelocity, x.info) this._drivers.push(driver) const stim = new SliderStimulus(slider) this._stimuli.push(stim) diff --git a/fission/src/systems/simulation/behavior/synthesis/GenericElevatorBehavior.ts b/fission/src/systems/simulation/behavior/synthesis/GenericElevatorBehavior.ts index fb8b237d16..cc5dfda7ee 100644 --- a/fission/src/systems/simulation/behavior/synthesis/GenericElevatorBehavior.ts +++ b/fission/src/systems/simulation/behavior/synthesis/GenericElevatorBehavior.ts @@ -8,8 +8,6 @@ class GenericElevatorBehavior extends Behavior { private _inputName: string private _brainIndex: number - private _linearSpeed = 2.5 - constructor(sliderDriver: SliderDriver, sliderStimulus: SliderStimulus, jointIndex: number, brainIndex: number) { super([sliderDriver], [sliderStimulus]) @@ -20,11 +18,12 @@ class GenericElevatorBehavior extends Behavior { // Changes the elevators target position moveElevator(linearVelocity: number) { + // Multiplied by velocity in driver this._sliderDriver.targetVelocity = linearVelocity } public Update(_: number): void { - this.moveElevator(InputSystem.getInput(this._inputName, this._brainIndex) * this._linearSpeed) + this.moveElevator(InputSystem.getInput(this._inputName, this._brainIndex)) } } diff --git a/fission/src/systems/simulation/driver/SliderDriver.ts b/fission/src/systems/simulation/driver/SliderDriver.ts index dd442b38aa..dcc26e0db0 100644 --- a/fission/src/systems/simulation/driver/SliderDriver.ts +++ b/fission/src/systems/simulation/driver/SliderDriver.ts @@ -10,6 +10,15 @@ class SliderDriver extends Driver { private _controlMode: DriverControlMode = DriverControlMode.Velocity private _targetVelocity: number = 0.0 private _targetPosition: number = 0.0 + private _maxVelocity: number = 0.0 + + public get maxVelocity(): number { + return this._maxVelocity + } + + public set maxVelocity(radsPerSec: number) { + this._maxVelocity = radsPerSec + } public get targetVelocity(): number { return this._targetVelocity @@ -56,7 +65,7 @@ class SliderDriver extends Driver { } } - public constructor(constraint: Jolt.SliderConstraint, info?: mirabuf.IInfo) { + public constructor(constraint: Jolt.SliderConstraint, maxVelocity: number, info?: mirabuf.IInfo) { super(info) this._constraint = constraint @@ -67,8 +76,8 @@ class SliderDriver extends Driver { springSettings.mDamping = 0.999 motorSettings.mSpringSettings = springSettings - motorSettings.mMinForceLimit = -900.0 - motorSettings.mMaxForceLimit = 900.0 + + this._maxVelocity = maxVelocity this._constraint.SetMotorState(JOLT.EMotorState_Velocity) this.controlMode = DriverControlMode.Velocity @@ -76,8 +85,9 @@ class SliderDriver extends Driver { public Update(_: number): void { if (this._controlMode == DriverControlMode.Velocity) { - this._constraint.SetTargetVelocity(this._targetVelocity) + this._constraint.SetTargetVelocity(this._targetVelocity * this._maxVelocity) } else if (this._controlMode == DriverControlMode.Position) { + //TODO: MaxVel checks diff this._constraint.SetTargetPosition(this._targetPosition) } } From 97227e26ef3fa796a4daf9f58949bce10ab4f29f Mon Sep 17 00:00:00 2001 From: a-crowell Date: Wed, 31 Jul 2024 14:30:55 -0700 Subject: [PATCH 02/34] Configure vel and force --- fission/src/Synthesis.tsx | 2 + fission/src/systems/physics/PhysicsSystem.ts | 9 +- .../systems/simulation/driver/SliderDriver.ts | 8 +- fission/src/ui/components/MainHUD.tsx | 1 + .../configuring/ConfigureJointsPanel.tsx | 157 ++++++++++++++++++ 5 files changed, 173 insertions(+), 4 deletions(-) create mode 100644 fission/src/ui/panels/configuring/ConfigureJointsPanel.tsx diff --git a/fission/src/Synthesis.tsx b/fission/src/Synthesis.tsx index 1b3d308176..7fbbff4470 100644 --- a/fission/src/Synthesis.tsx +++ b/fission/src/Synthesis.tsx @@ -40,6 +40,7 @@ import SpawnLocationsPanel from "@/panels/SpawnLocationPanel" import ConfigureGamepiecePickupPanel from "@/panels/configuring/ConfigureGamepiecePickupPanel" import ConfigureShotTrajectoryPanel from "@/panels/configuring/ConfigureShotTrajectoryPanel" import ScoringZonesPanel from "@/panels/configuring/scoring/ScoringZonesPanel" +import ConfigureJointsPanel from "@/panels/configuring/ConfigureJointsPanel" import ScoreboardPanel from "@/panels/information/ScoreboardPanel" import DriverStationPanel from "@/panels/simulation/DriverStationPanel" import PokerPanel from "@/panels/PokerPanel.tsx" @@ -253,6 +254,7 @@ const initialPanels: ReactElement[] = [ , , , + ] export default Synthesis diff --git a/fission/src/systems/physics/PhysicsSystem.ts b/fission/src/systems/physics/PhysicsSystem.ts index fce7525811..2ff61d3725 100644 --- a/fission/src/systems/physics/PhysicsSystem.ts +++ b/fission/src/systems/physics/PhysicsSystem.ts @@ -355,7 +355,10 @@ class PhysicsSystem extends WorldSystem { const motor = jointData.motorDefinitions![jDef.motorReference] - const maxVel = parser.assembly.data?.joints?.motorDefinitions![jDef.motorReference].simpleMotor?.maxVelocity + let maxVel = undefined; + if (parser.assembly.data?.joints?.motorDefinitions && parser.assembly.data?.joints?.motorDefinitions![jDef.motorReference] && parser.assembly.data?.joints?.motorDefinitions![jDef.motorReference].simpleMotor) { + maxVel = parser.assembly.data?.joints?.motorDefinitions![jDef.motorReference].simpleMotor?.maxVelocity + } switch (jDef.jointMotionType!) { case mirabuf.joint.JointMotion.REVOLUTE: @@ -385,12 +388,12 @@ class PhysicsSystem extends WorldSystem { } } else { constraints.push( - [this.CreateHingeConstraint(jInst, jDef, bodyA, bodyB, parser.assembly.info!.version!), maxVel ?? 40] + [this.CreateHingeConstraint(jInst, jDef, bodyA, bodyB, parser.assembly.info!.version!), maxVel ? maxVel /5 : 40] ) } break case mirabuf.joint.JointMotion.SLIDER: - constraints.push([this.CreateSliderConstraint(jInst, jDef, motor, bodyA, bodyB), maxVel ?? 40]) + constraints.push([this.CreateSliderConstraint(jInst, jDef, motor, bodyA, bodyB), maxVel ? maxVel / 5 : 40]) break default: console.debug("Unsupported joint detected. Skipping...") diff --git a/fission/src/systems/simulation/driver/SliderDriver.ts b/fission/src/systems/simulation/driver/SliderDriver.ts index dcc26e0db0..f1de635a9f 100644 --- a/fission/src/systems/simulation/driver/SliderDriver.ts +++ b/fission/src/systems/simulation/driver/SliderDriver.ts @@ -10,7 +10,7 @@ class SliderDriver extends Driver { private _controlMode: DriverControlMode = DriverControlMode.Velocity private _targetVelocity: number = 0.0 private _targetPosition: number = 0.0 - private _maxVelocity: number = 0.0 + private _maxVelocity: number = 1.0 public get maxVelocity(): number { return this._maxVelocity @@ -37,10 +37,16 @@ class SliderDriver extends Driver { ) } + public get minForceLimit(): number { + return this._constraint.GetMotorSettings().get_mMinForceLimit() + } public set minForceLimit(newtons: number) { const motorSettings = this._constraint.GetMotorSettings() motorSettings.mMinForceLimit = newtons } + public get maxForceLimit(): number { + return this._constraint.GetMotorSettings().get_mMaxForceLimit() + } public set maxForceLimit(newtons: number) { const motorSettings = this._constraint.GetMotorSettings() motorSettings.mMaxForceLimit = newtons diff --git a/fission/src/ui/components/MainHUD.tsx b/fission/src/ui/components/MainHUD.tsx index e25a7c6570..59a3679e1a 100644 --- a/fission/src/ui/components/MainHUD.tsx +++ b/fission/src/ui/components/MainHUD.tsx @@ -120,6 +120,7 @@ const MainHUD: React.FC = () => { }} /> } onClick={() => openModal("config-robot")} /> + } onClick={() => openPanel("joint-config")} /> } diff --git a/fission/src/ui/panels/configuring/ConfigureJointsPanel.tsx b/fission/src/ui/panels/configuring/ConfigureJointsPanel.tsx new file mode 100644 index 0000000000..96ac87751a --- /dev/null +++ b/fission/src/ui/panels/configuring/ConfigureJointsPanel.tsx @@ -0,0 +1,157 @@ +import { MiraType } from "@/mirabuf/MirabufLoader" +import MirabufSceneObject from "@/mirabuf/MirabufSceneObject" +import { MechanismConstraint } from "@/systems/physics/Mechanism" +import Driver from "@/systems/simulation/driver/Driver" +import SliderDriver from "@/systems/simulation/driver/SliderDriver" +import World from "@/systems/World" +import Button from "@/ui/components/Button" +import Label, { LabelSize } from "@/ui/components/Label" +import Panel, { PanelPropsImpl } from "@/ui/components/Panel" +import ScrollView from "@/ui/components/ScrollView" +import Slider from "@/ui/components/Slider" +import Stack, { StackDirection } from "@/ui/components/Stack" +import { useTheme } from "@/ui/ThemeContext" +import { Box } from "@mui/material" +import { useEffect, useMemo, useState } from "react" +import { FaGear } from "react-icons/fa6" + +type JointRowProps = { + driver: Driver +} + +const JointRow: React.FC = ({ driver }) => { + const [velocity, setVelocity] = useState((driver as SliderDriver).maxVelocity) + const [force, setForce] = useState((driver as SliderDriver).maxForceLimit) + + return ( + + + + { + setVelocity(vel as number); + (driver as SliderDriver).maxVelocity = velocity + }} + step={0.01} + /> + { + setForce(forc as number); + (driver as SliderDriver).maxForceLimit = force; + (driver as SliderDriver).minForceLimit = -force + }} + step={0.01} + /> + + + ) +} + + +const ConfigureJointsPanel: React.FC = ({ panelId, openLocation, sidePadding}) => { + const { currentTheme, themes } = useTheme() + const theme = useMemo(() => { + return themes[currentTheme] + }, [currentTheme, themes]) + + const [selectedRobot, setSelectedRobot] = useState(undefined) + + const robots = useMemo(() => { + const assemblies = [...World.SceneRenderer.sceneObjects.values()].filter(x => { + if (x instanceof MirabufSceneObject) { + return x.miraType === MiraType.ROBOT + } + return false + }) as MirabufSceneObject[] + return assemblies + }, []) + + const drivers = useMemo(() => { + return selectedRobot?.mechanism ? + World.SimulationSystem.GetSimulationLayer(selectedRobot.mechanism)?.drivers : undefined + }, [selectedRobot]) + + + return ( + } + panelId={panelId} + openLocation={openLocation} + sidePadding={sidePadding} + onAccept={() => {}} + onCancel={() => {/* Back to original */ }} + acceptEnabled={true} + > + {selectedRobot?.ejectorPreferences == undefined ? ( + <> + + {/** Scroll view for selecting a robot to configure */} +
+ {robots.map(mirabufSceneObject => { + return ( + + ) + })} +
+ + ) : ( + <> + {/* {selectedRobot.mechanism.constraints.filter(x=> x.constraint.GetSubType() == JOLT.EConstraintSubType_Slider).length > 0 ? ( + + {selectedRobot.mechanism.constraints.filter(x=> x.constraint.GetSubType() == JOLT.EConstraintSubType_Slider).map((mechanism: MechanismConstraint, i: number) => ( + + { + return driver + })()} + /> + + ))} + + ) : ( + + )} */} + + {drivers ? ( + + {drivers.filter(x => x instanceof SliderDriver).map((driver: Driver, i: number) => ( + { + return driver + })()} + /> + + ))} + + ) : ( + + )} + + )} + + +
+ + ) +} + +export default ConfigureJointsPanel \ No newline at end of file From bed9f1655427830e0afaecf707197db175a4ca1d Mon Sep 17 00:00:00 2001 From: a-crowell Date: Wed, 31 Jul 2024 14:37:07 -0700 Subject: [PATCH 03/34] Clean up --- .../configuring/ConfigureJointsPanel.tsx | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/fission/src/ui/panels/configuring/ConfigureJointsPanel.tsx b/fission/src/ui/panels/configuring/ConfigureJointsPanel.tsx index 96ac87751a..dc1f66b195 100644 --- a/fission/src/ui/panels/configuring/ConfigureJointsPanel.tsx +++ b/fission/src/ui/panels/configuring/ConfigureJointsPanel.tsx @@ -1,6 +1,5 @@ import { MiraType } from "@/mirabuf/MirabufLoader" import MirabufSceneObject from "@/mirabuf/MirabufSceneObject" -import { MechanismConstraint } from "@/systems/physics/Mechanism" import Driver from "@/systems/simulation/driver/Driver" import SliderDriver from "@/systems/simulation/driver/SliderDriver" import World from "@/systems/World" @@ -12,7 +11,7 @@ import Slider from "@/ui/components/Slider" import Stack, { StackDirection } from "@/ui/components/Stack" import { useTheme } from "@/ui/ThemeContext" import { Box } from "@mui/material" -import { useEffect, useMemo, useState } from "react" +import { useMemo, useState } from "react" import { FaGear } from "react-icons/fa6" type JointRowProps = { @@ -113,22 +112,6 @@ const ConfigureJointsPanel: React.FC = ({ panelId, openLocation, ) : ( <> - {/* {selectedRobot.mechanism.constraints.filter(x=> x.constraint.GetSubType() == JOLT.EConstraintSubType_Slider).length > 0 ? ( - - {selectedRobot.mechanism.constraints.filter(x=> x.constraint.GetSubType() == JOLT.EConstraintSubType_Slider).map((mechanism: MechanismConstraint, i: number) => ( - - { - return driver - })()} - /> - - ))} - - ) : ( - - )} */} {drivers ? ( From 16b988af92caaad59892cae5d308056844ec5b1e Mon Sep 17 00:00:00 2001 From: a-crowell Date: Wed, 31 Jul 2024 14:47:19 -0700 Subject: [PATCH 04/34] Merge conflicts --- fission/src/ui/components/MainHUD.tsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/fission/src/ui/components/MainHUD.tsx b/fission/src/ui/components/MainHUD.tsx index 0cc48c2b14..c29d1b1a5c 100644 --- a/fission/src/ui/components/MainHUD.tsx +++ b/fission/src/ui/components/MainHUD.tsx @@ -10,6 +10,7 @@ import APS, { APS_USER_INFO_UPDATE_EVENT } from "@/aps/APS" import { UserIcon } from "./UserIcon" import { Button } from "@mui/base/Button" import { ButtonIcon, SynthesisIcons } from "./StyledComponents" +import Synthesis from "@/Synthesis" type ButtonProps = { value: string @@ -119,8 +120,8 @@ const MainHUD: React.FC = () => { openPanel("scoring-zones") }} /> - } onClick={() => openModal("config-robot")} /> - } onClick={() => openPanel("joint-config")} /> + openModal("config-robot")} /> + openPanel("joint-config")} /> Date: Wed, 31 Jul 2024 17:23:29 -0700 Subject: [PATCH 05/34] Saves in prefs --- fission/src/systems/physics/PhysicsSystem.ts | 26 ++++++---- .../systems/preferences/PreferenceTypes.ts | 8 +++ .../systems/simulation/driver/SliderDriver.ts | 15 ++---- fission/src/ui/components/MainHUD.tsx | 1 - .../configuring/ConfigureJointsPanel.tsx | 52 +++++++++++++++---- 5 files changed, 71 insertions(+), 31 deletions(-) diff --git a/fission/src/systems/physics/PhysicsSystem.ts b/fission/src/systems/physics/PhysicsSystem.ts index 2ff61d3725..4dd011d066 100644 --- a/fission/src/systems/physics/PhysicsSystem.ts +++ b/fission/src/systems/physics/PhysicsSystem.ts @@ -23,6 +23,7 @@ import { OnContactValidateData, PhysicsEvent, } from "./ContactEvents" +import PreferencesSystem from "../preferences/PreferencesSystem" export type JoltBodyIndexAndSequence = number @@ -353,12 +354,20 @@ class PhysicsSystem extends WorldSystem { const constraints: [Jolt.Constraint, number][] = [] let listener: Jolt.PhysicsStepListener | undefined = undefined - const motor = jointData.motorDefinitions![jDef.motorReference] - + const motors = PreferencesSystem.getRobotPreferences(parser.assembly.info?.name ?? "").motors + let maxForce = jointData.motorDefinitions![jDef.motorReference].simpleMotor?.stallTorque let maxVel = undefined; if (parser.assembly.data?.joints?.motorDefinitions && parser.assembly.data?.joints?.motorDefinitions![jDef.motorReference] && parser.assembly.data?.joints?.motorDefinitions![jDef.motorReference].simpleMotor) { maxVel = parser.assembly.data?.joints?.motorDefinitions![jDef.motorReference].simpleMotor?.maxVelocity } + if (motors) { + const thisMotor = motors.filter(x => x.name == jInst.info?.name) + if (thisMotor && thisMotor[0]) { + maxVel = thisMotor[0].maxVelocity + maxForce = thisMotor[0].maxForce + } + + } switch (jDef.jointMotionType!) { case mirabuf.joint.JointMotion.REVOLUTE: @@ -388,12 +397,13 @@ class PhysicsSystem extends WorldSystem { } } else { constraints.push( - [this.CreateHingeConstraint(jInst, jDef, bodyA, bodyB, parser.assembly.info!.version!), maxVel ? maxVel /5 : 40] + [this.CreateHingeConstraint(jInst, jDef, bodyA, bodyB, parser.assembly.info!.version!), maxVel ? maxVel : 40] ) } break case mirabuf.joint.JointMotion.SLIDER: - constraints.push([this.CreateSliderConstraint(jInst, jDef, motor, bodyA, bodyB), maxVel ? maxVel / 5 : 40]) + + constraints.push([this.CreateSliderConstraint(jInst, jDef, maxForce ?? 200, bodyA, bodyB), maxVel ? maxVel : 40]) break default: console.debug("Unsupported joint detected. Skipping...") @@ -499,7 +509,7 @@ class PhysicsSystem extends WorldSystem { private CreateSliderConstraint( jointInstance: mirabuf.joint.JointInstance, jointDefinition: mirabuf.joint.Joint, - motor: mirabuf.motor.IMotor, + maxForce: number, bodyA: Jolt.Body, bodyB: Jolt.Body ): Jolt.Constraint { @@ -545,10 +555,8 @@ class PhysicsSystem extends WorldSystem { sliderConstraintSettings.mLimitsMin = -halfRange } - if (motor.simpleMotor?.stallTorque) { - sliderConstraintSettings.mMotorSettings.mMaxForceLimit = motor.simpleMotor?.stallTorque * 5 - sliderConstraintSettings.mMotorSettings.mMinForceLimit = -sliderConstraintSettings.mMotorSettings.mMaxForceLimit - } + sliderConstraintSettings.mMotorSettings.mMaxForceLimit = maxForce + sliderConstraintSettings.mMotorSettings.mMinForceLimit = -sliderConstraintSettings.mMotorSettings.mMaxForceLimit const constraint = sliderConstraintSettings.Create(bodyA, bodyB) diff --git a/fission/src/systems/preferences/PreferenceTypes.ts b/fission/src/systems/preferences/PreferenceTypes.ts index 37b04a83ce..27c1821ac6 100644 --- a/fission/src/systems/preferences/PreferenceTypes.ts +++ b/fission/src/systems/preferences/PreferenceTypes.ts @@ -45,10 +45,17 @@ export type EjectorPreferences = { export type RobotPreferences = { inputsSchemes: InputScheme[] + motors: MotorPreferences[] intake: IntakePreferences ejector: EjectorPreferences } +export type MotorPreferences = { + name: string + maxVelocity: number + maxForce: number +} + export type Alliance = "red" | "blue" export type ScoringZonePreferences = { @@ -70,6 +77,7 @@ export type FieldPreferences = { export function DefaultRobotPreferences(): RobotPreferences { return { inputsSchemes: [], + motors: [], intake: { deltaTransformation: [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], zoneDiameter: 0.5, diff --git a/fission/src/systems/simulation/driver/SliderDriver.ts b/fission/src/systems/simulation/driver/SliderDriver.ts index f1de635a9f..06dcb2e830 100644 --- a/fission/src/systems/simulation/driver/SliderDriver.ts +++ b/fission/src/systems/simulation/driver/SliderDriver.ts @@ -3,6 +3,7 @@ import Driver, { DriverControlMode } from "./Driver" import { GetLastDeltaT } from "@/systems/physics/PhysicsSystem" import JOLT from "@/util/loading/JoltSyncLoader" import { mirabuf } from "@/proto/mirabuf" +import PreferencesSystem from "@/systems/preferences/PreferencesSystem" class SliderDriver extends Driver { private _constraint: Jolt.SliderConstraint @@ -37,19 +38,13 @@ class SliderDriver extends Driver { ) } - public get minForceLimit(): number { - return this._constraint.GetMotorSettings().get_mMinForceLimit() + public get maxForce(): number { + return this._constraint.GetMotorSettings().mMaxForceLimit } - public set minForceLimit(newtons: number) { - const motorSettings = this._constraint.GetMotorSettings() - motorSettings.mMinForceLimit = newtons - } - public get maxForceLimit(): number { - return this._constraint.GetMotorSettings().get_mMaxForceLimit() - } - public set maxForceLimit(newtons: number) { + public set maxForce(newtons: number) { const motorSettings = this._constraint.GetMotorSettings() motorSettings.mMaxForceLimit = newtons + motorSettings.mMinForceLimit = -newtons } public get controlMode(): DriverControlMode { diff --git a/fission/src/ui/components/MainHUD.tsx b/fission/src/ui/components/MainHUD.tsx index c29d1b1a5c..af43cd3521 100644 --- a/fission/src/ui/components/MainHUD.tsx +++ b/fission/src/ui/components/MainHUD.tsx @@ -120,7 +120,6 @@ const MainHUD: React.FC = () => { openPanel("scoring-zones") }} /> - openModal("config-robot")} /> openPanel("joint-config")} /> = ({ driver }) => { +const JointRow: React.FC = ({ robot, driver }) => { const [velocity, setVelocity] = useState((driver as SliderDriver).maxVelocity) - const [force, setForce] = useState((driver as SliderDriver).maxForceLimit) + const [force, setForce] = useState((driver as SliderDriver).maxForce) return ( @@ -34,7 +36,22 @@ const JointRow: React.FC = ({ driver }) => { format={{ minimumFractionDigits: 2, maximumFractionDigits: 2 }} onChange={(_, vel: number | number[]) => { setVelocity(vel as number); - (driver as SliderDriver).maxVelocity = velocity + (driver as SliderDriver).maxVelocity = vel as number + if (driver.info && driver.info.name) { + const removedMotor = PreferencesSystem.getRobotPreferences(robot.assemblyName).motors ? PreferencesSystem.getRobotPreferences(robot.assemblyName).motors.filter(x => { + if (x.name) + return x.name != driver.info?.name + return false + }) : [] + + removedMotor.push({ + name: driver.info?.name ?? "", + maxVelocity: vel as number, + maxForce: force}) + + PreferencesSystem.getRobotPreferences(robot.assemblyName).motors = removedMotor + PreferencesSystem.savePreferences() + } }} step={0.01} /> @@ -46,8 +63,22 @@ const JointRow: React.FC = ({ driver }) => { format={{ minimumFractionDigits: 2, maximumFractionDigits: 2 }} onChange={(_, forc: number | number[]) => { setForce(forc as number); - (driver as SliderDriver).maxForceLimit = force; - (driver as SliderDriver).minForceLimit = -force + (driver as SliderDriver).maxForce = forc as number + if (driver.info && driver.info.name) { + const removedMotor = PreferencesSystem.getRobotPreferences(robot.assemblyName).motors ? PreferencesSystem.getRobotPreferences(robot.assemblyName).motors.filter(x => { + if (x.name) + return x.name != driver.info?.name + return false + }) : [] + + removedMotor.push({ + name: driver.info?.name ?? "", + maxVelocity: velocity, + maxForce: forc as number}) + + PreferencesSystem.getRobotPreferences(robot.assemblyName).motors = removedMotor + PreferencesSystem.savePreferences() + } }} step={0.01} /> @@ -58,10 +89,6 @@ const JointRow: React.FC = ({ driver }) => { const ConfigureJointsPanel: React.FC = ({ panelId, openLocation, sidePadding}) => { - const { currentTheme, themes } = useTheme() - const theme = useMemo(() => { - return themes[currentTheme] - }, [currentTheme, themes]) const [selectedRobot, setSelectedRobot] = useState(undefined) @@ -88,7 +115,7 @@ const ConfigureJointsPanel: React.FC = ({ panelId, openLocation, panelId={panelId} openLocation={openLocation} sidePadding={sidePadding} - onAccept={() => {}} + onAccept={() => { PreferencesSystem.savePreferences()}} onCancel={() => {/* Back to original */ }} acceptEnabled={true} > @@ -118,6 +145,9 @@ const ConfigureJointsPanel: React.FC = ({ panelId, openLocation, {drivers.filter(x => x instanceof SliderDriver).map((driver: Driver, i: number) => ( { + return selectedRobot + })()} driver={(() => { return driver })()} From 85966701b149167f5c2cdd33dfa7ae7c368748ec Mon Sep 17 00:00:00 2001 From: a-crowell Date: Wed, 31 Jul 2024 18:04:59 -0700 Subject: [PATCH 06/34] HingeDrivers --- fission/src/systems/physics/PhysicsSystem.ts | 15 +-- .../systems/simulation/SimulationSystem.ts | 2 +- .../behavior/synthesis/GenericArmBehavior.ts | 4 +- .../systems/simulation/driver/HingeDriver.ts | 26 ++-- .../systems/simulation/driver/SliderDriver.ts | 1 - .../configuring/ConfigureJointsPanel.tsx | 112 +++++++++++------- 6 files changed, 94 insertions(+), 66 deletions(-) diff --git a/fission/src/systems/physics/PhysicsSystem.ts b/fission/src/systems/physics/PhysicsSystem.ts index 4dd011d066..5f438fd913 100644 --- a/fission/src/systems/physics/PhysicsSystem.ts +++ b/fission/src/systems/physics/PhysicsSystem.ts @@ -355,18 +355,14 @@ class PhysicsSystem extends WorldSystem { let listener: Jolt.PhysicsStepListener | undefined = undefined const motors = PreferencesSystem.getRobotPreferences(parser.assembly.info?.name ?? "").motors + let maxVel = jointData.motorDefinitions![jDef.motorReference].simpleMotor?.maxVelocity let maxForce = jointData.motorDefinitions![jDef.motorReference].simpleMotor?.stallTorque - let maxVel = undefined; - if (parser.assembly.data?.joints?.motorDefinitions && parser.assembly.data?.joints?.motorDefinitions![jDef.motorReference] && parser.assembly.data?.joints?.motorDefinitions![jDef.motorReference].simpleMotor) { - maxVel = parser.assembly.data?.joints?.motorDefinitions![jDef.motorReference].simpleMotor?.maxVelocity - } if (motors) { const thisMotor = motors.filter(x => x.name == jInst.info?.name) - if (thisMotor && thisMotor[0]) { + if (thisMotor[0]) { maxVel = thisMotor[0].maxVelocity maxForce = thisMotor[0].maxForce } - } switch (jDef.jointMotionType!) { @@ -397,7 +393,7 @@ class PhysicsSystem extends WorldSystem { } } else { constraints.push( - [this.CreateHingeConstraint(jInst, jDef, bodyA, bodyB, parser.assembly.info!.version!), maxVel ? maxVel : 40] + [this.CreateHingeConstraint(jInst, jDef, maxForce ?? 200, bodyA, bodyB, parser.assembly.info!.version!), maxVel ? maxVel : 40] ) } break @@ -441,6 +437,7 @@ class PhysicsSystem extends WorldSystem { private CreateHingeConstraint( jointInstance: mirabuf.joint.JointInstance, jointDefinition: mirabuf.joint.Joint, + torque: number, bodyA: Jolt.Body, bodyB: Jolt.Body, versionNum: number @@ -490,6 +487,10 @@ class PhysicsSystem extends WorldSystem { hingeConstraintSettings.mLimitsMax = -lower } + hingeConstraintSettings.mMotorSettings.mMaxTorqueLimit = torque + hingeConstraintSettings.mMotorSettings.mMinTorqueLimit = -torque + + const constraint = hingeConstraintSettings.Create(bodyA, bodyB) this._joltPhysSystem.AddConstraint(constraint) diff --git a/fission/src/systems/simulation/SimulationSystem.ts b/fission/src/systems/simulation/SimulationSystem.ts index cd141d98ba..93e585c369 100644 --- a/fission/src/systems/simulation/SimulationSystem.ts +++ b/fission/src/systems/simulation/SimulationSystem.ts @@ -85,7 +85,7 @@ 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, x.info) + const driver = new HingeDriver(hinge, x.maxVelocity, x.info) this._drivers.push(driver) const stim = new HingeStimulus(hinge) this._stimuli.push(stim) diff --git a/fission/src/systems/simulation/behavior/synthesis/GenericArmBehavior.ts b/fission/src/systems/simulation/behavior/synthesis/GenericArmBehavior.ts index a9d19c5c03..1d55bfd9e6 100644 --- a/fission/src/systems/simulation/behavior/synthesis/GenericArmBehavior.ts +++ b/fission/src/systems/simulation/behavior/synthesis/GenericArmBehavior.ts @@ -8,8 +8,6 @@ class GenericArmBehavior extends Behavior { private _inputName: string private _brainIndex: number - private _rotationalSpeed = 6 - constructor(hingeDriver: HingeDriver, hingeStimulus: HingeStimulus, jointIndex: number, brainIndex: number) { super([hingeDriver], [hingeStimulus]) @@ -24,7 +22,7 @@ class GenericArmBehavior extends Behavior { } public Update(_: number): void { - this.rotateArm(InputSystem.getInput(this._inputName, this._brainIndex) * this._rotationalSpeed) + this.rotateArm(InputSystem.getInput(this._inputName, this._brainIndex)) } } diff --git a/fission/src/systems/simulation/driver/HingeDriver.ts b/fission/src/systems/simulation/driver/HingeDriver.ts index 29ab7fc6af..aa9ef3aeb5 100644 --- a/fission/src/systems/simulation/driver/HingeDriver.ts +++ b/fission/src/systems/simulation/driver/HingeDriver.ts @@ -10,6 +10,15 @@ class HingeDriver extends Driver { private _controlMode: DriverControlMode = DriverControlMode.Velocity private _targetVelocity: number = 0.0 private _targetAngle: number + private _maxVelocity: number + + public get maxVelocity(): number { + return this._maxVelocity + } + + public set maxVelocity(radsPerSec: number) { + this._maxVelocity = radsPerSec + } public get targetVelocity(): number { return this._targetVelocity @@ -25,13 +34,14 @@ class HingeDriver extends Driver { this._targetAngle = Math.max(this._constraint.GetLimitsMin(), Math.min(this._constraint.GetLimitsMax(), rads)) } - public set minTorqueLimit(nm: number) { - const motorSettings = this._constraint.GetMotorSettings() - motorSettings.mMinTorqueLimit = nm + public get maxTorque() { + return this._constraint.GetMotorSettings().mMaxTorqueLimit } - public set maxTorqueLimit(nm: number) { + + public set maxTorque(nm: number) { const motorSettings = this._constraint.GetMotorSettings() motorSettings.mMaxTorqueLimit = nm + motorSettings.mMinTorqueLimit = -nm } public get controlMode(): DriverControlMode { @@ -53,7 +63,7 @@ class HingeDriver extends Driver { } } - public constructor(constraint: Jolt.HingeConstraint, info?: mirabuf.IInfo) { + public constructor(constraint: Jolt.HingeConstraint, maxVelocity: number, info?: mirabuf.IInfo) { super(info) this._constraint = constraint @@ -66,18 +76,18 @@ class HingeDriver extends Driver { springSettings.mDamping = 0.995 motorSettings.mSpringSettings = springSettings - motorSettings.mMinTorqueLimit = -200.0 - motorSettings.mMaxTorqueLimit = 200.0 this._targetAngle = this._constraint.GetCurrentAngle() + this._maxVelocity = maxVelocity this.controlMode = DriverControlMode.Velocity } public Update(_: number): void { if (this._controlMode == DriverControlMode.Velocity) { - this._constraint.SetTargetAngularVelocity(this._targetVelocity) + this._constraint.SetTargetAngularVelocity(this._targetVelocity * this._maxVelocity) } else if (this._controlMode == DriverControlMode.Position) { + //TODO add maxVel to diff this._constraint.SetTargetAngle(this._targetAngle) } } diff --git a/fission/src/systems/simulation/driver/SliderDriver.ts b/fission/src/systems/simulation/driver/SliderDriver.ts index 06dcb2e830..f00249f521 100644 --- a/fission/src/systems/simulation/driver/SliderDriver.ts +++ b/fission/src/systems/simulation/driver/SliderDriver.ts @@ -3,7 +3,6 @@ import Driver, { DriverControlMode } from "./Driver" import { GetLastDeltaT } from "@/systems/physics/PhysicsSystem" import JOLT from "@/util/loading/JoltSyncLoader" import { mirabuf } from "@/proto/mirabuf" -import PreferencesSystem from "@/systems/preferences/PreferencesSystem" class SliderDriver extends Driver { private _constraint: Jolt.SliderConstraint diff --git a/fission/src/ui/panels/configuring/ConfigureJointsPanel.tsx b/fission/src/ui/panels/configuring/ConfigureJointsPanel.tsx index 4847c69ab5..f3545d308d 100644 --- a/fission/src/ui/panels/configuring/ConfigureJointsPanel.tsx +++ b/fission/src/ui/panels/configuring/ConfigureJointsPanel.tsx @@ -2,6 +2,7 @@ import { MiraType } from "@/mirabuf/MirabufLoader" import MirabufSceneObject from "@/mirabuf/MirabufSceneObject" import PreferencesSystem from "@/systems/preferences/PreferencesSystem" import Driver from "@/systems/simulation/driver/Driver" +import HingeDriver from "@/systems/simulation/driver/HingeDriver" import SliderDriver from "@/systems/simulation/driver/SliderDriver" import World from "@/systems/World" import Button from "@/ui/components/Button" @@ -10,9 +11,8 @@ import Panel, { PanelPropsImpl } from "@/ui/components/Panel" import ScrollView from "@/ui/components/ScrollView" import Slider from "@/ui/components/Slider" import Stack, { StackDirection } from "@/ui/components/Stack" -import { useTheme } from "@/ui/ThemeContext" import { Box } from "@mui/material" -import { useEffect, useMemo, useState } from "react" +import { useMemo, useState } from "react" import { FaGear } from "react-icons/fa6" type JointRowProps = { @@ -21,64 +21,84 @@ type JointRowProps = { } const JointRow: React.FC = ({ robot, driver }) => { - const [velocity, setVelocity] = useState((driver as SliderDriver).maxVelocity) - const [force, setForce] = useState((driver as SliderDriver).maxForce) + const [velocity, setVelocity] = useState(() => { + switch (driver.constructor) { + case SliderDriver: + return (driver as SliderDriver).maxVelocity + case HingeDriver: + return (driver as HingeDriver).maxVelocity + default: + return 40 + } + }) + const [force, setForce] = useState(() => { + switch (driver.constructor) { + case SliderDriver: + return (driver as SliderDriver).maxForce + case HingeDriver: + return (driver as HingeDriver).maxTorque + default: + return 40 + } + }) + + const onChange = (vel: number, force: number) => { + (driver as SliderDriver || driver as HingeDriver).maxVelocity = vel + switch (driver.constructor) { + case SliderDriver: + (driver as SliderDriver).maxForce = force + break + case HingeDriver: + (driver as HingeDriver).maxTorque = force + break + default: + return 40 + } + + // Preferences + if (driver.info && driver.info.name) { + const removedMotor = PreferencesSystem.getRobotPreferences(robot.assemblyName).motors ? PreferencesSystem.getRobotPreferences(robot.assemblyName).motors.filter(x => { + if (x.name) + return x.name != driver.info?.name + return false + }) : [] + + removedMotor.push({ + name: driver.info?.name ?? "", + maxVelocity: vel, + maxForce: force}) + + PreferencesSystem.getRobotPreferences(robot.assemblyName).motors = removedMotor + PreferencesSystem.savePreferences() + } + } + return ( - + { - setVelocity(vel as number); - (driver as SliderDriver).maxVelocity = vel as number - if (driver.info && driver.info.name) { - const removedMotor = PreferencesSystem.getRobotPreferences(robot.assemblyName).motors ? PreferencesSystem.getRobotPreferences(robot.assemblyName).motors.filter(x => { - if (x.name) - return x.name != driver.info?.name - return false - }) : [] - - removedMotor.push({ - name: driver.info?.name ?? "", - maxVelocity: vel as number, - maxForce: force}) - - PreferencesSystem.getRobotPreferences(robot.assemblyName).motors = removedMotor - PreferencesSystem.savePreferences() - } + onChange={(_, _velocity: number | number[]) => { + setVelocity(_velocity as number); + onChange(_velocity as number, force) }} step={0.01} /> {return driver instanceof HingeDriver ? 20 : 100})()} + max={(() => {return driver instanceof HingeDriver ? 200 : 800})()} value={force} - label="Force" + label={(() => {return driver instanceof HingeDriver ? "Max Torque" : "Max Force"})()} format={{ minimumFractionDigits: 2, maximumFractionDigits: 2 }} - onChange={(_, forc: number | number[]) => { - setForce(forc as number); - (driver as SliderDriver).maxForce = forc as number - if (driver.info && driver.info.name) { - const removedMotor = PreferencesSystem.getRobotPreferences(robot.assemblyName).motors ? PreferencesSystem.getRobotPreferences(robot.assemblyName).motors.filter(x => { - if (x.name) - return x.name != driver.info?.name - return false - }) : [] - - removedMotor.push({ - name: driver.info?.name ?? "", - maxVelocity: velocity, - maxForce: forc as number}) - - PreferencesSystem.getRobotPreferences(robot.assemblyName).motors = removedMotor - PreferencesSystem.savePreferences() - } + onChange={(_, _force: number | number[]) => { + setForce(_force as number); + onChange(velocity, _force as number) }} step={0.01} /> @@ -142,7 +162,7 @@ const ConfigureJointsPanel: React.FC = ({ panelId, openLocation, {drivers ? ( - {drivers.filter(x => x instanceof SliderDriver).map((driver: Driver, i: number) => ( + {drivers.filter(x => x instanceof SliderDriver || x instanceof HingeDriver).map((driver: Driver, i: number) => ( { @@ -156,7 +176,7 @@ const ConfigureJointsPanel: React.FC = ({ panelId, openLocation, ))} ) : ( - + )} )} From 4c8f71d97dc0afc8914a912d18ad90f708934262 Mon Sep 17 00:00:00 2001 From: a-crowell Date: Thu, 1 Aug 2024 14:38:32 -0700 Subject: [PATCH 07/34] Drivetrain --- fission/src/systems/physics/PhysicsSystem.ts | 17 ++- .../systems/preferences/PreferenceTypes.ts | 4 + .../systems/simulation/SimulationSystem.ts | 2 +- .../behavior/synthesis/ArcadeDriveBehavior.ts | 5 +- .../systems/simulation/driver/HingeDriver.ts | 4 +- .../systems/simulation/driver/WheelDriver.ts | 34 +++++- .../configuring/ConfigureJointsPanel.tsx | 111 ++++++++++-------- 7 files changed, 119 insertions(+), 58 deletions(-) diff --git a/fission/src/systems/physics/PhysicsSystem.ts b/fission/src/systems/physics/PhysicsSystem.ts index 5f438fd913..8e2e4d806c 100644 --- a/fission/src/systems/physics/PhysicsSystem.ts +++ b/fission/src/systems/physics/PhysicsSystem.ts @@ -108,7 +108,7 @@ class PhysicsSystem extends WorldSystem { const ground = this.CreateBox( new THREE.Vector3(5.0, 0.5, 5.0), undefined, - new THREE.Vector3(0.0, -2.05, 0.0), + new THREE.Vector3(0.0, -2.0, 0.0), undefined ) ground.SetFriction(FLOOR_FRICTION) @@ -354,9 +354,10 @@ class PhysicsSystem extends WorldSystem { const constraints: [Jolt.Constraint, number][] = [] let listener: Jolt.PhysicsStepListener | undefined = undefined - const motors = PreferencesSystem.getRobotPreferences(parser.assembly.info?.name ?? "").motors + // maxForce becomes maxForce for sliders, maxTorque for hinges, and maxAcceleration for wheels let maxVel = jointData.motorDefinitions![jDef.motorReference].simpleMotor?.maxVelocity let maxForce = jointData.motorDefinitions![jDef.motorReference].simpleMotor?.stallTorque + const motors = PreferencesSystem.getRobotPreferences(parser.assembly.info?.name ?? "").motors if (motors) { const thisMotor = motors.filter(x => x.name == jInst.info?.name) if (thisMotor[0]) { @@ -368,10 +369,17 @@ class PhysicsSystem extends WorldSystem { switch (jDef.jointMotionType!) { case mirabuf.joint.JointMotion.REVOLUTE: if (this.IsWheel(jDef)) { + const prefVel = PreferencesSystem.getRobotPreferences(parser.assembly.info?.name ?? "").driveVelocity + if (prefVel > 0) maxVel = prefVel + + const prefAcc = PreferencesSystem.getRobotPreferences(parser.assembly.info?.name ?? "").driveAcceleration + if (prefAcc > 0) maxForce = prefAcc + if (parser.directedGraph.GetAdjacencyList(rnA.id).length > 0) { const res = this.CreateWheelConstraint( jInst, jDef, + maxForce ?? 1.5, bodyA, bodyB, parser.assembly.info!.version! @@ -383,6 +391,7 @@ class PhysicsSystem extends WorldSystem { const res = this.CreateWheelConstraint( jInst, jDef, + maxForce ?? 1.5, bodyB, bodyA, parser.assembly.info!.version! @@ -492,6 +501,7 @@ class PhysicsSystem extends WorldSystem { const constraint = hingeConstraintSettings.Create(bodyA, bodyB) + this._constraints.push(constraint) this._joltPhysSystem.AddConstraint(constraint) return constraint @@ -570,6 +580,7 @@ class PhysicsSystem extends WorldSystem { public CreateWheelConstraint( jointInstance: mirabuf.joint.JointInstance, jointDefinition: mirabuf.joint.Joint, + maxAcc: number, bodyMain: Jolt.Body, bodyWheel: Jolt.Body, versionNum: number @@ -617,7 +628,7 @@ class PhysicsSystem extends WorldSystem { vehicleSettings.mWheels.push_back(wheelSettings) const controllerSettings = new JOLT.WheeledVehicleControllerSettings() - controllerSettings.mEngine.mMaxTorque = 1500.0 + controllerSettings.mEngine.mMaxTorque = maxAcc controllerSettings.mTransmission.mClutchStrength = 10.0 controllerSettings.mTransmission.mGearRatios.clear() controllerSettings.mTransmission.mGearRatios.push_back(2) diff --git a/fission/src/systems/preferences/PreferenceTypes.ts b/fission/src/systems/preferences/PreferenceTypes.ts index 27c1821ac6..d044a1ce22 100644 --- a/fission/src/systems/preferences/PreferenceTypes.ts +++ b/fission/src/systems/preferences/PreferenceTypes.ts @@ -48,6 +48,8 @@ export type RobotPreferences = { motors: MotorPreferences[] intake: IntakePreferences ejector: EjectorPreferences + driveVelocity: number + driveAcceleration: number } export type MotorPreferences = { @@ -88,6 +90,8 @@ export function DefaultRobotPreferences(): RobotPreferences { ejectorVelocity: 1, parentNode: undefined, }, + driveVelocity: 0, + driveAcceleration: 0 } } diff --git a/fission/src/systems/simulation/SimulationSystem.ts b/fission/src/systems/simulation/SimulationSystem.ts index 93e585c369..e9bad980f6 100644 --- a/fission/src/systems/simulation/SimulationSystem.ts +++ b/fission/src/systems/simulation/SimulationSystem.ts @@ -91,7 +91,7 @@ class SimulationLayer { 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, x.info) + const driver = new WheelDriver(vehicle, x.maxVelocity, x.info) this._drivers.push(driver) const stim = new WheelRotationStimulus(vehicle.GetWheel(0)) this._stimuli.push(stim) diff --git a/fission/src/systems/simulation/behavior/synthesis/ArcadeDriveBehavior.ts b/fission/src/systems/simulation/behavior/synthesis/ArcadeDriveBehavior.ts index 6851ad4305..035db861d0 100644 --- a/fission/src/systems/simulation/behavior/synthesis/ArcadeDriveBehavior.ts +++ b/fission/src/systems/simulation/behavior/synthesis/ArcadeDriveBehavior.ts @@ -8,9 +8,6 @@ class ArcadeDriveBehavior extends Behavior { private rightWheels: WheelDriver[] private _brainIndex: number - private _driveSpeed = 30 - private _turnSpeed = 30 - constructor( leftWheels: WheelDriver[], rightWheels: WheelDriver[], @@ -38,7 +35,7 @@ class ArcadeDriveBehavior extends Behavior { const driveInput = InputSystem.getInput("arcadeDrive", this._brainIndex) const turnInput = InputSystem.getInput("arcadeTurn", this._brainIndex) - this.DriveSpeeds(driveInput * this._driveSpeed, turnInput * this._turnSpeed) + this.DriveSpeeds(driveInput, turnInput) } } diff --git a/fission/src/systems/simulation/driver/HingeDriver.ts b/fission/src/systems/simulation/driver/HingeDriver.ts index aa9ef3aeb5..85babb888d 100644 --- a/fission/src/systems/simulation/driver/HingeDriver.ts +++ b/fission/src/systems/simulation/driver/HingeDriver.ts @@ -34,11 +34,11 @@ class HingeDriver extends Driver { this._targetAngle = Math.max(this._constraint.GetLimitsMin(), Math.min(this._constraint.GetLimitsMax(), rads)) } - public get maxTorque() { + public get maxForce() { return this._constraint.GetMotorSettings().mMaxTorqueLimit } - public set maxTorque(nm: number) { + public set maxForce(nm: number) { const motorSettings = this._constraint.GetMotorSettings() motorSettings.mMaxTorqueLimit = nm motorSettings.mMinTorqueLimit = -nm diff --git a/fission/src/systems/simulation/driver/WheelDriver.ts b/fission/src/systems/simulation/driver/WheelDriver.ts index 426e893f83..90dab968cd 100644 --- a/fission/src/systems/simulation/driver/WheelDriver.ts +++ b/fission/src/systems/simulation/driver/WheelDriver.ts @@ -15,6 +15,9 @@ class WheelDriver extends Driver { private _reversed: boolean private _targetWheelSpeed: number = 0.0 + private _prevVel: number = 0.0 + private _maxVelocity = 30.0 + private _maxAcceleration = 1.5 public get targetWheelSpeed(): number { return this._targetWheelSpeed @@ -23,12 +26,29 @@ class WheelDriver extends Driver { this._targetWheelSpeed = radsPerSec } + public get maxVelocity(): number { + return this._maxVelocity + } + + public set maxVelocity(radsPerSec: number) { + this._maxVelocity = radsPerSec + } + + public get maxForce(): number { + return this._maxAcceleration + } + + public set maxForce(acc: number) { + this._maxAcceleration = acc + } + public get constraint(): Jolt.VehicleConstraint { return this._constraint } public constructor( constraint: Jolt.VehicleConstraint, + maxVel: number, info?: mirabuf.IInfo, deviceType?: SimType, device?: string, @@ -37,6 +57,9 @@ class WheelDriver extends Driver { super(info) this._constraint = constraint + this._maxVelocity = maxVel + const controller = JOLT.castObject(this._constraint.GetController(), JOLT.WheeledVehicleController) + this._maxAcceleration = controller.GetEngine().mMaxTorque this._reversed = reversed this.deviceType = deviceType this.device = device @@ -46,7 +69,16 @@ class WheelDriver extends Driver { } public Update(_: number): void { - this._wheel.SetAngularVelocity(this._targetWheelSpeed * (this._reversed ? -1 : 1)) + let vel = this._targetWheelSpeed * (this._reversed ? -1 : 1) * this._maxVelocity + // if (InputSystem.isKeyPressed("KeyW")) console.log(`vel 1: ${vel}`) + + if (vel - this._prevVel < -this._maxAcceleration) vel = this._prevVel - this._maxAcceleration + if (vel - this._prevVel > this._maxAcceleration) vel = this._prevVel + this._maxAcceleration + // if (vel != 0) console.log(`prev: ${this._prevVel} vel 3: ${vel}`) + + + this._wheel.SetAngularVelocity(vel) + this._prevVel = vel } public set reversed(val: boolean) { diff --git a/fission/src/ui/panels/configuring/ConfigureJointsPanel.tsx b/fission/src/ui/panels/configuring/ConfigureJointsPanel.tsx index f3545d308d..4a6159a118 100644 --- a/fission/src/ui/panels/configuring/ConfigureJointsPanel.tsx +++ b/fission/src/ui/panels/configuring/ConfigureJointsPanel.tsx @@ -4,6 +4,7 @@ import PreferencesSystem from "@/systems/preferences/PreferencesSystem" import Driver from "@/systems/simulation/driver/Driver" import HingeDriver from "@/systems/simulation/driver/HingeDriver" import SliderDriver from "@/systems/simulation/driver/SliderDriver" +import WheelDriver from "@/systems/simulation/driver/WheelDriver" import World from "@/systems/World" import Button from "@/ui/components/Button" import Label, { LabelSize } from "@/ui/components/Label" @@ -21,63 +22,68 @@ type JointRowProps = { } const JointRow: React.FC = ({ robot, driver }) => { - const [velocity, setVelocity] = useState(() => { - switch (driver.constructor) { - case SliderDriver: - return (driver as SliderDriver).maxVelocity - case HingeDriver: - return (driver as HingeDriver).maxVelocity - default: - return 40 - } - }) - const [force, setForce] = useState(() => { + const wheelDrivers = useMemo(() => { + return robot?.mechanism ? + World.SimulationSystem.GetSimulationLayer(robot.mechanism)?.drivers.filter(x => x instanceof WheelDriver) : undefined + }, [robot]) + + const driverSwitch = (driver: Driver, slider: unknown, hinge: unknown, drivetrain: unknown) => { switch (driver.constructor) { case SliderDriver: - return (driver as SliderDriver).maxForce + return slider case HingeDriver: - return (driver as HingeDriver).maxTorque + return hinge + case WheelDriver: + return drivetrain default: - return 40 + return drivetrain } - }) + } + + const [velocity, setVelocity] = useState( + (driver as SliderDriver || driver as HingeDriver || driver as WheelDriver).maxVelocity) + const [force, setForce] = useState( + (driver as SliderDriver || driver as HingeDriver || driver as WheelDriver).maxForce) const onChange = (vel: number, force: number) => { - (driver as SliderDriver || driver as HingeDriver).maxVelocity = vel - switch (driver.constructor) { - case SliderDriver: - (driver as SliderDriver).maxForce = force - break - case HingeDriver: - (driver as HingeDriver).maxTorque = force - break - default: - return 40 + if (driver instanceof WheelDriver) { + wheelDrivers?.forEach(x => { + x.maxVelocity = vel + x.maxForce = force + }) + + // Preferences + PreferencesSystem.getRobotPreferences(robot.assemblyName).driveVelocity = vel + PreferencesSystem.getRobotPreferences(robot.assemblyName).driveAcceleration = force + } else { + (driver as SliderDriver || driver as HingeDriver).maxVelocity = vel; + (driver as SliderDriver || driver as HingeDriver).maxForce = force + + // Preferences + if (driver.info && driver.info.name) { + const removedMotor = PreferencesSystem.getRobotPreferences(robot.assemblyName).motors ? PreferencesSystem.getRobotPreferences(robot.assemblyName).motors.filter(x => { + if (x.name) + return x.name != driver.info?.name + return false + }) : [] + + removedMotor.push({ + name: driver.info?.name ?? "", + maxVelocity: vel, + maxForce: force}) + + PreferencesSystem.getRobotPreferences(robot.assemblyName).motors = removedMotor + } } - // Preferences - if (driver.info && driver.info.name) { - const removedMotor = PreferencesSystem.getRobotPreferences(robot.assemblyName).motors ? PreferencesSystem.getRobotPreferences(robot.assemblyName).motors.filter(x => { - if (x.name) - return x.name != driver.info?.name - return false - }) : [] - - removedMotor.push({ - name: driver.info?.name ?? "", - maxVelocity: vel, - maxForce: force}) - - PreferencesSystem.getRobotPreferences(robot.assemblyName).motors = removedMotor - PreferencesSystem.savePreferences() - } + PreferencesSystem.savePreferences() } return ( - + = ({ robot, driver }) => { step={0.01} /> {return driver instanceof HingeDriver ? 20 : 100})()} - max={(() => {return driver instanceof HingeDriver ? 200 : 800})()} + min={driverSwitch(driver, 100, 20, 0.1) as number} + max={driverSwitch(driver, 800, 200, 50) as number} value={force} - label={(() => {return driver instanceof HingeDriver ? "Max Torque" : "Max Force"})()} + label={driverSwitch(driver, "Max Force", "Max Torque", "Max Accel.") as string} format={{ minimumFractionDigits: 2, maximumFractionDigits: 2 }} onChange={(_, _force: number | number[]) => { setForce(_force as number); @@ -127,6 +133,8 @@ const ConfigureJointsPanel: React.FC = ({ panelId, openLocation, World.SimulationSystem.GetSimulationLayer(selectedRobot.mechanism)?.drivers : undefined }, [selectedRobot]) + //origPref: RobotPreferences that just set back to everything. + return ( = ({ panelId, openLocation, openLocation={openLocation} sidePadding={sidePadding} onAccept={() => { PreferencesSystem.savePreferences()}} - onCancel={() => {/* Back to original */ }} + onCancel={() => {/* TODO: Back to original */ }} acceptEnabled={true} > {selectedRobot?.ejectorPreferences == undefined ? ( @@ -162,9 +170,18 @@ const ConfigureJointsPanel: React.FC = ({ panelId, openLocation, {drivers ? ( + { + return selectedRobot + })()} + driver={(() => { + return drivers.filter(x => x instanceof WheelDriver)[0] + })()} + /> {drivers.filter(x => x instanceof SliderDriver || x instanceof HingeDriver).map((driver: Driver, i: number) => ( { return selectedRobot })()} From d0751a7c7812afc8235374d0692336d5e8e0a387 Mon Sep 17 00:00:00 2001 From: a-crowell Date: Thu, 1 Aug 2024 15:43:55 -0700 Subject: [PATCH 08/34] Cancel --- .../systems/preferences/PreferencesSystem.ts | 22 +++++--- .../configuring/ConfigureJointsPanel.tsx | 56 ++++++++++++++++++- 2 files changed, 68 insertions(+), 10 deletions(-) diff --git a/fission/src/systems/preferences/PreferencesSystem.ts b/fission/src/systems/preferences/PreferencesSystem.ts index 8933a44bd6..09b8c3961e 100644 --- a/fission/src/systems/preferences/PreferencesSystem.ts +++ b/fission/src/systems/preferences/PreferencesSystem.ts @@ -29,14 +29,6 @@ class PreferencesSystem { window.addEventListener("preferenceChanged", callback as EventListener) } - /** Sets a global preference to be a value of a specific type */ - public static setGlobalPreference(key: GlobalPreference, value: T) { - if (this._preferences == undefined) this.loadPreferences() - - window.dispatchEvent(new PreferenceEvent(key, value)) - this._preferences[key] = value - } - /** Gets any preference from the preferences map */ private static getPreference(key: string): T | undefined { if (this._preferences == undefined) this.loadPreferences() @@ -55,6 +47,14 @@ class PreferencesSystem { throw new Error("Preference '" + key + "' is not assigned a default!") } + /** Sets a global preference to be a value of a specific type */ + public static setGlobalPreference(key: GlobalPreference, value: T) { + if (this._preferences == undefined) this.loadPreferences() + + window.dispatchEvent(new PreferenceEvent(key, value)) + this._preferences[key] = value + } + /** Gets a RobotPreferences object for a robot of a specific mira name */ public static getRobotPreferences(miraName: string): RobotPreferences { const allRoboPrefs = this.getAllRobotPreferences() @@ -68,6 +68,12 @@ class PreferencesSystem { return allRoboPrefs[miraName] } + /** Sets the RobotPreferences object for the robot of a specific mira name */ + public static setRobotPreferences(miraName: string, value: RobotPreferences) { + const allRoboPrefs = this.getAllRobotPreferences() + allRoboPrefs[miraName] = value + } + /** Gets preferences for every robot in local storage */ public static getAllRobotPreferences(): { [key: string]: RobotPreferences } { let allRoboPrefs = this.getPreference<{ [key: string]: RobotPreferences }>(RobotPreferencesKey) diff --git a/fission/src/ui/panels/configuring/ConfigureJointsPanel.tsx b/fission/src/ui/panels/configuring/ConfigureJointsPanel.tsx index 4a6159a118..1268dbc229 100644 --- a/fission/src/ui/panels/configuring/ConfigureJointsPanel.tsx +++ b/fission/src/ui/panels/configuring/ConfigureJointsPanel.tsx @@ -1,6 +1,7 @@ import { MiraType } from "@/mirabuf/MirabufLoader" import MirabufSceneObject from "@/mirabuf/MirabufSceneObject" import PreferencesSystem from "@/systems/preferences/PreferencesSystem" +import { RobotPreferences } from "@/systems/preferences/PreferenceTypes" import Driver from "@/systems/simulation/driver/Driver" import HingeDriver from "@/systems/simulation/driver/HingeDriver" import SliderDriver from "@/systems/simulation/driver/SliderDriver" @@ -117,6 +118,7 @@ const JointRow: React.FC = ({ robot, driver }) => { const ConfigureJointsPanel: React.FC = ({ panelId, openLocation, sidePadding}) => { const [selectedRobot, setSelectedRobot] = useState(undefined) + const [origPref, setOrigPref] = useState(undefined) const robots = useMemo(() => { const assemblies = [...World.SceneRenderer.sceneObjects.values()].filter(x => { @@ -133,7 +135,56 @@ const ConfigureJointsPanel: React.FC = ({ panelId, openLocation, World.SimulationSystem.GetSimulationLayer(selectedRobot.mechanism)?.drivers : undefined }, [selectedRobot]) - //origPref: RobotPreferences that just set back to everything. + function saveOrigMotors(robot: MirabufSceneObject) { + drivers?.forEach(driver => { + if (driver.info && driver.info.name) { + if (!(driver instanceof WheelDriver)) { + const motors = PreferencesSystem.getRobotPreferences(robot.assemblyName).motors + const removedMotor = motors.filter(x => { + if (x.name) + return x.name != driver.info?.name + return false + }) + + if (removedMotor.length == drivers.length) { + removedMotor.push({ + name: driver.info?.name ?? "", + maxVelocity: (driver as SliderDriver || driver as HingeDriver).maxVelocity, + maxForce: (driver as SliderDriver || driver as HingeDriver).maxForce + }) + PreferencesSystem.getRobotPreferences(robot.assemblyName).motors = removedMotor + } + } + } + }) + PreferencesSystem.savePreferences() + setOrigPref({ ... PreferencesSystem.getRobotPreferences(robot.assemblyName)}) // clone + } + + function Cancel() { + if (selectedRobot && origPref) { + drivers?.forEach(driver => { + if (driver instanceof WheelDriver) { + driver.maxVelocity = origPref.driveVelocity + driver.maxForce = origPref.driveAcceleration + } else { + if (driver.info && driver.info.name) { + const motor = origPref.motors.filter(x => { + if (x.name) + return x.name == driver.info?.name + return false + })[0]; + if (motor) { + (driver as SliderDriver || driver as HingeDriver).maxVelocity = motor.maxVelocity; + (driver as SliderDriver || driver as HingeDriver).maxForce = motor.maxForce + } + } + } + }) + PreferencesSystem.setRobotPreferences(selectedRobot.assemblyName, origPref) + } + PreferencesSystem.savePreferences() + } return ( @@ -144,7 +195,7 @@ const ConfigureJointsPanel: React.FC = ({ panelId, openLocation, openLocation={openLocation} sidePadding={sidePadding} onAccept={() => { PreferencesSystem.savePreferences()}} - onCancel={() => {/* TODO: Back to original */ }} + onCancel={Cancel} acceptEnabled={true} > {selectedRobot?.ejectorPreferences == undefined ? ( @@ -158,6 +209,7 @@ const ConfigureJointsPanel: React.FC = ({ panelId, openLocation, value={mirabufSceneObject.assemblyName} onClick={() => { setSelectedRobot(mirabufSceneObject) + saveOrigMotors(mirabufSceneObject) }} key={mirabufSceneObject.id} > From 78a0aafb535b72772323bc85e19258206048f2b2 Mon Sep 17 00:00:00 2001 From: a-crowell Date: Thu, 1 Aug 2024 16:31:57 -0700 Subject: [PATCH 09/34] Refactor --- fission/src/systems/physics/Mechanism.ts | 2 +- fission/src/systems/physics/PhysicsSystem.ts | 21 +++++------- .../behavior/synthesis/ArcadeDriveBehavior.ts | 15 ++++----- .../behavior/synthesis/GenericArmBehavior.ts | 6 ++-- .../synthesis/GenericElevatorBehavior.ts | 7 ++-- .../systems/simulation/driver/HingeDriver.ts | 33 +++++++++---------- .../systems/simulation/driver/SliderDriver.ts | 31 ++++++++--------- .../systems/simulation/driver/WheelDriver.ts | 31 ++++++++--------- .../simulation/wpilib_brain/WPILibBrain.ts | 4 +-- 9 files changed, 69 insertions(+), 81 deletions(-) diff --git a/fission/src/systems/physics/Mechanism.ts b/fission/src/systems/physics/Mechanism.ts index 4a240576ed..ae5e0722d3 100644 --- a/fission/src/systems/physics/Mechanism.ts +++ b/fission/src/systems/physics/Mechanism.ts @@ -7,8 +7,8 @@ export interface MechanismConstraint { parentBody: Jolt.BodyID childBody: Jolt.BodyID constraint: Jolt.Constraint - info?: mirabuf.IInfo maxVelocity: number + info?: mirabuf.IInfo } class Mechanism { diff --git a/fission/src/systems/physics/PhysicsSystem.ts b/fission/src/systems/physics/PhysicsSystem.ts index 8e2e4d806c..7e8e592d30 100644 --- a/fission/src/systems/physics/PhysicsSystem.ts +++ b/fission/src/systems/physics/PhysicsSystem.ts @@ -351,7 +351,7 @@ class PhysicsSystem extends WorldSystem { const bodyA = this.GetBody(bodyIdA) const bodyB = this.GetBody(bodyIdB) - const constraints: [Jolt.Constraint, number][] = [] + const constraints: Jolt.Constraint[] = [] let listener: Jolt.PhysicsStepListener | undefined = undefined // maxForce becomes maxForce for sliders, maxTorque for hinges, and maxAcceleration for wheels @@ -384,8 +384,8 @@ class PhysicsSystem extends WorldSystem { bodyB, parser.assembly.info!.version! ) - constraints.push([res[0], maxVel ?? 40]) - constraints.push([res[1], maxVel ?? 40]) + constraints.push(res[0]) + constraints.push(res[1]) listener = res[2] } else { const res = this.CreateWheelConstraint( @@ -396,19 +396,17 @@ class PhysicsSystem extends WorldSystem { bodyA, parser.assembly.info!.version! ) - constraints.push([res[0], maxVel ?? 40]) - constraints.push([res[1], maxVel ?? 40]) + constraints.push(res[0]) + constraints.push(res[1]) listener = res[2] } } else { - constraints.push( - [this.CreateHingeConstraint(jInst, jDef, maxForce ?? 200, bodyA, bodyB, parser.assembly.info!.version!), maxVel ? maxVel : 40] - ) + constraints.push(this.CreateHingeConstraint(jInst, jDef, maxForce ?? 200, bodyA, bodyB, parser.assembly.info!.version!)) } break case mirabuf.joint.JointMotion.SLIDER: - constraints.push([this.CreateSliderConstraint(jInst, jDef, maxForce ?? 200, bodyA, bodyB), maxVel ? maxVel : 40]) + constraints.push(this.CreateSliderConstraint(jInst, jDef, maxForce ?? 200, bodyA, bodyB)) break default: console.debug("Unsupported joint detected. Skipping...") @@ -420,10 +418,9 @@ class PhysicsSystem extends WorldSystem { mechanism.AddConstraint({ parentBody: bodyIdA, childBody: bodyIdB, - constraint: x[0], - maxVelocity: x[1], + constraint: x, + maxVelocity: maxVel ?? 30, info: jInst.info ?? undefined, // remove possibility for null - }) ) } diff --git a/fission/src/systems/simulation/behavior/synthesis/ArcadeDriveBehavior.ts b/fission/src/systems/simulation/behavior/synthesis/ArcadeDriveBehavior.ts index 035db861d0..2146f64a72 100644 --- a/fission/src/systems/simulation/behavior/synthesis/ArcadeDriveBehavior.ts +++ b/fission/src/systems/simulation/behavior/synthesis/ArcadeDriveBehavior.ts @@ -23,19 +23,16 @@ class ArcadeDriveBehavior extends Behavior { } // Sets the drivetrains target linear and rotational velocity - private DriveSpeeds(linearVelocity: number, rotationVelocity: number) { - const leftSpeed = linearVelocity + rotationVelocity - const rightSpeed = linearVelocity - rotationVelocity + private DriveSpeeds(driveInput: number, turnInput: number) { + const leftDirection = driveInput + turnInput + const rightDirection = driveInput - turnInput - this.leftWheels.forEach(wheel => (wheel.targetWheelSpeed = leftSpeed)) - this.rightWheels.forEach(wheel => (wheel.targetWheelSpeed = rightSpeed)) + this.leftWheels.forEach(wheel => (wheel.accelerationDirection = leftDirection)) + this.rightWheels.forEach(wheel => (wheel.accelerationDirection = rightDirection)) } public Update(_: number): void { - const driveInput = InputSystem.getInput("arcadeDrive", this._brainIndex) - const turnInput = InputSystem.getInput("arcadeTurn", this._brainIndex) - - this.DriveSpeeds(driveInput, turnInput) + this.DriveSpeeds(InputSystem.getInput("arcadeDrive", this._brainIndex), InputSystem.getInput("arcadeTurn", this._brainIndex)) } } diff --git a/fission/src/systems/simulation/behavior/synthesis/GenericArmBehavior.ts b/fission/src/systems/simulation/behavior/synthesis/GenericArmBehavior.ts index 1d55bfd9e6..8a15a51c2a 100644 --- a/fission/src/systems/simulation/behavior/synthesis/GenericArmBehavior.ts +++ b/fission/src/systems/simulation/behavior/synthesis/GenericArmBehavior.ts @@ -16,9 +16,9 @@ class GenericArmBehavior extends Behavior { this._brainIndex = brainIndex } - // Sets the arms target rotational velocity - rotateArm(rotationalVelocity: number) { - this._hingeDriver.targetVelocity = rotationalVelocity + // Sets the arm's acceleration direction + rotateArm(input: number) { + this._hingeDriver.accelerationDirection = input } public Update(_: number): void { diff --git a/fission/src/systems/simulation/behavior/synthesis/GenericElevatorBehavior.ts b/fission/src/systems/simulation/behavior/synthesis/GenericElevatorBehavior.ts index cc5dfda7ee..198ae96fd5 100644 --- a/fission/src/systems/simulation/behavior/synthesis/GenericElevatorBehavior.ts +++ b/fission/src/systems/simulation/behavior/synthesis/GenericElevatorBehavior.ts @@ -16,10 +16,9 @@ class GenericElevatorBehavior extends Behavior { this._brainIndex = brainIndex } - // Changes the elevators target position - moveElevator(linearVelocity: number) { - // Multiplied by velocity in driver - this._sliderDriver.targetVelocity = linearVelocity + // Changes the elevator's acceleration direction + moveElevator(input: number) { + this._sliderDriver.accelerationDirection = input } public Update(_: number): void { diff --git a/fission/src/systems/simulation/driver/HingeDriver.ts b/fission/src/systems/simulation/driver/HingeDriver.ts index 85babb888d..31f752a6f9 100644 --- a/fission/src/systems/simulation/driver/HingeDriver.ts +++ b/fission/src/systems/simulation/driver/HingeDriver.ts @@ -8,23 +8,15 @@ class HingeDriver extends Driver { private _constraint: Jolt.HingeConstraint private _controlMode: DriverControlMode = DriverControlMode.Velocity - private _targetVelocity: number = 0.0 + private _accelerationDirection: number = 0.0 private _targetAngle: number private _maxVelocity: number - public get maxVelocity(): number { - return this._maxVelocity + public get accelerationDirection(): number { + return this._accelerationDirection } - - public set maxVelocity(radsPerSec: number) { - this._maxVelocity = radsPerSec - } - - public get targetVelocity(): number { - return this._targetVelocity - } - public set targetVelocity(radsPerSec: number) { - this._targetVelocity = radsPerSec + public set accelerationDirection(radsPerSec: number) { + this._accelerationDirection = radsPerSec } public get targetAngle(): number { @@ -34,6 +26,13 @@ class HingeDriver extends Driver { this._targetAngle = Math.max(this._constraint.GetLimitsMin(), Math.min(this._constraint.GetLimitsMax(), rads)) } + public get maxVelocity(): number { + return this._maxVelocity + } + public set maxVelocity(radsPerSec: number) { + this._maxVelocity = radsPerSec + } + public get maxForce() { return this._constraint.GetMotorSettings().mMaxTorqueLimit } @@ -67,6 +66,8 @@ class HingeDriver extends Driver { super(info) this._constraint = constraint + this._maxVelocity = maxVelocity + this._targetAngle = this._constraint.GetCurrentAngle() const motorSettings = this._constraint.GetMotorSettings() const springSettings = motorSettings.mSpringSettings @@ -74,18 +75,14 @@ class HingeDriver extends Driver { // These values were selected based on the suggestions of the documentation for stiff control. springSettings.mFrequency = 20 * (1.0 / GetLastDeltaT()) springSettings.mDamping = 0.995 - motorSettings.mSpringSettings = springSettings - this._targetAngle = this._constraint.GetCurrentAngle() - this._maxVelocity = maxVelocity - this.controlMode = DriverControlMode.Velocity } public Update(_: number): void { if (this._controlMode == DriverControlMode.Velocity) { - this._constraint.SetTargetAngularVelocity(this._targetVelocity * this._maxVelocity) + this._constraint.SetTargetAngularVelocity(this._accelerationDirection * this._maxVelocity) } else if (this._controlMode == DriverControlMode.Position) { //TODO add maxVel to diff this._constraint.SetTargetAngle(this._targetAngle) diff --git a/fission/src/systems/simulation/driver/SliderDriver.ts b/fission/src/systems/simulation/driver/SliderDriver.ts index f00249f521..192ac99400 100644 --- a/fission/src/systems/simulation/driver/SliderDriver.ts +++ b/fission/src/systems/simulation/driver/SliderDriver.ts @@ -8,23 +8,15 @@ class SliderDriver extends Driver { private _constraint: Jolt.SliderConstraint private _controlMode: DriverControlMode = DriverControlMode.Velocity - private _targetVelocity: number = 0.0 + private _accelerationDirection: number = 0.0 private _targetPosition: number = 0.0 private _maxVelocity: number = 1.0 - public get maxVelocity(): number { - return this._maxVelocity - } - - public set maxVelocity(radsPerSec: number) { - this._maxVelocity = radsPerSec - } - - public get targetVelocity(): number { - return this._targetVelocity + public get accelerationDirection(): number { + return this._accelerationDirection } - public set targetVelocity(radsPerSec: number) { - this._targetVelocity = radsPerSec + public set accelerationDirection(radsPerSec: number) { + this._accelerationDirection = radsPerSec } public get targetPosition(): number { @@ -37,6 +29,13 @@ class SliderDriver extends Driver { ) } + public get maxVelocity(): number { + return this._maxVelocity + } + public set maxVelocity(radsPerSec: number) { + this._maxVelocity = radsPerSec + } + public get maxForce(): number { return this._constraint.GetMotorSettings().mMaxForceLimit } @@ -69,23 +68,21 @@ class SliderDriver extends Driver { super(info) this._constraint = constraint + this._maxVelocity = maxVelocity const motorSettings = this._constraint.GetMotorSettings() const springSettings = motorSettings.mSpringSettings springSettings.mFrequency = 20 * (1.0 / GetLastDeltaT()) springSettings.mDamping = 0.999 - motorSettings.mSpringSettings = springSettings - this._maxVelocity = maxVelocity - this._constraint.SetMotorState(JOLT.EMotorState_Velocity) this.controlMode = DriverControlMode.Velocity } public Update(_: number): void { if (this._controlMode == DriverControlMode.Velocity) { - this._constraint.SetTargetVelocity(this._targetVelocity * this._maxVelocity) + this._constraint.SetTargetVelocity(this._accelerationDirection * this._maxVelocity) } else if (this._controlMode == DriverControlMode.Position) { //TODO: MaxVel checks diff this._constraint.SetTargetPosition(this._targetPosition) diff --git a/fission/src/systems/simulation/driver/WheelDriver.ts b/fission/src/systems/simulation/driver/WheelDriver.ts index 90dab968cd..35aa702494 100644 --- a/fission/src/systems/simulation/driver/WheelDriver.ts +++ b/fission/src/systems/simulation/driver/WheelDriver.ts @@ -14,22 +14,30 @@ class WheelDriver extends Driver { public device?: string private _reversed: boolean - private _targetWheelSpeed: number = 0.0 + private _accelerationDirection: number = 0.0 private _prevVel: number = 0.0 private _maxVelocity = 30.0 private _maxAcceleration = 1.5 - public get targetWheelSpeed(): number { - return this._targetWheelSpeed + private _targetVelocity = () => { + let vel = this._accelerationDirection * (this._reversed ? -1 : 1) * this._maxVelocity + + if (vel - this._prevVel < -this._maxAcceleration) vel = this._prevVel - this._maxAcceleration + if (vel - this._prevVel > this._maxAcceleration) vel = this._prevVel + this._maxAcceleration + + return vel } - public set targetWheelSpeed(radsPerSec: number) { - this._targetWheelSpeed = radsPerSec + + public get accelerationDirection(): number { + return this._accelerationDirection + } + public set accelerationDirection(radsPerSec: number) { + this._accelerationDirection = radsPerSec } public get maxVelocity(): number { return this._maxVelocity } - public set maxVelocity(radsPerSec: number) { this._maxVelocity = radsPerSec } @@ -37,7 +45,6 @@ class WheelDriver extends Driver { public get maxForce(): number { return this._maxAcceleration } - public set maxForce(acc: number) { this._maxAcceleration = acc } @@ -60,6 +67,7 @@ class WheelDriver extends Driver { this._maxVelocity = maxVel const controller = JOLT.castObject(this._constraint.GetController(), JOLT.WheeledVehicleController) this._maxAcceleration = controller.GetEngine().mMaxTorque + this._reversed = reversed this.deviceType = deviceType this.device = device @@ -69,14 +77,7 @@ class WheelDriver extends Driver { } public Update(_: number): void { - let vel = this._targetWheelSpeed * (this._reversed ? -1 : 1) * this._maxVelocity - // if (InputSystem.isKeyPressed("KeyW")) console.log(`vel 1: ${vel}`) - - if (vel - this._prevVel < -this._maxAcceleration) vel = this._prevVel - this._maxAcceleration - if (vel - this._prevVel > this._maxAcceleration) vel = this._prevVel + this._maxAcceleration - // if (vel != 0) console.log(`prev: ${this._prevVel} vel 3: ${vel}`) - - + const vel = this._targetVelocity() this._wheel.SetAngularVelocity(vel) this._prevVel = vel } diff --git a/fission/src/systems/simulation/wpilib_brain/WPILibBrain.ts b/fission/src/systems/simulation/wpilib_brain/WPILibBrain.ts index 57ca1a40bd..63bbba188d 100644 --- a/fission/src/systems/simulation/wpilib_brain/WPILibBrain.ts +++ b/fission/src/systems/simulation/wpilib_brain/WPILibBrain.ts @@ -298,9 +298,9 @@ export class PWMGroup extends SimOutputGroup { this.drivers.forEach(d => { if (d instanceof WheelDriver) { - d.targetWheelSpeed = average * 40 + d.accelerationDirection = average * 40 } else if (d instanceof HingeDriver || d instanceof SliderDriver) { - d.targetVelocity = average * 40 + d.accelerationDirection = average * 40 } d.Update(_deltaT) }) From 6944946a0e1c373c50d4e4a81d96d7cf01d1ff64 Mon Sep 17 00:00:00 2001 From: a-crowell Date: Thu, 1 Aug 2024 16:44:09 -0700 Subject: [PATCH 10/34] Max velocity on position setting --- fission/src/systems/simulation/driver/HingeDriver.ts | 7 ++++++- fission/src/systems/simulation/driver/SliderDriver.ts | 10 ++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/fission/src/systems/simulation/driver/HingeDriver.ts b/fission/src/systems/simulation/driver/HingeDriver.ts index 31f752a6f9..8a24e4e43f 100644 --- a/fission/src/systems/simulation/driver/HingeDriver.ts +++ b/fission/src/systems/simulation/driver/HingeDriver.ts @@ -12,6 +12,8 @@ class HingeDriver extends Driver { private _targetAngle: number private _maxVelocity: number + private _prevAng: number = 0.0 + public get accelerationDirection(): number { return this._accelerationDirection } @@ -84,7 +86,10 @@ class HingeDriver extends Driver { if (this._controlMode == DriverControlMode.Velocity) { this._constraint.SetTargetAngularVelocity(this._accelerationDirection * this._maxVelocity) } else if (this._controlMode == DriverControlMode.Position) { - //TODO add maxVel to diff + let ang = this._targetAngle + + if (ang - this._prevAng < -this.maxVelocity) ang = this._prevAng - this._maxVelocity + if (ang - this._prevAng > this.maxVelocity) ang = this._prevAng + this._maxVelocity this._constraint.SetTargetAngle(this._targetAngle) } } diff --git a/fission/src/systems/simulation/driver/SliderDriver.ts b/fission/src/systems/simulation/driver/SliderDriver.ts index 192ac99400..2c23c89304 100644 --- a/fission/src/systems/simulation/driver/SliderDriver.ts +++ b/fission/src/systems/simulation/driver/SliderDriver.ts @@ -12,6 +12,8 @@ class SliderDriver extends Driver { private _targetPosition: number = 0.0 private _maxVelocity: number = 1.0 + private _prevPos: number = 0.0 + public get accelerationDirection(): number { return this._accelerationDirection } @@ -84,8 +86,12 @@ class SliderDriver extends Driver { if (this._controlMode == DriverControlMode.Velocity) { this._constraint.SetTargetVelocity(this._accelerationDirection * this._maxVelocity) } else if (this._controlMode == DriverControlMode.Position) { - //TODO: MaxVel checks diff - this._constraint.SetTargetPosition(this._targetPosition) + let pos = this._targetPosition + + if (pos - this._prevPos < -this.maxVelocity) pos = this._prevPos - this._maxVelocity + if (pos - this._prevPos > this.maxVelocity) pos = this._prevPos + this._maxVelocity + + this._constraint.SetTargetPosition(pos) } } } From f8d6edf253c8ab023b16630cfe6be25982088e8a Mon Sep 17 00:00:00 2001 From: a-crowell Date: Thu, 1 Aug 2024 17:08:17 -0700 Subject: [PATCH 11/34] Field bug and range adjustments --- fission/src/systems/physics/PhysicsSystem.ts | 18 ++++++++++++++---- .../configuring/ConfigureJointsPanel.tsx | 2 +- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/fission/src/systems/physics/PhysicsSystem.ts b/fission/src/systems/physics/PhysicsSystem.ts index 7e8e592d30..1d325c1059 100644 --- a/fission/src/systems/physics/PhysicsSystem.ts +++ b/fission/src/systems/physics/PhysicsSystem.ts @@ -62,6 +62,10 @@ const FLOOR_FRICTION = 0.7 const SUSPENSION_MIN_FACTOR = 0.1 const SUSPENSION_MAX_FACTOR = 0.3 +// Motor constants +const VELOCITY_DEFAULT = 30 +const ACCELERATION_DEFAULT = 150 + /** * The PhysicsSystem handles all Jolt Physics interactions within Synthesis. * This system can create physical representations of objects such as Robots, @@ -355,8 +359,14 @@ class PhysicsSystem extends WorldSystem { let listener: Jolt.PhysicsStepListener | undefined = undefined // maxForce becomes maxForce for sliders, maxTorque for hinges, and maxAcceleration for wheels - let maxVel = jointData.motorDefinitions![jDef.motorReference].simpleMotor?.maxVelocity - let maxForce = jointData.motorDefinitions![jDef.motorReference].simpleMotor?.stallTorque + let maxVel = VELOCITY_DEFAULT + let maxForce; + const motor = jointData.motorDefinitions![jDef.motorReference] + if (motor && motor.simpleMotor) { + maxVel = motor.simpleMotor.maxVelocity ?? VELOCITY_DEFAULT + maxForce = motor.simpleMotor.stallTorque ?? ACCELERATION_DEFAULT + } + const motors = PreferencesSystem.getRobotPreferences(parser.assembly.info?.name ?? "").motors if (motors) { const thisMotor = motors.filter(x => x.name == jInst.info?.name) @@ -401,7 +411,7 @@ class PhysicsSystem extends WorldSystem { listener = res[2] } } else { - constraints.push(this.CreateHingeConstraint(jInst, jDef, maxForce ?? 200, bodyA, bodyB, parser.assembly.info!.version!)) + constraints.push(this.CreateHingeConstraint(jInst, jDef, maxForce ?? 50, bodyA, bodyB, parser.assembly.info!.version!)) } break case mirabuf.joint.JointMotion.SLIDER: @@ -419,7 +429,7 @@ class PhysicsSystem extends WorldSystem { parentBody: bodyIdA, childBody: bodyIdB, constraint: x, - maxVelocity: maxVel ?? 30, + maxVelocity: maxVel ?? VELOCITY_DEFAULT, info: jInst.info ?? undefined, // remove possibility for null }) ) diff --git a/fission/src/ui/panels/configuring/ConfigureJointsPanel.tsx b/fission/src/ui/panels/configuring/ConfigureJointsPanel.tsx index 1268dbc229..890d4132b5 100644 --- a/fission/src/ui/panels/configuring/ConfigureJointsPanel.tsx +++ b/fission/src/ui/panels/configuring/ConfigureJointsPanel.tsx @@ -99,7 +99,7 @@ const JointRow: React.FC = ({ robot, driver }) => { /> Date: Thu, 1 Aug 2024 17:36:08 -0700 Subject: [PATCH 12/34] Refactor and doc --- fission/src/systems/physics/PhysicsSystem.ts | 31 ++++++--------- fission/src/ui/components/MainHUD.tsx | 1 - .../configuring/ConfigureJointsPanel.tsx | 38 +++++++++---------- 3 files changed, 30 insertions(+), 40 deletions(-) diff --git a/fission/src/systems/physics/PhysicsSystem.ts b/fission/src/systems/physics/PhysicsSystem.ts index 1d325c1059..8d91986ced 100644 --- a/fission/src/systems/physics/PhysicsSystem.ts +++ b/fission/src/systems/physics/PhysicsSystem.ts @@ -62,9 +62,8 @@ const FLOOR_FRICTION = 0.7 const SUSPENSION_MIN_FACTOR = 0.1 const SUSPENSION_MAX_FACTOR = 0.3 -// Motor constants +// Motor constant const VELOCITY_DEFAULT = 30 -const ACCELERATION_DEFAULT = 150 /** * The PhysicsSystem handles all Jolt Physics interactions within Synthesis. @@ -358,23 +357,14 @@ class PhysicsSystem extends WorldSystem { const constraints: Jolt.Constraint[] = [] let listener: Jolt.PhysicsStepListener | undefined = undefined - // maxForce becomes maxForce for sliders, maxTorque for hinges, and maxAcceleration for wheels - let maxVel = VELOCITY_DEFAULT - let maxForce; - const motor = jointData.motorDefinitions![jDef.motorReference] - if (motor && motor.simpleMotor) { - maxVel = motor.simpleMotor.maxVelocity ?? VELOCITY_DEFAULT - maxForce = motor.simpleMotor.stallTorque ?? ACCELERATION_DEFAULT - } + // Motor preferences and mirabuf + const prefMotors = PreferencesSystem.getRobotPreferences(parser.assembly.info?.name ?? "").motors + const prefMotor = prefMotors ? prefMotors.filter(x => x.name == jInst.info?.name) : undefined + const miraMotor = jointData.motorDefinitions![jDef.motorReference] - const motors = PreferencesSystem.getRobotPreferences(parser.assembly.info?.name ?? "").motors - if (motors) { - const thisMotor = motors.filter(x => x.name == jInst.info?.name) - if (thisMotor[0]) { - maxVel = thisMotor[0].maxVelocity - maxForce = thisMotor[0].maxForce - } - } + // If preference motor exists, sets vel/acc to prefMotor. Then, if mirabuf motor exists, sets vel/acc to miraMotor. Then default + let maxVel = (prefMotor && prefMotor[0]) ? prefMotor[0].maxVelocity : ((miraMotor && miraMotor.simpleMotor) ? miraMotor.simpleMotor.maxVelocity ?? VELOCITY_DEFAULT : VELOCITY_DEFAULT) + let maxForce = (prefMotor && prefMotor[0]) ? prefMotor[0].maxForce : ((miraMotor && miraMotor.simpleMotor) ? miraMotor.simpleMotor.stallTorque : undefined) switch (jDef.jointMotionType!) { case mirabuf.joint.JointMotion.REVOLUTE: @@ -574,7 +564,7 @@ class PhysicsSystem extends WorldSystem { } sliderConstraintSettings.mMotorSettings.mMaxForceLimit = maxForce - sliderConstraintSettings.mMotorSettings.mMinForceLimit = -sliderConstraintSettings.mMotorSettings.mMaxForceLimit + sliderConstraintSettings.mMotorSettings.mMinForceLimit = -maxForce const constraint = sliderConstraintSettings.Create(bodyA, bodyB) @@ -634,6 +624,9 @@ class PhysicsSystem extends WorldSystem { vehicleSettings.mWheels.clear() vehicleSettings.mWheels.push_back(wheelSettings) + // Other than maxTorque, these controller settings are not being used as of now + // because ArcadeDriveBehavior goes directly to the WheelDrivers. + // MaxTorque is only used as communication for WheelDriver to get maxAcceleration const controllerSettings = new JOLT.WheeledVehicleControllerSettings() controllerSettings.mEngine.mMaxTorque = maxAcc controllerSettings.mTransmission.mClutchStrength = 10.0 diff --git a/fission/src/ui/components/MainHUD.tsx b/fission/src/ui/components/MainHUD.tsx index af43cd3521..723b392ab9 100644 --- a/fission/src/ui/components/MainHUD.tsx +++ b/fission/src/ui/components/MainHUD.tsx @@ -10,7 +10,6 @@ import APS, { APS_USER_INFO_UPDATE_EVENT } from "@/aps/APS" import { UserIcon } from "./UserIcon" import { Button } from "@mui/base/Button" import { ButtonIcon, SynthesisIcons } from "./StyledComponents" -import Synthesis from "@/Synthesis" type ButtonProps = { value: string diff --git a/fission/src/ui/panels/configuring/ConfigureJointsPanel.tsx b/fission/src/ui/panels/configuring/ConfigureJointsPanel.tsx index 890d4132b5..51fc4a3251 100644 --- a/fission/src/ui/panels/configuring/ConfigureJointsPanel.tsx +++ b/fission/src/ui/panels/configuring/ConfigureJointsPanel.tsx @@ -23,10 +23,6 @@ type JointRowProps = { } const JointRow: React.FC = ({ robot, driver }) => { - const wheelDrivers = useMemo(() => { - return robot?.mechanism ? - World.SimulationSystem.GetSimulationLayer(robot.mechanism)?.drivers.filter(x => x instanceof WheelDriver) : undefined - }, [robot]) const driverSwitch = (driver: Driver, slider: unknown, hinge: unknown, drivetrain: unknown) => { switch (driver.constructor) { @@ -48,6 +44,8 @@ const JointRow: React.FC = ({ robot, driver }) => { const onChange = (vel: number, force: number) => { if (driver instanceof WheelDriver) { + const wheelDrivers = robot?.mechanism ? + World.SimulationSystem.GetSimulationLayer(robot.mechanism)?.drivers.filter(x => x instanceof WheelDriver) : undefined wheelDrivers?.forEach(x => { x.maxVelocity = vel x.maxForce = force @@ -135,25 +133,24 @@ const ConfigureJointsPanel: React.FC = ({ panelId, openLocation, World.SimulationSystem.GetSimulationLayer(selectedRobot.mechanism)?.drivers : undefined }, [selectedRobot]) + // Gets motors in preferences for ease of saving into origPrefs which can be used to revert on Cancel() function saveOrigMotors(robot: MirabufSceneObject) { drivers?.forEach(driver => { - if (driver.info && driver.info.name) { - if (!(driver instanceof WheelDriver)) { - const motors = PreferencesSystem.getRobotPreferences(robot.assemblyName).motors - const removedMotor = motors.filter(x => { - if (x.name) - return x.name != driver.info?.name - return false - }) + if (driver.info && driver.info.name && !(driver instanceof WheelDriver)) { + const motors = PreferencesSystem.getRobotPreferences(robot.assemblyName).motors + const removedMotor = motors.filter(x => { + if (x.name) + return x.name != driver.info?.name + return false + }) - if (removedMotor.length == drivers.length) { - removedMotor.push({ - name: driver.info?.name ?? "", - maxVelocity: (driver as SliderDriver || driver as HingeDriver).maxVelocity, - maxForce: (driver as SliderDriver || driver as HingeDriver).maxForce - }) - PreferencesSystem.getRobotPreferences(robot.assemblyName).motors = removedMotor - } + if (removedMotor.length == drivers.length) { + removedMotor.push({ + name: driver.info?.name ?? "", + maxVelocity: (driver as SliderDriver || driver as HingeDriver).maxVelocity, + maxForce: (driver as SliderDriver || driver as HingeDriver).maxForce + }) + PreferencesSystem.getRobotPreferences(robot.assemblyName).motors = removedMotor } } }) @@ -222,6 +219,7 @@ const ConfigureJointsPanel: React.FC = ({ panelId, openLocation, {drivers ? ( + {/** Drivetrain row. Then other SliderDrivers and HingeDrivers */} { From f63d45c58a74778a1ecde4cdabb6cd42c30ca2c9 Mon Sep 17 00:00:00 2001 From: a-crowell Date: Thu, 1 Aug 2024 17:44:06 -0700 Subject: [PATCH 13/34] Refactor and formatting --- fission/src/Synthesis.tsx | 2 +- fission/src/systems/physics/PhysicsSystem.ts | 37 ++++-- .../systems/preferences/PreferenceTypes.ts | 2 +- .../behavior/synthesis/ArcadeDriveBehavior.ts | 5 +- .../systems/simulation/driver/HingeDriver.ts | 2 +- .../systems/simulation/driver/SliderDriver.ts | 4 +- fission/src/ui/components/MainHUD.tsx | 6 +- .../configuring/ConfigureJointsPanel.tsx | 108 +++++++++--------- 8 files changed, 96 insertions(+), 70 deletions(-) diff --git a/fission/src/Synthesis.tsx b/fission/src/Synthesis.tsx index c41ec83b31..f33227e360 100644 --- a/fission/src/Synthesis.tsx +++ b/fission/src/Synthesis.tsx @@ -254,7 +254,7 @@ const initialPanels: ReactElement[] = [ , , , - + , ] export default Synthesis diff --git a/fission/src/systems/physics/PhysicsSystem.ts b/fission/src/systems/physics/PhysicsSystem.ts index 8d91986ced..eaeb5f3dcc 100644 --- a/fission/src/systems/physics/PhysicsSystem.ts +++ b/fission/src/systems/physics/PhysicsSystem.ts @@ -327,7 +327,7 @@ class PhysicsSystem extends WorldSystem { const jointData = parser.assembly.data!.joints! for (const [jGuid, jInst] of Object.entries(jointData.jointInstances!) as [ string, - mirabuf.joint.JointInstance + mirabuf.joint.JointInstance, ][]) { if (jGuid == GROUNDED_JOINT_ID) continue @@ -357,22 +357,32 @@ class PhysicsSystem extends WorldSystem { const constraints: Jolt.Constraint[] = [] let listener: Jolt.PhysicsStepListener | undefined = undefined - // Motor preferences and mirabuf + // Motor velocity and acceleration. Prioritizes preferences then mirabuf. const prefMotors = PreferencesSystem.getRobotPreferences(parser.assembly.info?.name ?? "").motors const prefMotor = prefMotors ? prefMotors.filter(x => x.name == jInst.info?.name) : undefined const miraMotor = jointData.motorDefinitions![jDef.motorReference] - // If preference motor exists, sets vel/acc to prefMotor. Then, if mirabuf motor exists, sets vel/acc to miraMotor. Then default - let maxVel = (prefMotor && prefMotor[0]) ? prefMotor[0].maxVelocity : ((miraMotor && miraMotor.simpleMotor) ? miraMotor.simpleMotor.maxVelocity ?? VELOCITY_DEFAULT : VELOCITY_DEFAULT) - let maxForce = (prefMotor && prefMotor[0]) ? prefMotor[0].maxForce : ((miraMotor && miraMotor.simpleMotor) ? miraMotor.simpleMotor.stallTorque : undefined) + let maxVel = VELOCITY_DEFAULT + let maxForce + if (prefMotor && prefMotor[0]) { + maxVel = prefMotor[0].maxVelocity + maxForce = prefMotor[0].maxForce + } else if (miraMotor && miraMotor.simpleMotor) { + maxVel = miraMotor.simpleMotor.maxVelocity ?? VELOCITY_DEFAULT + maxForce = miraMotor.simpleMotor.stallTorque + } switch (jDef.jointMotionType!) { case mirabuf.joint.JointMotion.REVOLUTE: if (this.IsWheel(jDef)) { - const prefVel = PreferencesSystem.getRobotPreferences(parser.assembly.info?.name ?? "").driveVelocity + const prefVel = PreferencesSystem.getRobotPreferences( + parser.assembly.info?.name ?? "" + ).driveVelocity if (prefVel > 0) maxVel = prefVel - const prefAcc = PreferencesSystem.getRobotPreferences(parser.assembly.info?.name ?? "").driveAcceleration + const prefAcc = PreferencesSystem.getRobotPreferences( + parser.assembly.info?.name ?? "" + ).driveAcceleration if (prefAcc > 0) maxForce = prefAcc if (parser.directedGraph.GetAdjacencyList(rnA.id).length > 0) { @@ -401,11 +411,19 @@ class PhysicsSystem extends WorldSystem { listener = res[2] } } else { - constraints.push(this.CreateHingeConstraint(jInst, jDef, maxForce ?? 50, bodyA, bodyB, parser.assembly.info!.version!)) + constraints.push( + this.CreateHingeConstraint( + jInst, + jDef, + maxForce ?? 50, + bodyA, + bodyB, + parser.assembly.info!.version! + ) + ) } break case mirabuf.joint.JointMotion.SLIDER: - constraints.push(this.CreateSliderConstraint(jInst, jDef, maxForce ?? 200, bodyA, bodyB)) break default: @@ -496,7 +514,6 @@ class PhysicsSystem extends WorldSystem { hingeConstraintSettings.mMotorSettings.mMaxTorqueLimit = torque hingeConstraintSettings.mMotorSettings.mMinTorqueLimit = -torque - const constraint = hingeConstraintSettings.Create(bodyA, bodyB) this._constraints.push(constraint) this._joltPhysSystem.AddConstraint(constraint) diff --git a/fission/src/systems/preferences/PreferenceTypes.ts b/fission/src/systems/preferences/PreferenceTypes.ts index d044a1ce22..2402ead0c5 100644 --- a/fission/src/systems/preferences/PreferenceTypes.ts +++ b/fission/src/systems/preferences/PreferenceTypes.ts @@ -91,7 +91,7 @@ export function DefaultRobotPreferences(): RobotPreferences { parentNode: undefined, }, driveVelocity: 0, - driveAcceleration: 0 + driveAcceleration: 0, } } diff --git a/fission/src/systems/simulation/behavior/synthesis/ArcadeDriveBehavior.ts b/fission/src/systems/simulation/behavior/synthesis/ArcadeDriveBehavior.ts index 2146f64a72..72de9b4da3 100644 --- a/fission/src/systems/simulation/behavior/synthesis/ArcadeDriveBehavior.ts +++ b/fission/src/systems/simulation/behavior/synthesis/ArcadeDriveBehavior.ts @@ -32,7 +32,10 @@ class ArcadeDriveBehavior extends Behavior { } public Update(_: number): void { - this.DriveSpeeds(InputSystem.getInput("arcadeDrive", this._brainIndex), InputSystem.getInput("arcadeTurn", this._brainIndex)) + this.DriveSpeeds( + InputSystem.getInput("arcadeDrive", this._brainIndex), + InputSystem.getInput("arcadeTurn", this._brainIndex) + ) } } diff --git a/fission/src/systems/simulation/driver/HingeDriver.ts b/fission/src/systems/simulation/driver/HingeDriver.ts index 8a24e4e43f..243c0c4441 100644 --- a/fission/src/systems/simulation/driver/HingeDriver.ts +++ b/fission/src/systems/simulation/driver/HingeDriver.ts @@ -87,7 +87,7 @@ class HingeDriver extends Driver { this._constraint.SetTargetAngularVelocity(this._accelerationDirection * this._maxVelocity) } else if (this._controlMode == DriverControlMode.Position) { let ang = this._targetAngle - + if (ang - this._prevAng < -this.maxVelocity) ang = this._prevAng - this._maxVelocity if (ang - this._prevAng > this.maxVelocity) ang = this._prevAng + this._maxVelocity this._constraint.SetTargetAngle(this._targetAngle) diff --git a/fission/src/systems/simulation/driver/SliderDriver.ts b/fission/src/systems/simulation/driver/SliderDriver.ts index 2c23c89304..0cfbb2dc8d 100644 --- a/fission/src/systems/simulation/driver/SliderDriver.ts +++ b/fission/src/systems/simulation/driver/SliderDriver.ts @@ -87,10 +87,10 @@ class SliderDriver extends Driver { this._constraint.SetTargetVelocity(this._accelerationDirection * this._maxVelocity) } else if (this._controlMode == DriverControlMode.Position) { let pos = this._targetPosition - + if (pos - this._prevPos < -this.maxVelocity) pos = this._prevPos - this._maxVelocity if (pos - this._prevPos > this.maxVelocity) pos = this._prevPos + this._maxVelocity - + this._constraint.SetTargetPosition(pos) } } diff --git a/fission/src/ui/components/MainHUD.tsx b/fission/src/ui/components/MainHUD.tsx index 723b392ab9..e4ed7d8211 100644 --- a/fission/src/ui/components/MainHUD.tsx +++ b/fission/src/ui/components/MainHUD.tsx @@ -119,7 +119,11 @@ const MainHUD: React.FC = () => { openPanel("scoring-zones") }} /> - openPanel("joint-config")} /> + openPanel("joint-config")} + /> = ({ robot, driver }) => { - const driverSwitch = (driver: Driver, slider: unknown, hinge: unknown, drivetrain: unknown) => { switch (driver.constructor) { case SliderDriver: @@ -38,14 +37,19 @@ const JointRow: React.FC = ({ robot, driver }) => { } const [velocity, setVelocity] = useState( - (driver as SliderDriver || driver as HingeDriver || driver as WheelDriver).maxVelocity) + ((driver as SliderDriver) || (driver as HingeDriver) || (driver as WheelDriver)).maxVelocity + ) const [force, setForce] = useState( - (driver as SliderDriver || driver as HingeDriver || driver as WheelDriver).maxForce) + ((driver as SliderDriver) || (driver as HingeDriver) || (driver as WheelDriver)).maxForce + ) const onChange = (vel: number, force: number) => { if (driver instanceof WheelDriver) { - const wheelDrivers = robot?.mechanism ? - World.SimulationSystem.GetSimulationLayer(robot.mechanism)?.drivers.filter(x => x instanceof WheelDriver) : undefined + const wheelDrivers = robot?.mechanism + ? World.SimulationSystem.GetSimulationLayer(robot.mechanism)?.drivers.filter( + x => x instanceof WheelDriver + ) + : undefined wheelDrivers?.forEach(x => { x.maxVelocity = vel x.maxForce = force @@ -55,22 +59,24 @@ const JointRow: React.FC = ({ robot, driver }) => { PreferencesSystem.getRobotPreferences(robot.assemblyName).driveVelocity = vel PreferencesSystem.getRobotPreferences(robot.assemblyName).driveAcceleration = force } else { - (driver as SliderDriver || driver as HingeDriver).maxVelocity = vel; - (driver as SliderDriver || driver as HingeDriver).maxForce = force + ((driver as SliderDriver) || (driver as HingeDriver)).maxVelocity = vel + ;((driver as SliderDriver) || (driver as HingeDriver)).maxForce = force // Preferences if (driver.info && driver.info.name) { - const removedMotor = PreferencesSystem.getRobotPreferences(robot.assemblyName).motors ? PreferencesSystem.getRobotPreferences(robot.assemblyName).motors.filter(x => { - if (x.name) - return x.name != driver.info?.name - return false - }) : [] + const removedMotor = PreferencesSystem.getRobotPreferences(robot.assemblyName).motors + ? PreferencesSystem.getRobotPreferences(robot.assemblyName).motors.filter(x => { + if (x.name) return x.name != driver.info?.name + return false + }) + : [] removedMotor.push({ name: driver.info?.name ?? "", maxVelocity: vel, - maxForce: force}) - + maxForce: force, + }) + PreferencesSystem.getRobotPreferences(robot.assemblyName).motors = removedMotor } } @@ -78,11 +84,12 @@ const JointRow: React.FC = ({ robot, driver }) => { PreferencesSystem.savePreferences() } - return ( - + = ({ robot, driver }) => { label="Max Velocity" format={{ minimumFractionDigits: 2, maximumFractionDigits: 2 }} onChange={(_, _velocity: number | number[]) => { - setVelocity(_velocity as number); + setVelocity(_velocity as number) onChange(_velocity as number, force) }} step={0.01} @@ -102,7 +109,7 @@ const JointRow: React.FC = ({ robot, driver }) => { label={driverSwitch(driver, "Max Force", "Max Torque", "Max Accel.") as string} format={{ minimumFractionDigits: 2, maximumFractionDigits: 2 }} onChange={(_, _force: number | number[]) => { - setForce(_force as number); + setForce(_force as number) onChange(velocity, _force as number) }} step={0.01} @@ -112,9 +119,7 @@ const JointRow: React.FC = ({ robot, driver }) => { ) } - -const ConfigureJointsPanel: React.FC = ({ panelId, openLocation, sidePadding}) => { - +const ConfigureJointsPanel: React.FC = ({ panelId, openLocation, sidePadding }) => { const [selectedRobot, setSelectedRobot] = useState(undefined) const [origPref, setOrigPref] = useState(undefined) @@ -129,8 +134,9 @@ const ConfigureJointsPanel: React.FC = ({ panelId, openLocation, }, []) const drivers = useMemo(() => { - return selectedRobot?.mechanism ? - World.SimulationSystem.GetSimulationLayer(selectedRobot.mechanism)?.drivers : undefined + return selectedRobot?.mechanism + ? World.SimulationSystem.GetSimulationLayer(selectedRobot.mechanism)?.drivers + : undefined }, [selectedRobot]) // Gets motors in preferences for ease of saving into origPrefs which can be used to revert on Cancel() @@ -139,23 +145,22 @@ const ConfigureJointsPanel: React.FC = ({ panelId, openLocation, if (driver.info && driver.info.name && !(driver instanceof WheelDriver)) { const motors = PreferencesSystem.getRobotPreferences(robot.assemblyName).motors const removedMotor = motors.filter(x => { - if (x.name) - return x.name != driver.info?.name + if (x.name) return x.name != driver.info?.name return false }) if (removedMotor.length == drivers.length) { removedMotor.push({ name: driver.info?.name ?? "", - maxVelocity: (driver as SliderDriver || driver as HingeDriver).maxVelocity, - maxForce: (driver as SliderDriver || driver as HingeDriver).maxForce + maxVelocity: ((driver as SliderDriver) || (driver as HingeDriver)).maxVelocity, + maxForce: ((driver as SliderDriver) || (driver as HingeDriver)).maxForce, }) PreferencesSystem.getRobotPreferences(robot.assemblyName).motors = removedMotor } } }) PreferencesSystem.savePreferences() - setOrigPref({ ... PreferencesSystem.getRobotPreferences(robot.assemblyName)}) // clone + setOrigPref({ ...PreferencesSystem.getRobotPreferences(robot.assemblyName) }) // clone } function Cancel() { @@ -167,13 +172,12 @@ const ConfigureJointsPanel: React.FC = ({ panelId, openLocation, } else { if (driver.info && driver.info.name) { const motor = origPref.motors.filter(x => { - if (x.name) - return x.name == driver.info?.name + if (x.name) return x.name == driver.info?.name return false - })[0]; + })[0] if (motor) { - (driver as SliderDriver || driver as HingeDriver).maxVelocity = motor.maxVelocity; - (driver as SliderDriver || driver as HingeDriver).maxForce = motor.maxForce + ((driver as SliderDriver) || (driver as HingeDriver)).maxVelocity = motor.maxVelocity + ;((driver as SliderDriver) || (driver as HingeDriver)).maxForce = motor.maxForce } } } @@ -183,15 +187,16 @@ const ConfigureJointsPanel: React.FC = ({ panelId, openLocation, PreferencesSystem.savePreferences() } - return ( - } panelId={panelId} openLocation={openLocation} sidePadding={sidePadding} - onAccept={() => { PreferencesSystem.savePreferences()}} + onAccept={() => { + PreferencesSystem.savePreferences() + }} onCancel={Cancel} acceptEnabled={true} > @@ -216,7 +221,6 @@ const ConfigureJointsPanel: React.FC = ({ panelId, openLocation, ) : ( <> - {drivers ? ( {/** Drivetrain row. Then other SliderDrivers and HingeDrivers */} @@ -229,29 +233,27 @@ const ConfigureJointsPanel: React.FC = ({ panelId, openLocation, return drivers.filter(x => x instanceof WheelDriver)[0] })()} /> - {drivers.filter(x => x instanceof SliderDriver || x instanceof HingeDriver).map((driver: Driver, i: number) => ( - { - return selectedRobot - })()} - driver={(() => { - return driver - })()} - /> - - ))} + {drivers + .filter(x => x instanceof SliderDriver || x instanceof HingeDriver) + .map((driver: Driver, i: number) => ( + { + return selectedRobot + })()} + driver={(() => { + return driver + })()} + /> + ))} ) : ( )} )} - - - ) } -export default ConfigureJointsPanel \ No newline at end of file +export default ConfigureJointsPanel From 12ca571ac727d6e019845b97523e62997719fbc1 Mon Sep 17 00:00:00 2001 From: a-crowell Date: Thu, 1 Aug 2024 18:28:02 -0700 Subject: [PATCH 14/34] Acceleration string --- fission/src/ui/panels/configuring/ConfigureJointsPanel.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fission/src/ui/panels/configuring/ConfigureJointsPanel.tsx b/fission/src/ui/panels/configuring/ConfigureJointsPanel.tsx index 9af0ed7548..d183021153 100644 --- a/fission/src/ui/panels/configuring/ConfigureJointsPanel.tsx +++ b/fission/src/ui/panels/configuring/ConfigureJointsPanel.tsx @@ -106,7 +106,7 @@ const JointRow: React.FC = ({ robot, driver }) => { min={driverSwitch(driver, 100, 20, 0.1) as number} max={driverSwitch(driver, 800, 150, 15) as number} value={force} - label={driverSwitch(driver, "Max Force", "Max Torque", "Max Accel.") as string} + label={driverSwitch(driver, "Max Force", "Max Torque", "Max Acceleration") as string} format={{ minimumFractionDigits: 2, maximumFractionDigits: 2 }} onChange={(_, _force: number | number[]) => { setForce(_force as number) From 6f1fe3d7d011f4fce3c5f75af9fe6d06983fc519 Mon Sep 17 00:00:00 2001 From: a-crowell Date: Fri, 2 Aug 2024 13:27:54 -0700 Subject: [PATCH 15/34] Requested changes --- .../systems/simulation/driver/HingeDriver.ts | 28 +++++-------------- .../systems/simulation/driver/SliderDriver.ts | 26 ++++------------- .../systems/simulation/driver/WheelDriver.ts | 22 +++------------ .../configuring/ConfigureJointsPanel.tsx | 6 ++-- 4 files changed, 20 insertions(+), 62 deletions(-) diff --git a/fission/src/systems/simulation/driver/HingeDriver.ts b/fission/src/systems/simulation/driver/HingeDriver.ts index 243c0c4441..a356aa8062 100644 --- a/fission/src/systems/simulation/driver/HingeDriver.ts +++ b/fission/src/systems/simulation/driver/HingeDriver.ts @@ -8,19 +8,12 @@ class HingeDriver extends Driver { private _constraint: Jolt.HingeConstraint private _controlMode: DriverControlMode = DriverControlMode.Velocity - private _accelerationDirection: number = 0.0 private _targetAngle: number - private _maxVelocity: number + public accelerationDirection: number = 0.0 + public maxVelocity: number private _prevAng: number = 0.0 - public get accelerationDirection(): number { - return this._accelerationDirection - } - public set accelerationDirection(radsPerSec: number) { - this._accelerationDirection = radsPerSec - } - public get targetAngle(): number { return this._targetAngle } @@ -28,13 +21,6 @@ class HingeDriver extends Driver { this._targetAngle = Math.max(this._constraint.GetLimitsMin(), Math.min(this._constraint.GetLimitsMax(), rads)) } - public get maxVelocity(): number { - return this._maxVelocity - } - public set maxVelocity(radsPerSec: number) { - this._maxVelocity = radsPerSec - } - public get maxForce() { return this._constraint.GetMotorSettings().mMaxTorqueLimit } @@ -68,7 +54,7 @@ class HingeDriver extends Driver { super(info) this._constraint = constraint - this._maxVelocity = maxVelocity + this.maxVelocity = maxVelocity this._targetAngle = this._constraint.GetCurrentAngle() const motorSettings = this._constraint.GetMotorSettings() @@ -84,13 +70,13 @@ class HingeDriver extends Driver { public Update(_: number): void { if (this._controlMode == DriverControlMode.Velocity) { - this._constraint.SetTargetAngularVelocity(this._accelerationDirection * this._maxVelocity) + this._constraint.SetTargetAngularVelocity(this.accelerationDirection * this.maxVelocity) } else if (this._controlMode == DriverControlMode.Position) { let ang = this._targetAngle - if (ang - this._prevAng < -this.maxVelocity) ang = this._prevAng - this._maxVelocity - if (ang - this._prevAng > this.maxVelocity) ang = this._prevAng + this._maxVelocity - this._constraint.SetTargetAngle(this._targetAngle) + if (ang - this._prevAng < -this.maxVelocity) ang = this._prevAng - this.maxVelocity + if (ang - this._prevAng > this.maxVelocity) ang = this._prevAng + this.maxVelocity + this._constraint.SetTargetAngle(ang) } } } diff --git a/fission/src/systems/simulation/driver/SliderDriver.ts b/fission/src/systems/simulation/driver/SliderDriver.ts index 0cfbb2dc8d..d80a3fa681 100644 --- a/fission/src/systems/simulation/driver/SliderDriver.ts +++ b/fission/src/systems/simulation/driver/SliderDriver.ts @@ -8,19 +8,12 @@ class SliderDriver extends Driver { private _constraint: Jolt.SliderConstraint private _controlMode: DriverControlMode = DriverControlMode.Velocity - private _accelerationDirection: number = 0.0 private _targetPosition: number = 0.0 - private _maxVelocity: number = 1.0 + public accelerationDirection: number = 0.0 + public maxVelocity: number = 1.0 private _prevPos: number = 0.0 - public get accelerationDirection(): number { - return this._accelerationDirection - } - public set accelerationDirection(radsPerSec: number) { - this._accelerationDirection = radsPerSec - } - public get targetPosition(): number { return this._targetPosition } @@ -31,13 +24,6 @@ class SliderDriver extends Driver { ) } - public get maxVelocity(): number { - return this._maxVelocity - } - public set maxVelocity(radsPerSec: number) { - this._maxVelocity = radsPerSec - } - public get maxForce(): number { return this._constraint.GetMotorSettings().mMaxForceLimit } @@ -70,7 +56,7 @@ class SliderDriver extends Driver { super(info) this._constraint = constraint - this._maxVelocity = maxVelocity + this.maxVelocity = maxVelocity const motorSettings = this._constraint.GetMotorSettings() const springSettings = motorSettings.mSpringSettings @@ -84,12 +70,12 @@ class SliderDriver extends Driver { public Update(_: number): void { if (this._controlMode == DriverControlMode.Velocity) { - this._constraint.SetTargetVelocity(this._accelerationDirection * this._maxVelocity) + this._constraint.SetTargetVelocity(this.accelerationDirection * this.maxVelocity) } else if (this._controlMode == DriverControlMode.Position) { let pos = this._targetPosition - if (pos - this._prevPos < -this.maxVelocity) pos = this._prevPos - this._maxVelocity - if (pos - this._prevPos > this.maxVelocity) pos = this._prevPos + this._maxVelocity + if (pos - this._prevPos < -this.maxVelocity) pos = this._prevPos - this.maxVelocity + if (pos - this._prevPos > this.maxVelocity) pos = this._prevPos + this.maxVelocity this._constraint.SetTargetPosition(pos) } diff --git a/fission/src/systems/simulation/driver/WheelDriver.ts b/fission/src/systems/simulation/driver/WheelDriver.ts index 35aa702494..916a6c6a28 100644 --- a/fission/src/systems/simulation/driver/WheelDriver.ts +++ b/fission/src/systems/simulation/driver/WheelDriver.ts @@ -14,13 +14,13 @@ class WheelDriver extends Driver { public device?: string private _reversed: boolean - private _accelerationDirection: number = 0.0 + public accelerationDirection: number = 0.0 private _prevVel: number = 0.0 - private _maxVelocity = 30.0 + public maxVelocity = 30.0 private _maxAcceleration = 1.5 private _targetVelocity = () => { - let vel = this._accelerationDirection * (this._reversed ? -1 : 1) * this._maxVelocity + let vel = this.accelerationDirection * (this._reversed ? -1 : 1) * this.maxVelocity if (vel - this._prevVel < -this._maxAcceleration) vel = this._prevVel - this._maxAcceleration if (vel - this._prevVel > this._maxAcceleration) vel = this._prevVel + this._maxAcceleration @@ -28,20 +28,6 @@ class WheelDriver extends Driver { return vel } - public get accelerationDirection(): number { - return this._accelerationDirection - } - public set accelerationDirection(radsPerSec: number) { - this._accelerationDirection = radsPerSec - } - - public get maxVelocity(): number { - return this._maxVelocity - } - public set maxVelocity(radsPerSec: number) { - this._maxVelocity = radsPerSec - } - public get maxForce(): number { return this._maxAcceleration } @@ -64,7 +50,7 @@ class WheelDriver extends Driver { super(info) this._constraint = constraint - this._maxVelocity = maxVel + this.maxVelocity = maxVel const controller = JOLT.castObject(this._constraint.GetController(), JOLT.WheeledVehicleController) this._maxAcceleration = controller.GetEngine().mMaxTorque diff --git a/fission/src/ui/panels/configuring/ConfigureJointsPanel.tsx b/fission/src/ui/panels/configuring/ConfigureJointsPanel.tsx index d183021153..a290037354 100644 --- a/fission/src/ui/panels/configuring/ConfigureJointsPanel.tsx +++ b/fission/src/ui/panels/configuring/ConfigureJointsPanel.tsx @@ -14,7 +14,7 @@ import ScrollView from "@/ui/components/ScrollView" import Slider from "@/ui/components/Slider" import Stack, { StackDirection } from "@/ui/components/Stack" import { Box } from "@mui/material" -import { useMemo, useState } from "react" +import { useCallback, useMemo, useState } from "react" import { FaGear } from "react-icons/fa6" type JointRowProps = { @@ -43,7 +43,7 @@ const JointRow: React.FC = ({ robot, driver }) => { ((driver as SliderDriver) || (driver as HingeDriver) || (driver as WheelDriver)).maxForce ) - const onChange = (vel: number, force: number) => { + const onChange = useCallback((vel: number, force: number) => { if (driver instanceof WheelDriver) { const wheelDrivers = robot?.mechanism ? World.SimulationSystem.GetSimulationLayer(robot.mechanism)?.drivers.filter( @@ -82,7 +82,7 @@ const JointRow: React.FC = ({ robot, driver }) => { } PreferencesSystem.savePreferences() - } + }, [driver, velocity, force]) return ( From 33f72b08303cfd683c8988ada6e7bdbc65101038 Mon Sep 17 00:00:00 2001 From: a-crowell Date: Mon, 5 Aug 2024 10:53:35 -0700 Subject: [PATCH 16/34] Subsystem --- fission/src/Synthesis.tsx | 4 ++-- fission/src/ui/components/MainHUD.tsx | 4 ++-- ...sPanel.tsx => ConfigureSubsystemsPanel.tsx} | 18 +++++++++--------- 3 files changed, 13 insertions(+), 13 deletions(-) rename fission/src/ui/panels/configuring/{ConfigureJointsPanel.tsx => ConfigureSubsystemsPanel.tsx} (95%) diff --git a/fission/src/Synthesis.tsx b/fission/src/Synthesis.tsx index f33227e360..62b1a0e76f 100644 --- a/fission/src/Synthesis.tsx +++ b/fission/src/Synthesis.tsx @@ -40,7 +40,7 @@ import SpawnLocationsPanel from "@/panels/SpawnLocationPanel" import ConfigureGamepiecePickupPanel from "@/panels/configuring/ConfigureGamepiecePickupPanel" import ConfigureShotTrajectoryPanel from "@/panels/configuring/ConfigureShotTrajectoryPanel" import ScoringZonesPanel from "@/panels/configuring/scoring/ScoringZonesPanel" -import ConfigureJointsPanel from "@/panels/configuring/ConfigureJointsPanel" +import ConfigureSubsystemsPanel from "@/ui/panels/configuring/ConfigureSubsystemsPanel.tsx" import ScoreboardPanel from "@/panels/information/ScoreboardPanel" import DriverStationPanel from "@/panels/simulation/DriverStationPanel" import PokerPanel from "@/panels/PokerPanel.tsx" @@ -254,7 +254,7 @@ const initialPanels: ReactElement[] = [ , , , - , + , ] export default Synthesis diff --git a/fission/src/ui/components/MainHUD.tsx b/fission/src/ui/components/MainHUD.tsx index e4ed7d8211..52d1493c80 100644 --- a/fission/src/ui/components/MainHUD.tsx +++ b/fission/src/ui/components/MainHUD.tsx @@ -120,9 +120,9 @@ const MainHUD: React.FC = () => { }} /> openPanel("joint-config")} + onClick={() => openPanel("subsystem-config")} /> = ({ robot, driver }) => { +const SubsystemRow: React.FC = ({ robot, driver }) => { const driverSwitch = (driver: Driver, slider: unknown, hinge: unknown, drivetrain: unknown) => { switch (driver.constructor) { case SliderDriver: @@ -82,7 +82,7 @@ const JointRow: React.FC = ({ robot, driver }) => { } PreferencesSystem.savePreferences() - }, [driver, velocity, force]) + }, [driver, robot.mechanism, robot.assemblyName]) return ( @@ -119,7 +119,7 @@ const JointRow: React.FC = ({ robot, driver }) => { ) } -const ConfigureJointsPanel: React.FC = ({ panelId, openLocation, sidePadding }) => { +const ConfigureSubsystemsPanel: React.FC = ({ panelId, openLocation, sidePadding }) => { const [selectedRobot, setSelectedRobot] = useState(undefined) const [origPref, setOrigPref] = useState(undefined) @@ -189,7 +189,7 @@ const ConfigureJointsPanel: React.FC = ({ panelId, openLocation, return ( } panelId={panelId} openLocation={openLocation} @@ -224,7 +224,7 @@ const ConfigureJointsPanel: React.FC = ({ panelId, openLocation, {drivers ? ( {/** Drivetrain row. Then other SliderDrivers and HingeDrivers */} - { return selectedRobot @@ -236,7 +236,7 @@ const ConfigureJointsPanel: React.FC = ({ panelId, openLocation, {drivers .filter(x => x instanceof SliderDriver || x instanceof HingeDriver) .map((driver: Driver, i: number) => ( - { return selectedRobot @@ -248,7 +248,7 @@ const ConfigureJointsPanel: React.FC = ({ panelId, openLocation, ))} ) : ( - + )} )} @@ -256,4 +256,4 @@ const ConfigureJointsPanel: React.FC = ({ panelId, openLocation, ) } -export default ConfigureJointsPanel +export default ConfigureSubsystemsPanel From 14868c73c7c425c5e157dc29163075cd6506f4a9 Mon Sep 17 00:00:00 2001 From: a-crowell Date: Wed, 7 Aug 2024 10:39:25 -0700 Subject: [PATCH 17/34] Format --- .../configuring/ConfigureSubsystemsPanel.tsx | 71 ++++++++++--------- 1 file changed, 37 insertions(+), 34 deletions(-) diff --git a/fission/src/ui/panels/configuring/ConfigureSubsystemsPanel.tsx b/fission/src/ui/panels/configuring/ConfigureSubsystemsPanel.tsx index 348d49aac2..b454da7bf9 100644 --- a/fission/src/ui/panels/configuring/ConfigureSubsystemsPanel.tsx +++ b/fission/src/ui/panels/configuring/ConfigureSubsystemsPanel.tsx @@ -43,46 +43,49 @@ const SubsystemRow: React.FC = ({ robot, driver }) => { ((driver as SliderDriver) || (driver as HingeDriver) || (driver as WheelDriver)).maxForce ) - const onChange = useCallback((vel: number, force: number) => { - if (driver instanceof WheelDriver) { - const wheelDrivers = robot?.mechanism - ? World.SimulationSystem.GetSimulationLayer(robot.mechanism)?.drivers.filter( - x => x instanceof WheelDriver - ) - : undefined - wheelDrivers?.forEach(x => { - x.maxVelocity = vel - x.maxForce = force - }) + const onChange = useCallback( + (vel: number, force: number) => { + if (driver instanceof WheelDriver) { + const wheelDrivers = robot?.mechanism + ? World.SimulationSystem.GetSimulationLayer(robot.mechanism)?.drivers.filter( + x => x instanceof WheelDriver + ) + : undefined + wheelDrivers?.forEach(x => { + x.maxVelocity = vel + x.maxForce = force + }) - // Preferences - PreferencesSystem.getRobotPreferences(robot.assemblyName).driveVelocity = vel - PreferencesSystem.getRobotPreferences(robot.assemblyName).driveAcceleration = force - } else { - ((driver as SliderDriver) || (driver as HingeDriver)).maxVelocity = vel - ;((driver as SliderDriver) || (driver as HingeDriver)).maxForce = force + // Preferences + PreferencesSystem.getRobotPreferences(robot.assemblyName).driveVelocity = vel + PreferencesSystem.getRobotPreferences(robot.assemblyName).driveAcceleration = force + } else { + ((driver as SliderDriver) || (driver as HingeDriver)).maxVelocity = vel + ;((driver as SliderDriver) || (driver as HingeDriver)).maxForce = force - // Preferences - if (driver.info && driver.info.name) { - const removedMotor = PreferencesSystem.getRobotPreferences(robot.assemblyName).motors - ? PreferencesSystem.getRobotPreferences(robot.assemblyName).motors.filter(x => { - if (x.name) return x.name != driver.info?.name - return false - }) - : [] + // Preferences + if (driver.info && driver.info.name) { + const removedMotor = PreferencesSystem.getRobotPreferences(robot.assemblyName).motors + ? PreferencesSystem.getRobotPreferences(robot.assemblyName).motors.filter(x => { + if (x.name) return x.name != driver.info?.name + return false + }) + : [] - removedMotor.push({ - name: driver.info?.name ?? "", - maxVelocity: vel, - maxForce: force, - }) + removedMotor.push({ + name: driver.info?.name ?? "", + maxVelocity: vel, + maxForce: force, + }) - PreferencesSystem.getRobotPreferences(robot.assemblyName).motors = removedMotor + PreferencesSystem.getRobotPreferences(robot.assemblyName).motors = removedMotor + } } - } - PreferencesSystem.savePreferences() - }, [driver, robot.mechanism, robot.assemblyName]) + PreferencesSystem.savePreferences() + }, + [driver, robot.mechanism, robot.assemblyName] + ) return ( From c12f5e29769abd60d5a0120f816ad6ecf34eb8bc Mon Sep 17 00:00:00 2001 From: a-crowell Date: Wed, 7 Aug 2024 11:09:05 -0700 Subject: [PATCH 18/34] Playwright update --- fission/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fission/package.json b/fission/package.json index 6e1ae08b2b..0643c80a52 100644 --- a/fission/package.json +++ b/fission/package.json @@ -32,7 +32,7 @@ "colord": "^2.9.3", "framer-motion": "^10.13.1", "lygia": "^1.1.3", - "playwright": "^1.45.0", + "playwright": "^1.46.0", "postprocessing": "^6.35.6", "react": "^18.2.0", "react-colorful": "^5.6.1", From 557475c0f134bb395d805331c1fd622573a8f9f3 Mon Sep 17 00:00:00 2001 From: a-crowell Date: Wed, 7 Aug 2024 12:20:37 -0700 Subject: [PATCH 19/34] Velocity max and dividers --- .../configuring/ConfigureSubsystemsPanel.tsx | 67 ++++++++++--------- 1 file changed, 36 insertions(+), 31 deletions(-) diff --git a/fission/src/ui/panels/configuring/ConfigureSubsystemsPanel.tsx b/fission/src/ui/panels/configuring/ConfigureSubsystemsPanel.tsx index b454da7bf9..93a437ba01 100644 --- a/fission/src/ui/panels/configuring/ConfigureSubsystemsPanel.tsx +++ b/fission/src/ui/panels/configuring/ConfigureSubsystemsPanel.tsx @@ -13,6 +13,7 @@ import Panel, { PanelPropsImpl } from "@/ui/components/Panel" import ScrollView from "@/ui/components/ScrollView" import Slider from "@/ui/components/Slider" import Stack, { StackDirection } from "@/ui/components/Stack" +import { SectionDivider } from "@/ui/components/StyledComponents" import { Box } from "@mui/material" import { useCallback, useMemo, useState } from "react" import { FaGear } from "react-icons/fa6" @@ -88,37 +89,41 @@ const SubsystemRow: React.FC = ({ robot, driver }) => { ) return ( - - - - { - setVelocity(_velocity as number) - onChange(_velocity as number, force) - }} - step={0.01} - /> - { - setForce(_force as number) - onChange(velocity, _force as number) - }} - step={0.01} - /> - - + <> + + + + { + setVelocity(_velocity as number) + onChange(_velocity as number, force) + }} + step={0.01} + /> + { + setForce(_force as number) + onChange(velocity, _force as number) + }} + step={0.01} + /> + + + + + ) } From 3cfed80ce575e09aa398fa9873c9c6c6bc9dffac Mon Sep 17 00:00:00 2001 From: a-crowell Date: Wed, 7 Aug 2024 12:36:16 -0700 Subject: [PATCH 20/34] Format --- fission/src/ui/panels/configuring/ConfigureSubsystemsPanel.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/fission/src/ui/panels/configuring/ConfigureSubsystemsPanel.tsx b/fission/src/ui/panels/configuring/ConfigureSubsystemsPanel.tsx index 93a437ba01..309442f817 100644 --- a/fission/src/ui/panels/configuring/ConfigureSubsystemsPanel.tsx +++ b/fission/src/ui/panels/configuring/ConfigureSubsystemsPanel.tsx @@ -123,7 +123,6 @@ const SubsystemRow: React.FC = ({ robot, driver }) => { - ) } From 9c847850bcb364cd6f5ffd0f0388153909523c3b Mon Sep 17 00:00:00 2001 From: a-crowell Date: Thu, 8 Aug 2024 11:28:05 -0700 Subject: [PATCH 21/34] Optional realistic gravity/force config --- .../systems/preferences/PreferenceTypes.ts | 2 ++ .../systems/simulation/driver/HingeDriver.ts | 31 ++++++++++++++++-- .../systems/simulation/driver/SliderDriver.ts | 32 +++++++++++++++++-- .../ui/modals/configuring/SettingsModal.tsx | 11 +++++++ .../configuring/ConfigureSubsystemsPanel.tsx | 15 +++++++-- 5 files changed, 85 insertions(+), 6 deletions(-) diff --git a/fission/src/systems/preferences/PreferenceTypes.ts b/fission/src/systems/preferences/PreferenceTypes.ts index 2402ead0c5..06a33fe168 100644 --- a/fission/src/systems/preferences/PreferenceTypes.ts +++ b/fission/src/systems/preferences/PreferenceTypes.ts @@ -12,6 +12,7 @@ export type GlobalPreference = | "InputSchemes" | "RenderSceneTags" | "RenderScoreboard" + | "SubsystemGravity" export const RobotPreferencesKey: string = "Robots" export const FieldPreferencesKey: string = "Fields" @@ -27,6 +28,7 @@ export const DefaultGlobalPreferences: { [key: string]: unknown } = { InputSchemes: [], RenderSceneTags: true, RenderScoreboard: true, + SubsystemGravity: false, } export type QualitySetting = "Low" | "Medium" | "High" diff --git a/fission/src/systems/simulation/driver/HingeDriver.ts b/fission/src/systems/simulation/driver/HingeDriver.ts index a356aa8062..13e01d163a 100644 --- a/fission/src/systems/simulation/driver/HingeDriver.ts +++ b/fission/src/systems/simulation/driver/HingeDriver.ts @@ -3,17 +3,23 @@ import Driver, { DriverControlMode } from "./Driver" import { GetLastDeltaT } from "@/systems/physics/PhysicsSystem" import JOLT from "@/util/loading/JoltSyncLoader" import { mirabuf } from "@/proto/mirabuf" +import PreferencesSystem, { PreferenceEvent } from "@/systems/preferences/PreferencesSystem" + +const MAX_TORQUE_WITHOUT_GRAV = 100 class HingeDriver extends Driver { private _constraint: Jolt.HingeConstraint private _controlMode: DriverControlMode = DriverControlMode.Velocity private _targetAngle: number + private _maxTorqueWithGrav: number = 0.0 public accelerationDirection: number = 0.0 public maxVelocity: number private _prevAng: number = 0.0 + private _gravityChange?: (event: PreferenceEvent) => void + public get targetAngle(): number { return this._targetAngle } @@ -27,8 +33,8 @@ class HingeDriver extends Driver { public set maxForce(nm: number) { const motorSettings = this._constraint.GetMotorSettings() - motorSettings.mMaxTorqueLimit = nm - motorSettings.mMinTorqueLimit = -nm + motorSettings.set_mMaxTorqueLimit(nm) + motorSettings.set_mMinTorqueLimit(nm) } public get controlMode(): DriverControlMode { @@ -65,7 +71,28 @@ class HingeDriver extends Driver { springSettings.mDamping = 0.995 motorSettings.mSpringSettings = springSettings + this._maxTorqueWithGrav = motorSettings.get_mMaxTorqueLimit() + if (!PreferencesSystem.getGlobalPreference("SubsystemGravity")) { + motorSettings.set_mMaxTorqueLimit(MAX_TORQUE_WITHOUT_GRAV) + motorSettings.set_mMinTorqueLimit(-MAX_TORQUE_WITHOUT_GRAV) + } + this.controlMode = DriverControlMode.Velocity + + this._gravityChange = (event: PreferenceEvent) => { + if (event.prefName == "SubsystemGravity") { + const motorSettings = this._constraint.GetMotorSettings() + if (event.prefValue) { + motorSettings.set_mMaxTorqueLimit(this._maxTorqueWithGrav) + motorSettings.set_mMinTorqueLimit(-this._maxTorqueWithGrav) + } else { + motorSettings.set_mMaxTorqueLimit(MAX_TORQUE_WITHOUT_GRAV) + motorSettings.set_mMinTorqueLimit(-MAX_TORQUE_WITHOUT_GRAV) + } + } + } + + PreferencesSystem.addEventListener(this._gravityChange) } public Update(_: number): void { diff --git a/fission/src/systems/simulation/driver/SliderDriver.ts b/fission/src/systems/simulation/driver/SliderDriver.ts index d80a3fa681..9bf7bd7563 100644 --- a/fission/src/systems/simulation/driver/SliderDriver.ts +++ b/fission/src/systems/simulation/driver/SliderDriver.ts @@ -3,17 +3,24 @@ import Driver, { DriverControlMode } from "./Driver" import { GetLastDeltaT } from "@/systems/physics/PhysicsSystem" import JOLT from "@/util/loading/JoltSyncLoader" import { mirabuf } from "@/proto/mirabuf" +import PreferencesSystem, { PreferenceEvent } from "@/systems/preferences/PreferencesSystem" + +const MAX_FORCE_WITHOUT_GRAV = 500 class SliderDriver extends Driver { private _constraint: Jolt.SliderConstraint private _controlMode: DriverControlMode = DriverControlMode.Velocity private _targetPosition: number = 0.0 + private _maxForceWithGrav: number = 0.0 public accelerationDirection: number = 0.0 public maxVelocity: number = 1.0 private _prevPos: number = 0.0 + private _gravityChange?: (event: PreferenceEvent) => void + + public get targetPosition(): number { return this._targetPosition } @@ -29,8 +36,8 @@ class SliderDriver extends Driver { } public set maxForce(newtons: number) { const motorSettings = this._constraint.GetMotorSettings() - motorSettings.mMaxForceLimit = newtons - motorSettings.mMinForceLimit = -newtons + motorSettings.set_mMaxForceLimit(newtons) + motorSettings.set_mMinForceLimit(-newtons) } public get controlMode(): DriverControlMode { @@ -64,8 +71,29 @@ class SliderDriver extends Driver { springSettings.mDamping = 0.999 motorSettings.mSpringSettings = springSettings + this._maxForceWithGrav = motorSettings.get_mMaxForceLimit() + if (!PreferencesSystem.getGlobalPreference("SubsystemGravity")) { + motorSettings.set_mMaxForceLimit(MAX_FORCE_WITHOUT_GRAV) + motorSettings.set_mMinForceLimit(-MAX_FORCE_WITHOUT_GRAV) + } + this._constraint.SetMotorState(JOLT.EMotorState_Velocity) this.controlMode = DriverControlMode.Velocity + + this._gravityChange = (event: PreferenceEvent) => { + if (event.prefName == "SubsystemGravity") { + const motorSettings = this._constraint.GetMotorSettings() + if (event.prefValue) { + motorSettings.set_mMaxForceLimit(this._maxForceWithGrav) + motorSettings.set_mMinForceLimit(-this._maxForceWithGrav) + } else { + motorSettings.set_mMaxForceLimit(MAX_FORCE_WITHOUT_GRAV) + motorSettings.set_mMinForceLimit(-MAX_FORCE_WITHOUT_GRAV) + } + } + } + + PreferencesSystem.addEventListener(this._gravityChange) } public Update(_: number): void { diff --git a/fission/src/ui/modals/configuring/SettingsModal.tsx b/fission/src/ui/modals/configuring/SettingsModal.tsx index 9e2ab7e340..fdd91b3da2 100644 --- a/fission/src/ui/modals/configuring/SettingsModal.tsx +++ b/fission/src/ui/modals/configuring/SettingsModal.tsx @@ -41,6 +41,9 @@ const SettingsModal: React.FC = ({ modalId }) => { const [renderScoreboard, setRenderScoreboard] = useState( PreferencesSystem.getGlobalPreference("RenderScoreboard") ) + const [subsystemGravity, setSubsystemGravity] = useState( + PreferencesSystem.getGlobalPreference("SubsystemGravity") + ) const saveSettings = () => { PreferencesSystem.setGlobalPreference("QualitySettings", qualitySettings) @@ -52,6 +55,7 @@ const SettingsModal: React.FC = ({ modalId }) => { PreferencesSystem.setGlobalPreference("RenderScoringZones", renderScoringZones) PreferencesSystem.setGlobalPreference("RenderSceneTags", renderSceneTags) PreferencesSystem.setGlobalPreference("RenderScoreboard", renderScoreboard) + PreferencesSystem.setGlobalPreference("SubsystemGravity", subsystemGravity) PreferencesSystem.savePreferences() } @@ -122,6 +126,13 @@ const SettingsModal: React.FC = ({ modalId }) => { setUseMetric(checked) }} /> + ("SubsystemGravity")} + onClick={checked => { + setSubsystemGravity(checked) + }} + /> ("RenderScoringZones")} diff --git a/fission/src/ui/panels/configuring/ConfigureSubsystemsPanel.tsx b/fission/src/ui/panels/configuring/ConfigureSubsystemsPanel.tsx index 309442f817..2e39295082 100644 --- a/fission/src/ui/panels/configuring/ConfigureSubsystemsPanel.tsx +++ b/fission/src/ui/panels/configuring/ConfigureSubsystemsPanel.tsx @@ -97,7 +97,7 @@ const SubsystemRow: React.FC = ({ robot, driver }) => { = ({ robot, driver }) => { }} step={0.01} /> + {(PreferencesSystem.getGlobalPreference("SubsystemGravity") || driver instanceof WheelDriver) ? ( = ({ robot, driver }) => { }} step={0.01} /> + ) : ( + (driver instanceof HingeDriver) ? ( + + ) : ( + + ) + ) + } @@ -184,7 +193,9 @@ const ConfigureSubsystemsPanel: React.FC = ({ panelId, openLocat })[0] if (motor) { ((driver as SliderDriver) || (driver as HingeDriver)).maxVelocity = motor.maxVelocity - ;((driver as SliderDriver) || (driver as HingeDriver)).maxForce = motor.maxForce + ;((driver as SliderDriver) || (driver as HingeDriver)).maxForce = PreferencesSystem.getGlobalPreference("SubsystemGravity") + ? motor.maxForce + : ( driver instanceof SliderDriver ? 500 : 100) } } } From cd60dcbac91f3fa9f81629fc48ff640c7a38d033 Mon Sep 17 00:00:00 2001 From: a-crowell Date: Fri, 9 Aug 2024 09:49:04 -0700 Subject: [PATCH 22/34] Arm fix --- fission/src/systems/simulation/driver/HingeDriver.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fission/src/systems/simulation/driver/HingeDriver.ts b/fission/src/systems/simulation/driver/HingeDriver.ts index 13e01d163a..e86a6e5b48 100644 --- a/fission/src/systems/simulation/driver/HingeDriver.ts +++ b/fission/src/systems/simulation/driver/HingeDriver.ts @@ -34,7 +34,7 @@ class HingeDriver extends Driver { public set maxForce(nm: number) { const motorSettings = this._constraint.GetMotorSettings() motorSettings.set_mMaxTorqueLimit(nm) - motorSettings.set_mMinTorqueLimit(nm) + motorSettings.set_mMinTorqueLimit(-nm) } public get controlMode(): DriverControlMode { From b31793fcaa17339ed81754d6ede66b86bcffc8a1 Mon Sep 17 00:00:00 2001 From: a-crowell <53123817+a-crowell@users.noreply.github.com> Date: Fri, 9 Aug 2024 11:29:14 -0700 Subject: [PATCH 23/34] Merge conflict Co-authored-by: Brandon Pacewic <92102436+BrandonPacewic@users.noreply.github.com> --- fission/src/mirabuf/MirabufParser.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/fission/src/mirabuf/MirabufParser.ts b/fission/src/mirabuf/MirabufParser.ts index ae1607b97c..7dab72156b 100644 --- a/fission/src/mirabuf/MirabufParser.ts +++ b/fission/src/mirabuf/MirabufParser.ts @@ -240,7 +240,6 @@ class MirabufParser { console.log("Failed to get part definitions") return } - console.debug(partDefinitions) } private NewRigidNode(suffix?: string): RigidNode { From caee8eb51656f72f1ebdae7879c615791b2b1f09 Mon Sep 17 00:00:00 2001 From: a-crowell Date: Tue, 13 Aug 2024 09:25:57 -0700 Subject: [PATCH 24/34] Forgot to stage this one --- fission/src/Synthesis.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fission/src/Synthesis.tsx b/fission/src/Synthesis.tsx index 0e2fe2a29b..c1d33806ca 100644 --- a/fission/src/Synthesis.tsx +++ b/fission/src/Synthesis.tsx @@ -36,6 +36,7 @@ import ThemeEditorModal from "@/modals/configuring/theme-editor/ThemeEditorModal import MatchModeModal from "@/modals/spawning/MatchModeModal" import RobotSwitchPanel from "@/panels/RobotSwitchPanel" import SpawnLocationsPanel from "@/panels/SpawnLocationPanel" +import ConfigureSubsystemsPanel from "@/ui/panels/configuring/ConfigureSubsystemsPanel.tsx" import ScoreboardPanel from "@/panels/information/ScoreboardPanel" import DriverStationPanel from "@/panels/simulation/DriverStationPanel" import PokerPanel from "@/panels/PokerPanel.tsx" @@ -241,6 +242,7 @@ const initialPanels: ReactElement[] = [ , , , + , ] export default Synthesis From b991c2b059c2899a684df6750a4aabb563d5eb2c Mon Sep 17 00:00:00 2001 From: a-crowell Date: Tue, 13 Aug 2024 09:28:51 -0700 Subject: [PATCH 25/34] Formatting --- .../systems/simulation/driver/HingeDriver.ts | 4 +- .../systems/simulation/driver/SliderDriver.ts | 1 - .../configuring/ConfigureSubsystemsPanel.tsx | 46 +++++++++---------- 3 files changed, 25 insertions(+), 26 deletions(-) diff --git a/fission/src/systems/simulation/driver/HingeDriver.ts b/fission/src/systems/simulation/driver/HingeDriver.ts index c2edf011a6..755994921d 100644 --- a/fission/src/systems/simulation/driver/HingeDriver.ts +++ b/fission/src/systems/simulation/driver/HingeDriver.ts @@ -19,7 +19,7 @@ class HingeDriver extends Driver { public get constraint(): Jolt.HingeConstraint { return this._constraint } - + private _prevAng: number = 0.0 private _gravityChange?: (event: PreferenceEvent) => void @@ -82,7 +82,7 @@ class HingeDriver extends Driver { } this.controlMode = DriverControlMode.Velocity - + this._gravityChange = (event: PreferenceEvent) => { if (event.prefName == "SubsystemGravity") { const motorSettings = this._constraint.GetMotorSettings() diff --git a/fission/src/systems/simulation/driver/SliderDriver.ts b/fission/src/systems/simulation/driver/SliderDriver.ts index b880a097d3..eb80a871e6 100644 --- a/fission/src/systems/simulation/driver/SliderDriver.ts +++ b/fission/src/systems/simulation/driver/SliderDriver.ts @@ -24,7 +24,6 @@ class SliderDriver extends Driver { private _gravityChange?: (event: PreferenceEvent) => void - public get targetPosition(): number { return this._targetPosition } diff --git a/fission/src/ui/panels/configuring/ConfigureSubsystemsPanel.tsx b/fission/src/ui/panels/configuring/ConfigureSubsystemsPanel.tsx index 2e39295082..7e56fd27a0 100644 --- a/fission/src/ui/panels/configuring/ConfigureSubsystemsPanel.tsx +++ b/fission/src/ui/panels/configuring/ConfigureSubsystemsPanel.tsx @@ -107,27 +107,24 @@ const SubsystemRow: React.FC = ({ robot, driver }) => { }} step={0.01} /> - {(PreferencesSystem.getGlobalPreference("SubsystemGravity") || driver instanceof WheelDriver) ? ( - { - setForce(_force as number) - onChange(velocity, _force as number) - }} - step={0.01} - /> + {PreferencesSystem.getGlobalPreference("SubsystemGravity") || driver instanceof WheelDriver ? ( + { + setForce(_force as number) + onChange(velocity, _force as number) + }} + step={0.01} + /> + ) : driver instanceof HingeDriver ? ( + ) : ( - (driver instanceof HingeDriver) ? ( - - ) : ( - - ) - ) - } + + )} @@ -193,9 +190,12 @@ const ConfigureSubsystemsPanel: React.FC = ({ panelId, openLocat })[0] if (motor) { ((driver as SliderDriver) || (driver as HingeDriver)).maxVelocity = motor.maxVelocity - ;((driver as SliderDriver) || (driver as HingeDriver)).maxForce = PreferencesSystem.getGlobalPreference("SubsystemGravity") - ? motor.maxForce - : ( driver instanceof SliderDriver ? 500 : 100) + ;((driver as SliderDriver) || (driver as HingeDriver)).maxForce = + PreferencesSystem.getGlobalPreference("SubsystemGravity") + ? motor.maxForce + : driver instanceof SliderDriver + ? 500 + : 100 } } } From 9627c8aa765e0d443555cfce12db579e11999718 Mon Sep 17 00:00:00 2001 From: a-crowell Date: Wed, 14 Aug 2024 11:57:28 -0700 Subject: [PATCH 26/34] Formatting? --- fission/src/ui/panels/configuring/ConfigureSubsystemsPanel.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fission/src/ui/panels/configuring/ConfigureSubsystemsPanel.tsx b/fission/src/ui/panels/configuring/ConfigureSubsystemsPanel.tsx index 7e56fd27a0..b62db8debb 100644 --- a/fission/src/ui/panels/configuring/ConfigureSubsystemsPanel.tsx +++ b/fission/src/ui/panels/configuring/ConfigureSubsystemsPanel.tsx @@ -61,7 +61,7 @@ const SubsystemRow: React.FC = ({ robot, driver }) => { PreferencesSystem.getRobotPreferences(robot.assemblyName).driveVelocity = vel PreferencesSystem.getRobotPreferences(robot.assemblyName).driveAcceleration = force } else { - ((driver as SliderDriver) || (driver as HingeDriver)).maxVelocity = vel + ;((driver as SliderDriver) || (driver as HingeDriver)).maxVelocity = vel ;((driver as SliderDriver) || (driver as HingeDriver)).maxForce = force // Preferences From e4997bc5ed852a7566da00b67a6b54a58a21694d Mon Sep 17 00:00:00 2001 From: a-crowell Date: Wed, 14 Aug 2024 12:02:47 -0700 Subject: [PATCH 27/34] Formatting? pt. 2 --- fission/src/ui/panels/configuring/ConfigureSubsystemsPanel.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fission/src/ui/panels/configuring/ConfigureSubsystemsPanel.tsx b/fission/src/ui/panels/configuring/ConfigureSubsystemsPanel.tsx index b62db8debb..f633b2e83f 100644 --- a/fission/src/ui/panels/configuring/ConfigureSubsystemsPanel.tsx +++ b/fission/src/ui/panels/configuring/ConfigureSubsystemsPanel.tsx @@ -61,7 +61,8 @@ const SubsystemRow: React.FC = ({ robot, driver }) => { PreferencesSystem.getRobotPreferences(robot.assemblyName).driveVelocity = vel PreferencesSystem.getRobotPreferences(robot.assemblyName).driveAcceleration = force } else { - ;((driver as SliderDriver) || (driver as HingeDriver)).maxVelocity = vel + // prettier-ignore + ((driver as SliderDriver) || (driver as HingeDriver)).maxVelocity = vel ;((driver as SliderDriver) || (driver as HingeDriver)).maxForce = force // Preferences From 3f4ba0ba11333b5f6ee0ab9d1761c9a640dbc0c9 Mon Sep 17 00:00:00 2001 From: a-crowell Date: Wed, 14 Aug 2024 12:35:53 -0700 Subject: [PATCH 28/34] Formatting :/ pt. 3 --- .../ui/panels/configuring/ConfigureSubsystemsPanel.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/fission/src/ui/panels/configuring/ConfigureSubsystemsPanel.tsx b/fission/src/ui/panels/configuring/ConfigureSubsystemsPanel.tsx index f633b2e83f..2b44012616 100644 --- a/fission/src/ui/panels/configuring/ConfigureSubsystemsPanel.tsx +++ b/fission/src/ui/panels/configuring/ConfigureSubsystemsPanel.tsx @@ -61,10 +61,6 @@ const SubsystemRow: React.FC = ({ robot, driver }) => { PreferencesSystem.getRobotPreferences(robot.assemblyName).driveVelocity = vel PreferencesSystem.getRobotPreferences(robot.assemblyName).driveAcceleration = force } else { - // prettier-ignore - ((driver as SliderDriver) || (driver as HingeDriver)).maxVelocity = vel - ;((driver as SliderDriver) || (driver as HingeDriver)).maxForce = force - // Preferences if (driver.info && driver.info.name) { const removedMotor = PreferencesSystem.getRobotPreferences(robot.assemblyName).motors @@ -82,6 +78,10 @@ const SubsystemRow: React.FC = ({ robot, driver }) => { PreferencesSystem.getRobotPreferences(robot.assemblyName).motors = removedMotor } + + // Edit subsystems + ((driver as SliderDriver) || (driver as HingeDriver)).maxVelocity = vel + ;((driver as SliderDriver) || (driver as HingeDriver)).maxForce = force } PreferencesSystem.savePreferences() From eea49af801a025fc6c8c8610d9415f8f6321c774 Mon Sep 17 00:00:00 2001 From: a-crowell Date: Wed, 14 Aug 2024 12:39:39 -0700 Subject: [PATCH 29/34] Formatting -.- pt. 4 --- .../panels/configuring/ConfigureSubsystemsPanel.tsx | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/fission/src/ui/panels/configuring/ConfigureSubsystemsPanel.tsx b/fission/src/ui/panels/configuring/ConfigureSubsystemsPanel.tsx index 2b44012616..6efdeff732 100644 --- a/fission/src/ui/panels/configuring/ConfigureSubsystemsPanel.tsx +++ b/fission/src/ui/panels/configuring/ConfigureSubsystemsPanel.tsx @@ -61,6 +61,14 @@ const SubsystemRow: React.FC = ({ robot, driver }) => { PreferencesSystem.getRobotPreferences(robot.assemblyName).driveVelocity = vel PreferencesSystem.getRobotPreferences(robot.assemblyName).driveAcceleration = force } else { + // A function because ES Lint and Prettier are fighting over semicolon formatting + const editMotors = () => { + ((driver as SliderDriver) || (driver as HingeDriver)).maxVelocity = vel + ;((driver as SliderDriver) || (driver as HingeDriver)).maxForce = force + } + + editMotors() + // Preferences if (driver.info && driver.info.name) { const removedMotor = PreferencesSystem.getRobotPreferences(robot.assemblyName).motors @@ -79,9 +87,7 @@ const SubsystemRow: React.FC = ({ robot, driver }) => { PreferencesSystem.getRobotPreferences(robot.assemblyName).motors = removedMotor } - // Edit subsystems - ((driver as SliderDriver) || (driver as HingeDriver)).maxVelocity = vel - ;((driver as SliderDriver) || (driver as HingeDriver)).maxForce = force + } PreferencesSystem.savePreferences() From 48c23f0e9501170dc3caf472ae53e01f50eb1b87 Mon Sep 17 00:00:00 2001 From: a-crowell Date: Wed, 14 Aug 2024 12:45:51 -0700 Subject: [PATCH 30/34] Formatting :D pt. 5 --- .../panels/configuring/ConfigureSubsystemsPanel.tsx | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/fission/src/ui/panels/configuring/ConfigureSubsystemsPanel.tsx b/fission/src/ui/panels/configuring/ConfigureSubsystemsPanel.tsx index 6efdeff732..18848c4a9d 100644 --- a/fission/src/ui/panels/configuring/ConfigureSubsystemsPanel.tsx +++ b/fission/src/ui/panels/configuring/ConfigureSubsystemsPanel.tsx @@ -61,14 +61,6 @@ const SubsystemRow: React.FC = ({ robot, driver }) => { PreferencesSystem.getRobotPreferences(robot.assemblyName).driveVelocity = vel PreferencesSystem.getRobotPreferences(robot.assemblyName).driveAcceleration = force } else { - // A function because ES Lint and Prettier are fighting over semicolon formatting - const editMotors = () => { - ((driver as SliderDriver) || (driver as HingeDriver)).maxVelocity = vel - ;((driver as SliderDriver) || (driver as HingeDriver)).maxForce = force - } - - editMotors() - // Preferences if (driver.info && driver.info.name) { const removedMotor = PreferencesSystem.getRobotPreferences(robot.assemblyName).motors @@ -87,7 +79,9 @@ const SubsystemRow: React.FC = ({ robot, driver }) => { PreferencesSystem.getRobotPreferences(robot.assemblyName).motors = removedMotor } - + // eslint-disable-next-line no-extra-semi + ;((driver as SliderDriver) || (driver as HingeDriver)).maxVelocity = vel + ;((driver as SliderDriver) || (driver as HingeDriver)).maxForce = force } PreferencesSystem.savePreferences() From 84039e0f1f4d2997acac757ee78641cff0c0b1d9 Mon Sep 17 00:00:00 2001 From: a-crowell Date: Wed, 14 Aug 2024 12:49:17 -0700 Subject: [PATCH 31/34] Formatting? pt. 6 --- fission/src/ui/panels/configuring/ConfigureSubsystemsPanel.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fission/src/ui/panels/configuring/ConfigureSubsystemsPanel.tsx b/fission/src/ui/panels/configuring/ConfigureSubsystemsPanel.tsx index 18848c4a9d..12e3f032ce 100644 --- a/fission/src/ui/panels/configuring/ConfigureSubsystemsPanel.tsx +++ b/fission/src/ui/panels/configuring/ConfigureSubsystemsPanel.tsx @@ -79,7 +79,7 @@ const SubsystemRow: React.FC = ({ robot, driver }) => { PreferencesSystem.getRobotPreferences(robot.assemblyName).motors = removedMotor } - // eslint-disable-next-line no-extra-semi + // eslint-disable-next-line ;((driver as SliderDriver) || (driver as HingeDriver)).maxVelocity = vel ;((driver as SliderDriver) || (driver as HingeDriver)).maxForce = force } From ef86b555a4a249da337d0e2b92e3f98412419334 Mon Sep 17 00:00:00 2001 From: a-crowell Date: Wed, 14 Aug 2024 15:32:51 -0700 Subject: [PATCH 32/34] Formatting... pt. 7 --- .../src/ui/panels/configuring/ConfigureSubsystemsPanel.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fission/src/ui/panels/configuring/ConfigureSubsystemsPanel.tsx b/fission/src/ui/panels/configuring/ConfigureSubsystemsPanel.tsx index 12e3f032ce..8ef674b3cf 100644 --- a/fission/src/ui/panels/configuring/ConfigureSubsystemsPanel.tsx +++ b/fission/src/ui/panels/configuring/ConfigureSubsystemsPanel.tsx @@ -79,7 +79,9 @@ const SubsystemRow: React.FC = ({ robot, driver }) => { PreferencesSystem.getRobotPreferences(robot.assemblyName).motors = removedMotor } - // eslint-disable-next-line + // This line is purely for ES Lint and Prettier to agree on formatting the semicolon below. + PreferencesSystem.savePreferences() + ;((driver as SliderDriver) || (driver as HingeDriver)).maxVelocity = vel ;((driver as SliderDriver) || (driver as HingeDriver)).maxForce = force } From 6360df0e6c182d0be0cf49aec232eabdcefaa1ca Mon Sep 17 00:00:00 2001 From: a-crowell Date: Wed, 14 Aug 2024 15:38:33 -0700 Subject: [PATCH 33/34] Formatting :D pt. 8 --- .../configuring/ConfigureSubsystemsPanel.tsx | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/fission/src/ui/panels/configuring/ConfigureSubsystemsPanel.tsx b/fission/src/ui/panels/configuring/ConfigureSubsystemsPanel.tsx index 8ef674b3cf..afa71cd9c0 100644 --- a/fission/src/ui/panels/configuring/ConfigureSubsystemsPanel.tsx +++ b/fission/src/ui/panels/configuring/ConfigureSubsystemsPanel.tsx @@ -79,9 +79,7 @@ const SubsystemRow: React.FC = ({ robot, driver }) => { PreferencesSystem.getRobotPreferences(robot.assemblyName).motors = removedMotor } - // This line is purely for ES Lint and Prettier to agree on formatting the semicolon below. - PreferencesSystem.savePreferences() - + // eslint-disable-next-line no-extra-semi ;((driver as SliderDriver) || (driver as HingeDriver)).maxVelocity = vel ;((driver as SliderDriver) || (driver as HingeDriver)).maxForce = force } @@ -192,13 +190,14 @@ const ConfigureSubsystemsPanel: React.FC = ({ panelId, openLocat return false })[0] if (motor) { - ((driver as SliderDriver) || (driver as HingeDriver)).maxVelocity = motor.maxVelocity - ;((driver as SliderDriver) || (driver as HingeDriver)).maxForce = - PreferencesSystem.getGlobalPreference("SubsystemGravity") - ? motor.maxForce - : driver instanceof SliderDriver - ? 500 - : 100 + // This line is a separate variable to get ES Lint and Prettier to agree on formatting the semicolon below + const forcePref = PreferencesSystem.getGlobalPreference("SubsystemGravity") + ? motor.maxForce + : driver instanceof SliderDriver + ? 500 + : 100 + ;((driver as SliderDriver) || (driver as HingeDriver)).maxVelocity = motor.maxVelocity + ;((driver as SliderDriver) || (driver as HingeDriver)).maxForce = forcePref } } } From a14ab94c51e44de1955d7fae4ac28d4327f551de Mon Sep 17 00:00:00 2001 From: a-crowell Date: Wed, 14 Aug 2024 15:40:55 -0700 Subject: [PATCH 34/34] Formatting ._. pt. 9 --- .../src/ui/panels/configuring/ConfigureSubsystemsPanel.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fission/src/ui/panels/configuring/ConfigureSubsystemsPanel.tsx b/fission/src/ui/panels/configuring/ConfigureSubsystemsPanel.tsx index afa71cd9c0..cf343f012f 100644 --- a/fission/src/ui/panels/configuring/ConfigureSubsystemsPanel.tsx +++ b/fission/src/ui/panels/configuring/ConfigureSubsystemsPanel.tsx @@ -194,8 +194,8 @@ const ConfigureSubsystemsPanel: React.FC = ({ panelId, openLocat const forcePref = PreferencesSystem.getGlobalPreference("SubsystemGravity") ? motor.maxForce : driver instanceof SliderDriver - ? 500 - : 100 + ? 500 + : 100 ;((driver as SliderDriver) || (driver as HingeDriver)).maxVelocity = motor.maxVelocity ;((driver as SliderDriver) || (driver as HingeDriver)).maxForce = forcePref }