annotate web/calibrate/Light9Calibrate.ts @ 2420:d5750b2aaa9e

minor cam edits
author drewp@bigasterisk.com
date Tue, 21 May 2024 14:50:01 -0700
parents e3af0ac507c8
children 62dc1b3644a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2417
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
1 import debug from "debug";
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
2 import { css, html, LitElement } from "lit";
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
3 import { customElement, query, state } from "lit/decorators.js";
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
4 import { CollectorClient } from "../collector/CollectorClient";
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
5 import { getTopGraph } from "../RdfdbSyncedGraph";
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
6 import { SyncedGraph } from "../SyncedGraph";
2419
e3af0ac507c8 new exposure-finder algorithm
drewp@bigasterisk.com
parents: 2417
diff changeset
7 import { FindSafeExposure } from "./FindSafeExposure";
2417
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
8 import { Light9Camera } from "./Light9Camera";
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
9 import { XyPlot } from "./XyPlot";
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
10 export { RdfdbSyncedGraph } from "../RdfdbSyncedGraph";
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
11 export { Light9Camera } from "./Light9Camera";
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
12 export { XyPlot } from "./XyPlot";
2419
e3af0ac507c8 new exposure-finder algorithm
drewp@bigasterisk.com
parents: 2417
diff changeset
13
2417
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
14 debug.enable("*");
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
15 const log = debug("calibrate");
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
16
2419
e3af0ac507c8 new exposure-finder algorithm
drewp@bigasterisk.com
parents: 2417
diff changeset
17 export async function sleep(ms: number) {
2417
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
18 return new Promise((resolve) => setTimeout(resolve, ms));
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
19 }
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
20
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
21 @customElement("light9-calibrate")
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
22 export class Light9Calibrate extends LitElement {
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
23 graph!: SyncedGraph;
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
24 static styles = [
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
25 css`
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
26 button {
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
27 min-height: 3em;
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
28 min-width: 10em;
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
29 }
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
30 `,
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
31 ];
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
32 collector: CollectorClient = new CollectorClient("calibrate");
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
33 @query("light9-camera", true) cam?: Light9Camera;
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
34 @query("xy-plot", true) plot?: XyPlot;
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
35 @state() device: string;
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
36 constructor() {
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
37 super();
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
38 this.device = "http://light9.bigasterisk.com/theater/vet/device/parR3";
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
39 getTopGraph().then((g) => {
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
40 this.graph = g;
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
41 });
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
42 }
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
43
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
44 render() {
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
45 return html`<rdfdb-synced-graph></rdfdb-synced-graph>
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
46 <h1>Calibrate</h1>
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
47 <light9-camera></light9-camera>
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
48
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
49 <p>Device to calibrate: [ ${this.device} ]</p>
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
50
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
51 <ol>
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
52 <li><button @click=${this.setToFull}>Set to full</button></li>
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
53 <li><button @click=${this.findSafeExposure}>Find safe exposure</button></li>
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
54 <li><button @click=${this.setToZero}>Set to 0</button></li>
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
55 <li><button @click=${this.markTare}>Mark tare</button></li>
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
56 <li><button @click=${this.calibrateLoop}>Calibrate loop</button></li>
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
57 </ol>
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
58 <xy-plot label="zebra pixels vs exposure"></xy-plot>
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
59 r/g/b/r*g*b lines ,x=send y=seen `;
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
60 }
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
61
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
62 async withButtonSpinner(ev: MouseEvent, fn: () => Promise<void>) {
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
63 const btn = ev.target as HTMLButtonElement;
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
64 try {
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
65 btn.disabled = true;
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
66 await fn();
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
67 } finally {
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
68 btn.disabled = false;
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
69 }
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
70 }
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
71 async setToFull(ev: MouseEvent) {
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
72 await this.withButtonSpinner(ev, async () => {
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
73 this.collector.updateSettings([
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
74 /// device,attr,value
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
75 [this.device, "http://light9.bigasterisk.com/color", "#ffffff"],
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
76 [this.device, "http://light9.bigasterisk.com/white", 1],
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
77 ]);
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
78 });
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
79 }
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
80
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
81 async findSafeExposure(ev: MouseEvent) {
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
82 await this.withButtonSpinner(ev, async () => {
2419
e3af0ac507c8 new exposure-finder algorithm
drewp@bigasterisk.com
parents: 2417
diff changeset
83 const algo = new FindSafeExposure(this.cam!, this.plot!);
2420
d5750b2aaa9e minor cam edits
drewp@bigasterisk.com
parents: 2419
diff changeset
84 const expo = await algo.run();
2417
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
85 });
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
86 }
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
87 async setToZero(ev: MouseEvent) {
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
88 await this.withButtonSpinner(ev, async () => {
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
89 this.collector.updateSettings([
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
90 [this.device, "http://light9.bigasterisk.com/color", "#000000"],
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
91 [this.device, "http://light9.bigasterisk.com/white", 0],
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
92 ]);
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
93 });
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
94 }
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
95 async markTare(ev: MouseEvent) {
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
96 await this.withButtonSpinner(ev, async () => {});
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
97 }
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
98 async calibrateLoop(ev: MouseEvent) {
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
99 await this.withButtonSpinner(ev, async () => {});
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
100 }
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
101 }