Mercurial > code > home > repos > light9
comparison web/calibrate/Light9Calibrate.ts @ 2419:e3af0ac507c8
new exposure-finder algorithm
author | drewp@bigasterisk.com |
---|---|
date | Tue, 21 May 2024 14:08:17 -0700 |
parents | ae4b90efb55a |
children | d5750b2aaa9e |
comparison
equal
deleted
inserted
replaced
2418:9bb0eb587d5b | 2419:e3af0ac507c8 |
---|---|
2 import { css, html, LitElement } from "lit"; | 2 import { css, html, LitElement } from "lit"; |
3 import { customElement, query, state } from "lit/decorators.js"; | 3 import { customElement, query, state } from "lit/decorators.js"; |
4 import { CollectorClient } from "../collector/CollectorClient"; | 4 import { CollectorClient } from "../collector/CollectorClient"; |
5 import { getTopGraph } from "../RdfdbSyncedGraph"; | 5 import { getTopGraph } from "../RdfdbSyncedGraph"; |
6 import { SyncedGraph } from "../SyncedGraph"; | 6 import { SyncedGraph } from "../SyncedGraph"; |
7 import { FindSafeExposure } from "./FindSafeExposure"; | |
7 import { Light9Camera } from "./Light9Camera"; | 8 import { Light9Camera } from "./Light9Camera"; |
8 import { XyPlot } from "./XyPlot"; | 9 import { XyPlot } from "./XyPlot"; |
9 export { RdfdbSyncedGraph } from "../RdfdbSyncedGraph"; | 10 export { RdfdbSyncedGraph } from "../RdfdbSyncedGraph"; |
10 export { Light9Camera } from "./Light9Camera"; | 11 export { Light9Camera } from "./Light9Camera"; |
11 export { XyPlot } from "./XyPlot"; | 12 export { XyPlot } from "./XyPlot"; |
13 | |
12 debug.enable("*"); | 14 debug.enable("*"); |
13 const log = debug("calibrate"); | 15 const log = debug("calibrate"); |
14 | 16 |
15 async function sleep(ms: number) { | 17 export async function sleep(ms: number) { |
16 return new Promise((resolve) => setTimeout(resolve, ms)); | 18 return new Promise((resolve) => setTimeout(resolve, ms)); |
17 } | 19 } |
18 | 20 |
19 @customElement("light9-calibrate") | 21 @customElement("light9-calibrate") |
20 export class Light9Calibrate extends LitElement { | 22 export class Light9Calibrate extends LitElement { |
76 }); | 78 }); |
77 } | 79 } |
78 | 80 |
79 async findSafeExposure(ev: MouseEvent) { | 81 async findSafeExposure(ev: MouseEvent) { |
80 await this.withButtonSpinner(ev, async () => { | 82 await this.withButtonSpinner(ev, async () => { |
81 | 83 const algo = new FindSafeExposure(this.cam!, this.plot!); |
82 const gatherSample = async (expo: number) => { | 84 await algo.run(); |
83 await this.cam?.set("exposureTime", expo); | |
84 const settleUntil = Date.now() + 1000; | |
85 let miny = this.cam?.saturatedPixelCount!; | |
86 while (Date.now() < settleUntil) { | |
87 await sleep(50); | |
88 miny = Math.min(miny, this.cam?.saturatedPixelCount!); | |
89 } | |
90 this.plot!.insertPoint(expo, miny); | |
91 }; | |
92 | |
93 // todo: drive around without big skips, gradually slower, looking for the max workable expo | |
94 let fixedSteps = 8; | |
95 const expoMin = 1; | |
96 const expoMax = 200; | |
97 let expo = 0; | |
98 const data=this.plot!.data; | |
99 while (data.length < 20) { | |
100 if (data.length < fixedSteps + 1) { | |
101 expo = expoMin + ((expoMax - expoMin) / fixedSteps) * data.length; | |
102 } else { | |
103 let x2 = data.findIndex(([_, y]) => y > 2); | |
104 if (x2 < 1) x2 = 1; | |
105 const x1 = x2 - 1; | |
106 log(JSON.stringify([x1, data[x1], x2, data[x2]])); | |
107 expo = (data[x1][0] + data[x2][0]) / 2; | |
108 log(data); | |
109 } | |
110 await gatherSample(expo); | |
111 } | |
112 }); | 85 }); |
113 } | 86 } |
114 async setToZero(ev: MouseEvent) { | 87 async setToZero(ev: MouseEvent) { |
115 await this.withButtonSpinner(ev, async () => { | 88 await this.withButtonSpinner(ev, async () => { |
116 this.collector.updateSettings([ | 89 this.collector.updateSettings([ |