Skip to content

Commit

Permalink
pause resume workcell button, not tested on modules with no pause adm…
Browse files Browse the repository at this point in the history
…in action
  • Loading branch information
caseystone committed Aug 21, 2024
1 parent f7eb49e commit e0f27db
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/ui/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ declare module 'vue' {
ModulesPanel: typeof import('./src/components/ModulesPanel.vue')['default']
ModuleModal: typeof import('./src/components/ModuleModal.vue')['default']
PauseResumeModuleButton: typeof import('./src/components/PauseResumeModuleButton.vue')['default']
PauseResumeWorkcellButton: typeof import('./src/components/PauseResumeWorkcellButton.vue')['default']
Workflow: typeof import('./src/components/Workflow.vue')['default']
WorkflowModal: typeof import('./src/components/WorkflowModal.vue')['default']
WorkflowsPanel: typeof import('./src/components/WorkflowsPanel.vue')['default']
Expand Down
8 changes: 5 additions & 3 deletions src/ui/src/components/Dashboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@
<v-window-item :key="1" :value="1">
<v-container v-if="wc_state">
<v-card class="pa-1">
<v-card-title class="text-center">
<h2>{{ wc_info.name }}</h2>
</v-card-title>
<v-card-title class="text-center">
<h2>{{ wc_info.name }}</h2>
<PauseResumeWorkcellButton :main_url="main_url" />
</v-card-title>
<v-card-text>
<v-container class="pa-1">
<v-row dense wrap justify-content="space-evenly">
Expand Down Expand Up @@ -92,6 +93,7 @@
import { ref, watchEffect } from 'vue';
import VueJsonPretty from 'vue-json-pretty';
import 'vue-json-pretty/lib/styles.css';
import PauseResumeWorkcellButton from './PauseResumeWorkcellButton.vue';
const main_url = ref()
const state_url = ref()
const workcell_info_url = ref()
Expand Down
4 changes: 2 additions & 2 deletions src/ui/src/components/ModuleModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<template v-if="wc_state.modules[modal_title].about.admin_commands.includes('pause') && wc_state.modules[modal_title].about.admin_commands.includes('resume')">
<PauseResumeModuleButton :main_url="main_url" :module="modal_title" :module_status="wc_state.modules[modal_title].state.status" />
</template>

</div>
</v-card-title>

Expand Down Expand Up @@ -96,7 +96,7 @@

<script setup lang="ts">
import { ref } from 'vue';
import PauseResumeButton from './PauseResumeButton.vue';
import VueJsonPretty from 'vue-json-pretty';
import 'vue-json-pretty/lib/styles.css';
Expand Down
89 changes: 89 additions & 0 deletions src/ui/src/components/PauseResumeWorkcellButton.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<template>
<div>
<v-btn
@click="togglePauseResume"
:color="isPaused ? 'green darken-3' : 'red darken-3'"
dark
elevation="5">
<v-icon>
{{ isPaused ? 'mdi-play' : 'mdi-pause' }}
</v-icon>
</v-btn>
</div>
</template>

<script lang="ts" setup>
// TODO: Currently this changes all modules to BUSY regardless of starting state on resume.
import {defineProps, ref, watchEffect} from 'vue';
const props = defineProps(['main_url'])
const pause_url = ref()
const resume_url = ref()
const isPaused = ref(false);
// Format pause and resume urls
pause_url.value = props.main_url.concat('/admin/pause')
resume_url.value = props.main_url.concat('/admin/resume')
// Function to toggle pause/resume
const togglePauseResume = async () => {
if (isPaused.value) {
await sendResumeCommand();
} else {
await sendPauseCommand();
}
isPaused.value = !isPaused.value;
};
// Function to send pause command
const sendPauseCommand = async () => {
try {
const response = await fetch(pause_url.value, {
method: 'POST',
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
console.log('Workcell Paused');
} catch (error) {
console.error('Error pausing module:', error);
}
};
// Function to send resume command
const sendResumeCommand = async () => {
try {
const response = await fetch(resume_url.value, {
method: 'POST',
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
console.log('Workcell Resumed');
} catch (error) {
console.error('Error resuming module:', error);
}
};
</script>

<style scoped>
button {
padding: 10px 20px;
font-size: 16px;
background-color: #007bff;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
}
button:hover {
background-color: #0056b3;
}
</style>
4 changes: 3 additions & 1 deletion src/wei/modules/rest_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,9 @@ async def safety_stop(request: Request):

@self.router.post("/admin/pause")
async def pause(request: Request):

state = request.app.state
state.pre_paused_status = state.status
state.status = ModuleStatus.PAUSED
if self._pause:
return self._pause(state)
Expand All @@ -512,7 +514,7 @@ async def pause(request: Request):
@self.router.post("/admin/resume")
async def resume(request: Request):
state = request.app.state
state.status = ModuleStatus.BUSY # TODO: Is there a better way to do this? NOTE: If I don't put this there, it resumes with status PAUSED
state.status = state.pre_paused_status
if self._resume:
return self._resume(state)
else:
Expand Down

0 comments on commit e0f27db

Please sign in to comment.