From e33c803543e33a7f1da57d6a33512cac934ece31 Mon Sep 17 00:00:00 2001 From: LucaHaverty Date: Thu, 20 Jun 2024 11:32:06 -0700 Subject: [PATCH 1/4] Fixed elevator behavior and added velocity control to slider drivers --- .../behavior/GenericElevatorBehavior.ts | 10 ++-- .../src/systems/simulation/driver/Driver.ts | 5 ++ .../systems/simulation/driver/HingeDriver.ts | 11 ++--- .../systems/simulation/driver/SliderDriver.ts | 49 ++++++++++++++++--- 4 files changed, 55 insertions(+), 20 deletions(-) diff --git a/fission/src/systems/simulation/behavior/GenericElevatorBehavior.ts b/fission/src/systems/simulation/behavior/GenericElevatorBehavior.ts index 1190cff16a..e77b037eae 100644 --- a/fission/src/systems/simulation/behavior/GenericElevatorBehavior.ts +++ b/fission/src/systems/simulation/behavior/GenericElevatorBehavior.ts @@ -9,7 +9,7 @@ class GenericElevatorBehavior extends Behavior { private _positiveInput: string; private _negativeInput: string; - private _linearSpeed = 1; + private _linearSpeed = 10; constructor(sliderDriver: SliderDriver, sliderStimulus: SliderStimulus, jointIndex: number) { super([sliderDriver], [sliderStimulus]); @@ -25,12 +25,12 @@ class GenericElevatorBehavior extends Behavior { } // Changes the elevators target position - moveElevator(positionDelta: number) { - this._sliderDriver.targetPosition += positionDelta; + moveElevator(linearVelocity: number) { + this._sliderDriver.targetVelocity = linearVelocity; } - public Update(deltaT: number): void { - this.moveElevator(InputSystem.GetAxis(this._positiveInput, this._negativeInput)*this._linearSpeed*deltaT); + public Update(_: number): void { + this.moveElevator(InputSystem.GetAxis(this._positiveInput, this._negativeInput)*this._linearSpeed); } } diff --git a/fission/src/systems/simulation/driver/Driver.ts b/fission/src/systems/simulation/driver/Driver.ts index 19361c0361..409cebfbdf 100644 --- a/fission/src/systems/simulation/driver/Driver.ts +++ b/fission/src/systems/simulation/driver/Driver.ts @@ -2,4 +2,9 @@ abstract class Driver { public abstract Update(deltaT: number): void; } +export enum DriverControlMode { + Velocity = 0, + Position = 1 +} + export default Driver; \ No newline at end of file diff --git a/fission/src/systems/simulation/driver/HingeDriver.ts b/fission/src/systems/simulation/driver/HingeDriver.ts index 5e5c680baf..136b1ee546 100644 --- a/fission/src/systems/simulation/driver/HingeDriver.ts +++ b/fission/src/systems/simulation/driver/HingeDriver.ts @@ -1,5 +1,5 @@ import Jolt from "@barclah/jolt-physics"; -import Driver from "./Driver"; +import Driver, { DriverControlMode } from "./Driver"; import { SIMULATION_PERIOD } from "@/systems/physics/PhysicsSystem"; import JOLT from "@/util/loading/JoltSyncLoader"; @@ -22,7 +22,7 @@ class HingeDriver extends Driver { return this._targetAngle; } public set targetAngle(rads: number) { - this._targetAngle = rads; + this._targetAngle = Math.max(this._constraint.GetLimitsMin(), Math.min(this._constraint.GetLimitsMax(), rads)); } public set minTorqueLimit(nm: number) { @@ -37,6 +37,7 @@ class HingeDriver extends Driver { public get controlMode(): DriverControlMode { return this._controlMode; } + public set controlMode(mode: DriverControlMode) { this._controlMode = mode; switch (mode) { @@ -79,13 +80,7 @@ class HingeDriver extends Driver { } else if (this._controlMode == DriverControlMode.Position) { this._constraint.SetTargetAngle(this._targetAngle); } - } } -export enum DriverControlMode { - Velocity = 0, - Position = 1 -} - export default HingeDriver; \ No newline at end of file diff --git a/fission/src/systems/simulation/driver/SliderDriver.ts b/fission/src/systems/simulation/driver/SliderDriver.ts index b6ace1ad60..f278d70edd 100644 --- a/fission/src/systems/simulation/driver/SliderDriver.ts +++ b/fission/src/systems/simulation/driver/SliderDriver.ts @@ -1,14 +1,23 @@ import Jolt from "@barclah/jolt-physics"; -import Driver from "./Driver"; +import Driver, { DriverControlMode } from "./Driver"; import { SIMULATION_PERIOD } from "@/systems/physics/PhysicsSystem"; import JOLT from "@/util/loading/JoltSyncLoader"; -import InputSystem from "@/systems/input/InputSystem"; class SliderDriver extends Driver { private _constraint: Jolt.SliderConstraint; + + private _controlMode: DriverControlMode = DriverControlMode.Velocity; + private _targetVelocity: number = 0.0; private _targetPosition: number = 0.0; + public get targetVelocity(): number { + return this._targetVelocity; + } + public set targetVelocity(radsPerSec: number) { + this._targetVelocity = radsPerSec; + } + public get targetPosition(): number { return this._targetPosition; } @@ -25,6 +34,25 @@ class SliderDriver extends Driver { motorSettings.mMaxForceLimit = newtons; } + public get controlMode(): DriverControlMode { + return this._controlMode; + } + + public set controlMode(mode: DriverControlMode) { + this._controlMode = mode; + switch (mode) { + case DriverControlMode.Velocity: + this._constraint.SetMotorState(JOLT.EMotorState_Velocity); + break; + case DriverControlMode.Position: + this._constraint.SetMotorState(JOLT.EMotorState_Position); + break; + default: + // idk + break; + } + } + public constructor(constraint: Jolt.SliderConstraint) { super(); @@ -36,17 +64,24 @@ class SliderDriver extends Driver { springSettings.mDamping = 0.995; motorSettings.mSpringSettings = springSettings; - motorSettings.mMinForceLimit = -125.0; - motorSettings.mMaxForceLimit = 125.0; + motorSettings.mMinForceLimit = -250.0; + motorSettings.mMaxForceLimit = 250.0; - this._constraint.SetMotorState(JOLT.EMotorState_Position); + //this._constraint.SetMotorState(JOLT.EMotorState_Position); this.targetPosition = this._constraint.GetCurrentPosition(); + this.controlMode = DriverControlMode.Velocity; } public Update(_: number): void { - this._targetPosition += ((InputSystem.getInput("sliderUp") ? 1 : 0) - (InputSystem.getInput("sliderDown") ? 1 : 0))*3; - this._constraint.SetTargetPosition(this._targetPosition); + // this._targetPosition += ((InputSystem.getInput("sliderUp") ? 1 : 0) - (InputSystem.getInput("sliderDown") ? 1 : 0))*3; + // this._constraint.SetTargetVelocity(this._targetPosition); + + if (this._controlMode == DriverControlMode.Velocity) { + this._constraint.SetTargetVelocity(this._targetVelocity); + } else if (this._controlMode == DriverControlMode.Position) { + this._constraint.SetTargetPosition(this._targetPosition); + } } } From 125b44ebadf6318ec59f06d096e70f0c9525cd71 Mon Sep 17 00:00:00 2001 From: a-crowell Date: Thu, 20 Jun 2024 15:37:49 -0700 Subject: [PATCH 2/4] Minor clean up --- fission/src/systems/input/InputSystem.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fission/src/systems/input/InputSystem.ts b/fission/src/systems/input/InputSystem.ts index d64bb19d85..33e2b41e43 100644 --- a/fission/src/systems/input/InputSystem.ts +++ b/fission/src/systems/input/InputSystem.ts @@ -69,7 +69,7 @@ class InputSystem extends WorldSystem { } } - public Update(_: number): void {InputSystem + public Update(_: number): void { InputSystem._currentModifierState = { ctrl: InputSystem.isKeyPressed("ControlLeft") || InputSystem.isKeyPressed("ControlRight"), alt: InputSystem.isKeyPressed("AltLeft") || InputSystem.isKeyPressed("AltRight"), shift: InputSystem.isKeyPressed("ShiftLeft") || InputSystem.isKeyPressed("ShiftRight"), meta: InputSystem.isKeyPressed("MetaLeft") || InputSystem.isKeyPressed("MetaRight") } } From 156deb256b1120970e042227c6ca470504ec072a Mon Sep 17 00:00:00 2001 From: LucaHaverty Date: Wed, 26 Jun 2024 14:07:27 -0700 Subject: [PATCH 3/4] Greatly improved elevator stages moving each other --- fission/src/systems/input/InputSystem.ts | 3 +++ .../behavior/GenericElevatorBehavior.ts | 2 +- .../src/systems/simulation/driver/SliderDriver.ts | 15 +++++---------- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/fission/src/systems/input/InputSystem.ts b/fission/src/systems/input/InputSystem.ts index cd7f4610e6..3c28117609 100644 --- a/fission/src/systems/input/InputSystem.ts +++ b/fission/src/systems/input/InputSystem.ts @@ -123,6 +123,9 @@ class InputSystem extends WorldSystem { // Returns true if two modifier states are identical private static CompareModifiers(state1: ModifierState, state2: ModifierState) : boolean { + if (!state1 || !state2) + return false; + return state1.alt == state2.alt && state1.ctrl == state2.ctrl && state1.meta == state2.meta && state1.shift == state2.shift; } } diff --git a/fission/src/systems/simulation/behavior/GenericElevatorBehavior.ts b/fission/src/systems/simulation/behavior/GenericElevatorBehavior.ts index e77b037eae..49125917f8 100644 --- a/fission/src/systems/simulation/behavior/GenericElevatorBehavior.ts +++ b/fission/src/systems/simulation/behavior/GenericElevatorBehavior.ts @@ -9,7 +9,7 @@ class GenericElevatorBehavior extends Behavior { private _positiveInput: string; private _negativeInput: string; - private _linearSpeed = 10; + private _linearSpeed = 2.5; constructor(sliderDriver: SliderDriver, sliderStimulus: SliderStimulus, jointIndex: number) { super([sliderDriver], [sliderStimulus]); diff --git a/fission/src/systems/simulation/driver/SliderDriver.ts b/fission/src/systems/simulation/driver/SliderDriver.ts index 1d547159e2..2ad547a831 100644 --- a/fission/src/systems/simulation/driver/SliderDriver.ts +++ b/fission/src/systems/simulation/driver/SliderDriver.ts @@ -64,22 +64,17 @@ class SliderDriver extends Driver { const motorSettings = this._constraint.GetMotorSettings() const springSettings = motorSettings.mSpringSettings springSettings.mFrequency = 20 * (1.0 / SIMULATION_PERIOD) - springSettings.mDamping = 0.995 + springSettings.mDamping = 0.999 motorSettings.mSpringSettings = springSettings - motorSettings.mMinForceLimit = -250.0 - motorSettings.mMaxForceLimit = 250.0 + motorSettings.mMinForceLimit = -900.0 + motorSettings.mMaxForceLimit = 900.0 - this._constraint.SetMotorState(JOLT.EMotorState_Position) + this._constraint.SetMotorState(JOLT.EMotorState_Velocity) this.controlMode = DriverControlMode.Velocity; - this.targetPosition = this._constraint.GetCurrentPosition() } - public Update(_: number): void { - // this._targetPosition += ((InputSystem.getInput("sliderUp") ? 1 : 0) - (InputSystem.getInput("sliderDown") ? 1 : 0))*3; - // this._constraint.SetTargetVelocity(this._targetPosition); - - if (this._controlMode == DriverControlMode.Velocity) { + public Update(_: number): void {if (this._controlMode == DriverControlMode.Velocity) { this._constraint.SetTargetVelocity(this._targetVelocity); } else if (this._controlMode == DriverControlMode.Position) { this._constraint.SetTargetPosition(this._targetPosition); From dabe89faade6024dae01fa09584a1b11dea8146b Mon Sep 17 00:00:00 2001 From: LucaHaverty Date: Wed, 26 Jun 2024 14:15:16 -0700 Subject: [PATCH 4/4] Improved arm movement and reduced 'bouncing' against it's limits --- fission/src/systems/simulation/behavior/GenericArmBehavior.ts | 2 +- fission/src/systems/simulation/driver/HingeDriver.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/fission/src/systems/simulation/behavior/GenericArmBehavior.ts b/fission/src/systems/simulation/behavior/GenericArmBehavior.ts index 6e5a0b7c0c..79a9c6079c 100644 --- a/fission/src/systems/simulation/behavior/GenericArmBehavior.ts +++ b/fission/src/systems/simulation/behavior/GenericArmBehavior.ts @@ -9,7 +9,7 @@ class GenericArmBehavior extends Behavior { private _positiveInput: string; private _negativeInput: string; - private _rotationalSpeed = 30; + private _rotationalSpeed = 6; constructor(hingeDriver: HingeDriver, hingeStimulus: HingeStimulus, jointIndex: number) { super([hingeDriver], [hingeStimulus]); diff --git a/fission/src/systems/simulation/driver/HingeDriver.ts b/fission/src/systems/simulation/driver/HingeDriver.ts index 11f5e703e1..4500508490 100644 --- a/fission/src/systems/simulation/driver/HingeDriver.ts +++ b/fission/src/systems/simulation/driver/HingeDriver.ts @@ -65,8 +65,8 @@ class HingeDriver extends Driver { springSettings.mDamping = 0.995 motorSettings.mSpringSettings = springSettings - motorSettings.mMinTorqueLimit = -50.0 - motorSettings.mMaxTorqueLimit = 50.0 + motorSettings.mMinTorqueLimit = -200.0 + motorSettings.mMaxTorqueLimit = 200.0 this._targetAngle = this._constraint.GetCurrentAngle()