Skip to content

Commit

Permalink
Merge branch 'dev' into branp/1710/exporter-formatting-updates
Browse files Browse the repository at this point in the history
  • Loading branch information
HunterBarclay committed Jun 27, 2024
2 parents fd4f1e1 + 2202c34 commit db3f70e
Show file tree
Hide file tree
Showing 11 changed files with 157 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def __init__(self, options: ExporterOptions):
def export(self) -> bool:
try:
app = adsk.core.Application.get()
design = app.activeDocument.design
design: adsk.fusion.Design = app.activeDocument.design

assembly_out = assembly_pb2.Assembly()
fill_info(
Expand Down
2 changes: 1 addition & 1 deletion exporter/SynthesisFusionAddin/src/general_imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
A_EP = None

# Setup the global state
gm = GlobalManager()
gm: GlobalManager = GlobalManager()
my_addin_path = os.path.dirname(os.path.realpath(__file__))
except:
# should also log this
Expand Down
10 changes: 6 additions & 4 deletions fission/src/Synthesis.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,11 @@ import ScoringZonesPanel from "@/panels/configuring/scoring/ScoringZonesPanel"
import ZoneConfigPanel from "@/panels/configuring/scoring/ZoneConfigPanel"
import ScoreboardPanel from "@/panels/information/ScoreboardPanel"
import DriverStationPanel from "@/panels/simulation/DriverStationPanel"
import ManageAssembliesModal from "@/modals/spawning/ManageAssembliesModal.tsx"
import World from "@/systems/World.ts"
import { AddRobotsModal, AddFieldsModal, SpawningModal } from "@/modals/spawning/SpawningModals.tsx"
import ImportMirabufModal from "@/modals/mirabuf/ImportMirabufModal.tsx"
import ManageAssembliesModal from '@/modals/spawning/ManageAssembliesModal.tsx';
import World from '@/systems/World.ts';
import { AddRobotsModal, AddFieldsModal, SpawningModal } from '@/modals/spawning/SpawningModals.tsx';
import ImportMirabufModal from '@/modals/mirabuf/ImportMirabufModal.tsx';
import ImportLocalMirabufModal from '@/modals/mirabuf/ImportLocalMirabufModal.tsx';

const DEFAULT_MIRA_PATH = "/api/mira/Robots/Team 2471 (2018)_v7.mira"

Expand Down Expand Up @@ -192,6 +193,7 @@ const initialModals = [
<ConfigMotorModal modalId="config-motor" />,
<ManageAssembliesModal modalId="manage-assembles" />,
<ImportMirabufModal modalId="import-mirabuf" />,
<ImportLocalMirabufModal modalId="import-local-mirabuf" />,
]

const initialPanels: ReactElement[] = [
Expand Down
5 changes: 4 additions & 1 deletion fission/src/systems/input/InputSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down
8 changes: 4 additions & 4 deletions fission/src/systems/simulation/behavior/GenericArmBehavior.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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])
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 = 2.5;

constructor(sliderDriver: SliderDriver, sliderStimulus: SliderStimulus, jointIndex: number) {
super([sliderDriver], [sliderStimulus])
Expand All @@ -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);
}
}

Expand Down
7 changes: 6 additions & 1 deletion 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 default Driver
export enum DriverControlMode {
Velocity = 0,
Position = 1
}

export default Driver;
16 changes: 6 additions & 10 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 @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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()

Expand All @@ -81,9 +82,4 @@ class HingeDriver extends Driver {
}
}

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

export default HingeDriver
export default HingeDriver
63 changes: 46 additions & 17 deletions fission/src/systems/simulation/driver/SliderDriver.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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()

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

Expand Down
11 changes: 10 additions & 1 deletion fission/src/ui/components/MainHUD.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,16 @@ const MainHUD: React.FC = () => {
icon={<IoPeople />}
onClick={() => openModal("import-mirabuf")}
/>
<MainHUDButton value={"Test God Mode"} icon={<IoGameControllerOutline />} onClick={TestGodMode} />
<MainHUDButton
value={"Import Local Mira"}
icon={<IoPeople />}
onClick={() => openModal("import-local-mirabuf")}
/>
<MainHUDButton
value={"Test God Mode"}
icon={<IoGameControllerOutline />}
onClick={TestGodMode}
/>
</div>
<div className="flex flex-col gap-0 bg-background w-full rounded-3xl">
<MainHUDButton
Expand Down
68 changes: 68 additions & 0 deletions fission/src/ui/modals/mirabuf/ImportLocalMirabufModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import Button, { ButtonSize } from "@/components/Button"
import Modal, { ModalPropsImpl } from "../../components/Modal"
import { FaPlus } from "react-icons/fa6"
import { ChangeEvent, useRef, useState } from "react"
import Label, { LabelSize } from "@/components/Label"
import { useTooltipControlContext } from "@/ui/TooltipContext"
import { CreateMirabufFromUrl } from "@/mirabuf/MirabufSceneObject"
import World from "@/systems/World"

const ImportLocalMirabufModal: React.FC<ModalPropsImpl> = ({ modalId }) => {
// update tooltip based on type of drivetrain, receive message from Synthesis
const { showTooltip } = useTooltipControlContext()

const fileUploadRef = useRef<HTMLInputElement>(null)

const [selectedFile, setSelectedFile] = useState<File | undefined>(undefined)

const uploadClicked = () => {
if (fileUploadRef.current) {
fileUploadRef.current.click()
}
}

const onInputChanged = (e: ChangeEvent<HTMLInputElement>) => {
if (e.target.files) {
const file = e.target.files[0]
setSelectedFile(file)
}
}

return (
<Modal
name={"Import Local Assemblies"}
icon={<FaPlus />}
modalId={modalId}
acceptEnabled={selectedFile !== undefined}
onAccept={() => {
if (selectedFile) {
console.log(`Mira: '${selectedFile}'`)
showTooltip("controls", [
{ control: "WASD", description: "Drive" },
{ control: "E", description: "Intake" },
{ control: "Q", description: "Dispense" },
])

CreateMirabufFromUrl(URL.createObjectURL(selectedFile)).then(x => {
if (x) {
World.SceneRenderer.RegisterSceneObject(x)
}
})
}
}
}
>
<div className="flex flex-col items-center gap-5">
<input ref={fileUploadRef} onChange={onInputChanged} type="file" hidden={true} />
<Button value="Upload" size={ButtonSize.Large} onClick={uploadClicked} />
{
selectedFile
? (<Label className="text-center" size={LabelSize.Medium}>{`Selected File: ${selectedFile.name}`}</Label>)
: (<></>)
}
</div>
</Modal>
)
}

export default ImportLocalMirabufModal

0 comments on commit db3f70e

Please sign in to comment.