Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
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 }