我正在使用python
中的ROS服务器:
#! /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")
我从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;
};
callService_ = (service_name, service_type, params) => {
return new Promise((resolve, reject) => {
const srv = this.createService(service_name, service_type);
const req = this.requestService(params);
srv.callService(
req,
(result) => {
console.log(result);
resolve(result);
},
(error) => {
console.log(error);
reject(error);
}
);
});
};
}
async function validate(val) {
const service_name = "/validate_vision_info";
const service_type = "std_srvs/SetBool";
console.log(val);
const iface_ = new ROSInterface();
let serv = await iface_
.callService_(service_name, service_type, val)
.then((result) => {
return result;
}).catch(e => {
console.log(e);
});
console.log("service result", serv);
}
validate(true);
validate(false);
在两个服务调用中,我都在Python代码的Service Service Request中获得了False
。
你能告诉我怎么解吗?先谢了。
1条答案
按热度按时间rqenqsqc1#
1.当我使用VueJS3时,我不得不使用带有Reactivity的状态管理:变量存储在
store.js
中。1.消息(参数)必须以
{data: store.variable}
传递,以符合服务setBool描述