Persist rover observation configuration and calibrate Insta360 panorama

This commit is contained in:
DCCONSTRUCTIONS
2026-10-09 18:17:54 +03:00
parent c43b097a3a
commit b4dab01f2a
36 changed files with 1271 additions and 50 deletions
@@ -0,0 +1,40 @@
import assert from 'node:assert/strict';
import {after,before,test} from 'node:test';
import {createServer} from 'vite';
let server,optics,exposure;
before(async()=>{server=await createServer({appType:'custom',logLevel:'silent',server:{middlewareMode:true}});optics=await server.ssrLoadModule('../../plugins/insta360-x4/frontend/src/panoramaCalibration.ts');exposure=await server.ssrLoadModule('../../plugins/insta360-x4/frontend/src/panoramaExposure.ts');});
after(async()=>{await server?.close();});
const block=(cx)=>[1,240,240,cx,300,0,0,90,0,0,0,0,0,0,0,0,1600,600,71];
const fixture=()=>({offsets:[[2,...block(400),...block(1200),3*65536].join('_')],crop:{source_width:800,source_height:600,width:576,height:576,x:0,y:0}});
const close=(a,b)=>assert.ok(Math.abs(a-b)<1e-9,`${a} != ${b}`);
test('rectangular sensor calibration maps each centred preview crop independently',()=>{
const c=optics.liveCalibration(fixture());assert.equal(c.version,3);assert.equal(c.width,2);
assert.deepEqual(c.lenses.map(l=>l.center),[[.5,.5],[1.5,.5]]);
assert.deepEqual(optics.projectLens(c,0,[-1,0,0],90),[.25,.5]);
assert.deepEqual(optics.projectLens(c,1,[1,0,0],270),[.75,.5]);
const f=fixture();f.crop.x=12;f.crop.y=-6;const shifted=optics.liveCalibration(f);
close(shifted.lenses[0].center[0],.5-12/576);close(shifted.lenses[1].center[1],.5+6/576);
});
test('unrecognised, malformed and incompatible optics cannot appear calibrated',()=>{
for(const v of [null,{},'x',NaN,{offsets:['2_NaN']}, {...fixture(),offsets:['2__1']}, {...fixture(),offsets:[fixture().offsets[0].replace('_196608','_393216')]}, {...fixture(),crop:{...fixture().crop,width:900}}, {...fixture(),crop:{...fixture().crop,x:999}}, {...fixture(),crop:{...fixture().crop,width:575}}])assert.equal(optics.liveCalibration(v),null);
});
test('rays in both seam bands remain within the correct lens windows at all mounting rotations',()=>{
const c=optics.liveCalibration(fixture());
for(const turn of [0,90,180,270])for(const sign of [-1,1])for(let lat=-70;lat<=70;lat+=10){const a=lat*Math.PI/180,ray=[0,sign*Math.cos(a),Math.sin(a)];
for(const i of [0,1]){const uv=optics.projectLens(c,i,ray,turn);assert.ok(uv);assert.ok(uv[0]>=i*.5&&uv[0]<=(i+1)*.5);assert.ok(uv[1]>=0&&uv[1]<=1);}
}
assert.equal(optics.projectLens(c,0,[1,0,0],0),null);
});
test('overlap exposure matching brings equal scenes together without chasing black or saturated pixels',()=>{
const c=optics.liveCalibration(fixture()),width=384,height=192,data=new Uint8ClampedArray(width*height*4);
for(let y=0;y<height;y++)for(let x=0;x<width;x++){const k=(y*width+x)*4;data.fill(x<width/2?100:150,k,k+3);data[k+3]=255;}
const gains=exposure.overlapGains(data,width,height,c,[90,270]);assert.ok(gains);
for(let k=0;k<3;k++)close(100*gains[0][k],150*gains[1][k]);
data.fill(0);assert.equal(exposure.overlapGains(data,width,height,c,[90,270]),null);
data.fill(255);assert.equal(exposure.overlapGains(data,width,height,c,[90,270]),null);
});
test('extreme brightness mismatch is bounded rather than producing unlimited gain',()=>{
const c=optics.liveCalibration(fixture()),width=384,height=192,data=new Uint8ClampedArray(width*height*4);
for(let y=0;y<height;y++)for(let x=0;x<width;x++){const k=(y*width+x)*4;data.fill(x<width/2?25:225,k,k+3);data[k+3]=255;}
const gains=exposure.overlapGains(data,width,height,c,[90,270]);for(const lens of gains)for(const gain of lens)assert.ok(gain>=.75&&gain<=4/3);
});
@@ -0,0 +1,19 @@
import assert from 'node:assert/strict';
import {before,after,test} from 'node:test';
import {createServer} from 'vite';
let server,sameConfiguration;
before(async()=>{server=await createServer({appType:'custom',logLevel:'silent',server:{middlewareMode:true}});({sameConfiguration}=await server.ssrLoadModule('/src/core/fleet/configurationEquality.ts'));});
after(async()=>server?.close());
test('lost onboard acknowledgement reconciles across JSON key ordering',()=>{
const draft={cameras:{x4:{rotations:{left:90,right:270},panoramaYaw:15}},layouts:{version:1,presets:[]}};
const board={layouts:{presets:[],version:1},cameras:{x4:{panoramaYaw:15,rotations:{right:270,left:90}}}};
assert.equal(sameConfiguration(draft,board),true);
board.cameras.x4.rotations.left=180;
assert.equal(sameConfiguration(draft,board),false);
});
test('array order and absent fields remain meaningful configuration changes',()=>{
assert.equal(sameConfiguration({order:['left','right']},{order:['right','left']}),false);
assert.equal(sameConfiguration({yaw:0},{}),false);
assert.equal(sameConfiguration({yaw:0},{yaw:null}),false);
assert.equal(sameConfiguration(null,{}),false);
});