Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Haverty/elevator bug #983

Merged
merged 6 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion fission/src/systems/input/InputSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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") }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand All @@ -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);
}
}

Expand Down
5 changes: 5 additions & 0 deletions fission/src/systems/simulation/driver/Driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,9 @@ abstract class Driver {
public abstract Update(deltaT: number): void;
}

export enum DriverControlMode {
Velocity = 0,
Position = 1
}

export default Driver;
11 changes: 3 additions & 8 deletions fission/src/systems/simulation/driver/HingeDriver.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
49 changes: 42 additions & 7 deletions fission/src/systems/simulation/driver/SliderDriver.ts
Original file line number Diff line number Diff line change
@@ -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;
}
Expand All @@ -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();

Expand All @@ -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);
}
}
}

Expand Down
Loading