How to create a new item for a rosjava service list

asked 2016-02-13 00:35:00 -0500 gravatar image

I'm using the git repositories pulled with wstool as described at:


I added a new msg, rosjava/src/rosjava_test_msgs/msg/PhoneContact.msg

string last_name
string first_name  
string phone_number

I also added a new srv, SendContactsSmsMsg.srv

PhoneContact      contact0     
PhoneContact      contact1     
PhoneContact      contact2     
PhoneContact      contact3     
PhoneContact      contact4     
PhoneContact[]    contact_list
string            message   
bool              status

I added a new test client called to:


I've Cut-N-Pasted a copy below and would like to discuss it.

I'd like to remove the contact1...contac4 above. I added them because I'm having difficulty creating a PhoneContact to add to the contact_list above.

The genjava git repo seems to be generating only interface files which can't create an instance. For example:

Line 116 below rosjava_test_msgs.PhoneContact contact = new PhoneContact();

doesn't work because the public definition is only an interface. I tried implementing my on Phone Contact (Lines 41...79) below but I'm getting problems with the Raw Message class not being public.

Seems there should be a simple solution to this problem. My HACK is to get instances from the request message, modify them, and add them to the list (See lines 123...140).

I'm just sending a list of phone contacts with a message and sending the msg via SMS messaging interfaces available in Android. This test program just send the RPC and decodes the RPC. I'd image that creating a RPC with a list/array has been done a long time ago and it's trivial to add a instance of my phone_contact msg.

What's the trick?

     1  /*
     2   * Copyright (C) 2011 Google Inc.
     3   *
     4   * Licensed under the Apache License, Version 2.0 (the "License"); you may not
     5   * use this file except in compliance with the License. You may obtain a copy of
     6   * the License at
     7   *
     8   *
     9   *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
    12   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
    13   * License for the specific language governing permissions and limitations under
    14   * the License.
    15   */
    17  package org.ros.rosjava_tutorial_services;
    19  import org.ros.exception.RemoteException;
    20  import org.ros.exception.RosRuntimeException;
    21  import org.ros.exception.ServiceNotFoundException;
    22  import org.ros.namespace.GraphName;
    23  import org.ros.node.AbstractNodeMain;
    24  import org.ros.node.ConnectedNode;
    25  import org.ros.node.NodeMain;
    26  import org.ros.node.service.ServiceClient;
    27  import org.ros.node.service.ServiceResponseListener;
    29  import org.jboss.netty.buffer.ChannelBuffer;
    30  import org.ros.exception.RosMessageRuntimeException;
    31  import org.ros.internal.message.context.MessageContext;
    32  import org.ros.internal.message.field.Field;
    33  import org.ros.internal.message.field.MessageFieldType;
    34  import org.ros.internal.message.field.MessageFields;
    35  import org.ros ...
edit retag flag offensive close merge delete