layout complete

This commit is contained in:
Niko Feith 2023-02-28 19:33:48 +01:00
parent 899ef5be2e
commit d2d3cbb0cc
3 changed files with 23 additions and 9 deletions

View File

@ -12,7 +12,7 @@ const store = usePStore();
let chartHandle; let chartHandle;
function buildChart() { function buildChart() {
const policy = store.getPolicy(); const policy = store.getPolicy;
const policy_labels = Array(policy.length).fill(0).map((_, i) => i); const policy_labels = Array(policy.length).fill(0).map((_, i) => i);
const RewardPlot = { const RewardPlot = {
data: { data: {
@ -72,8 +72,12 @@ onMounted(() => {
buildChart(); buildChart();
}); });
watch(() => store.getPolicy(), () => { watch(() => store.getPolicy, () => {
chartHandle.data.dataset[0].data = store.getPolicy(); const policy = store.getPolicy;
const policy_labels = Array(policy.length).fill(0).map((_, i) => i)
chartHandle.options.scales.x.labels = policy_labels;
chartHandle.data.datasets[0].data = policy;
chartHandle.update(); chartHandle.update();
}); });

View File

@ -26,15 +26,19 @@
import * as ROS from 'roslib'; import * as ROS from 'roslib';
import { useBWStore } from '@/store/BaseWebsiteStore'; import { useBWStore } from '@/store/BaseWebsiteStore';
import { usePStore } from "@/store/PolicyStore"; import { usePStore } from "@/store/PolicyStore";
import {useCStore} from "@/store/ControlStore";
import { import {
reactive, reactive,
ref, ref,
watch, watch,
} from 'vue'; } from 'vue';
import * as ROSLIB from "roslib"; import * as ROSLIB from "roslib";
const store = useBWStore(); const store = useBWStore();
const pstore = usePStore(); const pstore = usePStore();
const cstore = useCStore();
const formState = reactive({ const formState = reactive({
ipaddress: 'localhost', ipaddress: 'localhost',
@ -98,12 +102,17 @@ const policy_service = new ROSLIB.Service({
serviceType: 'active_bo_msgs/srv/WeightToPolicy', serviceType: 'active_bo_msgs/srv/WeightToPolicy',
}); });
const policy_request = new ROSLIB.ServiceRequest({ watch(() => cstore.getSendWeights, () =>{
weights: pstore.weights,
nr_steps: pstore.nr_steps,
})
const policy_request = new ROSLIB.ServiceRequest({
weights: pstore.weights,
nr_steps: pstore.max_steps,
})
policy_service.callService(policy_request, function (result) {
pstore.setPolicy(result.policy)
});
});
</script> </script>

View File

@ -3,10 +3,10 @@ import { defineStore } from "pinia";
export const usePStore = defineStore('Policy Store', { export const usePStore = defineStore('Policy Store', {
state: () => { state: () => {
return { return {
policy: Array, policy: Array(10).fill(0),
nr_weights: 5, nr_weights: 5,
weights: [0, 0, 0, 0, 0], weights: [0, 0, 0, 0, 0],
max_steps: 0, max_steps: 10,
} }
}, },
getters: { getters: {
@ -17,6 +17,7 @@ export const usePStore = defineStore('Policy Store', {
}, },
actions: { actions: {
setPolicy(value) { setPolicy(value) {
this.policy = null;
this.policy = value; this.policy = value;
}, },
setNrWeights(value) { setNrWeights(value) {