$search
00001 import ros.*; 00002 import ros.communication.*; 00003 import ros.pkg.test_rosjava_jni.srv.*; 00004 00005 public class AddTwoIntsClient { 00006 public static void main(String args[]) 00007 throws InterruptedException, RosException, NumberFormatException { 00008 final Ros ros = Ros.getInstance(); 00009 00010 if (args.length != 2) { 00011 ros.logInfo("usage: add_two_ints_client X Y"); 00012 System.exit(1); 00013 } 00014 00015 ros.init("AddTwoIntsClient"); 00016 NodeHandle n = ros.createNodeHandle(); 00017 00018 ServiceClient<AddTwoInts.Request,AddTwoInts.Response,AddTwoInts>client= 00019 n.serviceClient("add_two_ints" , new AddTwoInts(), false); 00020 00021 AddTwoInts.Request rq = new AddTwoInts.Request(); 00022 00023 rq.a = Long.parseLong(args[0]); 00024 rq.b = Long.parseLong(args[1]); 00025 00026 try { 00027 AddTwoInts.Response resp = client.call(rq); 00028 ros.logInfo("Sum: " + resp.sum); 00029 } 00030 catch (RosException e) { 00031 ros.logError("Failed to call service add_two_ints"); 00032 System.exit(1); 00033 } 00034 00035 //If don't call n.shutdown, client thread will hang until ctrl+c 00036 n.shutdown(); 00037 } 00038 }