Working stage positioning

NB there is a server bug that means absolute moves fail -
this should be fixed in a separate branch.
This commit is contained in:
Richard 2021-03-24 13:23:20 +00:00
parent cd30872d62
commit 024f2566f0

View file

@ -117,6 +117,12 @@ export default {
}, },
snapshotStreamUri: function() { snapshotStreamUri: function() {
return `${this.$store.getters.baseUri}/api/v2/streams/snapshot`; return `${this.$store.getters.baseUri}/api/v2/streams/snapshot`;
},
getPositionUri: function() {
return `${this.$store.getters.baseUri}/api/v2/instrument/state/stage/position`;
},
moveActionUri: function() {
return `${this.$store.getters.baseUri}/api/v2/actions/stage/move`;
} }
}, },
mounted() { mounted() {
@ -220,6 +226,8 @@ export default {
// See here: https://valelab4.ucsf.edu/~MM/doc/MMCore/html/class_c_m_m_core.html // See here: https://valelab4.ucsf.edu/~MM/doc/MMCore/html/class_c_m_m_core.html
const snapshotUri = this.snapshotStreamUri; const snapshotUri = this.snapshotStreamUri;
const captureActionUri = this.captureActionUri; const captureActionUri = this.captureActionUri;
const getPositionUri = this.getPositionUri;
const moveActionUri = this.moveActionUri;
const modalError = this.modalError; const modalError = this.modalError;
async function pollUntilComplete(response) { async function pollUntilComplete(response) {
// Poll an action until its status is completed // Poll an action until its status is completed
@ -228,7 +236,7 @@ export default {
// axios.get // axios.get
// FIXME: this could be an infinite loop if the task is cancelled/errored // FIXME: this could be an infinite loop if the task is cancelled/errored
let r = response; let r = response;
while (r.data.status != "completed") { while (r.data.status == "active") {
await new Promise(resolve => setTimeout(resolve, 100)); await new Promise(resolve => setTimeout(resolve, 100));
r = await axios.get(r.data.href); r = await axios.get(r.data.href);
} }
@ -282,19 +290,38 @@ export default {
); );
return jpeg; //TODO: what is the expected output format??? return jpeg; //TODO: what is the expected output format???
}, },
setPosition() { setPosition(z) {
// The C api suggests this defaults to just Z, and can accept a "label" to // The C api suggests this defaults to just Z, and can accept a "label" to
// select the stage. // select the stage.
alert("Not implemented"); return service.setXYZPosition({
"z": z,
"absolute": true,
});
}, },
getPosition() { async getPosition() {
alert("Not implemented"); const pos = await service.getXYZPosition();
return pos.z;
}, },
setXYPosition() { async setXYPosition(x, y) {
alert("Not implemented"); return service.setXYZPosition({
"x": x,
"y": y,
"absolute": true,
});
}, },
getXYPosition() { async getXYPosition() {
alert("Not implemented"); const pos = await service.getXYZPosition();
return [pos.x, pos.y];
},
async getXYZPosition() {
return axios
.get(getPositionUri)
.then(r => r.data)
},
async setXYZPosition(payload) {
return axios
.post(moveActionUri, payload)
.then(pollUntilComplete)
} }
}; };
this.imjoy.pm.registerService({ name: "openflexure" }, service); this.imjoy.pm.registerService({ name: "openflexure" }, service);