| 19 | const LATENCY_MS = 120; |
| 20 | |
| 21 | export class SimCamera implements CameraDriver { |
| 22 | readonly kind = "sim" as const; |
| 23 | |
| 24 | private pose: CameraPose; |
| 25 | private goal: CameraPose | null = null; |
| 26 | private goalSpeeds = { panDps: Infinity, tiltDps: Infinity }; |
| 27 | private zoomGoal: number | null = null; |
| 28 | private jogRates = { pan: 0, tilt: 0, zoom: 0 }; |
| 29 | private timer: ReturnType<typeof setInterval> | null = null; |
| 30 | private commands = 0; |
| 31 | |
| 32 | constructor( |
| 33 | private limits: CameraLimits, |
| 34 | private units: ViscaUnitScale, |
| 35 | ) { |
| 36 | this.pose = { panDeg: 0, tiltDeg: 0, zoomUnits: units.zoomWideUnits }; |
| 37 | } |
| 38 | |
| 39 | start(): void { |
| 40 | if (this.timer) return; |
| 41 | this.timer = setInterval(() => this.tick(TICK_MS / 1000), TICK_MS); |
| 42 | } |
| 43 | |
| 44 | stop(): void { |
| 45 | if (this.timer) clearInterval(this.timer); |
| 46 | this.timer = null; |
| 47 | } |
| 48 | |
| 49 | gotoAbsolute(pose: CameraPose, speeds?: { panDps?: number; tiltDps?: number }): void { |
| 50 | this.commands++; |
| 51 | const clamped = clampPose(pose, this.limits, this.units); |
| 52 | setTimeout(() => { |
| 53 | this.jogRates = { pan: 0, tilt: 0, zoom: 0 }; |
| 54 | this.goal = clamped; |
| 55 | this.goalSpeeds = { |
| 56 | panDps: speeds?.panDps ?? this.limits.panSpeedMaxDps, |
| 57 | tiltDps: speeds?.tiltDps ?? this.limits.tiltSpeedMaxDps, |
| 58 | }; |
| 59 | }, LATENCY_MS); |
| 60 | } |
| 61 | |
| 62 | jog(pan: number, tilt: number, zoom: number): void { |
| 63 | this.commands++; |
| 64 | setTimeout(() => { |
| 65 | this.goal = null; |
| 66 | this.jogRates = { pan, tilt, zoom }; |
| 67 | }, LATENCY_MS); |
| 68 | } |
| 69 | |
| 70 | trackRate(panDps: number, tiltDps: number): void { |
| 71 | this.commands++; |
| 72 | setTimeout(() => { |
| 73 | this.goal = null; |
| 74 | this.jogRates = { |
| 75 | pan: panDps / this.limits.panSpeedMaxDps, |
| 76 | tilt: tiltDps / this.limits.tiltSpeedMaxDps, |
| 77 | zoom: this.jogRates.zoom, |
| 78 | }; |
nothing calls this directly
no outgoing calls
no test coverage detected