tried eval srv still not working

This commit is contained in:
Niko Feith 2023-03-27 15:56:30 +02:00
parent b7b1186b58
commit 98a8748b15

View File

@ -108,11 +108,11 @@ watch(stateCounter.value, (newValue) => {
}); });
// Policy Service // Policy Service
const policy_service = new ROSLIB.Service({ // const policy_service = new ROSLIB.Service({
ros: ros, // ros: ros,
name: "/policy_srv", // name: "/policy_srv",
serviceType: "active_bo_msgs/srv/WeightToPolicy", // serviceType: "active_bo_msgs/srv/WeightToPolicy",
}); // });
// RL Service + Feedback Suscriber // RL Service + Feedback Suscriber
const rl_feedback_subscriber = new ROSLIB.Topic({ const rl_feedback_subscriber = new ROSLIB.Topic({
@ -126,66 +126,99 @@ rl_feedback_subscriber.subscribe((msg) => {
mcstore.setRgbArrays(msg.red, msg.green, msg.blue); mcstore.setRgbArrays(msg.red, msg.green, msg.blue);
}); });
const active_rl_eval_sub = new ROSLIB.Topic({ // const active_rl_eval_sub = new ROSLIB.Topic({
ros: ros_eval, // ros: ros_eval,
name: "/active_rl_eval_request", // name: "/active_rl_eval_request",
messageType: "active_bo_msgs/msg/ActiveRLEval", // 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_eval,
// name: "/active_rl_eval_response",
// messageType: "active_bo_msgs/msg/ActiveRLEval",
// });
// Active RL Eval Service
let active_rl_eval_srv = 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); const pendingRequest = ref(false);
active_rl_eval_sub.subscribe((msg) => {
pstore.setPolicy(msg.policy); active_rl_eval_srv.advertise(function (request, response) {
pstore.setWeights(msg.weights); currentResponse = response;
currentServiceId = this.id;
pendingRequest.value = true; pendingRequest.value = true;
});
const active_rl_eval_pub = new ROSLIB.Topic({ pstore.setPolicy(request["old_policy"]);
ros: ros_eval, pstore.setWeights(request["old_weights"]);
name: "/active_rl_eval_response",
messageType: "active_bo_msgs/msg/ActiveRLEval",
});
const active_eval_response_first = new ROSLIB.Message({ console.log(request);
policy: pstore.policy,
weights: pstore.weights,
});
console.log(active_eval_response_first);
// active_rl_eval_pub.publish(active_eval_response_first);
// function sleep(ms) { return false;
// return new Promise((resolve) => setTimeout(resolve, ms)); });
// }
watch( watch(
() => cstore.getSendWeights, () => cstore.getSendWeights,
() => { () => {
const usr_mode = cstore.getUserMode; const usr_mode = cstore.getUserMode;
if (usr_mode === "manually") { // if (usr_mode === "manually") {
const policy_request = new ROSLIB.ServiceRequest({ // const policy_request = new ROSLIB.ServiceRequest({
weights: pstore.policy, // weights: pstore.policy,
nr_steps: pstore.weights, // nr_steps: pstore.weights,
}); // });
//
policy_service.callService(policy_request, function (result) { // policy_service.callService(policy_request, function (result) {
pstore.setPolicy(result.policy); // pstore.setPolicy(result.policy);
}); // });
} else if (usr_mode === "active BO") { // } else
if (usr_mode === "active BO") {
if (!pendingRequest.value) { if (!pendingRequest.value) {
return; return;
} }
console.log("Button pressed!"); console.log("Button pressed!");
const active_eval_response = new ROSLIB.Message({ // const active_eval_response = new ROSLIB.Message({
policy: pstore.policy, // policy: pstore.policy,
weights: pstore.weights, // weights: pstore.weights,
// });
//
// console.log(active_eval_response);
//
// active_rl_eval_pub.publish(active_eval_response);
// // await sleep(1000);
// console.log("New Policy/ Weights published");
// pendingRequest.value = false;
currentResponse["new_policy"] = pstore.getPolicy;
currentResponse["new_weights"] = pstore.getWeights;
console.log(currentResponse);
active_rl_eval_srv.ros.callOnConnection({
op: "service_response",
service: active_rl_eval_srv.name,
values: currentResponse,
id: currentServiceId,
result: true,
}); });
console.log(active_eval_response); console.log("Service Responded!");
active_rl_eval_pub.publish(active_eval_response);
// await sleep(1000);
console.log("New Policy/ Weights published");
// pendingRequest.value = false; // pendingRequest.value = false;
// currentResponse = null;
// currentServiceId = null;
} }
} }
); );