Skip to content

Commit

Permalink
Merge branch 'dev' into colbura/1777/friction-parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
HunterBarclay committed Dec 19, 2024
2 parents f3a953d + 37d677c commit 043988f
Show file tree
Hide file tree
Showing 74 changed files with 5,090 additions and 315 deletions.
3 changes: 1 addition & 2 deletions exporter/SynthesisFusionAddin/src/UI/GamepieceConfigTab.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,7 @@ def removeChildOccurrences(childOccurrences: adsk.fusion.OccurrenceList) -> None
def getGamepieces(self) -> list[Gamepiece]:
gamepieces: list[Gamepiece] = []
for row in range(1, self.gamepieceTable.rowCount): # Row is 1 indexed
occ = self.selectedGamepieceList[row - 1]
gamepieceEntityToken = guid_occurrence(occ)
gamepieceEntityToken = guid_occurrence(self.selectedGamepieceList[row - 1])
gamepieceWeight = convertMassUnitsTo(self.gamepieceTable.getInputAtPosition(row, 1).value)
gamepieceFrictionCoefficient = self.gamepieceTable.getInputAtPosition(row, 2).valueOne
gamepieces.append(Gamepiece(gamepieceEntityToken, gamepieceWeight, gamepieceFrictionCoefficient))
Expand Down
1 change: 1 addition & 0 deletions fission/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"@react-three/fiber": "^8.15.15",
"@vitest/browser": "^1.6.0",
"@vitest/coverage-v8": "^1.6.0",
"@xyflow/react": "^12.3.2",
"async-mutex": "^0.5.0",
"colord": "^2.9.3",
"framer-motion": "^10.13.1",
Expand Down
6 changes: 6 additions & 0 deletions fission/src/Synthesis.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,13 @@ import AnalyticsConsent from "./ui/components/AnalyticsConsent.tsx"
import PreferencesSystem from "./systems/preferences/PreferencesSystem.ts"
import APSManagementModal from "./ui/modals/APSManagementModal.tsx"
import ConfigurePanel from "./ui/panels/configuring/assembly-config/ConfigurePanel.tsx"
import WiringPanel from "./ui/panels/simulation/WiringPanel.tsx"
import CameraSelectionPanel from "./ui/panels/configuring/CameraSelectionPanel.tsx"
import ContextMenu from "./ui/components/ContextMenu.tsx"
import GlobalUIComponent from "./ui/components/GlobalUIComponent.tsx"
import InitialConfigPanel from "./ui/panels/configuring/initial-config/InitialConfigPanel.tsx"
import WPILibConnectionStatus from "./ui/components/WPILibConnectionStatus.tsx"
import AutoTestPanel from "./ui/panels/simulation/AutoTestPanel.tsx"

function Synthesis() {
const { openModal, closeModal, getActiveModalElement } = useModalManager(initialModals)
Expand Down Expand Up @@ -173,6 +176,7 @@ function Synthesis() {
)}
<ProgressNotifications key={"progress-notifications"} />
<ToastContainer key={"toast-container"} />
<WPILibConnectionStatus />

{!consentPopupDisable ? (
<AnalyticsConsent onClose={onDisableConsent} onConsent={onConsent} />
Expand Down Expand Up @@ -228,8 +232,10 @@ const initialPanels: ReactElement[] = [
<WSViewPanel key="ws-view" panelId="ws-view" />,
<DebugPanel key="debug" panelId="debug" />,
<ConfigurePanel key="configure" panelId="configure" />,
<WiringPanel key="wiring" panelId="wiring" />,
<CameraSelectionPanel key="camera-select" panelId="camera-select" />,
<InitialConfigPanel key="initial-config" panelId="initial-config" />,
<AutoTestPanel key="auto-test" panelId="auto-test" />,
]

export default Synthesis
4 changes: 0 additions & 4 deletions fission/src/aps/APS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,10 +339,6 @@ class APS {
email: json.email,
}

if (json.sub) {
World.AnalyticsSystem?.SetUserId(json.sub as string)
}

this.userInfo = info
} catch (e) {
console.error(e)
Expand Down
6 changes: 1 addition & 5 deletions fission/src/mirabuf/IntakeSensorSceneObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import {
ThreeVector3_JoltVec3,
} from "@/util/TypeConversions"
import { OnContactPersistedEvent } from "@/systems/physics/ContactEvents"
import InputSystem from "@/systems/input/InputSystem"
import SynthesisBrain from "@/systems/simulation/synthesis_brain/SynthesisBrain"

class IntakeSensorSceneObject extends SceneObject {
private _parentAssembly: MirabufSceneObject
Expand Down Expand Up @@ -44,9 +42,7 @@ class IntakeSensorSceneObject extends SceneObject {
}

this._collision = (event: OnContactPersistedEvent) => {
const brain = this._parentAssembly.brain
const brainIndex = brain instanceof SynthesisBrain ? brain.brainIndex ?? -1 : -1
if (InputSystem.getInput("intake", brainIndex)) {
if (this._parentAssembly.intakeActive) {
if (this._joltBodyId && !World.PhysicsSystem.isPaused) {
const body1 = event.message.body1
const body2 = event.message.body2
Expand Down
125 changes: 90 additions & 35 deletions fission/src/mirabuf/MirabufSceneObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import * as THREE from "three"
import JOLT from "@/util/loading/JoltSyncLoader"
import { BodyAssociate, LayerReserve } from "@/systems/physics/PhysicsSystem"
import Mechanism from "@/systems/physics/Mechanism"
import InputSystem from "@/systems/input/InputSystem"
import { EjectorPreferences, FieldPreferences, IntakePreferences } from "@/systems/preferences/PreferenceTypes"
import PreferencesSystem from "@/systems/preferences/PreferencesSystem"
import { MiraType } from "./MirabufLoader"
Expand All @@ -32,6 +31,8 @@ import {
ConfigurationType,
setSelectedConfigurationType,
} from "@/ui/panels/configuring/assembly-config/ConfigurationType"
import { SimConfigData } from "@/ui/panels/simulation/SimConfigShared"
import WPILibBrain from "@/systems/simulation/wpilib_brain/WPILibBrain"

const DEBUG_BODIES = false

Expand Down Expand Up @@ -68,6 +69,7 @@ class MirabufSceneObject extends SceneObject implements ContextSupplier {

private _intakePreferences: IntakePreferences | undefined
private _ejectorPreferences: EjectorPreferences | undefined
private _simConfigData: SimConfigData | undefined

private _fieldPreferences: FieldPreferences | undefined

Expand All @@ -77,6 +79,22 @@ class MirabufSceneObject extends SceneObject implements ContextSupplier {

private _nameTag: SceneOverlayTag | undefined

private _intakeActive = false
private _ejectorActive = false

public get intakeActive() {
return this._intakeActive
}
public get ejectorActive() {
return this._ejectorActive
}
public set intakeActive(a: boolean) {
this._intakeActive = a
}
public set ejectorActive(a: boolean) {
this._ejectorActive = a
}

get mirabufInstance() {
return this._mirabufInstance
}
Expand All @@ -97,6 +115,10 @@ class MirabufSceneObject extends SceneObject implements ContextSupplier {
return this._ejectorPreferences
}

get simConfigData() {
return this._simConfigData
}

get fieldPreferences() {
return this._fieldPreferences
}
Expand All @@ -117,6 +139,12 @@ class MirabufSceneObject extends SceneObject implements ContextSupplier {
return this._brain
}

public set brain(brain: Brain | undefined) {
this._brain = brain
const simLayer = World.SimulationSystem.GetSimulationLayer(this._mechanism)!
simLayer.SetBrain(brain)
}

public constructor(mirabufInstance: MirabufInstance, assemblyName: string, progressHandle?: ProgressHandle) {
super()

Expand All @@ -133,11 +161,15 @@ class MirabufSceneObject extends SceneObject implements ContextSupplier {
this.getPreferences()

// creating nametag for robots
if (this.miraType !== MiraType.ROBOT) return

this._nameTag = new SceneOverlayTag(() =>
this._brain instanceof SynthesisBrain ? this._brain.inputSchemeName : "Not Configured"
)
if (this.miraType === MiraType.ROBOT) {
this._nameTag = new SceneOverlayTag(() =>
this._brain instanceof SynthesisBrain
? this._brain.inputSchemeName
: this._brain instanceof WPILibBrain
? "Magic"
: "Not Configured"
)
}
}

public Setup(): void {
Expand Down Expand Up @@ -175,7 +207,7 @@ class MirabufSceneObject extends SceneObject implements ContextSupplier {
if (this.miraType == MiraType.ROBOT) {
World.SimulationSystem.RegisterMechanism(this._mechanism)
const simLayer = World.SimulationSystem.GetSimulationLayer(this._mechanism)!
this._brain = new SynthesisBrain(this._mechanism, this._assemblyName)
this._brain = new SynthesisBrain(this, this._assemblyName)
simLayer.SetBrain(this._brain)
}

Expand Down Expand Up @@ -210,13 +242,11 @@ class MirabufSceneObject extends SceneObject implements ContextSupplier {
}

public Update(): void {
const brainIndex = this._brain instanceof SynthesisBrain ? this._brain.brainIndex ?? -1 : -1
if (InputSystem.getInput("eject", brainIndex)) {
if (this.ejectorActive) {
this.Eject()
}

this.UpdateMeshTransforms()

this.UpdateBatches()
this.UpdateNameTag()
}
Expand Down Expand Up @@ -450,12 +480,26 @@ class MirabufSceneObject extends SceneObject implements ContextSupplier {
}

private getPreferences(): void {
this._intakePreferences = PreferencesSystem.getRobotPreferences(this.assemblyName)?.intake
this._ejectorPreferences = PreferencesSystem.getRobotPreferences(this.assemblyName)?.ejector
const robotPrefs = PreferencesSystem.getRobotPreferences(this.assemblyName)
if (robotPrefs) {
this._intakePreferences = robotPrefs.intake
this._ejectorPreferences = robotPrefs.ejector
this._simConfigData = robotPrefs.simConfig
}

this._fieldPreferences = PreferencesSystem.getFieldPreferences(this.assemblyName)
}

public UpdateSimConfig(config: SimConfigData | undefined) {
const robotPrefs = PreferencesSystem.getRobotPreferences(this.assemblyName)
if (robotPrefs) {
this._simConfigData = robotPrefs.simConfig = config
PreferencesSystem.setRobotPreferences(this.assemblyName, robotPrefs)
PreferencesSystem.savePreferences()
;(this._brain as WPILibBrain)?.loadSimConfig?.()
}
}

public EnablePhysics() {
this._mirabufInstance.parser.rigidNodes.forEach(rn => {
World.PhysicsSystem.EnablePhysicsForBody(this._mechanism.GetBodyByNodeId(rn.id)!)
Expand All @@ -482,31 +526,42 @@ class MirabufSceneObject extends SceneObject implements ContextSupplier {
public getSupplierData(): ContextData {
const data: ContextData = { title: this.miraType == MiraType.ROBOT ? "A Robot" : "A Field", items: [] }

data.items.push({
name: "Move",
func: () => {
setSelectedConfigurationType(
this.miraType == MiraType.ROBOT ? ConfigurationType.ROBOT : ConfigurationType.FIELD
)
setNextConfigurePanelSettings({
configMode: ConfigMode.MOVE,
selectedAssembly: this,
})
Global_OpenPanel?.("configure")
data.items.push(
{
name: "Move",
func: () => {
setSelectedConfigurationType(
this.miraType == MiraType.ROBOT ? ConfigurationType.ROBOT : ConfigurationType.FIELD
)
setNextConfigurePanelSettings({
configMode: ConfigMode.MOVE,
selectedAssembly: this,
})
Global_OpenPanel?.("configure")
},
},
})

if (this.miraType == MiraType.ROBOT) {
const brainIndex = (this.brain as SynthesisBrain)?.brainIndex
if (brainIndex != undefined) {
data.items.push({
name: "Set Scheme",
func: () => {
setSpotlightAssembly(this)
Global_OpenPanel?.("choose-scheme")
},
})
{
name: "Configure",
func: () => {
setSelectedConfigurationType(
this.miraType == MiraType.ROBOT ? ConfigurationType.ROBOT : ConfigurationType.FIELD
)
setNextConfigurePanelSettings({
configMode: undefined,
selectedAssembly: this,
})
Global_OpenPanel?.("configure")
},
}
)

if (this.brain?.brainType == "wpilib") {
data.items.push({
name: "Auto Testing",
func: () => {
Global_OpenPanel?.("auto-test")
},
})
}

if (World.SceneRenderer.currentCameraControls.controlsType == "Orbit") {
Expand Down
17 changes: 11 additions & 6 deletions fission/src/systems/World.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import AnalyticsSystem, { AccumTimes } from "./analytics/AnalyticsSystem"
class World {
private static _isAlive: boolean = false
private static _clock: THREE.Clock
private static _currentDeltaT: number = 0

private static _sceneRenderer: SceneRenderer
private static _physicsSystem: PhysicsSystem
Expand Down Expand Up @@ -91,18 +92,22 @@ class World {
}

public static UpdateWorld() {
const deltaT = World._clock.getDelta()
this._currentDeltaT = World._clock.getDelta()

this._accumTimes.frames++

this._accumTimes.totalTime += this.time(() => {
this._accumTimes.simulationTime += this.time(() => World._simulationSystem.Update(deltaT))
this._accumTimes.physicsTime += this.time(() => World._physicsSystem.Update(deltaT))
this._accumTimes.inputTime += this.time(() => World._inputSystem.Update(deltaT))
this._accumTimes.sceneTime += this.time(() => World._sceneRenderer.Update(deltaT))
this._accumTimes.simulationTime += this.time(() => World._simulationSystem.Update(this._currentDeltaT))
this._accumTimes.physicsTime += this.time(() => World._physicsSystem.Update(this._currentDeltaT))
this._accumTimes.inputTime += this.time(() => World._inputSystem.Update(this._currentDeltaT))
this._accumTimes.sceneTime += this.time(() => World._sceneRenderer.Update(this._currentDeltaT))
})

World._analyticsSystem?.Update(deltaT)
World._analyticsSystem?.Update(this._currentDeltaT)
}

public static get currentDeltaT(): number {
return this._currentDeltaT
}

private static time(func: () => void): number {
Expand Down
23 changes: 23 additions & 0 deletions fission/src/systems/physics/PhysicsSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1112,6 +1112,29 @@ class PhysicsSystem extends WorldSystem {
)
}

public SetBodyPositionRotationAndVelocity(
id: Jolt.BodyID,
position: Jolt.RVec3,
rotation: Jolt.Quat,
linear: Jolt.Vec3,
angular: Jolt.Vec3,
activate: boolean = true
): void {
if (!this.IsBodyAdded(id)) {
return
}

this._joltBodyInterface.SetPositionAndRotation(
id,
position,
rotation,
activate ? JOLT.EActivation_Activate : JOLT.EActivation_DontActivate
)

this._joltBodyInterface.SetLinearVelocity(id, linear)
this._joltBodyInterface.SetAngularVelocity(id, angular)
}

/**
* Exposes SetShape method on the _joltBodyInterface
* Sets the shape of the body
Expand Down
4 changes: 4 additions & 0 deletions fission/src/systems/preferences/PreferenceTypes.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { SimConfigData } from "@/ui/panels/simulation/SimConfigShared"
import { InputScheme } from "../input/InputSchemeManager"
import { Vector3Tuple } from "three"

Expand All @@ -14,6 +15,7 @@ export type GlobalPreference =
| "RenderSceneTags"
| "RenderScoreboard"
| "SubsystemGravity"
| "SimAutoReconnect"

export const RobotPreferencesKey: string = "Robots"
export const FieldPreferencesKey: string = "Fields"
Expand All @@ -34,6 +36,7 @@ export const DefaultGlobalPreferences: { [key: string]: unknown } = {
RenderSceneTags: true,
RenderScoreboard: true,
SubsystemGravity: false,
SimAutoReconnect: false,
}

export type QualitySetting = "Low" | "Medium" | "High"
Expand Down Expand Up @@ -79,6 +82,7 @@ export type RobotPreferences = {
driveVelocity: number
driveAcceleration: number
sequentialConfig?: SequentialBehaviorPreferences[]
simConfig?: SimConfigData
}

export type MotorPreferences = {
Expand Down
Loading

0 comments on commit 043988f

Please sign in to comment.