Upgraded autofocus to taskSubmitters

This commit is contained in:
Joel Collins 2019-11-21 17:01:32 +00:00
parent 1e9303ee90
commit 80ad33fdd8

View file

@ -40,7 +40,12 @@
<a class="uk-accordion-title" href="#">Move-to</a> <a class="uk-accordion-title" href="#">Move-to</a>
<div class="uk-accordion-content"> <div class="uk-accordion-content">
<form @submit.prevent="handleSubmit"> <form @submit.prevent="handleSubmit">
<div class="uk-grid-small uk-child-width-1-3" uk-grid> <!-- Text boxes to set and view position -->
<div
v-if="setPosition"
class="uk-grid-small uk-child-width-1-3"
uk-grid
>
<div> <div>
<label class="uk-form-label" for="form-stacked-text">x</label> <label class="uk-form-label" for="form-stacked-text">x</label>
<div class="uk-form-controls"> <div class="uk-form-controls">
@ -80,7 +85,7 @@
<p> <p>
<button <button
class="uk-button uk-button-primary uk-form-small uk-float-right uk-width-1-1" class="uk-button uk-button-default uk-form-small uk-float-right uk-width-1-1"
> >
Move Move
</button> </button>
@ -90,44 +95,44 @@
</li> </li>
<!--Show autofocus if default plugin is enabled--> <!--Show autofocus if default plugin is enabled-->
<li <li class="uk-open">
v-if="this.$store.state.apiState.plugin.includes('default_autofocus')"
class="uk-open"
>
<a class="uk-accordion-title" href="#">Autofocus</a> <a class="uk-accordion-title" href="#">Autofocus</a>
<div class="uk-accordion-content"> <div class="uk-accordion-content">
<div v-if="isAutofocusing"> <div class="uk-grid-small uk-child-width-expand" uk-grid>
<progressBar /> <div v-show="!isAutofocusing || isAutofocusing == 1">
</div> <taskSubmitter
v-if="fastAutofocusUri"
:submit-url="fastAutofocusUri"
:submit-data="{ dz: 2000, backlash: 300 }"
:submit-label="'Fast'"
@taskStarted="isAutofocusing = 1"
@finished="isAutofocusing = 0"
>
</taskSubmitter>
</div>
<div <div v-show="!isAutofocusing || isAutofocusing == 2">
class="uk-grid-small uk-child-width-1-3" <taskSubmitter
:hidden="isAutofocusing" v-if="normalAutofocusUri"
uk-grid :submit-url="normalAutofocusUri"
> :submit-data="{ dz: [-60, -30, 0, 30, 60] }"
<div> :submit-label="'Medium'"
<button @taskStarted="isAutofocusing = 2"
class="uk-button uk-button-default uk-form-small uk-float-right uk-width-1-1" @finished="isAutofocusing = 0"
@click="runFastAutofocus(2000, 300)"
> >
Fast </taskSubmitter>
</button>
</div> </div>
<div>
<button <div v-show="!isAutofocusing || isAutofocusing == 3">
class="uk-button uk-button-default uk-form-small uk-float-right uk-width-1-1" <taskSubmitter
@click="runAutofocus([-60, -30, 0, 30, 60])" v-if="normalAutofocusUri"
:submit-url="normalAutofocusUri"
:submit-data="{ dz: [-20, -10, 0, 10, 20] }"
:submit-label="'Fine'"
@taskStarted="isAutofocusing = 3"
@finished="isAutofocusing = 0"
> >
Medium </taskSubmitter>
</button>
</div>
<div>
<button
class="uk-button uk-button-default uk-form-small uk-float-right uk-width-1-1"
@click="runAutofocus([-20, -10, 0, 10, 20])"
>
Fine
</button>
</div> </div>
</div> </div>
</div> </div>
@ -138,7 +143,7 @@
<script> <script>
import axios from "axios"; import axios from "axios";
import progressBar from "../genericComponents/progressBar"; import taskSubmitter from "../genericComponents/taskSubmitter";
// Key Codes // Key Codes
const keyCodes = { const keyCodes = {
@ -157,7 +162,7 @@ export default {
name: "PaneNavigate", name: "PaneNavigate",
components: { components: {
progressBar taskSubmitter
}, },
data: function() { data: function() {
@ -165,23 +170,29 @@ export default {
keysDown: {}, keysDown: {},
stepXy: 200, stepXy: 200,
stepZz: 50, stepZz: 50,
setPosition: this.$store.state.apiState.stage.position, setPosition: null,
isAutofocusing: false, isAutofocusing: 0,
moveLock: false moveLock: false,
fastAutofocusUri: null,
normalAutofocusUri: null
}; };
}, },
computed: { computed: {
positionApiUri: function() { moveActionUri: function() {
return this.$store.getters.uri + "/stage/position"; return `http://${this.$store.state.host}:${
this.$store.state.port
}/api/v2/actions/stage/move`;
}, },
autofocusApiUri: function() { positionStatusUri: function() {
return this.$store.getters.uri + "/plugin/default/autofocus/autofocus"; return `http://${this.$store.state.host}:${
this.$store.state.port
}/api/v2/status/stage/position`;
}, },
fastAutofocusApiUri: function() { pluginsUri: function() {
return ( return `http://${this.$store.state.host}:${
this.$store.getters.uri + "/plugin/default/autofocus/fast_autofocus" this.$store.state.port
); }/api/v2/plugins`;
} }
}, },
@ -196,6 +207,10 @@ export default {
this.$root.$on("globalMoveEvent", (x, y, z, absolute) => { this.$root.$on("globalMoveEvent", (x, y, z, absolute) => {
this.moveRequest(x, y, z, absolute); this.moveRequest(x, y, z, absolute);
}); });
// Update the current position in text boxes
this.updatePosition();
// Look for autofocus plugin
this.updateAutofocusUri();
}, },
beforeDestroy() { beforeDestroy() {
@ -287,15 +302,14 @@ export default {
// Send move request // Send move request
axios axios
.post(this.positionApiUri, { .post(this.moveActionUri, {
x: x, x: x,
y: y, y: y,
z: z, z: z,
absolute: absolute absolute: absolute
}) })
.then(response => { .then(() => {
this.$store.dispatch("updateState"); // Update store state this.updatePosition(); // Update the position in text boxes
this.setPosition = response.data.stage.position; // Update boxes from response
}) })
.catch(error => { .catch(error => {
this.modalError(error); // Let mixin handle error this.modalError(error); // Let mixin handle error
@ -306,64 +320,40 @@ export default {
} }
}, },
runAutofocus: function(dz) { updatePosition: function() {
if (!this.moveLock) { axios
// Lock move requests .get(this.positionStatusUri)
this.moveLock = true; .then(response => {
this.isAutofocusing = true; this.setPosition = response.data;
axios })
.post(this.autofocusApiUri, { dz: dz }) .catch(error => {
.then(response => { this.modalError(error); // Let mixin handle error
console.log("Autofocus Task ID: " + response.data.id); });
// Start the store polling TaskId for success
return this.$store.dispatch("pollTask", [
response.data.id,
null,
null
]);
})
.then(() => {
console.log("Successfully finished autofocus");
})
.catch(error => {
this.modalError(error); // Let mixin handle error
})
.finally(() => {
console.log("Cleaning up after autofocus.");
this.isAutofocusing = false;
this.moveLock = false; // Release the move lock
});
}
}, },
runFastAutofocus: function(dz, backlash) { updateAutofocusUri: function() {
if (!this.moveLock) { axios
// Lock move requests .get(this.pluginsUri) // Get a list of plugins
this.moveLock = true; .then(response => {
this.isAutofocusing = true; var plugins = response.data;
axios // if ScanPlugin is enabled
.post(this.fastAutofocusApiUri, { dz: dz, backlash: backlash }) if ("AutofocusPlugin" in plugins) {
.then(response => { // Get plugin action link
console.log("Autofocus Task ID: " + response.data.id); var fastLink =
// Start the store polling TaskId for success plugins.AutofocusPlugin.views.fast_autofocus.links.self;
return this.$store.dispatch("pollTask", [ var normalLink = plugins.AutofocusPlugin.views.autofocus.links.self;
response.data.id, // Store plugin action URI
null, this.fastAutofocusUri = `http://${this.$store.state.host}:${
null this.$store.state.port
]); }${fastLink}`;
}) this.normalAutofocusUri = `http://${this.$store.state.host}:${
.then(() => { this.$store.state.port
console.log("Successfully finished autofocus"); }${normalLink}`;
}) }
.catch(error => { })
this.modalError(error); // Let mixin handle error .catch(error => {
}) this.modalError(error); // Let mixin handle error
.finally(() => { });
console.log("Cleaning up after autofocus.");
this.isAutofocusing = false;
this.moveLock = false; // Release the move lock
});
}
} }
} }
}; };