manual use without image transfer

This commit is contained in:
Niko Feith 2023-03-02 11:15:25 +01:00
parent d2d3cbb0cc
commit 33a44b5f26
4 changed files with 57 additions and 7 deletions

View File

@ -100,15 +100,18 @@ onMounted(() => {
buildChart(); buildChart();
}); });
watch(() => store.getMean, () => { watch(() => store.getTrigger, () => {
const reward_mean = store.getMean; const reward_mean = store.getMean;
const reward_std = store.getStd; const reward_std = store.getStd;
const upper_bound = Array(reward_mean.length).fill(0).map((_, i) => reward_mean[i] + 1.96 * reward_std[i]); const upper_bound = Array(reward_mean.length).fill(0).map((_, i) => reward_mean[i] + 1.96 * reward_std[i]);
const lower_bound = Array(reward_mean.length).fill(0).map((_, i) => reward_mean[i] - 1.96 * reward_std[i]); const lower_bound = Array(reward_mean.length).fill(0).map((_, i) => reward_mean[i] - 1.96 * reward_std[i]);
chartHandle.data.dataset[0].data = reward_mean; const reward_labels = Array(reward_mean.length).fill(0).map((_, i) => i);
chartHandle.data.dataset[1].data = upper_bound;
chartHandle.data.dataset[2].data = lower_bound; chartHandle.options.scales.x.labels = reward_labels;
chartHandle.data.datasets[0].data = reward_mean;
chartHandle.data.datasets[1].data = upper_bound;
chartHandle.data.datasets[2].data = lower_bound;
chartHandle.update(); chartHandle.update();
}); });

View File

@ -35,10 +35,14 @@ import {
} from 'vue'; } from 'vue';
import * as ROSLIB from "roslib"; import * as ROSLIB from "roslib";
import {useRStore} from "@/store/RewardStore";
import {useMCStore} from "@/store/MountainCarStore";
const store = useBWStore(); const store = useBWStore();
const pstore = usePStore(); const pstore = usePStore();
const cstore = useCStore(); const cstore = useCStore();
const rstore = useRStore();
const mcstore = useMCStore();
const formState = reactive({ const formState = reactive({
ipaddress: 'localhost', ipaddress: 'localhost',
@ -95,7 +99,7 @@ watch(stateCounter.value, (newValue) => {
} }
}); });
// Services // Policy Service
const policy_service = new ROSLIB.Service({ const policy_service = new ROSLIB.Service({
ros: ros, ros: ros,
name: '/policy_srv', name: '/policy_srv',
@ -114,6 +118,35 @@ watch(() => cstore.getSendWeights, () =>{
}); });
}); });
// RL Service + Feedback Suscriber
const rl_feedback_subscriber = new ROSLIB.Topic({
ros: ros,
name: '/rl_feedback',
message: 'active_bo_msgs/msg/ImageFeedback',
});
rl_feedback_subscriber.subscribe( (msg) => {
mcstore.setDim(msg.height, msg.width);
});
const rl_service = new ROSLIB.Service({
ros: ros,
name: '/rl_srv',
serviceType: 'active_bo_msgs/srv/RLRollOut',
});
watch(() => cstore.getRunner, () =>{
const rl_request = new ROSLIB.ServiceRequest({
policy: pstore.policy,
})
rl_service.callService(rl_request, function (rl_result) {
rstore.addMeanManually(rl_result.reward)
});
});
</script> </script>
<style scoped> <style scoped>

View File

@ -5,11 +5,14 @@ export const useMCStore = defineStore('Mountain Car Store', {
return { return {
play: false, play: false,
rgbArray: Array, rgbArray: Array,
width: 0,
height: 0,
} }
}, },
getters: { getters: {
getPlay: (state) => state.play, getPlay: (state) => state.play,
getRgbArray: (state) => state.rgbarray, getRgbArray: (state) => state.rgbarray,
getDim: (state) => [state.height, state.width],
}, },
actions: { actions: {
setPlay() { setPlay() {
@ -18,5 +21,9 @@ export const useMCStore = defineStore('Mountain Car Store', {
setRgbArray(value) { setRgbArray(value) {
this.rgbArray = value; this.rgbArray = value;
}, },
setDim(height, width) {
this.height = height;
this.width = width;
},
} }
}) })

View File

@ -3,13 +3,15 @@ import { defineStore } from "pinia";
export const useRStore = defineStore('Reward Store', { export const useRStore = defineStore('Reward Store', {
state: () => { state: () => {
return { return {
reward_mean: [0,], reward_mean: [],
reward_std: [0,], reward_std: [],
trigger: false,
} }
}, },
getters: { getters: {
getMean: (state) => state.reward_mean, getMean: (state) => state.reward_mean,
getStd: (state) => state.reward_std, getStd: (state) => state.reward_std,
getTrigger: (state) => state.trigger,
}, },
actions: { actions: {
setMean(value) { setMean(value) {
@ -18,5 +20,10 @@ export const useRStore = defineStore('Reward Store', {
setStd(value) { setStd(value) {
this.reward_std = value; this.reward_std = value;
}, },
addMeanManually(value) {
this.reward_mean[this.reward_mean.length] = value;
this.reward_std[this.reward_std.length] = 0;
this.trigger = !this.trigger;
},
} }
}) })