diff --git a/fission/src/systems/input/InputSystem.ts b/fission/src/systems/input/InputSystem.ts index 21aca82ee7..8535301569 100644 --- a/fission/src/systems/input/InputSystem.ts +++ b/fission/src/systems/input/InputSystem.ts @@ -121,7 +121,10 @@ class InputSystem extends WorldSystem { } // Returns true if two modifier states are identical - private static CompareModifiers(state1: ModifierState, state2: ModifierState): boolean { + private static CompareModifiers(state1: ModifierState, state2: ModifierState) : boolean { + if (!state1 || !state2) + return false; + return ( state1.alt == state2.alt && state1.ctrl == state2.ctrl && diff --git a/fission/src/systems/simulation/behavior/GenericArmBehavior.ts b/fission/src/systems/simulation/behavior/GenericArmBehavior.ts index b2d50d8064..5f38eb14c6 100644 --- a/fission/src/systems/simulation/behavior/GenericArmBehavior.ts +++ b/fission/src/systems/simulation/behavior/GenericArmBehavior.ts @@ -6,10 +6,10 @@ import InputSystem, { emptyModifierState } from "@/systems/input/InputSystem" class GenericArmBehavior extends Behavior { private _hingeDriver: HingeDriver - private _positiveInput: string - private _negativeInput: string - - private _rotationalSpeed = 30 + private _positiveInput: string; + private _negativeInput: string; + + private _rotationalSpeed = 6; constructor(hingeDriver: HingeDriver, hingeStimulus: HingeStimulus, jointIndex: number) { super([hingeDriver], [hingeStimulus]) diff --git a/fission/src/systems/simulation/behavior/GenericElevatorBehavior.ts b/fission/src/systems/simulation/behavior/GenericElevatorBehavior.ts index 0d9ce8de79..2b9f41936b 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 = 2.5; constructor(sliderDriver: SliderDriver, sliderStimulus: SliderStimulus, jointIndex: number) { super([sliderDriver], [sliderStimulus]) @@ -34,12 +34,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 39c3aefa0e..400b7bde30 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 default Driver +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 172a7cc095..4500508490 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" @@ -21,7 +21,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) { @@ -36,6 +36,7 @@ class HingeDriver extends Driver { public get controlMode(): DriverControlMode { return this._controlMode } + public set controlMode(mode: DriverControlMode) { this._controlMode = mode switch (mode) { @@ -64,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() @@ -81,9 +82,4 @@ class HingeDriver extends Driver { } } -export enum DriverControlMode { - Velocity = 0, - Position = 1, -} - -export default HingeDriver +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 050a41c925..2ad547a831 100644 --- a/fission/src/systems/simulation/driver/SliderDriver.ts +++ b/fission/src/systems/simulation/driver/SliderDriver.ts @@ -1,12 +1,22 @@ -import Jolt from "@barclah/jolt-physics" -import Driver from "./Driver" -import { SIMULATION_PERIOD } from "@/systems/physics/PhysicsSystem" -import JOLT from "@/util/loading/JoltSyncLoader" -import InputSystem from "@/systems/input/InputSystem" +import Jolt from "@barclah/jolt-physics"; +import Driver, { DriverControlMode } from "./Driver"; +import { SIMULATION_PERIOD } from "@/systems/physics/PhysicsSystem"; +import JOLT from "@/util/loading/JoltSyncLoader"; class SliderDriver extends Driver { - private _constraint: Jolt.SliderConstraint - private _targetPosition: number = 0.0 + + 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 @@ -27,6 +37,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() @@ -35,21 +64,21 @@ 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 = -125.0 - motorSettings.mMaxForceLimit = 125.0 - - this._constraint.SetMotorState(JOLT.EMotorState_Position) + motorSettings.mMinForceLimit = -900.0 + motorSettings.mMaxForceLimit = 900.0 - this.targetPosition = this._constraint.GetCurrentPosition() + this._constraint.SetMotorState(JOLT.EMotorState_Velocity) + 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) + 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); + } } }