ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Tell me how to use parameter server with rosjava

asked 2018-07-25 02:37:20 -0500

hamada gravatar image

I want to make parameter server with rosjava. But I can not. As far as I've looked up, I can not find the latest information on parameter server anywhere. That's why I want you to help me

I want to use AddTwoInts. However, when executing catkin_make, it says that the package of AddTwolnts can not be found. I guessed I had to edit build.gradle. But I do not know how to edit it

che License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package com.github.rosjava.test;
import org.apache.commons.logging.Log;  
import org.ros.node.Node;  
import org.ros.node.NodeMain;  
import org.ros.node.service.ServiceClient;  
import org.ros.node.service.ServiceResponseListener;  
import org.ros.exception.RemoteException;  
import org.ros.service.test_ros.AddTwoInts;  
import org.ros.namespace.GraphName;  

// add for parameter  
import org.ros.node.parameter.ParameterTree;  

/* 
 * @author OTL 
 */  
public class Parameters implements NodeMain {  

  @Override  
  public GraphName getDefaultNodeName() {  
    return new GraphName("rosjava_tutorial_service/client");  
  }  

  @Override  
  public void onStart(Node node) {  
    try {  
      ServiceClient<AddTwoInts.Request, AddTwoInts.Response> client =  
          node.newServiceClient("/add_two_ints", "test_ros/AddTwoInts");  
      Thread.sleep(100);  
      AddTwoInts.Request srv = new AddTwoInts.Request();  

      // add for parameter  
      ParameterTree params = node.newParameterTree();  
      srv.a = params.getInteger("/a", 1);  
      srv.b = params.getInteger("/b", 5);  

      client.call(srv, new ServiceResponseListener<AddTwoInts.Response>() {  
            @Override  
                public void onSuccess(AddTwoInts.Response res) {  
              log.info("call service success! " + res.sum);  
            }  
            @Override  
                public void onFailure(RemoteException arg) {  
              log.info("call service fail");  
            }  
        });  
    } catch (Exception e) {  
      if (node != null) {  
        node.getLog().fatal(e);  
      } else {  
        e.printStackTrace();  
      }  
    }  
  }  

  @Override  
  public void onShutdown(Node node) {  
  }  

  @Override  
  public void onShutdownComplete(Node node) {  
  }  
}
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2018-08-01 08:33:04 -0500

jubeira gravatar image

Hi @hamada! First of all, take a look into https://wiki.ros.org/rosjava ; that's the entry point for the most up-to-date tutorials (see Kinetic version).

Regarding this question in particular, I see two different issues: - AddTwoInts is a service; take a look around here for reference: http://wiki.ros.org/rosjava_build_too... . - About the parameter server, you can check this link for reference: http://library.isr.ist.utl.pt/docs/ro... . The API hasn't changed since then.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2018-07-25 02:37:20 -0500

Seen: 258 times

Last updated: Aug 01 '18