0
$\begingroup$

Rosanswers logo

I'm working recently with Rosjava Kinetic and I have some problems and doubts. I have imported the project to Eclipse to mix it with another project that I have, called PELEA, composed of several modules, to make the message passing through a client-server. Of course, I have a terminal running roscore and a server running inside eclipse. I make the new client and the new message in this way:

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);
        }
    });
}

And I get this error:

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)

So.. I don't know what is the problem, I think it should works..

I appreciate any help, advide or guide.

Thanks a lot and sorry for my bad english.


Originally posted by A.Grag on ROS Answers with karma: 1 on 2018-07-30

Post score: 0


Original comments

Comment by jayess on 2018-07-30:
Just so you know, the <pre> and <code> tags don't do a very good job at marking up code and terminal output. It's usually easier to highlight the text then click on the 101010 button instead. That way your code is marked up with syntax highlighting.

Comment by A.Grag on 2018-07-30:
Ok, you are right... sorry.

Comment by jayess on 2018-07-30:
It's not a problem, just for reference for the next time that you ask a question :)

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

@A.Grag std_msgs.String is a standard message, and you are dealing with service clients in that piece of code.

I suggest you to take a look at https://github.com/rosjava/rosjava_core/tree/kinetic/rosjava_tutorial_pubsub and http://wiki.ros.org/rosjava_build_tools/Tutorials/indigo/WritingPublisherSubscriber%28Java%29 first, I think you are mixing the concepts of messages and topics with services.


Originally posted by jubeira with karma: 1054 on 2018-08-02

This answer was ACCEPTED on the original site

Post score: 1


Original comments

Comment by A.Grag on 2018-08-03:
Thanks for your answer. Finally, I found a way to create a custom message with genjava.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.