I 'm using this service server in Python
:
#! /usr/bin/env python3
import rospy
from std_srvs.srv import SetBool, SetBoolResponse
class StateController:
def __init__(self):
rospy.init_node("state_controller", anonymous=True)
rospy.Service("validate_vision_info", SetBool, self.validVision)
rospy.spin()
def validVision(self, req):
model_valid = req.data
rospy.logwarn("Vision Model Validation: {}".format(req.data))
return SetBoolResponse(success=True, message="")
if __name__ == "__main__":
try:
controller_ = StateController()
except rospy.ROSInterruptException:
logging.error("Error in the State Controller")
And this service client in JavaScript
:
import { Ros, Service, ServiceRequest } from "roslib";
class ROSInterface {
constructor() {
this.ros = new Ros({
url: "ws://localhost:9090",
});
}
createService = (service_name, service_type) => {
let service = new Service({
ros: this.ros,
name: service_name,
serviceType: service_type,
});
return service;
};
requestService = (params) => {
let request = new ServiceRequest(params);
return request;
};
}
function validate(val) {
const service_name = "/validate_vision_info";
const service_type = "std_srvs/SetBool";
const iface_ = new ROSInterface();
const srv = iface_.createService(service_name, service_type);
const req = iface_.requestService(val);
srv.callService(
req,
(result) => {
console.log(result);
},
(error) => {
console.log(error);
});
}
validate(true);
validate(false);
My problem is that: always the service request data is False
no matter what is the sent request true
or false
!
Can you please tell me how can I solve my problem? thanks in advance.
Originally posted by bhomaidan on ROS Answers with karma: 114 on 2023-02-09
Post score: 0