我最近正在与Rosjava Kinetic合作,但我有一些问题和疑问。我已经将该项目导入Eclipse,以使其与另一个我称为PELEA的项目混合,该项目由多个模块组成,以使消息通过客户端服务器传递。当然,我有一个运行roscore的终端和一个运行在eclipse中的服务器。我以这种方式制作新客户和新消息:
public void onStart(final ConnectedNode connectedNode) {
ServiceClient<std_msgs.String, std_msgs.String> serviceClient;
try {
serviceClient = connectedNode.newServiceClient("custom_service", std_msgs.String._TYPE);
} catch (ServiceNotFoundException e) {
throw new RosRuntimeException(e);
}
final std_msgs.String request = serviceClient.newMessage(); //ERROR!!
request.setData("Hello");
serviceClient.call(request, new ServiceResponseListener<std_msgs.String>() {
@Override
public void onSuccess(std_msgs.String response) {
connectedNode.getLog().info(String.format("The response is: "));
response.getData();}
@Override
public void onFailure(org.ros.exception.RemoteException e) {
throw new RosRuntimeException(e);
}
});
}
我收到此错误:
Exception in thread "pool-1-thread-3" java.lang.ClassCastException: org.ros.internal.message.$Proxy4 cannot be cast to std_msgs.String
at org.squeleton.executiondeclarative.ExecutionSqueleton.clientManagement(ExecutionSqueleton.java:591)
at org.squeleton.executiondeclarative.Client.onStart(Client.java:57)
at org.ros.internal.node.DefaultNode$5.run(DefaultNode.java:507)
at org.ros.internal.node.DefaultNode$5.run(DefaultNode.java:504)
at org.ros.concurrent.EventDispatcher.loop(EventDispatcher.java:43)
at org.ros.concurrent.CancellableLoop.run(CancellableLoop.java:56)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
所以..我不知道问题出在哪里,我认为这应该可行。
我感谢您提供的任何帮助,建议或指导。
非常感谢,我的英语不好。