app-Beobot2GistSalMaster.C
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 #include "Component/ModelManager.H"
00043 #include "Component/ModelComponent.H"
00044 #include "Component/ModelOptionDef.H"
00045 #include "Robots/Beobot2/Localization/Beobot2GistSalMaster.H"
00046
00047 #include <Ice/Ice.h>
00048 #include <Ice/Service.h>
00049 #include "Ice/RobotSimEvents.ice.H"
00050 #include "Ice/RobotBrainObjects.ice.H"
00051 #include "Ice/SimEventsUtils.H"
00052 #include "Ice/IceImageUtils.H"
00053
00054 #include "Beobot/beobot-GSnav-def.H"
00055 #include "Beobot/GSnavResult.H"
00056
00057
00058
00059 class RobotBrainServiceService : public Ice::Service {
00060 protected:
00061 virtual bool start(int, char* argv[]);
00062 virtual bool stop() {
00063 if (itsMgr)
00064 delete itsMgr;
00065 return true;
00066 }
00067
00068 private:
00069 Ice::ObjectAdapterPtr itsAdapter;
00070 ModelManager *itsMgr;
00071 };
00072
00073
00074 bool RobotBrainServiceService::start(int argc, char* argv[])
00075 {
00076 MYLOGVERB = LOG_INFO;
00077
00078 char adapterStr[255];
00079
00080 LINFO("Creating Topic!");
00081
00082
00083
00084
00085
00086
00087 int port = RobotBrainObjects::RobotBrainPort;
00088 bool connected = false;
00089
00090
00091 LDEBUG("Opening Connection");
00092 while(!connected)
00093 {
00094 try
00095 {
00096 LINFO("Trying Port:%d", port);
00097 sprintf(adapterStr, "default -p %i", port);
00098 itsAdapter = communicator()->createObjectAdapterWithEndpoints
00099 ("Beobot2GistSalMaster", adapterStr);
00100 connected = true;
00101 }
00102 catch(Ice::SocketException)
00103 {
00104 port++;
00105 }
00106 }
00107
00108
00109 itsMgr = new ModelManager("Beobot2GistSalMasterService");
00110
00111
00112 LINFO("Starting Beobot2GistSalMaster");
00113 nub::ref<Beobot2GistSalMasterI> GSMaster
00114 (new Beobot2GistSalMasterI(*itsMgr, "Beobot2GistSalMaster",
00115 "Beobot2GistSalMaster"));
00116 LINFO("Beobot2GistSalMaster Created");
00117 itsMgr->addSubComponent(GSMaster);
00118 LINFO("Beobot2GistSalMaster Added As Sub Component");
00119 GSMaster->init(communicator(), itsAdapter);
00120 LINFO("Beobot2GistSalMaster Initiated");
00121
00122
00123 if (itsMgr->parseCommandLine((const int)argc, (const char**)argv,
00124 "[input frame rate]", 0, 1)
00125 == false) return(1);
00126
00127 int w = GSMaster->getIfs()->getWidth(), h = GSMaster->getIfs()->getHeight();
00128 std::string dims = convertToString(Dims(w, h));
00129 LINFO("image size: [%dx%d]", w, h);
00130 itsMgr->setOptionValString(&OPT_InputFrameDims, dims);
00131 itsMgr->setModelParamVal("InputFrameDims", Dims(w, h),
00132 MC_RECURSE | MC_IGNORE_MISSING);
00133
00134
00135 uint64 inputFrameRate = 0;
00136 if(itsMgr->numExtraArgs() > 0)
00137 inputFrameRate = itsMgr->getExtraArgAs<uint>(0);
00138 LINFO("frame frequency: %f ms/frame", inputFrameRate/1000.0F);
00139 GSMaster->setInputFrameRate(inputFrameRate);
00140
00141
00142 itsAdapter->activate();
00143 itsMgr->start();
00144
00145 return true;
00146 }
00147
00148
00149
00150 int main(int argc, char** argv) {
00151
00152 LINFO("Creating Service...");
00153 RobotBrainServiceService svc;
00154 LINFO("Service Created...");
00155 return svc.main(argc, argv);
00156 }
00157
00158
00159
00160
00161
00162