From 12c5fd25be4e7e7d7216c4e8979a80ff55471ac6 Mon Sep 17 00:00:00 2001 From: Niko Date: Tue, 21 Mar 2023 14:59:19 +0100 Subject: [PATCH] now trying to use topics for abo --- ActiveBOWeb/src/components/RosBar.vue | 118 +++++++++++++++++++------- 1 file changed, 85 insertions(+), 33 deletions(-) diff --git a/ActiveBOWeb/src/components/RosBar.vue b/ActiveBOWeb/src/components/RosBar.vue index a991857..866fdfa 100644 --- a/ActiveBOWeb/src/components/RosBar.vue +++ b/ActiveBOWeb/src/components/RosBar.vue @@ -107,6 +107,57 @@ const policy_service = new ROSLIB.Service({ serviceType: "active_bo_msgs/srv/WeightToPolicy", }); +// RL Service + Feedback Suscriber +const rl_feedback_subscriber = new ROSLIB.Topic({ + ros: ros, + name: "/rl_feedback", + messageType: "active_bo_msgs/msg/ImageFeedback", +}); + +rl_feedback_subscriber.subscribe((msg) => { + mcstore.setDim(msg.height, msg.width); + mcstore.setRgbArrays(msg.red, msg.green, msg.blue); +}); + +const active_rl_eval_sub = new ROSLIB.Topic({ + ros: ros, + name: "/active_rl_eval_request", + messageType: "active_bo_msgs/msg/ActiveRLEval", +}); + +const pendingRequest = ref(false); +active_rl_eval_sub.subscribe((msg) => { + pstore.setPolicy(msg.policy); + pstore.setWeights(msg.weights); + pendingRequest.value = true; +}); + +const active_rl_eval_pub = new ROSLIB.Topic({ + ros: ros, + name: "/active_rl_eval_response", + messageType: "active_bo_msgs/msg/ActiveRLEval", +}); +// const active_rl_eval_service = new ROSLIB.Service({ +// ros: ros, +// name: "/active_rl_eval_srv", +// serviceType: "active_bo_msgs/srv/ActiveRLEval", +// }); +// +// let currentResponse = null; +// let currentServiceId = null; +// const pendingRequest = ref(false); +// +// active_rl_eval_service.advertise(function (request, response) { +// currentResponse = response; +// currentServiceId = this.id; +// pendingRequest.value = true; +// +// pstore.setPolicy(request["old_policy"]); +// pstore.setWeights(request["old_weights"]); +// +// return false; +// }); + watch( () => cstore.getSendWeights, () => { @@ -121,43 +172,44 @@ watch( policy_service.callService(policy_request, function (result) { pstore.setPolicy(result.policy); }); + // } else if (usr_mode === "active BO") { + // if (!pendingRequest.value) { + // return; + // } + // console.log('after Button') + // currentResponse["new_policy"] = pstore.getPolicy; + // currentResponse["new_weights"] = pstore.getWeights; + // + // active_rl_eval_service.ros.callOnConnection({ + // op: "service_response", + // service: active_rl_eval_service.name, + // values: currentResponse, + // result: true, + // id: currentServiceId, + // }); + // console.log('call on connection') + // pendingRequest.value = false; + // currentResponse = null; + // currentServiceId = null; + } else if (usr_mode === "active BO") { + if (!pendingRequest.value) { + return; + } + console.log("Button pressed!"); + const active_eval_response = new ROSLIB.Message({ + policy: pstore.getPolicy, + weights: pstore.getWeights, + }); + + console.log(active_eval_response); + + active_rl_eval_pub.publish(active_eval_response); + console.log("New Policy/ Weights published"); + // pendingRequest.value = false; } } ); -// 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); - mcstore.setRgbArrays(msg.red, msg.green, msg.blue); -}); - -const active_rl_eval_service = new ROSLIB.Service({ - ros: ros, - name: "/active_rl_eval_srv", - serviceType: "active_bo_msgs/srv/ActiveRLEval", -}); - -active_rl_eval_service.advertise(function (request, response) { - pstore.setPolicy(request["old_policy"]); - pstore.setWeights(request["old_weights"]); - - watch( - () => cstore.getSendWeights, - () => { - response["new_policy"] = pstore.getPolicy; - response["new_weights"] = pstore.getWeights; - - return true; - } - ); -}); - const rl_service = new ROSLIB.Service({ ros: ros, name: "/rl_srv",