MapExtractorHandler.java
Go to the documentation of this file.
00001 /* \file MapExtractorHandler.java
00002  * \brief 2d map extraction handler
00003  *
00004  * The 2d map extractor handler provides the callbacks for ROS services 
00005  * related to requesting 2d maps from RoboEarth.
00006  * 
00007  * This file is part of the RoboEarth ROS re_comm_core package.
00008  * 
00009  * It was originally created for <a href="http://www.roboearth.org/">RoboEarth</a>.
00010  * The research leading to these results has received funding from the 
00011  * European Union Seventh Framework Programme FP7/2007-2013 
00012  * under grant agreement no248942 RoboEarth.
00013  *
00014  * Copyright (C) 2011 by 
00015  * <a href=" mailto:perzylo@cs.tum.edu">Alexander Perzylo</a>
00016  * Technische Universitaet Muenchen
00017  * 
00018  * Redistribution and use in source and binary forms, with or without
00019  * modification, are permitted provided that the following conditions are met:
00020  * 
00021  *    <UL>
00022  *     <LI> Redistributions of source code must retain the above copyright
00023  *       notice, this list of conditions and the following disclaimer.
00024  *     <LI> Redistributions in binary form must reproduce the above copyright
00025  *       notice, this list of conditions and the following disclaimer in the
00026  *       documentation and/or other materials provided with the distribution.
00027  *     <LI> Neither the name of Willow Garage, Inc. nor the names of its
00028  *       contributors may be used to endorse or promote products derived from
00029  *       this software without specific prior written permission.
00030  *    </UL>
00031  * 
00032  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00033  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00034  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00035  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00036  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00037  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00038  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00039  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00040  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00041  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00042  * POSSIBILITY OF SUCH DAMAGE.
00043  *
00044  * \author Alexander Perzylo
00045  * \version 1.0
00046  * \date 2011
00047  */
00048 package roboearth.wp5.module;
00049 
00050 import java.util.ArrayList;
00051 
00052 import org.semanticweb.owlapi.model.OWLOntology;
00053 
00054 import roboearth.wp5.conn.REInterface;
00055 import roboearth.wp5.owl.OWLIO;
00056 import ros.NodeHandle;
00057 import ros.Ros;
00058 import ros.RosException;
00059 import ros.ServiceServer;
00060 import ros.pkg.re_srvs.srv.Request2DMap;
00061 import ros.pkg.re_srvs.srv.RequestProj2DMap;
00062 
00063 public class MapExtractorHandler extends AbstractHandler {
00064 
00065         public MapExtractorHandler(Ros ros, NodeHandle n) throws RosException {
00066                 super(ros, n);
00067                 
00068                 this.n.advertiseService("/re_comm/request_2d_map", new Request2DMap(), new Request2DMapCallback());
00069                 this.n.advertiseService("/re_comm/request_proj_2d_map", new RequestProj2DMap(), new RequestProj2DMapCallback());
00070                 
00071                 ros.logInfo("Module 'MapExtractorHandler' loaded.");
00072         }
00073 
00081         class Request2DMapCallback implements ServiceServer.Callback<Request2DMap.Request, Request2DMap.Response> {
00082 
00083                 @Override
00084                 public Request2DMap.Response call(Request2DMap.Request req) {
00085 
00086                         Request2DMap.Response res = new Request2DMap.Response();
00087                         res.success = false;
00088 
00089                         REInterface con = getREConnection(guestInterfaceKey);
00090                         OWLOntology srdl = OWLIO.loadOntologyFromString(req.srdl);
00091                         ArrayList<byte[]> map = con.request2dMap(req.envUID, srdl, req.baseScannerLink, req.targetMapName);
00092 
00093                         res.success = (map == null || map.size() != 2 || 
00094                                         map.get(0) == null || map.get(1) == null ? false:true);
00095                         if (res.success) {
00096                                 res.map.name = req.targetMapName+".pgm";
00097                                 res.map.data = map.get(0);
00098                                 res.meta.name = req.targetMapName+".yaml";
00099                                 res.meta.data = map.get(1);
00100                                 ros.logInfo("Request2dMap (UID: " + req.envUID + "): Done");
00101                         } else {
00102                                 ros.logInfo("Request2dMap (UID: " + req.envUID + "): Failed");
00103                         }
00104 
00105                         return res;
00106 
00107                 }
00108 
00109         }
00110 
00118         class RequestProj2DMapCallback implements ServiceServer.Callback<RequestProj2DMap.Request, RequestProj2DMap.Response> {
00119 
00120                 @Override
00121                 public RequestProj2DMap.Response call(RequestProj2DMap.Request req) {
00122 
00123                         RequestProj2DMap.Response res = new RequestProj2DMap.Response();
00124                         res.success = false;
00125 
00126                         REInterface con = getREConnection(guestInterfaceKey);
00127                         
00128                         ArrayList<byte[]> map = con.requestProjected2dMap(req.envUID, req.minZ, req.maxZ, req.targetMapName);
00129 
00130                         res.success = (map == null || map.size() != 2 || 
00131                                         map.get(0) == null || map.get(1) == null ? false:true);
00132                         if (res.success) {
00133                                 res.map.name = req.targetMapName+".pgm";
00134                                 res.map.data = map.get(0);
00135                                 res.meta.name = req.targetMapName+".yaml";
00136                                 res.meta.data = map.get(1);
00137                                 ros.logInfo("RequestProj2dMap (UID: " + req.envUID + ", minZ: " + req.minZ + ",maxZ: " + req.maxZ + "): Done");
00138                         } else {
00139                                 ros.logInfo("RequestProj2dMap (UID: " + req.envUID + ", minZ: " + req.minZ + ",maxZ: " + req.maxZ + "): Failed");
00140                         }
00141 
00142                         return res;
00143 
00144                 }
00145 
00146         }
00147         
00148 }


re_comm_core
Author(s): Alexander Perzylo
autogenerated on Sun Jan 5 2014 11:29:33