Skip to content
Snippets Groups Projects
Commit 9845422f authored by Damon Kohler's avatar Damon Kohler
Browse files

Add tutorial project for services.

Small improvements to debugging output and javadoc.
parent e85bf56c
Branches
Tags
No related merge requests found
Showing with 199 additions and 5 deletions
......@@ -219,4 +219,9 @@ public class DefaultServiceServer<T, S> implements ServiceServer<T, S> {
public void removeListener(ServiceServerListener<T, S> listener) {
listenerCollection.remove(listener);
}
@Override
public String toString() {
return "ServiceServer<" + getDeclaration() + ">";
}
}
......@@ -24,8 +24,7 @@ import org.ros.node.NodeMain;
import org.ros.node.topic.Subscriber;
/**
* This is a simple rosjava {@link Subscriber} {@link Node}. It assumes an
* external roscore is already running.
* A simple {@link Subscriber} {@link NodeMain}.
*
* @author damonkohler@google.com (Damon Kohler)
*/
......
......@@ -23,7 +23,7 @@ import org.ros.node.NodeMain;
import org.ros.node.topic.Publisher;
/**
* A simple {@link Publisher} {@link Node}.
* A simple {@link Publisher} {@link NodeMain}.
*
* @author damonkohler@google.com (Damon Kohler)
*/
......
/*
* Copyright (C) 2011 Google Inc.
*
* Licensed under the Apache 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.
*/
apply plugin: 'application'
mainClassName = 'org.ros.RosRun'
dependencies {
compile project(':rosjava')
}
/**
\mainpage
\htmlinclude manifest.html
\b rosjava_tutorial_services is ...
<!--
Provide an overview of your package.
-->
\section codeapi Code API
<!--
Provide links to specific auto-generated API documentation within your
package that is of particular interest to a reader. Doxygen will
document pretty much every part of your code, so do your best here to
point the reader to the actual API.
If your codebase is fairly large or has different sets of APIs, you
should use the doxygen 'group' tag to keep these APIs together. For
example, the roscpp documentation has 'libros' group.
-->
*/
<package>
<description brief="rosjava_tutorial_services">
rosjava_tutorial_services is a simple example project.
</description>
<author>Damon Kohler</author>
<license>Apache 2.0</license>
<review status="unreviewed" notes="" />
<url>http://ros.org/wiki/rosjava_tutorial_services</url>
</package>
/*
* Copyright (C) 2011 Google Inc.
*
* Licensed under the Apache 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 org.ros.rosjava_tutorial_services;
import org.ros.exception.RemoteException;
import org.ros.exception.RosRuntimeException;
import org.ros.exception.ServiceNotFoundException;
import org.ros.namespace.GraphName;
import org.ros.node.Node;
import org.ros.node.NodeMain;
import org.ros.node.service.ServiceClient;
import org.ros.node.service.ServiceResponseListener;
import test_ros.AddTwoInts.Response;
/**
* A simple {@link ServiceClient} {@link NodeMain}.
*
* @author damonkohler@google.com (Damon Kohler)
*/
public class Client implements NodeMain {
@Override
public GraphName getDefaultNodeName() {
return new GraphName("rosjava_tutorial_services/client");
}
@Override
public void onStart(final Node node) {
ServiceClient<test_ros.AddTwoInts.Request, test_ros.AddTwoInts.Response> serviceClient;
try {
serviceClient = node.newServiceClient("add_two_ints", test_ros.AddTwoInts._TYPE);
} catch (ServiceNotFoundException e) {
throw new RosRuntimeException(e);
}
final test_ros.AddTwoInts.Request request = serviceClient.newMessage();
request.setA(2);
request.setB(2);
serviceClient.call(request, new ServiceResponseListener<test_ros.AddTwoInts.Response>() {
@Override
public void onSuccess(Response response) {
node.getLog().info(
String.format("%d + %d = %d", request.getA(), request.getB(), response.getSum()));
}
@Override
public void onFailure(RemoteException e) {
throw new RosRuntimeException(e);
}
});
}
@Override
public void onShutdown(Node node) {
}
@Override
public void onShutdownComplete(Node node) {
}
}
/*
* Copyright (C) 2011 Google Inc.
*
* Licensed under the Apache 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 org.ros.rosjava_tutorial_services;
import org.ros.internal.node.service.ServiceException;
import org.ros.internal.node.service.ServiceResponseBuilder;
import org.ros.namespace.GraphName;
import org.ros.node.Node;
import org.ros.node.NodeMain;
import org.ros.node.service.ServiceServer;
import test_ros.AddTwoInts.Request;
import test_ros.AddTwoInts.Response;
/**
* This is a simple {@link ServiceServer} {@link NodeMain}.
*
* @author damonkohler@google.com (Damon Kohler)
*/
public class Server implements NodeMain {
@Override
public GraphName getDefaultNodeName() {
return new GraphName("rosjava_tutorial_services/server");
}
@Override
public void onStart(Node node) {
node.newServiceServer("add_two_ints", test_ros.AddTwoInts._TYPE,
new ServiceResponseBuilder<test_ros.AddTwoInts.Request, test_ros.AddTwoInts.Response>() {
@Override
public void build(Request request, Response response) throws ServiceException {
response.setSum(request.getA() + request.getB());
}
});
}
@Override
public void onShutdown(Node node) {
}
@Override
public void onShutdownComplete(Node node) {
}
}
......@@ -16,6 +16,7 @@
include 'rosjava_bootstrap', 'rosjava_messages', 'apache_xmlrpc_common',
'apache_xmlrpc_client', 'apache_xmlrpc_server', 'rosjava',
'rosjava_geometry', 'rosjava_tutorial_pubsub', 'docs'
'rosjava_geometry', 'rosjava_tutorial_pubsub',
'rosjava_tutorial_services', 'docs'
// TODO(damonkohler): Enable these once actionlib is working again.
// 'rosjava_actionlib', 'rosjava_actionlib_tutorial'
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment