Ask Your Question
0

ParameterTree rosjava

asked 2014-03-08 00:57:44 -0600

NullX4 gravatar image

Hi, I'm trying to do a simple test to use a parameter tree in my code.

I have the following:

package org.ros.rosjava_tutorial_pubsub;

import org.ros.concurrent.CancellableLoop;
import org.ros.namespace.GraphName;
import org.ros.node.AbstractNodeMain;
import org.ros.node.ConnectedNode;
import org.ros.node.NodeMain;
import org.ros.node.topic.Publisher;
import org.ros.node.parameter.ParameterTree;

public class test extends AbstractNodeMain {
@Override
public GraphName getDefaultNodeName() {
    return GraphName.of("rosjava_tutorial_pubsub/test");
}

@Override
public void onStart(final ConnectedNode connectedNode) {
    final Publisher<geometry_msgs.Twist> publisher = connectedNode
            .newPublisher("/cmd_vel", geometry_msgs.Twist._TYPE);


    connectedNode.executeCancellableLoop(new CancellableLoop() {
        ParameterTree params = connectedNode.newParameterTree();
        params.set("rosjava_tutorial_pubsub/test/time", 50);
        int max=params.getInteger("rosjava_tutorial_pubsub/test/time");
        int contador=0;
        @Override
        protected void loop() throws InterruptedException {
            geometry_msgs.Twist cmd_msg = publisher.newMessage();
            if (contador<max) cmd_msg.getLinear().setX(0.5); // m/s
            else cmd_msg.getLinear().setX(0);
            publisher.publish(cmd_msg);
            Thread.sleep(100);
            contador++;
        }
    });
}
}

And the compiler says:

/home/user-linux/ros_ws/src/rosjava_foo/dude/src/main/java/org/ros/rosjava_tutorial_pubsub/test.java:26: <identifier> expected
        params.set("rosjava_tutorial_pubsub/test/time", 50);
                  ^
/home/user-linux/ros_ws/src/rosjava_foo/dude/src/main/java/org/ros/rosjava_tutorial_pubsub/test.java:26: illegal start of type
            params.set("rosjava_tutorial_pubsub/test/time", 50);
                       ^
/home/user-linux/ros_ws/src/rosjava_foo/dude/src/main/java/org/ros/rosjava_tutorial_pubsub/test.java:26: illegal start of type
            params.set("rosjava_tutorial_pubsub/test/time", 50);

I don't know what else to do. Any suggestions?

Thank you very much for your time.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

answered 2017-11-07 09:54:51 -0600

jubeira gravatar image

This is a Java question; it has nothing to do with rosjava.

The code inside CancellableLoop has to be inside a method, not in the body of the subclass you are creating; see this answer: https://stackoverflow.com/questions/1... .

That should be

connectedNode.executeCancellableLoop(new CancellableLoop() {
    @Override
    public void run() {
    // Your code has to be here
    }
}
edit flag offensive delete link more
0

answered 2019-03-01 09:32:03 -0600

I had similar problems. The solution which worked for me: use getParameterTree() instead of newParameterTree()

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2014-03-08 00:57:44 -0600

Seen: 364 times

Last updated: Mar 01