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

CAN Support #1050

Merged
merged 63 commits into from
Aug 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
95f37f6
Merge branch 'jwrigh/1746/wpilibbrain-mapping' of https://github.com/…
azaleacolburn Jul 23, 2024
b340392
begin working on talonfx
azaleacolburn Jul 24, 2024
8e2dd98
Merge branch 'dev' of https://github.com/Autodesk/synthesis into colb…
azaleacolburn Jul 25, 2024
81b1a49
Merge branch 'dev' of https://github.com/Autodesk/synthesis into colb…
azaleacolburn Jul 25, 2024
698658f
fix behavior inputs
azaleacolburn Jul 25, 2024
34a7933
Send all data through CANMotor to the websocket
azaleacolburn Jul 26, 2024
5ea10ec
Merge branch 'dev' of https://github.com/Autodesk/synthesis into colb…
azaleacolburn Jul 26, 2024
f5dedc5
removed awful switch statement in brain
azaleacolburn Jul 26, 2024
3a15e49
Merge branch 'dev' of https://github.com/Autodesk/synthesis into colb…
azaleacolburn Jul 29, 2024
1c065f4
restore brain changes lost in merge
azaleacolburn Jul 29, 2024
dd56b75
refactor sim input + output, encoder configuration modal
PepperLola Jul 29, 2024
d02b2d6
Merge branch 'dev' of github.com:Autodesk/synthesis into jwrigh/1766/…
PepperLola Jul 30, 2024
762281e
connect encoder to WPILibBrain
PepperLola Jul 30, 2024
825e1ff
Merge branch 'dev' of https://github.com/Autodesk/synthesis into colb…
azaleacolburn Jul 30, 2024
cd226cf
ignore this commit, i made a mistake with git
azaleacolburn Jul 30, 2024
e2168f9
Merge branch 'dev' of https://github.com/Autodesk/synthesis into colb…
azaleacolburn Jul 30, 2024
58bfb16
merged properly this time
azaleacolburn Jul 30, 2024
46a3215
Merge branch 'colbura/1747/can-motor-support' of https://github.com/A…
azaleacolburn Jul 30, 2024
f1d60d7
changed to local server, will change back before merge
azaleacolburn Jul 30, 2024
8a7bb77
added can devices to modal
azaleacolburn Jul 30, 2024
d9271f1
added deadband suport for talonFX
azaleacolburn Jul 31, 2024
c9c23e7
controller support and fixed wpilibbrain reset issue
PepperLola Aug 1, 2024
bb0d302
add .gitignore to ignore simulation project config folders
PepperLola Aug 1, 2024
e71ac28
added spark encoder wrapper class
azaleacolburn Aug 1, 2024
07600b5
Merge branch 'dev' of github.com:Autodesk/synthesis into jwrigh/1766/…
PepperLola Aug 1, 2024
064636d
!tried using reflection to fix private constructor issue, failed
azaleacolburn Aug 1, 2024
9a3bd50
lol I forgot to save, idk how to use vscode since my jdtls broke
azaleacolburn Aug 1, 2024
03bed7b
started on gyro support
PepperLola Aug 2, 2024
3410eef
Merge branch 'dev' of https://github.com/Autodesk/synthesis into colb…
azaleacolburn Aug 2, 2024
8d9f430
added init to can motor and encoder
azaleacolburn Aug 2, 2024
05d9acf
workaround for sim types
azaleacolburn Aug 3, 2024
781cbc0
added filter for non-Synthesim CAN devices
azaleacolburn Aug 3, 2024
289095a
Fixed SimDevice type recognition
HunterBarclay Aug 3, 2024
e20c834
changed cansparkmax names to conform to new type format
azaleacolburn Aug 5, 2024
b65ff0a
fix port NaN bug
azaleacolburn Aug 6, 2024
df28bf6
Merge branch 'jwrigh/1766/sim-io' of https://github.com/Autodesk/synt…
azaleacolburn Aug 6, 2024
fd4ab63
fixes from merge conflict
azaleacolburn Aug 6, 2024
737e92d
change java sample test
azaleacolburn Aug 6, 2024
510bf5f
verify canencoder sim
azaleacolburn Aug 7, 2024
d53a2f8
sparkmax absolute encoder support
azaleacolburn Aug 7, 2024
7fcf795
test proper codesim autos w/encoder
azaleacolburn Aug 8, 2024
b787cd4
disable CANMotor inputs
azaleacolburn Aug 8, 2024
b54cec9
fix build
azaleacolburn Aug 8, 2024
744c15f
add cansparkmax following support
azaleacolburn Aug 8, 2024
e2fcd38
ran formatter
azaleacolburn Aug 8, 2024
2a75af3
Merge branch 'dev' of https://github.com/Autodesk/synthesis into colb…
azaleacolburn Aug 12, 2024
856db4b
Merge branch 'dev' of https://github.com/Autodesk/synthesis into colb…
azaleacolburn Aug 12, 2024
df15877
talonfx encoder support
azaleacolburn Aug 12, 2024
7014c80
Update fission/src/systems/simulation/wpilib_brain/SimInput.ts
azaleacolburn Aug 13, 2024
ba5b871
cleaned up wpilib brain
azaleacolburn Aug 13, 2024
8643db1
Merge branch 'colbura/1747/can-motor-support' of https://github.com/A…
azaleacolburn Aug 13, 2024
0c595e1
elaborated on output averaging solution
azaleacolburn Aug 13, 2024
f2c6bce
removed vite single file comment
azaleacolburn Aug 13, 2024
4c734c4
type wsdata
azaleacolburn Aug 13, 2024
0bfcfcc
ran formatter
azaleacolburn Aug 13, 2024
9899b6a
fix types for build
azaleacolburn Aug 13, 2024
463bfd3
removed old logs
azaleacolburn Aug 13, 2024
4617fbe
remove log in sample code
azaleacolburn Aug 13, 2024
a3daee6
removed vendordeps from git ignore
azaleacolburn Aug 14, 2024
9c777d6
fix encoder issue maybe
azaleacolburn Aug 15, 2024
25a44bb
Merge branch 'dev' into colbura/1747/can-motor-support
azaleacolburn Aug 17, 2024
37b65dd
fix and cleanup code sim
azaleacolburn Aug 17, 2024
3d0e24f
Formatted
HunterBarclay Aug 17, 2024
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
10 changes: 4 additions & 6 deletions fission/src/systems/simulation/SimulationSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,19 +87,19 @@ class SimulationLayer {
const hinge = JOLT.castObject(x.constraint, JOLT.HingeConstraint)
const driver = new HingeDriver(hinge, x.maxVelocity, x.info)
this._drivers.push(driver)
const stim = new HingeStimulus(hinge)
const stim = new HingeStimulus(hinge, x.info)
this._stimuli.push(stim)
} else if (x.constraint.GetSubType() == JOLT.EConstraintSubType_Vehicle) {
const vehicle = JOLT.castObject(x.constraint, JOLT.VehicleConstraint)
const driver = new WheelDriver(vehicle, x.maxVelocity, x.info)
this._drivers.push(driver)
const stim = new WheelRotationStimulus(vehicle.GetWheel(0))
const stim = new WheelRotationStimulus(vehicle.GetWheel(0), x.info)
this._stimuli.push(stim)
} else if (x.constraint.GetSubType() == JOLT.EConstraintSubType_Slider) {
const slider = JOLT.castObject(x.constraint, JOLT.SliderConstraint)
const driver = new SliderDriver(slider, x.maxVelocity, x.info)
this._drivers.push(driver)
const stim = new SliderStimulus(slider)
const stim = new SliderStimulus(slider, x.info)
this._stimuli.push(stim)
}
})
Expand All @@ -117,9 +117,7 @@ class SimulationLayer {

this._brain = brain

if (this._brain) {
this._brain.Enable()
}
if (this._brain) this._brain.Enable()
}
}

Expand Down
2 changes: 1 addition & 1 deletion fission/src/systems/simulation/driver/WheelDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class WheelDriver extends Driver {
public maxVelocity = 30.0
private _maxAcceleration = 1.5

private _targetVelocity = () => {
public _targetVelocity = () => {
let vel = this.accelerationDirection * (this._reversed ? -1 : 1) * this.maxVelocity

if (vel - this._prevVel < -this._maxAcceleration) vel = this._prevVel - this._maxAcceleration
Expand Down
5 changes: 3 additions & 2 deletions fission/src/systems/simulation/stimulus/ChassisStimulus.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Jolt from "@barclah/jolt-physics"
import Stimulus from "./Stimulus"
import World from "@/systems/World"
import { mirabuf } from "@/proto/mirabuf"

class ChassisStimulus extends Stimulus {
private _body: Jolt.Body
Expand All @@ -19,8 +20,8 @@ class ChassisStimulus extends Stimulus {
return this._body.GetRotation().GetEulerAngles()
}

public constructor(bodyId: Jolt.BodyID) {
super()
public constructor(bodyId: Jolt.BodyID, info?: mirabuf.IInfo) {
super(info)

this._body = World.PhysicsSystem.GetBody(bodyId)
this._mass = this._body.GetShape().GetMassProperties().mMass
Expand Down
5 changes: 3 additions & 2 deletions fission/src/systems/simulation/stimulus/EncoderStimulus.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { mirabuf } from "@/proto/mirabuf"
import Stimulus from "./Stimulus"

abstract class EncoderStimulus extends Stimulus {
public abstract get positionValue(): number
public abstract get velocityValue(): number

protected constructor() {
super()
protected constructor(info?: mirabuf.IInfo) {
super(info)
}

public abstract Update(_: number): void
Expand Down
5 changes: 3 additions & 2 deletions fission/src/systems/simulation/stimulus/HingeStimulus.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Jolt from "@barclah/jolt-physics"
import EncoderStimulus from "./EncoderStimulus"
import { mirabuf } from "@/proto/mirabuf"

class HingeStimulus extends EncoderStimulus {
private _accum: boolean = false
Expand All @@ -25,8 +26,8 @@ class HingeStimulus extends EncoderStimulus {
this._accum = shouldAccum
}

public constructor(hinge: Jolt.HingeConstraint) {
super()
public constructor(hinge: Jolt.HingeConstraint, info?: mirabuf.IInfo) {
super(info)

this._hinge = hinge
}
Expand Down
5 changes: 3 additions & 2 deletions fission/src/systems/simulation/stimulus/SliderStimulus.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Jolt from "@barclah/jolt-physics"
import EncoderStimulus from "./EncoderStimulus"
import { mirabuf } from "@/proto/mirabuf"

class SliderStimulus extends EncoderStimulus {
private _slider: Jolt.SliderConstraint
Expand All @@ -12,8 +13,8 @@ class SliderStimulus extends EncoderStimulus {
return this._velocity
}

public constructor(slider: Jolt.SliderConstraint) {
super()
public constructor(slider: Jolt.SliderConstraint, info?: mirabuf.IInfo) {
super(info)

this._slider = slider
}
Expand Down
12 changes: 12 additions & 0 deletions fission/src/systems/simulation/stimulus/Stimulus.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
import { mirabuf } from "@/proto/mirabuf"

abstract class Stimulus {
private _info?: mirabuf.IInfo

constructor(info?: mirabuf.IInfo) {
this._info = info
}

public abstract Update(deltaT: number): void

public get info() {
return this._info
}
}

export default Stimulus
5 changes: 3 additions & 2 deletions fission/src/systems/simulation/stimulus/WheelStimulus.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Jolt from "@barclah/jolt-physics"
import EncoderStimulus from "./EncoderStimulus"
import { mirabuf } from "@/proto/mirabuf"

/**
*
Expand Down Expand Up @@ -28,8 +29,8 @@ class WheelRotationStimulus extends EncoderStimulus {
this._accum = shouldAccum
}

public constructor(wheel: Jolt.Wheel) {
super()
public constructor(wheel: Jolt.Wheel, info?: mirabuf.IInfo) {
super(info)

this._wheel = wheel
}
Expand Down
69 changes: 69 additions & 0 deletions fission/src/systems/simulation/wpilib_brain/SimInput.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import World from "@/systems/World"
import EncoderStimulus from "../stimulus/EncoderStimulus"
import { SimCANEncoder, SimGyro } from "./WPILibBrain"
import Mechanism from "@/systems/physics/Mechanism"
import Jolt from "@barclah/jolt-physics"
import JOLT from "@/util/loading/JoltSyncLoader"

export interface SimInput {
Update: (deltaT: number) => void
}

export class SimEncoderInput implements SimInput {
private _device: string
private _stimulus: EncoderStimulus

constructor(device: string, stimulus: EncoderStimulus) {
this._device = device
this._stimulus = stimulus
}

public Update(_deltaT: number) {
SimCANEncoder.SetPosition(this._device, this._stimulus.positionValue)
SimCANEncoder.SetVelocity(this._device, this._stimulus.velocityValue)
}
}

export class SimGyroInput implements SimInput {
private _device: string
private _robot: Mechanism
private _joltID?: Jolt.BodyID
private _joltBody?: Jolt.Body

private static AXIS_X: Jolt.Vec3 = new JOLT.Vec3(1, 0, 0)
private static AXIS_Y: Jolt.Vec3 = new JOLT.Vec3(0, 1, 0)
private static AXIS_Z: Jolt.Vec3 = new JOLT.Vec3(0, 0, 1)

constructor(device: string, robot: Mechanism) {
this._device = device
this._robot = robot
this._joltID = this._robot.nodeToBody.get(this._robot.rootBody)

if (this._joltID) this._joltBody = World.PhysicsSystem.GetBody(this._joltID)
}

private GetAxis(axis: Jolt.Vec3): number {
return ((this._joltBody?.GetRotation().GetRotationAngle(axis) ?? 0) * 180) / Math.PI
}

private GetX(): number {
return this.GetAxis(SimGyroInput.AXIS_X)
}

private GetY(): number {
return this.GetAxis(SimGyroInput.AXIS_Y)
}

private GetZ(): number {
return this.GetAxis(SimGyroInput.AXIS_Z)
}

public Update(_deltaT: number) {
const x = this.GetX()
const y = this.GetY()
const z = this.GetZ()
SimGyro.SetAngleX(this._device, x)
SimGyro.SetAngleY(this._device, y)
SimGyro.SetAngleZ(this._device, z)
}
}
74 changes: 74 additions & 0 deletions fission/src/systems/simulation/wpilib_brain/SimOutput.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import Driver from "../driver/Driver"
import HingeDriver from "../driver/HingeDriver"
import SliderDriver from "../driver/SliderDriver"
import WheelDriver from "../driver/WheelDriver"
import { SimCAN, SimPWM, SimType } from "./WPILibBrain"

// TODO: Averaging is probably not the right solution (if we want large output groups)
// We can keep averaging, but we need a better ui for creating one to one (or just small) output groups
// The issue is that if a drivetrain is one output group, then each driver is given the average of all the motors
// We instead want a system where every driver gets (a) unique motor(s) that control it
// That way a single driver might get the average of two motors or something, if it has two motors to control it
// A system where motors a drivers are visually "linked" with "threads" in the UI would work well in my opinion
export abstract class SimOutputGroup {
public name: string
public ports: number[]
public drivers: Driver[]
public type: SimType

public constructor(name: string, ports: number[], drivers: Driver[], type: SimType) {
this.name = name
this.ports = ports
this.drivers = drivers
this.type = type
}

public abstract Update(deltaT: number): void
}

export class PWMOutputGroup extends SimOutputGroup {
public constructor(name: string, ports: number[], drivers: Driver[]) {
super(name, ports, drivers, SimType.PWM)
}

public Update(_deltaT: number) {
const average =
this.ports.reduce((sum, port) => {
const speed = SimPWM.GetSpeed(`${port}`) ?? 0
console.debug(port, speed)
return sum + speed
}, 0) / this.ports.length

this.drivers.forEach(d => {
if (d instanceof WheelDriver) {
d.accelerationDirection = average
} else if (d instanceof HingeDriver || d instanceof SliderDriver) {
d.accelerationDirection = average
}
d.Update(_deltaT)
})
}
}

export class CANOutputGroup extends SimOutputGroup {
public constructor(name: string, ports: number[], drivers: Driver[]) {
super(name, ports, drivers, SimType.CANMotor)
}

public Update(deltaT: number): void {
const average =
this.ports.reduce((sum, port) => {
const device = SimCAN.GetDeviceWithID(port, SimType.CANMotor)
return sum + (device?.get("<percentOutput") ?? 0)
}, 0) / this.ports.length

this.drivers.forEach(d => {
if (d instanceof WheelDriver) {
d.accelerationDirection = average
} else if (d instanceof HingeDriver || d instanceof SliderDriver) {
d.accelerationDirection = average
}
d.Update(deltaT)
})
}
}
Loading
Loading